@antiers/product-package

1.3.2 • Public • Published

product-package

Exchange all common utilities includes in this package

Installation

npm i @antiers/product-package
yarn add @antiers/product-package

Example usage

import * as helpers from '@antiers/product-package'

const redisCredentials = {
    host: "",
    port:"",
    jwtsecret:""
}
const kafkaCredentials = {
    clientId: "",
    brokers: [""]
}
const dbCredentials = {
    host: "",
    user: ""
    password:"",
    database:"",
    connectionLimit: "",
    port:"",
    timezone: ""
    
}
const mailCredentials = {
    host: "",
    port: "",
    user: "",
    password:"",
    secure: ""
}

let DbHelper, RedisHelper, KafkaHelper, MailHelper;

//function to create connection by passing credentials to helper classes
async function createConnection() {
    DbHelper = await new helpers.Dbhelper(DbCredentials)
    RedisHelper = await new helpers.redisHelper(redisCredentials)
    KafkaHelper = await main.KafkaHelper(rabbitMqCredentials)
    MailHelper = await main.MailHelper(kafkaCredentials)
}

/**
redis function to setString 
@param key
@param value
@param expires
**/
await RedisHelper.setString(key,value,expires);

/**
redis function to getString 
@param key
**/
const getValuefromRedis = await RedisHelper.getString(key)

/**
Kafka function to produce message
@param topic
**/
await KafkaHelper.produceMessage(topic, [
    {
        value: 'message1'
    },{
        value: 'message2'
    }
])

/**
Kafka function to consume message
@param topic
**/
await kafka.consumeMessage(topic);

/**
Mail helper function to send mail 
@param receipient address
@param subject
@param message
@param template
**/
await MailHelper.sendMail(receipient_address, subject, message, template)

/**
Define Model
@param query
**/
const User = db.sequelize.define(tablename, {
            // Model attributes are defined here
            firstName: {
                type: DataTypes.STRING,
                allowNull: false
            },
            lastName: {
                type: DataTypes.STRING
                // allowNull defaults to true
            },
            age: {
                type: DataTypes.INTEGER,
                allowNull: false
            }
        }, {
            // Other model options go here
            timestamps: false
        });
        
/**
 * Simple query to select all records from table using model
 **/
const data = await User.findAll();

/**
 * jwtMiddleware
 **/
public jwtMiddleware = helpers.jwtValidateToken()
this.app.get('/', this.jwtMiddleware, (req: any, res: any) => {
    res.send("user token validated")
})
public adminMiddleware = helpers.adminValidateToken()
this.app.get('/', this.adminMiddleware, (req: any, res: any) => {
    res.send("admin token validated")
})

NOTE

  • Before using any other function make sure that you pass credentials for all helper classess otherwise you will got error.
  • Once credentials passed you can use any helper class and its function as shown in above examples.

Package Sidebar

Install

npm i @antiers/product-package

Weekly Downloads

260

Version

1.3.2

License

MIT

Unpacked Size

127 kB

Total Files

38

Last publish

Collaborators

  • priyanka023
  • antiers_npm