@builttocreate/engine-utils 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.normalizeArray = exports["default"] = void 0;
7
-
8
7
  /**
9
8
  * Normalize an array of objects
10
9
  *
@@ -23,7 +22,7 @@ exports.normalizeArray = exports["default"] = void 0;
23
22
  * 'bob': {name: 'bob', age: 44} ,
24
23
  * }
25
24
  */
26
- var normalizeArray = function normalizeArray(key, array) {
25
+ var normalizeArray = exports.normalizeArray = function normalizeArray(key, array) {
27
26
  var obj = {};
28
27
  array.forEach(function (e) {
29
28
  var objectKey = typeof key === 'function' ? key(e) : e[key];
@@ -31,9 +30,6 @@ var normalizeArray = function normalizeArray(key, array) {
31
30
  });
32
31
  return obj;
33
32
  };
34
-
35
- exports.normalizeArray = normalizeArray;
36
- var _default = {
33
+ var _default = exports["default"] = {
37
34
  normalizeArray: normalizeArray
38
- };
39
- exports["default"] = _default;
35
+ };
@@ -1,27 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = exports.CALL_API = void 0;
9
-
10
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
-
12
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
-
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
-
18
- var CALL_API = 'CALL API';
19
- exports.CALL_API = CALL_API;
20
-
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ var CALL_API = exports.CALL_API = 'CALL API';
21
13
  var callApiMiddleware = function callApiMiddleware(_ref) {
22
14
  var dispatch = _ref.dispatch,
23
- getState = _ref.getState;
24
-
15
+ getState = _ref.getState;
25
16
  /**
26
17
  * @param next //Callback for the action
27
18
  * @param action //Action object
@@ -37,13 +28,15 @@ var callApiMiddleware = function callApiMiddleware(_ref) {
37
28
  */
38
29
  return function (next) {
39
30
  return function (action) {
40
- var callApi = action[CALL_API]; //If callApi is not defined then it is a normal action (synchronous) pass it through
31
+ var callApi = action[CALL_API];
41
32
 
33
+ //If callApi is not defined then it is a normal action (synchronous) pass it through
42
34
  if (typeof callApi === 'undefined') return next(action);
43
35
  var types = callApi.types,
44
- apiCall = callApi.apiCall;
36
+ apiCall = callApi.apiCall;
45
37
  var successCallback = callApi.success;
46
38
  var errorCallback = callApi.error;
39
+
47
40
  /**
48
41
  * Action validation
49
42
  *
@@ -58,29 +51,23 @@ var callApiMiddleware = function callApiMiddleware(_ref) {
58
51
  if (!Array.isArray(types) || types.length !== 3) {
59
52
  throw new Error('action.types: Expected an array of three action types');
60
53
  }
61
-
62
54
  if (!types.every(function (type) {
63
55
  return typeof type === 'string';
64
56
  })) {
65
57
  throw new Error('action.types: Expected action types to be strings');
66
58
  }
67
-
68
59
  if (typeof apiCall !== 'function') {
69
60
  throw new Error('action.apiCall: Expected apiCall to be a function');
70
61
  }
71
-
72
62
  var actionWith = function actionWith(data) {
73
63
  var finalAction = _objectSpread(_objectSpread({}, action), data);
74
-
75
64
  delete finalAction[CALL_API];
76
65
  return finalAction;
77
66
  };
78
-
79
67
  var _callApi$types = (0, _slicedToArray2["default"])(callApi.types, 3),
80
- requestType = _callApi$types[0],
81
- successType = _callApi$types[1],
82
- failureType = _callApi$types[2];
83
-
68
+ requestType = _callApi$types[0],
69
+ successType = _callApi$types[1],
70
+ failureType = _callApi$types[2];
84
71
  next(actionWith({
85
72
  type: requestType
86
73
  }));
@@ -101,6 +88,4 @@ var callApiMiddleware = function callApiMiddleware(_ref) {
101
88
  };
102
89
  };
103
90
  };
104
-
105
- var _default = callApiMiddleware;
106
- exports["default"] = _default;
91
+ var _default = exports["default"] = callApiMiddleware;
@@ -1,21 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.hasRoles = exports.hasAdminRole = exports["default"] = void 0;
9
-
10
8
  var _Roles = _interopRequireDefault(require("./constants/Roles"));
11
-
12
- var hasAdminRole = function hasAdminRole(permissions) {
9
+ var hasAdminRole = exports.hasAdminRole = function hasAdminRole(permissions) {
13
10
  return hasRoles([_Roles["default"].admin.value], permissions);
14
11
  };
15
-
16
- exports.hasAdminRole = hasAdminRole;
17
-
18
- var hasRoles = function hasRoles(roles, permissions) {
12
+ var hasRoles = exports.hasRoles = function hasRoles(roles, permissions) {
19
13
  /**
20
14
  * If one of users permissions has a role inside of the
21
15
  * roles property then return true
@@ -24,10 +18,7 @@ var hasRoles = function hasRoles(roles, permissions) {
24
18
  return roles.indexOf(perm.role) !== -1;
25
19
  });
26
20
  };
27
-
28
- exports.hasRoles = hasRoles;
29
- var _default = {
21
+ var _default = exports["default"] = {
30
22
  hasAdminRole: hasAdminRole,
31
23
  hasRoles: hasRoles
32
- };
33
- exports["default"] = _default;
24
+ };