1.4.10 • Published 3 years ago

reduxpress v1.4.10

Weekly downloads
149
License
MIT
Repository
github
Last release
3 years ago

A utility framework built on top of expressJS to provide single line implementations for commonly used tasks.

view on npm view on npm


It provides the following functionality

  • Request Validation
  • Formatted Console Logs
  • Authentication
  • Response Handling
  • Error Handling
  • Object Logging in File or DB

Example Usage

  1. Install the reduxpress module
  • npm i reduxpress --save
  1. 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>'
})

    ...
  1. 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);

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

ParamTypeDescription
optionsObject
options.saveTraceBooleanWhether the generated logs should be save
options.supressInitMessageBooleanWhether to suppress request entry message in the console {defaults to false}
options.ipHeaderBooleanWhich header to parse in order to get the IP address of user. Defaults to the express default.
options.mongooseInstanceStringThe mongoose instance for saving the data when the storage engine is db
options.extendIpDataBooleanWhether or not to extend the IP address data
options.engineStringThe storage engine to use. Either file or db. Defaults to db.
options.errorsStringThe error object to extend the internal stored errors. Overwrites the internal errors if the same error is code is passed.
options.auth.externalBooleanIs the authentication logic local or external
options.auth.apiUrlStringAPI Url of the external authentication node
options.auth.methodStringThe HTTP method to use {defaults to GET}
options.auth.oauthTokenStringThe oauth token to be used for authentication
options.auth.scopeStringThe scope for oauth
options.authCallbackStringCallback function to be executed once the token has been validated
options.onErrorStringCallback 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

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

ParamTypeDescription
request
tokenStringThe 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.

1.4.10

3 years ago

1.4.9

4 years ago

1.4.8

4 years ago

1.4.7

4 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9-1090

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago