@aven-cloud/cloud-utils
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -1,2 +0,9 @@ | ||
export default function createDispatcher(actions, fallbackDispatch) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = createDispatcher; | ||
function createDispatcher(actions, fallbackDispatch) { | ||
function dispatch(action) { | ||
@@ -6,8 +13,11 @@ if (actions[action.type]) { | ||
} | ||
if (fallbackDispatch) { | ||
return fallbackDispatch(action); | ||
} | ||
throw new Error(`Cannot find action "${action.type}"`); | ||
throw new Error("Cannot find action \"".concat(action.type, "\"")); | ||
} | ||
return dispatch; | ||
} |
@@ -1,10 +0,32 @@ | ||
import uuidv1 from 'uuid/v1'; | ||
import { hash, compare } from 'bcrypt'; | ||
"use strict"; | ||
const crypto = require('crypto'); | ||
const { promisify } = require('util'); | ||
const randomBytes = promisify(crypto.randomBytes); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.checksum = checksum; | ||
exports.genAuthCode = genAuthCode; | ||
exports.genKey = genKey; | ||
exports.uuid = uuid; | ||
exports.hashSecureString = hashSecureString; | ||
exports.compareSecureString = compareSecureString; | ||
export function checksum(input) { | ||
const shasum = crypto.createHash('sha1'); | ||
var _v = _interopRequireDefault(require("uuid/v1")); | ||
var _bcrypt = require("bcrypt"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
var crypto = require('crypto'); | ||
var _require = require('util'), | ||
promisify = _require.promisify; | ||
var randomBytes = promisify(crypto.randomBytes); | ||
function checksum(input) { | ||
var shasum = crypto.createHash('sha1'); | ||
shasum.update(input); | ||
@@ -14,26 +36,130 @@ return shasum.digest('hex'); | ||
export async function genAuthCode(length = 6) { | ||
const randBuf = await randomBytes(48); | ||
const hex = randBuf.toString('hex'); | ||
const int = parseInt(hex, 16); | ||
const intStr = String(int); | ||
return intStr.substr(3, length); | ||
function genAuthCode() { | ||
return _genAuthCode.apply(this, arguments); | ||
} | ||
export async function genKey() { | ||
const randBuf = await randomBytes(48); | ||
const hex = randBuf.toString('hex'); | ||
return hex; | ||
function _genAuthCode() { | ||
_genAuthCode = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee() { | ||
var length, | ||
randBuf, | ||
hex, | ||
int, | ||
intStr, | ||
_args = arguments; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
length = _args.length > 0 && _args[0] !== undefined ? _args[0] : 6; | ||
_context.next = 3; | ||
return randomBytes(48); | ||
case 3: | ||
randBuf = _context.sent; | ||
hex = randBuf.toString('hex'); | ||
int = parseInt(hex, 16); | ||
intStr = String(int); | ||
return _context.abrupt("return", intStr.substr(3, length)); | ||
case 8: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return _genAuthCode.apply(this, arguments); | ||
} | ||
export function uuid() { | ||
return uuidv1(); | ||
function genKey() { | ||
return _genKey.apply(this, arguments); | ||
} | ||
export async function hashSecureString(secretInput) { | ||
return await hash(secretInput, 10); | ||
function _genKey() { | ||
_genKey = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee2() { | ||
var randBuf, hex; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return randomBytes(48); | ||
case 2: | ||
randBuf = _context2.sent; | ||
hex = randBuf.toString('hex'); | ||
return _context2.abrupt("return", hex); | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
return _genKey.apply(this, arguments); | ||
} | ||
export async function compareSecureString(testSecretInput, hash) { | ||
return await compare(testSecretInput, hash); | ||
function uuid() { | ||
return (0, _v.default)(); | ||
} | ||
function hashSecureString(_x) { | ||
return _hashSecureString.apply(this, arguments); | ||
} | ||
function _hashSecureString() { | ||
_hashSecureString = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee3(secretInput) { | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.next = 2; | ||
return (0, _bcrypt.hash)(secretInput, 10); | ||
case 2: | ||
return _context3.abrupt("return", _context3.sent); | ||
case 3: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, this); | ||
})); | ||
return _hashSecureString.apply(this, arguments); | ||
} | ||
function compareSecureString(_x2, _x3) { | ||
return _compareSecureString.apply(this, arguments); | ||
} | ||
function _compareSecureString() { | ||
_compareSecureString = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee4(testSecretInput, hash) { | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
_context4.next = 2; | ||
return (0, _bcrypt.compare)(testSecretInput, hash); | ||
case 2: | ||
return _context4.abrupt("return", _context4.sent); | ||
case 3: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, this); | ||
})); | ||
return _compareSecureString.apply(this, arguments); | ||
} |
@@ -1,41 +0,62 @@ | ||
export function getListDocName(name) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getListDocName = getListDocName; | ||
exports.getListBlocksName = getListBlocksName; | ||
exports.getAuthDocName = getAuthDocName; | ||
function getListDocName(name) { | ||
if (name == null) { | ||
return null; | ||
} | ||
if (name === '_children') { | ||
return ''; | ||
} | ||
const match = name.match(/^(.*)\/_children$/); | ||
var match = name.match(/^(.*)\/_children$/); | ||
if (match) { | ||
return match[1]; | ||
} | ||
return null; | ||
} | ||
export function getListBlocksName(name) { | ||
function getListBlocksName(name) { | ||
if (name == null) { | ||
return null; | ||
} | ||
if (name === '_blocks') { | ||
return ''; | ||
} | ||
const match = name.match(/^(.*)\/_blocks$/); | ||
var match = name.match(/^(.*)\/_blocks$/); | ||
if (match) { | ||
return match[1]; | ||
} | ||
return null; | ||
} | ||
export function getAuthDocName(name) { | ||
function getAuthDocName(name) { | ||
if (name == null) { | ||
return null; | ||
} | ||
if (name === '_auth') { | ||
return ''; | ||
} | ||
const match = name.match(/^(.*)\/_auth$/); | ||
var match = name.match(/^(.*)\/_auth$/); | ||
if (match) { | ||
return match[1]; | ||
} | ||
return null; | ||
} |
{ | ||
"name": "@aven-cloud/cloud-utils", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"dependencies": { | ||
@@ -8,10 +8,10 @@ "bcrypt": "3.0.2" | ||
"scripts": { | ||
"build": "babel --no-babelrc --plugins=syntax-jsx,syntax-class-properties,syntax-object-rest-spread src --copy-files --out-dir dist --ignore '**/__tests__/**'" | ||
"build": "babel src --out-dir dist" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-plugin-syntax-class-properties": "^6.13.0", | ||
"babel-plugin-syntax-jsx": "^6.18.0", | ||
"babel-plugin-syntax-object-rest-spread": "^6.13.0" | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.2.2", | ||
"@babel/node": "^7.2.2", | ||
"@babel/preset-env": "^7.3.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
119554
9
280