reduxpress v1.4.10
A utility framework built on top of expressJS to provide single line implementations for commonly used tasks.
It provides the following functionality
- Request Validation
- Formatted Console Logs
- Authentication
- Response Handling
- Error Handling
- Object Logging in File or DB
Example Usage
- Install the reduxpress module
npm i reduxpress --save
- Configure the module before the endpoints
// server.js
import reduxpress from 'reduxpress'
// var reduxpress = require('reduxpress')
import api from './api';
// var api = require('./api');
...
reduxpress.setOptions({
saveTrace : true,
// default - false | Flag to save the data generated with each request,
secret : '<YOUR JWT SECRET HERE>'
})
...
- Mount the object as a middleware before the endpoints you want to have reduxpress included in
// server.js
...
app.use(reduxpress.mount);
// OR app.use('/api', reduxpress.mount);
...
app.post('/api', api);
...
- Access the redux object from the request object directly. Each redux object is unique and is saved separately for all the incoming requests
// api.js
module.exports = function(request, response) {
var redux = request.redux;
redux
.bodyValidator(response, ['name', '^email'])
.then(function(body) {
// body should now contain name property and an optional email
redux.sendSuccess(response, body, 'body');
})
.catch(function(err) {
// if the name property is not present in the body of the request, an error will be thrown
redux.sendError(response, err);
})
}
## Modules
Classes
Members
reduxpress
reduxpress.schema
Exports the model object
Kind: static property of reduxpress
Export: Model
reduxpress.logger
Exports the logger object
Kind: static property of reduxpress
Export: logger
reduxpress.setOptions(options)
Set options for the redux framework
Kind: static method of reduxpress
Param | Type | Description |
---|---|---|
options | Object | |
options.saveTrace | Boolean | Whether the generated logs should be save |
options.supressInitMessage | Boolean | Whether to suppress request entry message in the console {defaults to false} |
options.ipHeader | Boolean | Which header to parse in order to get the IP address of user. Defaults to the express default. |
options.mongooseInstance | String | The mongoose instance for saving the data when the storage engine is db |
options.extendIpData | Boolean | Whether or not to extend the IP address data |
options.engine | String | The storage engine to use. Either file or db. Defaults to db. |
options.errors | String | The error object to extend the internal stored errors. Overwrites the internal errors if the same error is code is passed. |
options.auth.external | Boolean | Is the authentication logic local or external |
options.auth.apiUrl | String | API Url of the external authentication node |
options.auth.method | String | The HTTP method to use {defaults to GET} |
options.auth.oauthToken | String | The oauth token to be used for authentication |
options.auth.scope | String | The scope for oauth |
options.authCallback | String | Callback function to be executed once the token has been validated |
options.onError | String | Callback function to be executed when an error is encountered |
Example
{
reduxpress.setOptions({
saveTrace : false
});
}
reduxpress.registerFilter(name, executorFn, hookName)
Kind: static method of reduxpress
Param |
---|
name |
executorFn |
hookName |
reduxpress.mount(request, response, next)
Kind: static method of reduxpress
Param |
---|
request |
response |
next |
reduxpress.startCronJobs()
Kind: static method of reduxpress
Description-: Starts the internal cron jobs
reduxpress.router() ⇒ Routes
Kind: static method of reduxpress
reduxpress.crud() ⇒ Crud
Kind: static method of reduxpress
reduxpress.getTestDouble(options)
Kind: static method of reduxpress
Param |
---|
options |
reduxpress~tokenValidatorMiddleware(aclRules, debug)
Kind: inner method of reduxpress
Param |
---|
aclRules |
debug |
Redux
Redux
Kind: global class
- Redux
- new Redux(model, options)
- instance
- .logger() ⇒ Redux.logger | *
- .printTrace()
- .log(data, title)
- .err(data)
- .suppressInput() ⇒ Redux
- .paramsValidator(request, params)
- .bodyValidator(request, params)
- .queryValidator(request, params)
- .utils() ⇒
- .idValidator(data)
- .response() ⇒
- .setExtra(key, value) ⇒ Redux
- .sendSuccess(response, data, key)
- .sendJSON(response, data, status)
- .sendError(response, data, message)
- .auth() ⇒ exports.auth | *
- .attachData() ⇒ Redux
- .interceptor(request, params, findDataIn)
- .putInterceptor(request, bodyData, params)
- .invokeAcl(value, debug) ⇒ Redux
- .suppressAuthError() ⇒ Redux
- .tokenValidator(request, [token])
- .setCurrentUser(user)
- .addTag(tags)
- .saveAuthDetails(data)
- .verifyToken(token) ⇒ Promise
- .verifyRefreshToken(token, suppressError) ⇒ Promise
- .generateToken(user, accessTokenTime, refreshTokenTime, unit) ⇒ Promise
.issueNewToken(refreshToken, user, accessTokenTime, refreshTokenTime, unit) ⇒ Promise- .generateOTP(secret, options) ⇒ Promise
- .verifyOTP(secret, OTP, options) ⇒ Promise
- .generateError(code, message) ⇒ *
- .sendSingleSMS(mobile, message) ⇒ bluebird
- .setMetaData(data) ⇒ Redux
- static
new Redux(model, options)
Param |
---|
model |
options |
redux.logger() ⇒ Redux.logger | *
Kind: instance method of Redux
redux.printTrace()
Kind: instance method of Redux
redux.log(data, title)
Kind: instance method of Redux
Param |
---|
data |
title |
redux.err(data)
Kind: instance method of Redux
Param |
---|
data |
redux.suppressInput() ⇒ Redux
Kind: instance method of Redux
redux.paramsValidator(request, params)
Kind: instance method of Redux
Param |
---|
request |
params |
redux.bodyValidator(request, params)
Kind: instance method of Redux
Param |
---|
request |
params |
redux.queryValidator(request, params)
Kind: instance method of Redux
Param |
---|
request |
params |
redux.utils() ⇒
Kind: instance method of Redux
Returns: Utils
redux.idValidator(data)
Kind: instance method of Redux
Param |
---|
data |
redux.response() ⇒
Kind: instance method of Redux
Returns: Response
redux.setExtra(key, value) ⇒ Redux
Kind: instance method of Redux
Param |
---|
key |
value |
redux.sendSuccess(response, data, key)
Send back data to the client with the pre defined schema
Kind: instance method of Redux
Param |
---|
response |
data |
key |
redux.sendJSON(response, data, status)
Sends response as raw JSON passed as parameter to the client instead of enforcing a schema
Kind: instance method of Redux
Param |
---|
response |
data |
status |
redux.sendError(response, data, message)
Send back error to the client
Kind: instance method of Redux
Param |
---|
response |
data |
message |
redux.auth() ⇒ exports.auth | *
Kind: instance method of Redux
redux.attachData() ⇒ Redux
Kind: instance method of Redux
redux.interceptor(request, params, findDataIn)
Kind: instance method of Redux
Param |
---|
request |
params |
findDataIn |
redux.putInterceptor(request, bodyData, params)
Kind: instance method of Redux
Param |
---|
request |
bodyData |
params |
redux.invokeAcl(value, debug) ⇒ Redux
Kind: instance method of Redux
Param |
---|
value |
debug |
redux.suppressAuthError() ⇒ Redux
Kind: instance method of Redux
redux.tokenValidator(request, token)
Kind: instance method of Redux
Param | Type | Description |
---|---|---|
request | ||
token | String | The token to validate against. By default reduxpress tries to find the token in headers at x-access-token or as a query in url name access_token. |
redux.setCurrentUser(user)
Kind: instance method of Redux
Param |
---|
user |
redux.addTag(tags)
Kind: instance method of Redux
Param |
---|
tags |
redux.saveAuthDetails(data)
Kind: instance method of Redux
Param |
---|
data |
redux.verifyToken(token) ⇒ Promise
Kind: instance method of Redux
Param |
---|
token |
redux.verifyRefreshToken(token, suppressError) ⇒ Promise
Kind: instance method of Redux
Since: 1.4.6
Param |
---|
token |
suppressError |
redux.generateToken(user, accessTokenTime, refreshTokenTime, unit) ⇒ Promise
Kind: instance method of Redux
Param |
---|
user |
accessTokenTime |
refreshTokenTime |
unit |
redux.issueNewToken(refreshToken, user, accessTokenTime, refreshTokenTime, unit) ⇒ Promise
Deprecated
Kind: instance method of Redux
Since: 1.4.5
Param |
---|
refreshToken |
user |
accessTokenTime |
refreshTokenTime |
unit |
redux.generateOTP(secret, options) ⇒ Promise
Kind: instance method of Redux
Param |
---|
secret |
options |
redux.verifyOTP(secret, OTP, options) ⇒ Promise
Kind: instance method of Redux
Param |
---|
secret |
OTP |
options |
redux.generateError(code, message) ⇒ *
Kind: instance method of Redux
Param |
---|
code |
message |
redux.sendSingleSMS(mobile, message) ⇒ bluebird
Kind: instance method of Redux
Param |
---|
mobile |
message |
redux.setMetaData(data) ⇒ Redux
Kind: instance method of Redux
Param |
---|
data |
Redux.filter(filterNameOrFunction, hookName) ⇒ Redux
Kind: static method of Redux
Param |
---|
filterNameOrFunction |
hookName |
defaultOptions : Object
Kind: global variable
Default: Default Options
router
Created by kumardivyarajat on 10/10/16.
Kind: global variable
Copyright (c) 2017-2018 Kumar DIvya Rajat
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago