@builttocreate/engine-utils 2.9.1-beta.758 → 2.9.1-beta.758.2
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.
- package/dist/activityHelper.js +167 -0
- package/dist/changedKeys.js +34 -0
- package/dist/chartHelper.js +35 -0
- package/dist/constants/ActivityTypes.js +14 -0
- package/dist/constants/DocumentTypes.js +12 -0
- package/dist/constants/FieldDisplayTypes.js +38 -0
- package/dist/constants/FieldPresentationModes.js +18 -0
- package/dist/constants/FieldTableColumnTypes.js +16 -0
- package/dist/constants/FieldTableCustomColumnIds.js +12 -0
- package/dist/constants/FieldTypes.js +67 -0
- package/dist/constants/FileTypes.js +12 -0
- package/dist/constants/FileViews.js +10 -0
- package/dist/constants/FormStyleOptions.js +23 -0
- package/dist/constants/ListTypes.js +12 -0
- package/dist/constants/PageLayoutModes.js +15 -0
- package/dist/constants/PageTypes.js +15 -0
- package/dist/constants/Roles.js +36 -0
- package/dist/constants/Table.js +76 -0
- package/dist/fieldHelper.js +307 -0
- package/dist/fileHelper.js +26 -0
- package/dist/generateObjectId.js +18 -0
- package/dist/index.js +86 -0
- package/dist/joyDocHelper.js +936 -0
- package/dist/paginationHelper.js +35 -0
- package/dist/reduxApiMiddleware.js +91 -0
- package/dist/roleHelper.js +24 -0
- package/dist/tableHelper.js +1142 -0
- package/dist/validateObjectId.js +10 -0
- package/package.json +4 -5
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.normalizeArray = exports["default"] = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Normalize an array of objects
|
|
9
|
+
*
|
|
10
|
+
* @param {String|Func} key
|
|
11
|
+
* @param {Array} array
|
|
12
|
+
* @param {Function} keyExtractor //optional
|
|
13
|
+
*
|
|
14
|
+
* Example Input:
|
|
15
|
+
* param key = 'name';
|
|
16
|
+
* param array = [{name: 'frank', age: 19}, {name: 'joe', age: 22}, {name: 'bob', age: 44}]
|
|
17
|
+
*
|
|
18
|
+
* Example return:
|
|
19
|
+
* {
|
|
20
|
+
* 'frank': {name: 'frank', age: 19} ,
|
|
21
|
+
* 'joe': {name: 'joe', age: 22} ,
|
|
22
|
+
* 'bob': {name: 'bob', age: 44} ,
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
var normalizeArray = exports.normalizeArray = function normalizeArray(key, array) {
|
|
26
|
+
var obj = {};
|
|
27
|
+
array.forEach(function (e) {
|
|
28
|
+
var objectKey = typeof key === 'function' ? key(e) : e[key];
|
|
29
|
+
obj[objectKey] = e;
|
|
30
|
+
});
|
|
31
|
+
return obj;
|
|
32
|
+
};
|
|
33
|
+
var _default = exports["default"] = {
|
|
34
|
+
normalizeArray: normalizeArray
|
|
35
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = exports.CALL_API = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
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';
|
|
13
|
+
var callApiMiddleware = function callApiMiddleware(_ref) {
|
|
14
|
+
var dispatch = _ref.dispatch,
|
|
15
|
+
getState = _ref.getState;
|
|
16
|
+
/**
|
|
17
|
+
* @param next //Callback for the action
|
|
18
|
+
* @param action //Action object
|
|
19
|
+
*
|
|
20
|
+
* async action example: {
|
|
21
|
+
* CALL_API: {
|
|
22
|
+
* types: [ACTION_REQUEST, ACTION_SUCCESS, ACTION_FAILURE],
|
|
23
|
+
* apiCall: apiMethodCall, //apiMethodCall should return a promise
|
|
24
|
+
* success: callbackFunction,
|
|
25
|
+
* error: callbackFunction
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
return function (next) {
|
|
30
|
+
return function (action) {
|
|
31
|
+
var callApi = action[CALL_API];
|
|
32
|
+
|
|
33
|
+
//If callApi is not defined then it is a normal action (synchronous) pass it through
|
|
34
|
+
if (typeof callApi === 'undefined') return next(action);
|
|
35
|
+
var types = callApi.types,
|
|
36
|
+
apiCall = callApi.apiCall;
|
|
37
|
+
var successCallback = callApi.success;
|
|
38
|
+
var errorCallback = callApi.error;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Action validation
|
|
42
|
+
*
|
|
43
|
+
* Types:
|
|
44
|
+
* All async actions should have three action types: requested, success, & failure
|
|
45
|
+
* All actions should be strings.
|
|
46
|
+
*
|
|
47
|
+
* apiCall:
|
|
48
|
+
* All aysnc actions should have an apiCall function
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
if (!Array.isArray(types) || types.length !== 3) {
|
|
52
|
+
throw new Error('action.types: Expected an array of three action types');
|
|
53
|
+
}
|
|
54
|
+
if (!types.every(function (type) {
|
|
55
|
+
return typeof type === 'string';
|
|
56
|
+
})) {
|
|
57
|
+
throw new Error('action.types: Expected action types to be strings');
|
|
58
|
+
}
|
|
59
|
+
if (typeof apiCall !== 'function') {
|
|
60
|
+
throw new Error('action.apiCall: Expected apiCall to be a function');
|
|
61
|
+
}
|
|
62
|
+
var actionWith = function actionWith(data) {
|
|
63
|
+
var finalAction = _objectSpread(_objectSpread({}, action), data);
|
|
64
|
+
delete finalAction[CALL_API];
|
|
65
|
+
return finalAction;
|
|
66
|
+
};
|
|
67
|
+
var _callApi$types = (0, _slicedToArray2["default"])(callApi.types, 3),
|
|
68
|
+
requestType = _callApi$types[0],
|
|
69
|
+
successType = _callApi$types[1],
|
|
70
|
+
failureType = _callApi$types[2];
|
|
71
|
+
next(actionWith({
|
|
72
|
+
type: requestType
|
|
73
|
+
}));
|
|
74
|
+
return apiCall().then(function (response) {
|
|
75
|
+
next(actionWith({
|
|
76
|
+
type: successType,
|
|
77
|
+
payload: response
|
|
78
|
+
}));
|
|
79
|
+
if (successCallback) successCallback(response, dispatch, getState);
|
|
80
|
+
})["catch"](function (error) {
|
|
81
|
+
next(actionWith({
|
|
82
|
+
type: failureType,
|
|
83
|
+
payload: error,
|
|
84
|
+
error: true
|
|
85
|
+
}));
|
|
86
|
+
if (errorCallback) errorCallback(error, dispatch, getState);
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
var _default = exports["default"] = callApiMiddleware;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.hasRoles = exports.hasAdminRole = exports["default"] = void 0;
|
|
8
|
+
var _Roles = _interopRequireDefault(require("./constants/Roles"));
|
|
9
|
+
var hasAdminRole = exports.hasAdminRole = function hasAdminRole(permissions) {
|
|
10
|
+
return hasRoles([_Roles["default"].admin.value], permissions);
|
|
11
|
+
};
|
|
12
|
+
var hasRoles = exports.hasRoles = function hasRoles(roles, permissions) {
|
|
13
|
+
/**
|
|
14
|
+
* If one of users permissions has a role inside of the
|
|
15
|
+
* roles property then return true
|
|
16
|
+
*/
|
|
17
|
+
return !permissions || permissions.length < 1 ? false : permissions.find(function (perm) {
|
|
18
|
+
return roles.indexOf(perm.role) !== -1;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var _default = exports["default"] = {
|
|
22
|
+
hasAdminRole: hasAdminRole,
|
|
23
|
+
hasRoles: hasRoles
|
|
24
|
+
};
|