@maui-mf/app-auth 0.0.1-security → 10.0.0-alpha.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of @maui-mf/app-auth might be problematic. Click here for more details.

package/index.js ADDED
@@ -0,0 +1,866 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.Link = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var classnames_1 = require("classnames");
6
+ var React = require("react");
7
+ require("./link.css");
8
+ exports.Link = React.forwardRef(function (props, ref) {
9
+ var className = props.className, children = props.children, underlined = props.underlined, _a = props.dataTest, dataTest = _a === void 0 ? 'link' : _a, _b = props.type, type = _b === void 0 ? 'link' : _b, _c = props.appearance, appearance = _c === void 0 ? 'normal' : _c, icon = props.icon, iconPosition = props.iconPosition, disabled = props.disabled, other = tslib_1.__rest(props, ["className", "children", "underlined", "dataTest", "type", "appearance", "icon", "iconPosition", "disabled"]);
10
+ var classes = classnames_1["default"]('dsc-link', underlined && 'is-underlined', icon && 'has-icon', appearance !== 'normal' && "is-" + appearance, className, iconPosition === 'right' && 'is-right', type === 'link' && disabled && 'is-disabled');
11
+ var iconMarkup = icon && React.createElement("span", { className: "dsc-link__icon" }, icon);
12
+ return type === 'link' ? (disabled ? (React.createElement("span", tslib_1.__assign({}, other, { className: classes, "data-test": dataTest }),
13
+ iconMarkup,
14
+ children)) : (React.createElement("a", tslib_1.__assign({}, other, { className: classes, "data-test": dataTest }),
15
+ iconMarkup,
16
+ children))) : (React.createElement("button", tslib_1.__assign({}, other, { type: type, className: classes, "data-test": dataTest, ref: ref, disabled: disabled }),
17
+ iconMarkup,
18
+ children));
19
+ });
20
+
21
+
22
+
23
+
24
+ 'use strict';
25
+
26
+ Object.defineProperty(exports, '__esModule', { value: true });
27
+
28
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
29
+
30
+ var assignDefaults = _interopDefault(require('lodash.defaults'));
31
+ var merge = _interopDefault(require('lodash.merge'));
32
+ var createLogger = _interopDefault(require('@nbc-studio/debug'));
33
+ var pick = _interopDefault(require('lodash.pick'));
34
+ var React = require('react');
35
+ var React__default = _interopDefault(React);
36
+
37
+ function _typeof(obj) {
38
+ "@babel/helpers - typeof";
39
+
40
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
41
+ _typeof = function (obj) {
42
+ return typeof obj;
43
+ };
44
+ } else {
45
+ _typeof = function (obj) {
46
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
47
+ };
48
+ }
49
+
50
+ return _typeof(obj);
51
+ }
52
+
53
+ function _defineProperty(obj, key, value) {
54
+ if (key in obj) {
55
+ Object.defineProperty(obj, key, {
56
+ value: value,
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true
60
+ });
61
+ } else {
62
+ obj[key] = value;
63
+ }
64
+
65
+ return obj;
66
+ }
67
+
68
+ function ownKeys(object, enumerableOnly) {
69
+ var keys = Object.keys(object);
70
+
71
+ if (Object.getOwnPropertySymbols) {
72
+ var symbols = Object.getOwnPropertySymbols(object);
73
+ if (enumerableOnly) symbols = symbols.filter(function (sym) {
74
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
75
+ });
76
+ keys.push.apply(keys, symbols);
77
+ }
78
+
79
+ return keys;
80
+ }
81
+
82
+ function _objectSpread2(target) {
83
+ for (var i = 1; i < arguments.length; i++) {
84
+ var source = arguments[i] != null ? arguments[i] : {};
85
+
86
+ if (i % 2) {
87
+ ownKeys(Object(source), true).forEach(function (key) {
88
+ _defineProperty(target, key, source[key]);
89
+ });
90
+ } else if (Object.getOwnPropertyDescriptors) {
91
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
92
+ } else {
93
+ ownKeys(Object(source)).forEach(function (key) {
94
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
95
+ });
96
+ }
97
+ }
98
+
99
+ return target;
100
+ }
101
+
102
+ function _objectWithoutPropertiesLoose(source, excluded) {
103
+ if (source == null) return {};
104
+ var target = {};
105
+ var sourceKeys = Object.keys(source);
106
+ var key, i;
107
+
108
+ for (i = 0; i < sourceKeys.length; i++) {
109
+ key = sourceKeys[i];
110
+ if (excluded.indexOf(key) >= 0) continue;
111
+ target[key] = source[key];
112
+ }
113
+
114
+ return target;
115
+ }
116
+
117
+ function _objectWithoutProperties(source, excluded) {
118
+ if (source == null) return {};
119
+
120
+ var target = _objectWithoutPropertiesLoose(source, excluded);
121
+
122
+ var key, i;
123
+
124
+ if (Object.getOwnPropertySymbols) {
125
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
126
+
127
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
128
+ key = sourceSymbolKeys[i];
129
+ if (excluded.indexOf(key) >= 0) continue;
130
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
131
+ target[key] = source[key];
132
+ }
133
+ }
134
+
135
+ return target;
136
+ }
137
+
138
+ function _slicedToArray(arr, i) {
139
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
140
+ }
141
+
142
+ function _toConsumableArray(arr) {
143
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
144
+ }
145
+
146
+ function _arrayWithoutHoles(arr) {
147
+ if (Array.isArray(arr)) {
148
+ for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
149
+
150
+ return arr2;
151
+ }
152
+ }
153
+
154
+ function _arrayWithHoles(arr) {
155
+ if (Array.isArray(arr)) return arr;
156
+ }
157
+
158
+ function _iterableToArray(iter) {
159
+ if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
160
+ }
161
+
162
+ function _iterableToArrayLimit(arr, i) {
163
+ if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
164
+ return;
165
+ }
166
+
167
+ var _arr = [];
168
+ var _n = true;
169
+ var _d = false;
170
+ var _e = undefined;
171
+
172
+ try {
173
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
174
+ _arr.push(_s.value);
175
+
176
+ if (i && _arr.length === i) break;
177
+ }
178
+ } catch (err) {
179
+ _d = true;
180
+ _e = err;
181
+ } finally {
182
+ try {
183
+ if (!_n && _i["return"] != null) _i["return"]();
184
+ } finally {
185
+ if (_d) throw _e;
186
+ }
187
+ }
188
+
189
+ return _arr;
190
+ }
191
+
192
+ function _nonIterableSpread() {
193
+ throw new TypeError("Invalid attempt to spread non-iterable instance");
194
+ }
195
+
196
+ function _nonIterableRest() {
197
+ throw new TypeError("Invalid attempt to destructure non-iterable instance");
198
+ }
199
+
200
+ var STATE_KEY = '@@maui-analytics';
201
+ var defaultState = {
202
+ hooks: {}
203
+ };
204
+ var getGlobalState = function getGlobalState() {
205
+ var _global = window || self || global;
206
+
207
+ var state = _global[STATE_KEY];
208
+
209
+ if (!state) {
210
+ _global[STATE_KEY] = defaultState;
211
+ return defaultState;
212
+ }
213
+
214
+ return state;
215
+ };
216
+
217
+ function registerHook(name, hook) {
218
+ getGlobalState().hooks[name] = hook;
219
+ }
220
+ function getRegisteredHooks() {
221
+ return getGlobalState().hooks;
222
+ }
223
+ function removeHook(name) {
224
+ var _getGlobalState = getGlobalState(),
225
+ hooks = _getGlobalState.hooks;
226
+
227
+ delete hooks[name];
228
+ }
229
+ function clearHooks() {
230
+ getGlobalState().hooks = {};
231
+ }
232
+ function executeHooks(event) {
233
+ var hooks = Object.values(getGlobalState().hooks);
234
+ return hooks.reduce(function (result, hook) {
235
+ return hook(result);
236
+ }, event);
237
+ }
238
+ var extendContext = function extendContext(context) {
239
+ return function (event) {
240
+ return _objectSpread2(_objectSpread2({}, event), {}, {
241
+ context: merge({}, event.context, typeof context === 'function' ? context(event) : context)
242
+ });
243
+ };
244
+ };
245
+
246
+ var TaggingActions = {
247
+ pageReady: 'PR',
248
+ pageLoad: 'PL',
249
+ pageError: 'PE',
250
+ formLaunch: 'FL',
251
+ scroll: 'SC',
252
+ toolLaunch: 'TL',
253
+ faqLaunch: 'FAQL',
254
+ faqScroll: 'FAQS',
255
+ faqSearch: 'FAQSC',
256
+ faqClose: 'FAQC',
257
+ faqOpen: 'FAQO',
258
+ chatLaunch: 'CL',
259
+ searchLaunch: 'SCL',
260
+ formError: 'FE',
261
+ roadblock: 'RB',
262
+ fieldFilled: 'FF',
263
+ helpDisplayed: 'HD',
264
+ clickToCall: 'CC',
265
+ clickToEmail: 'CE',
266
+ clickToShowPhone: 'CTP',
267
+ clickToShowEmail: 'CTE',
268
+ videoLaunch: 'VL',
269
+ clickCTA: 'CCTA'
270
+ };
271
+
272
+ var concat = function concat(items, separator) {
273
+ return items.filter(function (x) {
274
+ return x;
275
+ }).join(separator) || undefined;
276
+ };
277
+
278
+ var trimObject = function trimObject(source) {
279
+ var obj = source;
280
+ Object.keys(source).forEach(function (key) {
281
+ return obj[key] === undefined && delete obj[key];
282
+ });
283
+ return obj;
284
+ };
285
+
286
+ function formatUCSId(event) {
287
+ var _event$context = event.context,
288
+ ucsId = _event$context.ucsId,
289
+ formId = _event$context.formId;
290
+
291
+ if (typeof ucsId === 'string') {
292
+ return ucsId;
293
+ }
294
+
295
+ if (typeof ucsId === 'number') {
296
+ return formId ? "UCS".concat(ucsId.toString().padStart(4, '0'), "-").concat(formId) : "UCS".concat(ucsId.toString().padStart(4, '0'));
297
+ }
298
+
299
+ return undefined;
300
+ }
301
+
302
+ function getEventName(event) {
303
+ if (event.context.technicalError) {
304
+ return 'pageError';
305
+ }
306
+
307
+ if (event.type === 'state') {
308
+ return 'pageLoad';
309
+ }
310
+
311
+ if (event.context.roadblock) {
312
+ return 'roadblock';
313
+ }
314
+
315
+ if (event.context.formError) {
316
+ return 'formError';
317
+ }
318
+
319
+ if (event.context.fieldFilled) {
320
+ return 'fieldFilled';
321
+ }
322
+
323
+ if (event.context.helpText) {
324
+ return 'helpDisplayed';
325
+ }
326
+
327
+ return event.name;
328
+ }
329
+
330
+ function getEventId(event) {
331
+ var _event$context2 = event.context,
332
+ stepType = _event$context2.stepType,
333
+ fieldFilled = _event$context2.fieldFilled,
334
+ helpText = _event$context2.helpText,
335
+ formError = _event$context2.formError,
336
+ roadblock = _event$context2.roadblock,
337
+ technicalError = _event$context2.technicalError,
338
+ formId = _event$context2.formId;
339
+
340
+ if (!formId) {
341
+ return undefined;
342
+ }
343
+
344
+ if (technicalError) {
345
+ return "".concat(TaggingActions.pageError, "-").concat(formId);
346
+ }
347
+
348
+ if (roadblock) {
349
+ return "".concat(TaggingActions.roadblock, "-").concat(formId);
350
+ }
351
+
352
+ if (formError) {
353
+ return "".concat(TaggingActions.formError, "-").concat(formId);
354
+ }
355
+
356
+ if (fieldFilled) {
357
+ return "".concat(TaggingActions.fieldFilled, "-").concat(formId);
358
+ }
359
+
360
+ if (helpText) {
361
+ return "".concat(TaggingActions.helpDisplayed, "-").concat(formId);
362
+ }
363
+
364
+ if (event.type === 'action') {
365
+ var prefix = TaggingActions[event.name];
366
+ return prefix && "".concat(prefix, "-").concat(formId);
367
+ }
368
+
369
+ if (stepType === 'first') {
370
+ return "FS-".concat(formId);
371
+ }
372
+
373
+ if (stepType === 'last') {
374
+ return "FC-".concat(formId);
375
+ }
376
+
377
+ return "ST-".concat(formId);
378
+ }
379
+
380
+ var formatSeconds = function formatSeconds(ms) {
381
+ return "".concat(Math.round(ms / 100) / 10, "s");
382
+ };
383
+
384
+ var withTaggingPlan = function withTaggingPlan(defaults) {
385
+ return function (event) {
386
+ var type = event.type;
387
+
388
+ var _assignDefaults = assignDefaults({}, event.context, defaults),
389
+ ucsId = _assignDefaults.ucsId,
390
+ formId = _assignDefaults.formId,
391
+ stepType = _assignDefaults.stepType,
392
+ stepId = _assignDefaults.stepId,
393
+ stepName = _assignDefaults.stepName,
394
+ eventSource = _assignDefaults.eventSource,
395
+ eventSourceDetail = _assignDefaults.eventSourceDetail,
396
+ flowId = _assignDefaults.flowId,
397
+ fieldFilled = _assignDefaults.fieldFilled,
398
+ formError = _assignDefaults.formError,
399
+ lob = _assignDefaults.lob,
400
+ phoneDisplayed = _assignDefaults.phoneDisplayed,
401
+ technicalError = _assignDefaults.technicalError,
402
+ productCategory = _assignDefaults.productCategory,
403
+ productName = _assignDefaults.productName,
404
+ productPricing = _assignDefaults.productPricing,
405
+ promoDetail = _assignDefaults.promoDetail,
406
+ interaction = _assignDefaults.interaction,
407
+ loadTime = _assignDefaults.loadTime,
408
+ loadTimeout = _assignDefaults.loadTimeout,
409
+ timeOnStep = _assignDefaults.timeOnStep,
410
+ timeToComplete = _assignDefaults.timeToComplete,
411
+ roadblock = _assignDefaults.roadblock,
412
+ referenceId = _assignDefaults.referenceId,
413
+ customProps = _objectWithoutProperties(_assignDefaults, ["ucsId", "formId", "stepType", "stepId", "stepName", "eventSource", "eventSourceDetail", "flowId", "fieldFilled", "formError", "lob", "phoneDisplayed", "technicalError", "productCategory", "productName", "productPricing", "promoDetail", "interaction", "loadTime", "loadTimeout", "timeOnStep", "timeToComplete", "roadblock", "referenceId"]);
414
+
415
+ var getPageName = function getPageName(step) {
416
+ return concat([eventSource, lob, formId || eventSourceDetail, step], ':');
417
+ };
418
+
419
+ var payload = _objectSpread2({
420
+ ucsId: formatUCSId(event),
421
+ ucsState: type === 'state' ? 'pv' : 'non-pv',
422
+ eventName: getEventName(event),
423
+ eventSource: eventSource,
424
+ eventSourceDetail: eventSourceDetail,
425
+ eventTime: new Date(),
426
+ eventId: getEventId(event),
427
+ interaction: interaction || (type === 'action' ? event.name : undefined),
428
+ fieldFilled: fieldFilled,
429
+ pageName: getPageName(stepName),
430
+ lob: lob,
431
+ phoneDisplayed: phoneDisplayed,
432
+ technicalError: technicalError,
433
+ stepId: stepId,
434
+ stepName: stepName,
435
+ formId: formId,
436
+ flowId: flowId,
437
+ productCategory: productCategory,
438
+ productName: productName,
439
+ productPricing: productPricing,
440
+ promoDetail: promoDetail,
441
+ loadTime: loadTime ? formatSeconds(loadTime) : undefined,
442
+ loadTimeout: loadTimeout,
443
+ timeOnStep: timeOnStep ? formatSeconds(timeOnStep) : undefined,
444
+ timeToComplete: timeToComplete ? formatSeconds(timeToComplete) : undefined,
445
+ formError: formError,
446
+ roadblock: roadblock,
447
+ referenceId: referenceId
448
+ }, customProps);
449
+
450
+ var name = type === 'state' ? payload.pageName || 'untitled state' : payload.eventName || 'untitled action';
451
+ return {
452
+ type: type,
453
+ name: name,
454
+ context: trimObject(payload)
455
+ };
456
+ };
457
+ };
458
+ var enableTagging = function enableTagging(defaults) {
459
+ registerHook('tagging', withTaggingPlan(defaults));
460
+ };
461
+ var disableTagging = function disableTagging() {
462
+ removeHook('tagging');
463
+ };
464
+
465
+ var logger = createLogger('maui-analytics');
466
+ logger.color = 'magenta';
467
+ var debug = createLogger('maui-analytics:debug');
468
+ debug.color = 'red';
469
+
470
+ var launchMappings = {
471
+ eventInfo: {
472
+ ucsId: null,
473
+ ucsState: null,
474
+ eventName: null,
475
+ eventSource: null,
476
+ eventSourceDetail: null,
477
+ eventTime: null,
478
+ eventId: null,
479
+ interaction: undefined,
480
+ technicalError: undefined,
481
+ formError: undefined,
482
+ roadblock: undefined,
483
+ fieldFilled: undefined,
484
+ fieldAnswer: undefined,
485
+ helpText: undefined
486
+ },
487
+ page: {
488
+ pageName: null,
489
+ language: null,
490
+ loadTime: null,
491
+ lob: null,
492
+ breakPoints: undefined,
493
+ scrollPortion: undefined,
494
+ category: undefined,
495
+ phoneDisplayed: undefined
496
+ },
497
+ product: {
498
+ productCategory: null,
499
+ productName: null,
500
+ productPricing: null,
501
+ promoDetail: null
502
+ },
503
+ search: {
504
+ searchTerms: null,
505
+ searchResults: null,
506
+ searchMethod: null
507
+ },
508
+ offer: {
509
+ name: null,
510
+ position: null,
511
+ step: null,
512
+ action: null
513
+ },
514
+ step: {
515
+ stepName: null,
516
+ stepId: null,
517
+ formStatus: null,
518
+ formId: null,
519
+ flowId: null,
520
+ flowDetails: null,
521
+ timeOnStep: undefined,
522
+ timeToComplete: undefined
523
+ },
524
+ user: {
525
+ mauiId: undefined,
526
+ age: undefined,
527
+ gender: undefined,
528
+ postalCode: undefined,
529
+ province: undefined,
530
+ referenceId: null,
531
+ residencyStatus: undefined,
532
+ jobStatus: undefined,
533
+ accountUsage: undefined,
534
+ fundSource: undefined,
535
+ SINinput: undefined,
536
+ taxes: undefined,
537
+ applicantNumber: undefined,
538
+ applicantId: undefined,
539
+ loginMethod: null
540
+ }
541
+ };
542
+
543
+ var isEmpty = function isEmpty(source) {
544
+ return !(source && Object.keys(source).length > 0);
545
+ };
546
+
547
+ var trimObject$1 = function trimObject(source) {
548
+ var obj = source;
549
+ Object.keys(source).forEach(function (key) {
550
+ if (obj[key] === undefined) {
551
+ delete obj[key];
552
+ } else if (obj[key] !== null && _typeof(obj[key]) === 'object') {
553
+ trimObject(obj[key]);
554
+ }
555
+ });
556
+ return obj;
557
+ };
558
+
559
+ var mapContext = function mapContext(context, mappings) {
560
+ return pick(context, Object.keys(mappings).filter(function (key) {
561
+ return key in mappings;
562
+ }));
563
+ };
564
+
565
+ var formatDataLayer = function formatDataLayer(event) {
566
+ var mappings = merge({}, launchMappings);
567
+ var dataObject = {
568
+ eventInfo: _objectSpread2({}, mapContext(event.context, mappings.eventInfo)),
569
+ page: _objectSpread2({}, mapContext(event.context, mappings.page)),
570
+ product: _objectSpread2({}, mapContext(event.context, mappings.product)),
571
+ search: _objectSpread2({}, mapContext(event.context, mappings.search)),
572
+ offer: _objectSpread2({}, mapContext(event.context, mappings.offer)),
573
+ step: _objectSpread2({}, mapContext(event.context, mappings.step)),
574
+ user: _objectSpread2(_objectSpread2({}, mapContext(event.context, mappings.user)), {}, {
575
+ loggedStatus: Boolean(event.context.mauiId)
576
+ }),
577
+ event: event.type === 'state' ? 'trackPageView' : 'trackEvent'
578
+ };
579
+ var filteredObject = Object.entries(dataObject).reduce(function (prev, _ref) {
580
+ var _ref2 = _slicedToArray(_ref, 2),
581
+ key = _ref2[0],
582
+ value = _ref2[1];
583
+
584
+ if (!isEmpty(value)) {
585
+ return _objectSpread2(_objectSpread2({}, prev), {}, _defineProperty({}, key, value));
586
+ }
587
+
588
+ return prev;
589
+ }, {});
590
+
591
+ if (event.type === 'state' && !event.context.technicalError) {
592
+ var template = trimObject$1(_objectSpread2({}, mappings));
593
+ return merge({}, template, filteredObject);
594
+ }
595
+
596
+ return filteredObject;
597
+ };
598
+
599
+ function track(event) {
600
+ var dataLayer = formatDataLayer(event);
601
+
602
+ if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test') {
603
+ if (typeof window.dataLayer === 'undefined') {
604
+ window.dataLayer = [];
605
+ }
606
+
607
+ window.dataLayer.push(dataLayer);
608
+ } else {
609
+ if (!window.mockDataLayer) {
610
+ window.mockDataLayer = [];
611
+ window.mockDataLayer.computedState = {};
612
+ }
613
+
614
+ window.mockDataLayer.push(dataLayer);
615
+ merge(window.mockDataLayer.computedState, dataLayer);
616
+ logger('dataLayer', dataLayer);
617
+ }
618
+ }
619
+
620
+ function trackState(page, context) {
621
+ var event = {
622
+ type: 'state',
623
+ name: page,
624
+ context: context
625
+ };
626
+ logger("trackState:".concat(page), context);
627
+ track(executeHooks(event));
628
+ }
629
+ function trackAction(action, context) {
630
+ var event = {
631
+ type: 'action',
632
+ name: action,
633
+ context: context
634
+ };
635
+ logger("trackAction:".concat(action), context);
636
+ track(executeHooks(event));
637
+ }
638
+
639
+ var ReactTaggingContext = React.createContext({});
640
+ ReactTaggingContext.displayName = 'TaggingContext';
641
+ var Tagging = function Tagging(props) {
642
+ var parent = React.useContext(ReactTaggingContext);
643
+
644
+ var children = props.children,
645
+ overrides = _objectWithoutProperties(props, ["children"]);
646
+
647
+ return React__default.createElement(ReactTaggingContext.Provider, {
648
+ value: _objectSpread2(_objectSpread2({}, parent), overrides)
649
+ }, children);
650
+ };
651
+
652
+ var TaggingFormContext = React.createContext({
653
+ formTime: undefined,
654
+ stepTime: undefined,
655
+ pushStep: function pushStep() {
656
+ return 0;
657
+ }
658
+ });
659
+ TaggingFormContext.displayName = 'TaggingFormContext';
660
+ var TaggingForm = function TaggingForm(props) {
661
+ var _useState = React.useState(Date.now()),
662
+ _useState2 = _slicedToArray(_useState, 1),
663
+ formTime = _useState2[0];
664
+
665
+ var _useState3 = React.useState(0),
666
+ _useState4 = _slicedToArray(_useState3, 2),
667
+ stepTime = _useState4[0],
668
+ setStepStartTime = _useState4[1];
669
+
670
+ var _useState5 = React.useState([]),
671
+ _useState6 = _slicedToArray(_useState5, 2),
672
+ steps = _useState6[0],
673
+ setSteps = _useState6[1];
674
+
675
+ var pushStep = function pushStep(step) {
676
+ var nextSteps = steps;
677
+ setStepStartTime(Date.now());
678
+
679
+ if (!steps.includes(step)) {
680
+ nextSteps = [].concat(_toConsumableArray(steps), [step]);
681
+ setSteps(nextSteps);
682
+ }
683
+
684
+ return nextSteps.indexOf(step);
685
+ };
686
+
687
+ var children = props.children,
688
+ context = _objectWithoutProperties(props, ["children"]);
689
+
690
+ return React__default.createElement(Tagging, Object.assign({}, context), React__default.createElement(TaggingFormContext.Provider, {
691
+ value: {
692
+ formTime: formTime,
693
+ stepTime: stepTime,
694
+ pushStep: pushStep
695
+ }
696
+ }, children));
697
+ };
698
+
699
+ var TaggingStep = function TaggingStep(_ref) {
700
+ var children = _ref.children,
701
+ props = _objectWithoutProperties(_ref, ["children"]);
702
+
703
+ var _useContext = React.useContext(TaggingFormContext),
704
+ pushStep = _useContext.pushStep;
705
+
706
+ var stepIndex = React.useMemo(function () {
707
+ return pushStep(props.stepName);
708
+ }, [props.stepName]);
709
+ return React__default.createElement(Tagging, Object.assign({}, props, {
710
+ stepId: props.stepId || stepIndex + 1,
711
+ stepType: props.stepType || (stepIndex === 0 ? 'first' : 'step')
712
+ }), children);
713
+ };
714
+
715
+ var useTagging = function useTagging() {
716
+ var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
717
+ var parent = React.useContext(ReactTaggingContext);
718
+ var form = React.useContext(TaggingFormContext);
719
+
720
+ var merged = _objectSpread2(_objectSpread2({}, parent), context);
721
+
722
+ var tagging = _objectSpread2(_objectSpread2({}, merged), {}, {
723
+ timeOnStep: merged.timeOnStep || (form.stepTime ? Date.now() - form.stepTime : undefined),
724
+ timeToComplete: merged.timeToComplete || (form.formTime && merged.stepType === 'last' ? Date.now() - form.formTime : undefined)
725
+ });
726
+
727
+ return {
728
+ context: tagging,
729
+ trackState: function trackState$1(name, params) {
730
+ trackState(name, _objectSpread2(_objectSpread2({}, tagging), params));
731
+ },
732
+ trackAction: function trackAction$1(name, params) {
733
+ trackAction(name, _objectSpread2(_objectSpread2({}, tagging), params));
734
+ }
735
+ };
736
+ };
737
+
738
+ var TrackAction = function TrackAction(_ref) {
739
+ var children = _ref.children,
740
+ _ref$type = _ref.type,
741
+ type = _ref$type === void 0 ? 'clickCTA' : _ref$type,
742
+ _ref$dependencies = _ref.dependencies,
743
+ dependencies = _ref$dependencies === void 0 ? [] : _ref$dependencies,
744
+ props = _objectWithoutProperties(_ref, ["children", "type", "dependencies"]);
745
+
746
+ var _useTagging = useTagging(props),
747
+ context = _useTagging.context,
748
+ trackAction = _useTagging.trackAction;
749
+
750
+ var name = type;
751
+
752
+ if (context.technicalError) {
753
+ name = 'pageError';
754
+ } else if (context.roadblock) {
755
+ name = 'roadblock';
756
+ } else if (context.formError) {
757
+ name = 'formError';
758
+ } else if (context.fieldFilled) {
759
+ name = 'fieldFilled';
760
+ } else if (context.helpText) {
761
+ name = 'helpDisplayed';
762
+ }
763
+
764
+ React.useEffect(function () {
765
+ return trackAction(name);
766
+ }, dependencies);
767
+ return React__default.createElement(React__default.Fragment, null, children);
768
+ };
769
+
770
+ var TrackingTimer = function TrackingTimer(_ref) {
771
+ var finished = _ref.finished,
772
+ timeout = _ref.timeout,
773
+ children = _ref.children;
774
+ var startTime = React.useMemo(Date.now, []);
775
+
776
+ var _useState = React.useState(0),
777
+ _useState2 = _slicedToArray(_useState, 2),
778
+ stopTime = _useState2[0],
779
+ setStop = _useState2[1];
780
+
781
+ var _useState3 = React.useState(false),
782
+ _useState4 = _slicedToArray(_useState3, 2),
783
+ timedOut = _useState4[0],
784
+ setTimedOut = _useState4[1];
785
+
786
+ var stopTimer = function stopTimer() {
787
+ return setStop(Date.now());
788
+ };
789
+
790
+ React.useEffect(function () {
791
+ var timer;
792
+
793
+ if (!finished) {
794
+ timer = setTimeout(function () {
795
+ setTimedOut(true);
796
+ stopTimer();
797
+ }, timeout);
798
+ } else {
799
+ stopTimer();
800
+ }
801
+
802
+ return function () {
803
+ if (timer) {
804
+ clearTimeout(timer);
805
+ stopTimer();
806
+ }
807
+ };
808
+ }, [finished]);
809
+
810
+ if (!stopTime) {
811
+ return null;
812
+ }
813
+
814
+ return React__default.createElement(Tagging, {
815
+ loadTime: stopTime - startTime,
816
+ loadTimeout: timedOut ? true : undefined
817
+ }, children);
818
+ };
819
+
820
+ function getStateName(_ref) {
821
+ var formId = _ref.formId,
822
+ stepId = _ref.stepId,
823
+ stepName = _ref.stepName;
824
+
825
+ if (formId && stepName) {
826
+ return "".concat(formId, ".").concat(stepName);
827
+ }
828
+
829
+ return stepName || stepId ? "step".concat(stepId) : 'untitled state';
830
+ }
831
+ var TrackState = function TrackState(_ref2) {
832
+ var children = _ref2.children,
833
+ _ref2$dependencies = _ref2.dependencies,
834
+ dependencies = _ref2$dependencies === void 0 ? [] : _ref2$dependencies,
835
+ props = _objectWithoutProperties(_ref2, ["children", "dependencies"]);
836
+
837
+ var _useTagging = useTagging(props),
838
+ trackState = _useTagging.trackState,
839
+ context = _useTagging.context;
840
+
841
+ React.useEffect(function () {
842
+ return trackState(getStateName(context));
843
+ }, dependencies);
844
+ return React__default.createElement(React__default.Fragment, null, children);
845
+ };
846
+
847
+ enableTagging();
848
+
849
+ exports.Tagging = Tagging;
850
+ exports.TaggingActions = TaggingActions;
851
+ exports.TaggingForm = TaggingForm;
852
+ exports.TaggingStep = TaggingStep;
853
+ exports.TrackAction = TrackAction;
854
+ exports.TrackState = TrackState;
855
+ exports.TrackingTimer = TrackingTimer;
856
+ exports.clearHooks = clearHooks;
857
+ exports.disableTagging = disableTagging;
858
+ exports.enableTagging = enableTagging;
859
+ exports.executeHooks = executeHooks;
860
+ exports.extendContext = extendContext;
861
+ exports.getRegisteredHooks = getRegisteredHooks;
862
+ exports.registerHook = registerHook;
863
+ exports.removeHook = removeHook;
864
+ exports.trackAction = trackAction;
865
+ exports.trackState = trackState;
866
+ exports.useTagging = useTagging;