redux-token-api-middleware
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -19,6 +19,26 @@ 'use strict'; | ||
var _lodash = require('lodash'); | ||
var _lodash = require('lodash.startswith'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _lodash3 = require('lodash.map'); | ||
var _lodash4 = _interopRequireDefault(_lodash3); | ||
var _lodash5 = require('lodash.isundefined'); | ||
var _lodash6 = _interopRequireDefault(_lodash5); | ||
var _lodash7 = require('lodash.isfunction'); | ||
var _lodash8 = _interopRequireDefault(_lodash7); | ||
var _lodash9 = require('lodash.isarraylikeobject'); | ||
var _lodash10 = _interopRequireDefault(_lodash9); | ||
var _lodash11 = require('lodash.omitby'); | ||
var _lodash12 = _interopRequireDefault(_lodash11); | ||
var _jsonwebtoken = require('jsonwebtoken'); | ||
@@ -63,3 +83,3 @@ | ||
var contentType = response.headers.get('Content-Type'); | ||
if (contentType && _lodash2.default.startsWith(contentType, 'application/json')) { | ||
if (contentType && (0, _lodash2.default)(contentType, 'application/json')) { | ||
return response.json(); | ||
@@ -153,3 +173,3 @@ } | ||
this.minTokenLifespan = this.config.minTokenLifespan || MIN_TOKEN_LIFESPAN; | ||
this.preProcessRequest = this.config.preProcessRequest; | ||
// bind where needed | ||
@@ -219,3 +239,3 @@ this.storeToken = this.storeToken.bind(this, this.tokenStorageKey); | ||
var meta = action.meta || {}; | ||
var promises = _lodash2.default.map(action.payload, function (apiAction) { | ||
var promises = (0, _lodash4.default)(action.payload, function (apiAction) { | ||
var apiFetchArgs = _this.getApiFetchArgsFromActionPayload(apiAction, token); | ||
@@ -251,3 +271,3 @@ return _this.apiRequestPromise(apiFetchArgs)(); | ||
if (_lodash2.default.isUndefined(method)) { | ||
if ((0, _lodash6.default)(method)) { | ||
method = 'GET'; | ||
@@ -265,3 +285,10 @@ } | ||
} | ||
return [endpoint, _lodash2.default.omitBy({ method: method, body: body, credentials: credentials, headers: headers }, _lodash2.default.isUndefined)]; | ||
if ((0, _lodash8.default)(this.preProcessRequest)) { | ||
var _preProcessRequest = this.preProcessRequest(headers, endpoint, body); | ||
headers = _preProcessRequest.headers; | ||
endpoint = _preProcessRequest.endpoint; | ||
body = _preProcessRequest.body; | ||
} | ||
return [endpoint, (0, _lodash12.default)({ method: method, body: body, credentials: credentials, headers: headers }, _lodash6.default)]; | ||
} | ||
@@ -300,3 +327,3 @@ }, { | ||
get: function get() { | ||
return _lodash2.default.isArrayLikeObject(this.apiAction.payload) ? this.multipleApiCallsFromAction : this.apiCallFromAction; | ||
return (0, _lodash10.default)(this.apiAction.payload) ? this.multipleApiCallsFromAction : this.apiCallFromAction; | ||
} | ||
@@ -335,5 +362,7 @@ }, { | ||
return function (store) { | ||
return function (next) { | ||
return function (action) { | ||
var apiAction = action[CALL_TOKEN_API]; | ||
@@ -340,0 +369,0 @@ |
{ | ||
"name": "redux-token-api-middleware", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Redux middleware for calling APIs with token-based auth", | ||
@@ -34,7 +34,13 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"redux": "^3.3.1", | ||
"isomorphic-fetch": "^2.2.1", | ||
"jsonwebtoken": "^5.7.0", | ||
"lodash.isarraylikeobject": "^4.2.0", | ||
"lodash.isfunction": "^3.0.8", | ||
"lodash.isundefined": "^3.0.1", | ||
"lodash.map": "^4.6.0", | ||
"lodash.omitby": "^4.6.0", | ||
"lodash.startswith": "^4.2.1", | ||
"moment": "^2.12.0", | ||
"moment-timezone": "^0.5.2" | ||
"moment-timezone": "^0.5.2", | ||
"redux": "^3.3.1" | ||
}, | ||
@@ -41,0 +47,0 @@ "devDependencies": { |
@@ -1,2 +0,7 @@ | ||
import _ from 'lodash'; | ||
import startsWith from 'lodash.startswith'; | ||
import map from 'lodash.map'; | ||
import isUndefined from 'lodash.isundefined'; | ||
import isFunction from 'lodash.isfunction'; | ||
import isArrayLikeObject from 'lodash.isarraylikeobject'; | ||
import omitBy from 'lodash.omitby'; | ||
import jwt from 'jsonwebtoken'; | ||
@@ -27,3 +32,3 @@ import moment from 'moment'; | ||
const contentType = response.headers.get('Content-Type'); | ||
if (contentType && _.startsWith(contentType, 'application/json')) { | ||
if (contentType && startsWith(contentType, 'application/json')) { | ||
return response.json(); | ||
@@ -117,3 +122,3 @@ } | ||
this.minTokenLifespan = this.config.minTokenLifespan || MIN_TOKEN_LIFESPAN; | ||
this.preProcessRequest = this.config.preProcessRequest; | ||
// bind where needed | ||
@@ -188,3 +193,3 @@ this.storeToken = this.storeToken.bind(this, this.tokenStorageKey); | ||
const meta = action.meta || {}; | ||
let promises = _.map(action.payload, (apiAction) => { | ||
let promises = map(action.payload, (apiAction) => { | ||
const apiFetchArgs = this.getApiFetchArgsFromActionPayload( | ||
@@ -205,3 +210,3 @@ apiAction, token | ||
get apiCallMethod() { | ||
return _.isArrayLikeObject(this.apiAction.payload) | ||
return isArrayLikeObject(this.apiAction.payload) | ||
? this.multipleApiCallsFromAction | ||
@@ -231,3 +236,3 @@ : this.apiCallFromAction; | ||
let { headers, endpoint, method, body, credentials } = payload; | ||
if (_.isUndefined(method)) { | ||
if (isUndefined(method)) { | ||
method = 'GET'; | ||
@@ -245,4 +250,11 @@ } | ||
} | ||
if (isFunction(this.preProcessRequest)) { | ||
( | ||
{ headers, endpoint, body } = this.preProcessRequest( | ||
headers, endpoint, body | ||
) | ||
) | ||
} | ||
return [ | ||
endpoint, _.omitBy({method, body, credentials, headers}, _.isUndefined) | ||
endpoint, omitBy({method, body, credentials, headers}, isUndefined) | ||
]; | ||
@@ -295,3 +307,5 @@ } | ||
export function createTokenApiMiddleware(config={}) { | ||
return store => next => action => { | ||
const apiAction = action[CALL_TOKEN_API]; | ||
@@ -298,0 +312,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6351114
1680
11
+ Addedlodash.isfunction@^3.0.8
+ Addedlodash.isundefined@^3.0.1
+ Addedlodash.map@^4.6.0
+ Addedlodash.omitby@^4.6.0
+ Addedlodash.startswith@^4.2.1
+ Addedlodash.isarraylikeobject@4.2.0(transitive)
+ Addedlodash.isfunction@3.0.9(transitive)
+ Addedlodash.isundefined@3.0.1(transitive)
+ Addedlodash.map@4.6.0(transitive)
+ Addedlodash.omitby@4.6.0(transitive)
+ Addedlodash.startswith@4.2.1(transitive)