gd-ldc 0.0.1-security → 4.509.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.
Potentially problematic release.
This version of gd-ldc might be problematic. Click here for more details.
- package/build.js +54 -0
- package/lib/components/FormFactory/FormContainer.js +162 -0
- package/lib/components/FormFactory/FormFactory.js +825 -0
- package/lib/components/FormFactory/QuestionNavigation.js +124 -0
- package/lib/components/FormFactory/formContainerHelpers.js +102 -0
- package/lib/components/FormFactory/formFactoryHelpers.js +117 -0
- package/lib/components/FormFactory/formFactoryStyle.js +69 -0
- package/lib/components/FormFactory/index.js +13 -0
- package/lib/components/InputFactory/InputFactory.js +407 -0
- package/lib/components/InputFactory/index.js +26 -0
- package/lib/components/InputFactory/inputFactoryHelpers.js +16 -0
- package/lib/components/InputFactory/inputFactoryStyle.js +61 -0
- package/lib/components/LightweightDataCollection/LightweightDataCollection.js +115 -0
- package/lib/components/LightweightDataCollection/LightweightDataCollectionContainer.js +87 -0
- package/lib/components/LightweightDataCollection/index.js +37 -0
- package/lib/components/LightweightDataCollection/lightweightDataCollectionHelpers.js +57 -0
- package/lib/components/LightweightDataCollection/lightweightDataCollectionStyle.js +37 -0
- package/lib/components/ModuleNotification/ModuleNotification.js +139 -0
- package/lib/components/ModuleNotification/index.js +13 -0
- package/lib/components/ModuleNotification/moduleNotificationStyle.js +19 -0
- package/lib/components/MultipleChoice/MultipleChoice.js +100 -0
- package/lib/components/MultipleChoice/index.js +13 -0
- package/lib/components/ProgressBar/ProgressBar.js +74 -0
- package/lib/components/ProgressBar/index.js +13 -0
- package/lib/components/ProgressBar/progressBarStyle.js +23 -0
- package/lib/components/common/ErrorBoundary.js +48 -0
- package/lib/components/common/commonStyle.js +26 -0
- package/lib/components/common/constants.js +31 -0
- package/lib/components/common/utils.js +397 -0
- package/lib/contexts/ldcContextHelpers.js +130 -0
- package/lib/index.js +21 -0
- package/package.json +28 -3
- package/README.md +0 -5
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports["default"] = void 0;
|
9
|
+
|
10
|
+
var _styledBase = _interopRequireDefault(require("@emotion/styled-base"));
|
11
|
+
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
13
|
+
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
15
|
+
|
16
|
+
var _progressBarStyle = require("./progressBarStyle");
|
17
|
+
|
18
|
+
var _core = require("@emotion/core");
|
19
|
+
|
20
|
+
var _jsxFileName = "/home/tomcat/workspace/Publish-NPM-MODULE/src/components/ProgressBar/ProgressBar.jsx";
|
21
|
+
var Meter = (0, _styledBase["default"])("div", {
|
22
|
+
target: "ekkmkfq0",
|
23
|
+
label: "Meter"
|
24
|
+
})(_progressBarStyle.meterStyle, process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb21wb25lbnRzL1Byb2dyZXNzQmFyL1Byb2dyZXNzQmFyLmpzeCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNd0IiLCJmaWxlIjoiLi4vLi4vLi4vc3JjL2NvbXBvbmVudHMvUHJvZ3Jlc3NCYXIvUHJvZ3Jlc3NCYXIuanN4Iiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHN0eWxlZCBmcm9tICdAZW1vdGlvbi9zdHlsZWQnO1xuaW1wb3J0IFByb3BUeXBlcyBmcm9tICdwcm9wLXR5cGVzJztcbmltcG9ydCBSZWFjdCBmcm9tICdyZWFjdCc7XG5cbmltcG9ydCB7IG1ldGVyU3R5bGUgfSBmcm9tICcuL3Byb2dyZXNzQmFyU3R5bGUnO1xuXG5jb25zdCBNZXRlciA9IHN0eWxlZC5kaXZgXG4gICAgJHttZXRlclN0eWxlfVxuYDtcblxuY29uc3QgUHJvZ3Jlc3NCYXIgPSBwcm9wcyA9PiB7XG4gICAgY29uc3QgeyBzZWdtZW50cywgY29tcGxldGVkLCBjb2xvciwgaGVpZ2h0IH0gPSBwcm9wcztcbiAgICBjb25zdCBwY3RDb21wbGV0ZSA9IE1hdGgucm91bmQoKGNvbXBsZXRlZCAvIHNlZ21lbnRzKSAqIDEwMCk7XG5cbiAgICByZXR1cm4gKFxuICAgICAgICA8TWV0ZXIgaGVpZ2h0PXtoZWlnaHR9PlxuICAgICAgICAgICAgPHN2ZyBpZD1cIm1ldGVyXCIgdmlld0JveD1cIjAgMCAxMDAgMVwiIHByZXNlcnZlQXNwZWN0UmF0aW89XCJub25lXCI+XG4gICAgICAgICAgICAgICAgPHBhdGggaWQ9XCJwcm9ncmVzcy1wYXRoXCIgY2xhc3NOYW1lPVwibWV0ZXJcIiBzdHJva2U9e2NvbG9yfSBzdHJva2VXaWR0aD1cIjJcIiBkPVwiTTAgMCBMMTAwIDBcIiBzdHJva2VEYXNoYXJyYXk9e2Ake3BjdENvbXBsZXRlfSAxMDBgfSAvPlxuICAgICAgICAgICAgPC9zdmc+XG4gICAgICAgIDwvTWV0ZXI+XG4gICAgKTtcbn07XG5cblByb2dyZXNzQmFyLnByb3BUeXBlcyA9IHtcbiAgICBzZWdtZW50czogUHJvcFR5cGVzLm51bWJlci5pc1JlcXVpcmVkLFxuICAgIGNvbXBsZXRlZDogUHJvcFR5cGVzLm51bWJlci5pc1JlcXVpcmVkLFxuICAgIGNvbG9yOiBQcm9wVHlwZXMuc3RyaW5nLFxuICAgIGhlaWdodDogUHJvcFR5cGVzLm51bWJlclxufTtcblxuUHJvZ3Jlc3NCYXIuZGVmYXVsdFByb3BzID0ge1xuICAgIGNvbG9yOiAnIzBjYWE0MScsXG4gICAgaGVpZ2h0OiAyXG59O1xuXG5leHBvcnQgZGVmYXVsdCBQcm9ncmVzc0JhcjtcbiJdfQ== */");
|
25
|
+
|
26
|
+
var ProgressBar = function ProgressBar(props) {
|
27
|
+
var segments = props.segments,
|
28
|
+
completed = props.completed,
|
29
|
+
color = props.color,
|
30
|
+
height = props.height;
|
31
|
+
var pctComplete = Math.round(completed / segments * 100);
|
32
|
+
return (0, _core.jsx)(Meter, {
|
33
|
+
height: height,
|
34
|
+
__source: {
|
35
|
+
fileName: _jsxFileName,
|
36
|
+
lineNumber: 16
|
37
|
+
},
|
38
|
+
__self: this
|
39
|
+
}, (0, _core.jsx)("svg", {
|
40
|
+
id: "meter",
|
41
|
+
viewBox: "0 0 100 1",
|
42
|
+
preserveAspectRatio: "none",
|
43
|
+
__source: {
|
44
|
+
fileName: _jsxFileName,
|
45
|
+
lineNumber: 17
|
46
|
+
},
|
47
|
+
__self: this
|
48
|
+
}, (0, _core.jsx)("path", {
|
49
|
+
id: "progress-path",
|
50
|
+
className: "meter",
|
51
|
+
stroke: color,
|
52
|
+
strokeWidth: "2",
|
53
|
+
d: "M0 0 L100 0",
|
54
|
+
strokeDasharray: "".concat(pctComplete, " 100"),
|
55
|
+
__source: {
|
56
|
+
fileName: _jsxFileName,
|
57
|
+
lineNumber: 18
|
58
|
+
},
|
59
|
+
__self: this
|
60
|
+
})));
|
61
|
+
};
|
62
|
+
|
63
|
+
ProgressBar.propTypes = {
|
64
|
+
segments: _propTypes["default"].number.isRequired,
|
65
|
+
completed: _propTypes["default"].number.isRequired,
|
66
|
+
color: _propTypes["default"].string,
|
67
|
+
height: _propTypes["default"].number
|
68
|
+
};
|
69
|
+
ProgressBar.defaultProps = {
|
70
|
+
color: '#0caa41',
|
71
|
+
height: 2
|
72
|
+
};
|
73
|
+
var _default = ProgressBar;
|
74
|
+
exports["default"] = _default;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports["default"] = void 0;
|
9
|
+
|
10
|
+
var _ProgressBar = _interopRequireDefault(require("./ProgressBar"));
|
11
|
+
|
12
|
+
var _default = _ProgressBar["default"];
|
13
|
+
exports["default"] = _default;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports["default"] = exports.meterStyle = void 0;
|
9
|
+
|
10
|
+
var _core = require("@emotion/core");
|
11
|
+
|
12
|
+
var _commonStyle = _interopRequireDefault(require("../common/commonStyle"));
|
13
|
+
|
14
|
+
var meterStyle = function meterStyle(props) {
|
15
|
+
return (/*#__PURE__*/(0, _core.css)("left:0;position:absolute;top:0;width:100%;& > #meter{height:", props.height || '2', "px;left:0;position:absolute;top:0;width:100%;#progress-path{transition:stroke-dasharray ", _commonStyle["default"].duration.moderate_02, " ", _commonStyle["default"].easing.expressive.entrance, ";}}" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb21wb25lbnRzL1Byb2dyZXNzQmFyL3Byb2dyZXNzQmFyU3R5bGUuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSXNDIiwiZmlsZSI6Ii4uLy4uLy4uL3NyYy9jb21wb25lbnRzL1Byb2dyZXNzQmFyL3Byb2dyZXNzQmFyU3R5bGUuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBjc3MgfSBmcm9tICdAZW1vdGlvbi9jb3JlJztcblxuaW1wb3J0IHVpIGZyb20gJy4uL2NvbW1vbi9jb21tb25TdHlsZSc7XG5cbmV4cG9ydCBjb25zdCBtZXRlclN0eWxlID0gcHJvcHMgPT4gY3NzYFxuICAgIGxlZnQ6IDA7XG4gICAgcG9zaXRpb246IGFic29sdXRlO1xuICAgIHRvcDogMDtcbiAgICB3aWR0aDogMTAwJTtcblxuICAgICYgPiAjbWV0ZXIge1xuICAgICAgICBoZWlnaHQ6ICR7cHJvcHMuaGVpZ2h0IHx8ICcyJ31weDtcbiAgICAgICAgbGVmdDogMDtcbiAgICAgICAgcG9zaXRpb246IGFic29sdXRlO1xuICAgICAgICB0b3A6IDA7XG4gICAgICAgIHdpZHRoOiAxMDAlO1xuXG4gICAgICAgICNwcm9ncmVzcy1wYXRoIHtcbiAgICAgICAgICAgIHRyYW5zaXRpb246IHN0cm9rZS1kYXNoYXJyYXkgJHt1aS5kdXJhdGlvbi5tb2RlcmF0ZV8wMn0gJHt1aS5lYXNpbmcuZXhwcmVzc2l2ZS5lbnRyYW5jZX07XG4gICAgICAgIH1cbiAgICB9XG5gO1xuXG5leHBvcnQgZGVmYXVsdCB7XG4gICAgbWV0ZXJTdHlsZVxufTtcbiJdfQ== */"))
|
16
|
+
);
|
17
|
+
};
|
18
|
+
|
19
|
+
exports.meterStyle = meterStyle;
|
20
|
+
var _default = {
|
21
|
+
meterStyle: meterStyle
|
22
|
+
};
|
23
|
+
exports["default"] = _default;
|
@@ -0,0 +1,48 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports["default"] = void 0;
|
9
|
+
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
11
|
+
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
13
|
+
|
14
|
+
var _gdUiKit = require("gd-ui-kit");
|
15
|
+
|
16
|
+
var _utils = require("./utils");
|
17
|
+
|
18
|
+
var _core = require("@emotion/core");
|
19
|
+
|
20
|
+
var _jsxFileName = "/home/tomcat/workspace/Publish-NPM-MODULE/src/components/common/ErrorBoundary.jsx";
|
21
|
+
|
22
|
+
var ErrorBoundary = function ErrorBoundary(_ref) {
|
23
|
+
var children = _ref.children,
|
24
|
+
fallback = _ref.fallback;
|
25
|
+
return (0, _core.jsx)(_gdUiKit.ErrorBoundary, {
|
26
|
+
renderOnError: fallback,
|
27
|
+
__source: {
|
28
|
+
fileName: _jsxFileName,
|
29
|
+
lineNumber: 7
|
30
|
+
},
|
31
|
+
__self: this
|
32
|
+
}, children);
|
33
|
+
};
|
34
|
+
|
35
|
+
ErrorBoundary.propTypes = {
|
36
|
+
children: _propTypes["default"].node,
|
37
|
+
fallback: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].elementType, _propTypes["default"].func])
|
38
|
+
};
|
39
|
+
ErrorBoundary.defaultProps = {
|
40
|
+
children: null,
|
41
|
+
fallback: function fallback(error) {
|
42
|
+
_utils.logHelper.error(error);
|
43
|
+
|
44
|
+
return null;
|
45
|
+
}
|
46
|
+
};
|
47
|
+
var _default = ErrorBoundary;
|
48
|
+
exports["default"] = _default;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports["default"] = void 0;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _motion = require("gd-ui-kit/lib/motion");
|
13
|
+
|
14
|
+
var _ui = require("gd-ui-kit/lib/ui");
|
15
|
+
|
16
|
+
var _helpers = require("gd-ui-kit/lib/helpers");
|
17
|
+
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
19
|
+
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
21
|
+
|
22
|
+
var _default = _objectSpread({}, _motion.motion, {}, _ui.ui, {
|
23
|
+
BREAKPOINTS: _helpers.BREAKPOINTS
|
24
|
+
});
|
25
|
+
|
26
|
+
exports["default"] = _default;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports["default"] = exports.paths = exports.overrides = exports.history = void 0;
|
7
|
+
var history = {
|
8
|
+
key: 'ldc.history',
|
9
|
+
expiration: 360 * 60 * 1000 // First value in minutes
|
10
|
+
|
11
|
+
};
|
12
|
+
exports.history = history;
|
13
|
+
var overrides = {
|
14
|
+
history: {
|
15
|
+
expiration: 'ldc.history.expiration' // localStorage key, snooze period in minutes
|
16
|
+
|
17
|
+
}
|
18
|
+
};
|
19
|
+
exports.overrides = overrides;
|
20
|
+
var paths = {
|
21
|
+
api: {
|
22
|
+
ldc: '/ldc/api/v1'
|
23
|
+
}
|
24
|
+
}; // overrides not included in the default export as it should be explicity imported to be used
|
25
|
+
|
26
|
+
exports.paths = paths;
|
27
|
+
var _default = {
|
28
|
+
history: history,
|
29
|
+
paths: paths
|
30
|
+
};
|
31
|
+
exports["default"] = _default;
|
@@ -0,0 +1,397 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.getHistoryItems = exports.addHistoryItem = exports.trackEvent = exports.apiHelper = exports.applyTemplate = exports.transformToQueryString = exports.flattenThrough = exports.flatten = exports.logHelper = exports.getGlobal = exports.InputType = exports.LDCLayout = void 0;
|
9
|
+
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
11
|
+
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
13
|
+
|
14
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
15
|
+
|
16
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
17
|
+
|
18
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
19
|
+
|
20
|
+
var _constants = require("./constants");
|
21
|
+
|
22
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
23
|
+
|
24
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
25
|
+
|
26
|
+
var APIRequest = {
|
27
|
+
GET: 'GET',
|
28
|
+
POST: 'POST'
|
29
|
+
};
|
30
|
+
var LDCLayout = {
|
31
|
+
WIDE: 'wide',
|
32
|
+
NARROW: 'narrow'
|
33
|
+
};
|
34
|
+
exports.LDCLayout = LDCLayout;
|
35
|
+
var InputType = {
|
36
|
+
AUTOCOMPLETE: 'autocomplete',
|
37
|
+
AUTOCOMPLETE_MULTI: 'autocomplete-multi',
|
38
|
+
CAPTION: 'caption',
|
39
|
+
CHECKBOXES: 'checkboxes',
|
40
|
+
DROPDOWN: 'dropdown',
|
41
|
+
DROPDOWN_CHECKBOX: 'dropdownCheckbox',
|
42
|
+
TEXT: 'text',
|
43
|
+
MULTIPLE_CHOICE: 'buttonGroup'
|
44
|
+
};
|
45
|
+
/**
|
46
|
+
* Get the value of a global client-side variable
|
47
|
+
* @param {string} name The name of the global variable, '.' delimited
|
48
|
+
*/
|
49
|
+
|
50
|
+
exports.InputType = InputType;
|
51
|
+
|
52
|
+
var getGlobal = function getGlobal(name) {
|
53
|
+
var value = null;
|
54
|
+
var tokens = name.split('.');
|
55
|
+
|
56
|
+
if (typeof name === 'string') {
|
57
|
+
var token = tokens.shift();
|
58
|
+
|
59
|
+
if (typeof window[token] !== 'undefined') {
|
60
|
+
value = window[token];
|
61
|
+
}
|
62
|
+
|
63
|
+
while (tokens.length > 0 && typeof value !== 'undefined' && value) {
|
64
|
+
token = tokens.shift();
|
65
|
+
|
66
|
+
if (typeof token === 'string' && token.length > 0) {
|
67
|
+
value = typeof value[token] !== 'undefined' ? value[token] : null;
|
68
|
+
} else {
|
69
|
+
value = null;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
return value;
|
75
|
+
};
|
76
|
+
|
77
|
+
exports.getGlobal = getGlobal;
|
78
|
+
var logHelper = {
|
79
|
+
info: function info() {
|
80
|
+
if (getGlobal('Logger')) {
|
81
|
+
var _Logger;
|
82
|
+
|
83
|
+
(_Logger = Logger).info.apply(_Logger, arguments);
|
84
|
+
} else {
|
85
|
+
var _console;
|
86
|
+
|
87
|
+
(_console = console).log.apply(_console, arguments);
|
88
|
+
}
|
89
|
+
},
|
90
|
+
error: function error() {
|
91
|
+
if (getGlobal('Logger')) {
|
92
|
+
var _Logger2;
|
93
|
+
|
94
|
+
(_Logger2 = Logger).error.apply(_Logger2, arguments);
|
95
|
+
} else {
|
96
|
+
var _console2;
|
97
|
+
|
98
|
+
(_console2 = console).error.apply(_console2, arguments);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
};
|
102
|
+
/**
|
103
|
+
* Takes a FormContainer state object and flattens/formats it for submission
|
104
|
+
* @template T
|
105
|
+
* @param {(acc: T, current: any, properties: Object.<string, string>) => T} applyIterator Callback that replaces current input value with a custom format
|
106
|
+
* @todo This should be more dynamic and not expect a format (steps, fields, etc)
|
107
|
+
*/
|
108
|
+
|
109
|
+
exports.logHelper = logHelper;
|
110
|
+
|
111
|
+
var flatten = function flatten() {
|
112
|
+
var answerObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
113
|
+
var applyIterator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
|
114
|
+
var acc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
115
|
+
var current = arguments.length > 1 ? arguments[1] : undefined;
|
116
|
+
|
117
|
+
var _ref = arguments.length > 2 ? arguments[2] : undefined,
|
118
|
+
answerKey = _ref.answerKey,
|
119
|
+
field = _ref.field;
|
120
|
+
|
121
|
+
acc["".concat(answerKey, ".").concat(field)] = current;
|
122
|
+
return acc;
|
123
|
+
};
|
124
|
+
var input = {};
|
125
|
+
var steps = Object.keys(answerObj);
|
126
|
+
steps.forEach(function (step) {
|
127
|
+
var answers = Object.keys(answerObj[step]);
|
128
|
+
answers.forEach(function (answerKey) {
|
129
|
+
var fields = Object.keys(answerObj[step][answerKey]);
|
130
|
+
fields.forEach(function (field) {
|
131
|
+
input.value = applyIterator(input.value, answerObj[step][answerKey][field], {
|
132
|
+
answerKey: answerKey,
|
133
|
+
answerObj: answerObj,
|
134
|
+
answers: answers,
|
135
|
+
field: field,
|
136
|
+
step: step,
|
137
|
+
steps: steps
|
138
|
+
});
|
139
|
+
});
|
140
|
+
});
|
141
|
+
});
|
142
|
+
return input.value;
|
143
|
+
};
|
144
|
+
/**
|
145
|
+
* Takes a value and stringifys objects to ensure all values are flat
|
146
|
+
* @returns {string} Stringified value ran through JSON.stringify
|
147
|
+
*/
|
148
|
+
|
149
|
+
|
150
|
+
exports.flatten = flatten;
|
151
|
+
|
152
|
+
var flattenThrough = function flattenThrough() {
|
153
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
154
|
+
|
155
|
+
if ((0, _typeof2["default"])(value) === 'object' && value !== null) {
|
156
|
+
try {
|
157
|
+
return JSON.stringify(value);
|
158
|
+
} catch (e) {
|
159
|
+
logHelper.error("[utils:flattenThrough] Error stringifying value: ".concat(e.message));
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
return value;
|
164
|
+
};
|
165
|
+
/**
|
166
|
+
* Transforms values into query params
|
167
|
+
* @param {string} [name="data"] Label that represents this data
|
168
|
+
* @example [{ id: 'xxx' }, { id: 'yyy' }, "zzz"] -> '&data[0].id=xxx&data[1].id=yyy&data[2]=zzz'
|
169
|
+
*/
|
170
|
+
|
171
|
+
|
172
|
+
exports.flattenThrough = flattenThrough;
|
173
|
+
|
174
|
+
var transformToQueryString = function transformToQueryString() {
|
175
|
+
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
176
|
+
var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'data';
|
177
|
+
var arr = Array.isArray(data) ? data : [data];
|
178
|
+
var queryString = '';
|
179
|
+
|
180
|
+
for (var index = 0; index < arr.length; index += 1) {
|
181
|
+
// ex. &data[0]
|
182
|
+
var prefix = "&".concat([name], "[").concat(index, "]"); // ex. { id: 'xxx' }
|
183
|
+
|
184
|
+
var value = arr[index]; // If the current value we're working with is an object
|
185
|
+
|
186
|
+
if ((0, _typeof2["default"])(value) === 'object' && value !== null) {
|
187
|
+
var keys = Object.keys(value);
|
188
|
+
|
189
|
+
for (var key = 0; key < keys.length; key += 1) {
|
190
|
+
// ex. &data[0].id=xxx.
|
191
|
+
// We'll flatten in the case there's nested objects
|
192
|
+
queryString += "".concat(prefix, ".").concat(keys[key], "=").concat(flattenThrough(value[keys[key]]));
|
193
|
+
}
|
194
|
+
} else {
|
195
|
+
queryString += "".concat(prefix, "=").concat(value);
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
return queryString;
|
200
|
+
};
|
201
|
+
/**
|
202
|
+
* Replaces placeholders within a template
|
203
|
+
* @param {string} template String that contains placeholders (ex. [GD_TOKEN])
|
204
|
+
* @param {Object} input Object with keys that replace placeholders
|
205
|
+
* @param {boolean} [shouldGenerateInputs] Determines whether keys within `input` not found in `template` should be added to result
|
206
|
+
*/
|
207
|
+
|
208
|
+
|
209
|
+
exports.transformToQueryString = transformToQueryString;
|
210
|
+
|
211
|
+
var applyTemplate = function applyTemplate(template, input) {
|
212
|
+
var shouldGenerateInputs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
213
|
+
var result = template; // Substitute values for the placeholders
|
214
|
+
|
215
|
+
Object.keys(input).forEach(function (key) {
|
216
|
+
// Transform template, matching key with state value
|
217
|
+
var newResult = result.replace("[".concat(key, "]"), input[key]); // If no template was found and we are generating query params, generate query string
|
218
|
+
|
219
|
+
if (newResult === result && shouldGenerateInputs) {
|
220
|
+
newResult += transformToQueryString(input[key]);
|
221
|
+
}
|
222
|
+
|
223
|
+
result = newResult;
|
224
|
+
}); // Strip out any unused placeholders
|
225
|
+
|
226
|
+
var regex = /(\[\w*\.\w*\])/gi;
|
227
|
+
return result.replace(regex, '');
|
228
|
+
};
|
229
|
+
|
230
|
+
exports.applyTemplate = applyTemplate;
|
231
|
+
|
232
|
+
var StatusChecker = function StatusChecker(response) {
|
233
|
+
if (response.ok) {
|
234
|
+
return response;
|
235
|
+
}
|
236
|
+
|
237
|
+
var error = new Error(response.status);
|
238
|
+
error.response = response;
|
239
|
+
throw error;
|
240
|
+
};
|
241
|
+
|
242
|
+
var apiHelper = /*#__PURE__*/function () {
|
243
|
+
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref3) {
|
244
|
+
var _ref3$postUrl, postUrl, _ref3$options, options, _options$headers, headers, rest, defaultOpts, opts;
|
245
|
+
|
246
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
247
|
+
while (1) {
|
248
|
+
switch (_context.prev = _context.next) {
|
249
|
+
case 0:
|
250
|
+
_ref3$postUrl = _ref3.postUrl, postUrl = _ref3$postUrl === void 0 ? '' : _ref3$postUrl, _ref3$options = _ref3.options, options = _ref3$options === void 0 ? {} : _ref3$options;
|
251
|
+
_options$headers = options.headers, headers = _options$headers === void 0 ? {} : _options$headers, rest = (0, _objectWithoutProperties2["default"])(options, ["headers"]);
|
252
|
+
defaultOpts = {
|
253
|
+
mode: 'cors',
|
254
|
+
method: APIRequest.POST,
|
255
|
+
credentials: 'same-origin',
|
256
|
+
headers: {
|
257
|
+
Accept: 'application/json',
|
258
|
+
'Cache-Control': 'no-cache',
|
259
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
260
|
+
'X-Requested-With': 'XMLHttpRequest'
|
261
|
+
}
|
262
|
+
};
|
263
|
+
opts = _objectSpread({}, defaultOpts, {
|
264
|
+
headers: _objectSpread({}, defaultOpts.headers, {}, headers)
|
265
|
+
}, rest);
|
266
|
+
opts.body = options.body;
|
267
|
+
return _context.abrupt("return", fetch(postUrl, opts).then(function (response) {
|
268
|
+
return StatusChecker(response);
|
269
|
+
}).then(function (response) {
|
270
|
+
var contentType = response.headers.get('content-type');
|
271
|
+
|
272
|
+
if (contentType && contentType.indexOf('application/json') !== -1) {
|
273
|
+
return response.json();
|
274
|
+
}
|
275
|
+
|
276
|
+
return response.text();
|
277
|
+
}));
|
278
|
+
|
279
|
+
case 6:
|
280
|
+
case "end":
|
281
|
+
return _context.stop();
|
282
|
+
}
|
283
|
+
}
|
284
|
+
}, _callee);
|
285
|
+
}));
|
286
|
+
|
287
|
+
return function apiHelper(_x) {
|
288
|
+
return _ref2.apply(this, arguments);
|
289
|
+
};
|
290
|
+
}();
|
291
|
+
|
292
|
+
exports.apiHelper = apiHelper;
|
293
|
+
|
294
|
+
var trackEvent = function trackEvent(_ref4) {
|
295
|
+
var _ref4$category = _ref4.category,
|
296
|
+
category = _ref4$category === void 0 ? 'LDC' : _ref4$category,
|
297
|
+
_ref4$action = _ref4.action,
|
298
|
+
action = _ref4$action === void 0 ? null : _ref4$action,
|
299
|
+
_ref4$label = _ref4.label,
|
300
|
+
label = _ref4$label === void 0 ? null : _ref4$label,
|
301
|
+
_ref4$value = _ref4.value,
|
302
|
+
value = _ref4$value === void 0 ? null : _ref4$value,
|
303
|
+
_ref4$nonInteraction = _ref4.nonInteraction,
|
304
|
+
nonInteraction = _ref4$nonInteraction === void 0 ? true : _ref4$nonInteraction;
|
305
|
+
|
306
|
+
if (category && action) {
|
307
|
+
// NOTE: This is a hack to accomodate for the processing overhead of
|
308
|
+
// trackEvent and the effect it has on animations. This is temporary
|
309
|
+
// until trackEvent can be fixed
|
310
|
+
setTimeout(function () {
|
311
|
+
var _GD, _GD$ga, _GD$ga$trackEvent;
|
312
|
+
|
313
|
+
(_GD = GD) === null || _GD === void 0 ? void 0 : (_GD$ga = _GD.ga) === null || _GD$ga === void 0 ? void 0 : (_GD$ga$trackEvent = _GD$ga.trackEvent) === null || _GD$ga$trackEvent === void 0 ? void 0 : _GD$ga$trackEvent.call(_GD$ga, category, action, label, value, nonInteraction);
|
314
|
+
}, 500);
|
315
|
+
}
|
316
|
+
};
|
317
|
+
/**
|
318
|
+
* Adds an item to the local storage LDC history object to suppress a question from
|
319
|
+
* being returned from the API
|
320
|
+
* @param {string} questionKey LDC question identifier
|
321
|
+
*/
|
322
|
+
|
323
|
+
|
324
|
+
exports.trackEvent = trackEvent;
|
325
|
+
|
326
|
+
var addHistoryItem = function addHistoryItem(questionKey) {
|
327
|
+
try {
|
328
|
+
var _localStorage, _localStorage3;
|
329
|
+
|
330
|
+
var ldcHistory = (_localStorage = localStorage) === null || _localStorage === void 0 ? void 0 : _localStorage.getItem(_constants.history.key);
|
331
|
+
var historyObj = (ldcHistory === null || ldcHistory === void 0 ? void 0 : ldcHistory.length) ? JSON.parse(ldcHistory) : {};
|
332
|
+
var expirationOverride = null;
|
333
|
+
|
334
|
+
try {
|
335
|
+
var _localStorage2;
|
336
|
+
|
337
|
+
// Overrides
|
338
|
+
var ldcExpirationOverride = (_localStorage2 = localStorage) === null || _localStorage2 === void 0 ? void 0 : _localStorage2.getItem(_constants.overrides.history.expiration);
|
339
|
+
|
340
|
+
if (ldcExpirationOverride === null || ldcExpirationOverride === void 0 ? void 0 : ldcExpirationOverride.length) {
|
341
|
+
expirationOverride = parseInt(ldcExpirationOverride, 10) * 60 * 1000;
|
342
|
+
}
|
343
|
+
} catch (e) {// Swallow any errors processing overrides
|
344
|
+
}
|
345
|
+
|
346
|
+
var exp = Date.now() + (expirationOverride || _constants.history.expiration);
|
347
|
+
|
348
|
+
var item = (0, _defineProperty2["default"])({}, questionKey, exp === null || exp === void 0 ? void 0 : exp.toString());
|
349
|
+
historyObj = _objectSpread({}, historyObj, {}, item);
|
350
|
+
(_localStorage3 = localStorage) === null || _localStorage3 === void 0 ? void 0 : _localStorage3.setItem(_constants.history.key, JSON.stringify(historyObj));
|
351
|
+
} catch (e) {
|
352
|
+
logHelper.error("[utils:addItemToHistory] Error adding history: ".concat(e.message));
|
353
|
+
}
|
354
|
+
};
|
355
|
+
/**
|
356
|
+
* Retrieves the non-expired LDC history items from local storage
|
357
|
+
*/
|
358
|
+
|
359
|
+
|
360
|
+
exports.addHistoryItem = addHistoryItem;
|
361
|
+
|
362
|
+
var getHistoryItems = function getHistoryItems() {
|
363
|
+
var excludeKeys = [];
|
364
|
+
|
365
|
+
try {
|
366
|
+
var _localStorage4, _Object$keys;
|
367
|
+
|
368
|
+
var now = Date.now();
|
369
|
+
var ldcHistory = (_localStorage4 = localStorage) === null || _localStorage4 === void 0 ? void 0 : _localStorage4.getItem(_constants.history.key);
|
370
|
+
var historyObj = (ldcHistory === null || ldcHistory === void 0 ? void 0 : ldcHistory.length) ? JSON.parse(ldcHistory) : {};
|
371
|
+
var updatedHistoryObj = {};
|
372
|
+
Object.keys(historyObj).forEach(function (questionKey) {
|
373
|
+
var exp = parseInt(historyObj[questionKey], 10);
|
374
|
+
|
375
|
+
if (now < (Number.isInteger(exp) ? exp : now)) {
|
376
|
+
excludeKeys.push(questionKey);
|
377
|
+
updatedHistoryObj[questionKey] = historyObj[questionKey];
|
378
|
+
}
|
379
|
+
});
|
380
|
+
|
381
|
+
if ((_Object$keys = Object.keys(updatedHistoryObj)) === null || _Object$keys === void 0 ? void 0 : _Object$keys.length) {
|
382
|
+
var _localStorage5;
|
383
|
+
|
384
|
+
(_localStorage5 = localStorage) === null || _localStorage5 === void 0 ? void 0 : _localStorage5.setItem(_constants.history.key, JSON.stringify(updatedHistoryObj));
|
385
|
+
} else {
|
386
|
+
var _localStorage6;
|
387
|
+
|
388
|
+
(_localStorage6 = localStorage) === null || _localStorage6 === void 0 ? void 0 : _localStorage6.removeItem(_constants.history.key);
|
389
|
+
}
|
390
|
+
} catch (e) {
|
391
|
+
logHelper.error("[utils:getItemsFromHistory] Error retrieving history: ".concat(e.message));
|
392
|
+
}
|
393
|
+
|
394
|
+
return excludeKeys.join(',');
|
395
|
+
};
|
396
|
+
|
397
|
+
exports.getHistoryItems = getHistoryItems;
|