1.3.2 • Published 2 years ago

@antiers/product-package v1.3.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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.
1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.9

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago