1. Introduction
āāā 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')
const {
logInfo,
logError,
....
....
all the utilities function here
} = require('@mvp-rockets/namma-lib/utilities')
const {
logInfo,
logError,
....
....
all the utilities function here
} = require('@mvp-rockets/namma-lib/validations')
const {
token
} = 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.
<!-- 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();
});
});
3. Video walkthrough Tutorials
Youtube Tutorials