npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mvp-rockets/namma-lib

v2.1.0

Published

A functional utility library for developing express api

Downloads

4,231

Readme

1. Introduction

A lib to help us the ease of functional programming (based on ramda (https://ramdajs.com/) & folktale(https://www.npmjs.com/package/folktale))

└── lib
    ├── logger.js
    ├── token.js
    ├── utilities
    │   ├── api-error.js
    │   ├── args.js
    │   ├── compose-result.js
    │   ├── doNothing.js
    │   ├── http-constant.js
    │   ├── ifElse.js
    │   ├── logger.js
    │   ├── respond.js
    │   ├── transform-to-result.js
    │   ├── uuid.js
    │   ├── whenResult.js
    │   └── with-args.js
    └── validations
        ├── check-given-values.js
        ├── has-length-of.js
        ├── is-boolean.js
        ├── is-email.js
        ├── is-mobile-number.js
        ├── is-string-numeric.js
        ├── is-timestamp.js
        ├── is-undefined.js
        ├── max-value.js
        ├── min-value.js
        ├── not-empty.js
        ├── numeric.js
        ├── should-be-uuid.js
        ├── validate-given-pattern.js
        └── validate.js

3. Installation

    npm install @mvp-rockets/namma-lib

4. How to imports.

  • All the function from @mvp-rockets/namma-lib
    const {
        utilities:{
                logInfo,
                logError,
                ....
                ....
                all the utilities function here
         },
         validations:{
            isBoolean,
	        hasLengthOf,
            ....
            ....
            all the validations function here
         },
         HTTP_CONSTANT,
         token
        } = require('@mvp-rockets/namma-lib')
  • Only the utilities
const {
        logInfo,
        logError,
        ....
        ....
        all the utilities function here
        } = require('@mvp-rockets/namma-lib/utilities')
  • Only the validations
const {
        logInfo,
        logError,
        ....
        ....
        all the utilities function here
        } = require('@mvp-rockets/namma-lib/validations')
  • Only the token
const {
         token
        } = require('@mvp-rockets/namma-lib')
  • Only the HTTP_CONSTANT

    const {
    HTTP_CONSTANT
    } = require('@mvp-rockets/namma-lib')

5. How to use token

<!-- initialize token in your index.js -->
const {
         token
        } = require('@mvp-rockets/namma-lib');

token.initialize("Your Jwt secret key");

<!-- Generate Token  -->
const tokenResult =  await token.generate("Your object")

console.log(tokenResult); // Result.Ok("Your generated token")

<!-- decode token -->
const decodedTokenResult =  await token.decode("Your token")

console.log(decodedTokenResult); // Result.Ok("Your decoded object")

if case of invalid or expired token
console.log(decodedTokenResult); // Result.Error("Invalid token")

6. How to use logger.

Now logger comes with two libraries internally ie, winston and pino. By default it uses winston.

<!-- initialize logger in your index.js -->
const { Logger } = require('@mvp-rockets/namma-lib');

Logger.initialize({
	isEnable: true, // for dev,qa use false
	type: 'aws',
	environment: "<env name>",
	clsNameSpace: <"cls name for trace Id">,
	configurations: {
		region: <"aws region">,
		accessKeyId: <"aws access Key Id">,
		secretKey: <"aws secret Key">,
		logGroupName: <"log group name">,
		logStreamName: <"log stream name">
	}
});

<!-- add below code for unique traceId for each request -->
const { logInfo } = require('@mvp-rockets/namma-lib/utilitiesut');
app.use((req, res, next) => {
	const namespace = cls.getNamespace("<cls name for trace Id>");
	const platform = req.headers['x-platform'] || 'unknown-platform';
	namespace.run(() => {
		namespace.set('traceId', uuid.v4());
		logInfo(`${req.method} ${req.originalUrl}`, { ...req.body, platform });
		next();
	});
});
To use pino, you need to pass following properties
        loggerType: "pino"
        loggerOptions: "cloudwatch"

Using pino logger you can send logs to more than one destination. for now Options are file, cloudwatch, terminal and loki.
To use more than one destination you can specify in loggerOptions by comma separated values.
for example:
        loggerOptions: "cloudwatch, file, loki"

Usage example for pino logger:

Logger.initialize({
	environment: "<env name>",
	clsNameSpace: <"cls name for trace Id">,
	configurations: {
		region: <"aws region">,
		accessKeyId: <"aws access Key Id">,
		secretKey: <"aws secret Key">,
		logGroupName: <"log group name">,
		logStreamName: <"log stream name">,
                interval: <"interval integer value">
	},
        loggerType: "pino"
        loggerOptions: "cloudwatch"
});

NOTE: Before switching to pino logger, make sure if you have alerts based on level: error. you need to make some change because for now using this library. level will be integer(info as 30, error as 50) and there will be another property label where value will be error, info, debug.


3. Video walkthrough Tutorials

Youtube Tutorials