How to use the @mojaloop/central-services-shared.Logger function in @mojaloop/central-services-shared

To help you get started, we’ve selected a few @mojaloop/central-services-shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mojaloop / central-ledger / src / domain / settlement / settlementEventListener.js View on Github external
'use strict'

const nodemailer = require('nodemailer')
const Config = require('../../lib/config')
const Logger = require('@mojaloop/central-services-shared').Logger

const sendEmail = () => {
  return (mailInformation) => {
    // create reusable transporter object using SMTP transport
    const transporter = nodemailer.createTransport({
      host: Config.EMAIL_SMTP,
      port: 465,
      secure: true, // use SSL
      auth: {
        party: Config.EMAIL_PARTY,
        pass: Config.EMAIL_PASSWORD
      }
    })

    const mailOptions = {
      from: Config.EMAIL_PARTY, // sender address
github mojaloop / central-ledger / src / admin / auth / admin.js View on Github external
'use strict'

// const Bcrypt = require('bcrypt') for later use
const Config = require('../../lib/config')
const Logger = require('@mojaloop/central-services-shared').Logger

const validate = async (request, username, password, h) => {
  if (!(username && password && Config.ADMIN_KEY && Config.ADMIN_SECRET)) {
    return {credentials: null, isValid: false}
  }
  const isValid = password === Config.ADMIN_SECRET
  // const isValid = await Bcrypt.compare(password, Config.ADMIN_SECRET) to be used in the future to hash passwords
  if (username === Config.ADMIN_KEY && isValid) {
    const credentials = {id: 'test', name: username, is_admin: true}
    Logger.info('is a valid admin')
    return {isValid: true, credentials}
  } else {
    return {credentials: null, isValid: false}
  }
}
github mojaloop / central-ledger / src / handlers / bulk / prepare / handler.js View on Github external
Gates Foundation organization for an example). Those individuals should have
 their names indented and be marked with a '-'. Email address can be added
 optionally within square brackets .

 * Gates Foundation
 - Name Surname 

 * Georgi Georgiev 
 * Valentin Genev 
 --------------
 ******/
'use strict'

const AwaitifyStream = require('awaitify-stream')
const Uuid = require('uuid4')
const Logger = require('@mojaloop/central-services-shared').Logger
const BulkTransferService = require('../../../domain/bulkTransfer')
const Util = require('../../lib/utility')
const Kafka = require('../../lib/kafka')
const Validator = require('../shared/validator')
const Enum = require('../../../lib/enum')
const TransferEventType = Enum.transferEventType
const TransferEventAction = Enum.transferEventAction
const Metrics = require('@mojaloop/central-services-metrics')
const Config = require('../../../lib/config')
const BulkTransferModels = require('@mojaloop/central-object-store').Models.BulkTransfer
const encodePayload = require('@mojaloop/central-services-stream/src/kafka/protocol').encodePayload

const location = { module: 'BulkPrepareHandler', method: '', path: '' } // var object used as pointer

const consumerCommit = true
// const fromSwitch = true
github mojaloop / central-ledger / src / domain / settlement / index.js View on Github external
'use strict'

const Decimal = require('decimal.js')
const Util = require('../../../src/lib/util')
const Events = require('../../lib/events')
const csv = require('../../lib/csv')
const settlementEventListener = require('./settlementEventListener')
// const ParticipantDatabase = require('../../domain/participant')
const Logger = require('@mojaloop/central-services-shared').Logger

const mapToSettlement = (settlement) => {
  return {
    source: {
      participant_number: settlement.sourceParticipantNumber,
      routing_number: settlement.sourceRoutingNumber
    },
    destination: {
      participant_number: settlement.destinationParticipantNumber,
      routing_number: settlement.destinationRoutingNumber
    },
    amount: {
      currency_code: 'TZS',
      value: settlement.payerAmount || settlement.payerAmount,
      description: settlement.debitParticipantName || settlement.payerParticipantName
    }
github mojaloop / central-ledger / src / api / worker / index.js View on Github external
'use strict'

const Logger = require('@mojaloop/central-services-shared').Logger
const TransferService = require('../../domain/transfer')
const TokenService = require('../../domain/token')
const Config = require('../../lib/config')

const rejectExpiredTransfers = () => {
  return TransferService.rejectExpired()
    .then(x => {
      Logger.info(`Rejected transfers: ${x}`)
      return x
    })
    .catch(e => {
      Logger.error('Error rejecting transfers', e)
    })
}

const rejectExpiredTokens = () => {
github mojaloop / central-ledger / src / api / transfers / validator.js View on Github external
'use strict'

const P = require('bluebird')
const Decimal = require('decimal.js')
const Moment = require('moment')
const Config = require('../../lib/config')
const UrlParser = require('../../lib/urlParser')
const Participant = require('../../domain/participant')
const ValidationError = require('../../errors').ValidationError
const CryptoConditions = require('../../cryptoConditions')
const Logger = require('@mojaloop/central-services-shared').Logger

const allowedScale = Config.AMOUNT.SCALE
const allowedPrecision = Config.AMOUNT.PRECISION

const validateEntry = (entry) => {
  const participantName = UrlParser.nameFromParticipantUri(entry.participant)
  if (!participantName) {
    throw new ValidationError(`Invalid participant URI: ${entry.participant}`)
  }

  const decimalAmount = new Decimal(entry.amount)

  if (decimalAmount.decimalPlaces() > allowedScale) {
    throw new ValidationError(`Amount ${entry.amount} exceeds allowed scale of ${allowedScale}`)
  }
github mojaloop / central-ledger / src / handlers / lib / kafka / producer.js View on Github external
* Gates Foundation
 - Name Surname 

 * Rajiv Mothilal 
 * Miguel de Barros 

 --------------
 ******/
'use strict'

/**
 * @module src/handlers/lib/kafka
 */

const Producer = require('@mojaloop/central-services-stream').Kafka.Producer
const Logger = require('@mojaloop/central-services-shared').Logger
const ErrorHandler = require('@mojaloop/central-services-error-handling')

const listOfProducers = {}

/**
 * @function ProduceMessage
 *
 * @param {string} messageProtocol - message being created against topic
 * @param {object} topicConf - configuration for the topic to produce to
 * @param {object} config - Producer configuration, eg: to produce batch or poll
 *
 * @description Creates a producer on Kafka for the specified topic and configuration
 *
 * @returns {boolean} - returns true if producer successfully created and producers to
 * @throws {error} - if not successfully create/produced to
 */
github mojaloop / central-ledger / src / api / transfers / handler.js View on Github external
'use strict'

const Validator = require('./validator')
const TransferService = require('../../domain/transfer')
const RejectionType = require('../../lib/enum').rejectionType
const TransferObjectTransform = require('../../domain/transfer/transform')
const NotFoundError = require('../../errors').NotFoundError
const Sidecar = require('../../lib/sidecar')
const Logger = require('@mojaloop/central-services-shared').Logger
const Boom = require('boom')

const buildGetTransferResponse = (record) => {
  if (!record) {
    throw new NotFoundError('The requested resource could not be found.')
  }
  return TransferObjectTransform.toTransfer(record)
}

exports.prepareTransfer = async function (request, h) {
  try {
    Logger.info('entering prepare transfer')
    Sidecar.logRequest(request)
    const payload = await Validator.validate(request.payload, request.params.id)
    const result = await TransferService.prepare(payload)
    return h.response(result.transfer).code((result.existing === true) ? 200 : 201)
github mojaloop / central-ledger / src / lib / mongodb.js View on Github external
contributed from an organization can be listed under the organization
 that actually holds the copyright for their contributions (see the
 Gates Foundation organization for an example). Those individuals should have
 their names indented and be marked with a '-'. Email address can be added
 optionally within square brackets .

 * Gates Foundation
 - Name Surname 

 * Georgi Georgiev 
 --------------
 ******/
'use strict'

const Mongoose = require('mongoose')
const Logger = require('@mojaloop/central-services-shared').Logger

Mongoose.connection.on('error', (err) => { Logger.info('connection error ', err) })
Mongoose.connection.once('open', function callback () {
  Logger.info('MongoDB succesfully connected')
})

Mongoose.set('useFindAndModify', false)
Mongoose.set('useNewUrlParser', true)
Mongoose.set('useCreateIndex', true)

exports.Mongoose = Mongoose
exports.db = Mongoose.connection
github mojaloop / central-ledger / src / handlers / lib / kafka / consumer.js View on Github external
* Gates Foundation
 - Name Surname 

 * Lazola Lucas 
 * Rajiv Mothilal 
 * Miguel de Barros 
 --------------
 ******/
'use strict'

/**
 * @module src/handlers/lib/kafka
 */

const Consumer = require('@mojaloop/central-services-stream').Kafka.Consumer
const Logger = require('@mojaloop/central-services-shared').Logger
const ErrorHandler = require('@mojaloop/central-services-error-handling')

const listOfConsumers = {}

/**
 * @function CreateHandler
 *
 * @param {string} topicName - the topic name to be registered for the required handler. Example: 'topic-dfsp1-transfer-prepare'
 * @param {object} config - the config for the consumer for the specific functionality and action, retrieved from the default.json. Example: found in default.json 'KAFKA.CONSUMER.TRANSFER.PREPARE'
 * @param {function} command - the callback handler for the topic. Will be called when the topic is produced against. Example: Command.prepareHandler()
 *
 * @description Parses the accountUri into a participant name from the uri string
 *
 * @returns {object} - Returns a Promise
 * @throws {Error} -  if failure occurs
 */