You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-action-validation

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-action-validation - npm Package Compare versions

Comparing version

to
0.0.5-alpha

internals/publish.js

21

.eslintrc.js

@@ -7,5 +7,15 @@ const fs = require('fs');

'parser': 'babel-eslint',
'extends': ['prettier', 'plugin:import/errors'],
'ignorePatterns': ['*.test.js', '*.spec.js', '*.config.js', '**/dist/*', '**/node_modules/*'],
'plugins': ['prettier', 'import'],
'env': {
browser: true,
node: true,
jest: true,
es6: true,
},
'extends': [
'prettier',
'plugin:import/errors',
'plugin:jest/recommended'
],
'ignorePatterns': ['*.config.js', '**/dist/*', '**/node_modules/*'],
'plugins': ['prettier', 'import', 'jest'],
'rules': {

@@ -33,3 +43,8 @@ 'prettier/prettier': ['error', prettierOptions],

'no-console': 1,
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/prefer-to-have-length': 'warn',
'jest/valid-expect': 'error'
}
};
module.exports = {
env: {
test: {
plugins: ["@babel/plugin-transform-runtime"]
}
},
presets: [

@@ -3,0 +8,0 @@ '@babel/preset-env',

60

dist/index.js

@@ -93,16 +93,48 @@ import Joi from '@hapi/joi';

return function (next) {
return function (action) {
if (!validations[action.type]) {
next(action);
} else {
var validation = new validations[action.type]();
validation.validate(action.payload).then(function () {
validation.accept(action.type);
next(action);
})["catch"](function (e) {
console.error(e);
validation.reject(action.type);
});
}
};
return /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(action) {
var validation;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (validations[action.type]) {
_context.next = 4;
break;
}
next(action);
_context.next = 16;
break;
case 4:
validation = new validations[action.type]();
_context.prev = 5;
_context.next = 8;
return validation.validate(action.payload);
case 8:
validation.accept(action.type);
next(action);
_context.next = 16;
break;
case 12:
_context.prev = 12;
_context.t0 = _context["catch"](5);
console.error(_context.t0);
validation.reject(action.type);
case 16:
case "end":
return _context.stop();
}
}
}, _callee, null, [[5, 12]]);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
};

@@ -109,0 +141,0 @@ };

{
"name": "react-action-validation",
"version": "0.0.4-alpha",
"version": "0.0.5-alpha",
"description": "validates the payload of the dispatched action",
"main": "./dist/index.js",
"scripts": {
"build": "rollup --config ./rollup.config.js",
"lint:staged": "lint-staged"
"build": "rollup --config ./internals/rollup.config.js",
"lint:staged": "lint-staged",
"test": "jest",
"coverage": "jest --coverage",
"release": "node ./internals/publish.js"
},

@@ -40,2 +43,3 @@ "repository": {

"@babel/plugin-transform-object-assign": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.10.4",
"@babel/preset-env": "^7.6.3",

@@ -47,2 +51,3 @@ "babel-eslint": "^10.0.3",

"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^23.17.1",
"eslint-plugin-prettier": "^3.1.1",

@@ -49,0 +54,0 @@ "jest": "^24.9.0",

@@ -1,2 +0,2 @@

export default validations => () => next => action => {
export default validations => () => next => async action => {
if (!validations[action.type]) {

@@ -6,13 +6,11 @@ next(action);

const validation = new validations[action.type]();
validation
.validate(action.payload)
.then(() => {
validation.accept(action.type);
next(action);
})
.catch(e => {
console.error(e);
validation.reject(action.type);
});
try {
await validation.validate(action.payload);
validation.accept(action.type);
next(action);
} catch (e) {
console.error(e);
validation.reject(action.type);
}
}
};