firefly-sdk-ts 0.0.1-security.1 → 2.1.0

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

Potentially problematic release.


This version of firefly-sdk-ts might be problematic. Click here for more details.

Files changed (37) hide show
  1. package/.babelrc +5 -0
  2. package/LICENSE +0 -0
  3. package/dist/analytics.js +119 -0
  4. package/dist/constants/ff-api-names.js +9 -0
  5. package/dist/constants/storage-keys.js +9 -0
  6. package/dist/constants/task-status.js +9 -0
  7. package/dist/event-manager.js +77 -0
  8. package/dist/firefly.js +83 -0
  9. package/dist/helpers/browser.js +111 -0
  10. package/dist/helpers/event.js +63 -0
  11. package/dist/helpers/identity.js +38 -0
  12. package/dist/helpers/storage.js +14 -0
  13. package/dist/helpers/task.js +34 -0
  14. package/dist/index.js +27 -0
  15. package/dist/interceptors/data-layer-interceptor.js +13 -0
  16. package/dist/interceptors/event-interceptor.js +52 -0
  17. package/dist/interceptors/global-data-layer-interceptor.js +44 -0
  18. package/dist/requests/kafka-rest-proxy-request.js +19 -0
  19. package/dist copy/constants/ff-api-names.js +6 -0
  20. package/dist copy/constants/storage-keys.js +9 -0
  21. package/dist copy/constants/task-status.js +9 -0
  22. package/dist copy/event-manager.js +77 -0
  23. package/dist copy/firefly.js +83 -0
  24. package/dist copy/helpers/browser.js +111 -0
  25. package/dist copy/helpers/event.js +63 -0
  26. package/dist copy/helpers/identity.js +38 -0
  27. package/dist copy/helpers/storage.js +14 -0
  28. package/dist copy/helpers/task.js +34 -0
  29. package/dist copy/index.js +27 -0
  30. package/dist copy/interceptors/data-layer-interceptor.js +13 -0
  31. package/dist copy/interceptors/event-interceptor.js +52 -0
  32. package/dist copy/interceptors/global-data-layer-interceptor.js +44 -0
  33. package/dist copy/requests/kafka-rest-proxy-request.js +19 -0
  34. package/package.json +23 -3
  35. package/src/analytics.js +82 -0
  36. package/src/constants/ff-api-names.js +6 -0
  37. package/README.md +0 -5
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var firefly_utilities_ts_1 = require("firefly-utilities-ts");
4
+ var firefly_shared_ts_1 = require("firefly-shared-ts");
5
+ var event_1 = require("../helpers/event");
6
+ var task_1 = require("../helpers/task");
7
+ var browser_1 = require("../helpers/browser");
8
+ var EventInterceptor = /** @class */ (function () {
9
+ function EventInterceptor() {
10
+ }
11
+ EventInterceptor.prototype.apply = function (json, persistMethod, isInternalApp) {
12
+ var currentTimezone = firefly_shared_ts_1.Device.getCurrentTimezone();
13
+ var eventId = firefly_shared_ts_1.Event.createEventId();
14
+ var orientation = firefly_shared_ts_1.Browser.getScreenOrientation();
15
+ var previousPageName = (0, event_1.getPrevPageName)(persistMethod);
16
+ var previousPageType = (0, event_1.getPrevPageType)(persistMethod);
17
+ var sdkVersion = (0, event_1.getSdkVersion)();
18
+ var sessionHit = (0, event_1.getSessionHit)(persistMethod);
19
+ var systemTime = firefly_shared_ts_1.Event.getSystemTime();
20
+ var timezoneOffset = firefly_shared_ts_1.Device.getTimezoneOffset();
21
+ var oldInterceptorJSON = {
22
+ application: { id: eventId },
23
+ appState: { previousPageName: previousPageName, previousPageType: previousPageType, sessionHit: sessionHit },
24
+ guest: { currentTimezone: currentTimezone, systemTime: systemTime, timezoneOffset: timezoneOffset }
25
+ };
26
+ var newInterceptorJSON = {
27
+ application: { sdkVersion: sdkVersion },
28
+ device: { currentTimezone: currentTimezone, systemTime: systemTime, timezoneOffset: timezoneOffset },
29
+ event: { id: eventId, sessionHit: sessionHit },
30
+ view: {
31
+ previousName: previousPageName,
32
+ previousType: previousPageType,
33
+ orientation: orientation
34
+ },
35
+ browser: undefined,
36
+ task: undefined
37
+ };
38
+ if (isInternalApp) {
39
+ var sessionId = void 0, task = void 0;
40
+ sessionId = (0, browser_1.setInternalAppSessionId)();
41
+ task = (0, task_1.setInternalAppTaskNode)(json, systemTime);
42
+ newInterceptorJSON.browser = { sessionId: sessionId };
43
+ newInterceptorJSON.task = task;
44
+ }
45
+ var interceptorJSON = firefly_utilities_ts_1.Utilities.extend(oldInterceptorJSON, newInterceptorJSON);
46
+ (0, event_1.setPrevPageName)(json, persistMethod);
47
+ (0, event_1.setPrevPageType)(json, persistMethod);
48
+ return firefly_utilities_ts_1.Utilities.extend(json, interceptorJSON);
49
+ };
50
+ return EventInterceptor;
51
+ }());
52
+ exports.default = EventInterceptor;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var firefly_utilities_ts_1 = require("firefly-utilities-ts");
4
+ var firefly_shared_ts_1 = require("firefly-shared-ts");
5
+ var browser_1 = require("../helpers/browser");
6
+ var event_1 = require("../helpers/event");
7
+ var identity_1 = require("../helpers/identity");
8
+ var GlobalDataLayerInterceptor = /** @class */ (function () {
9
+ function GlobalDataLayerInterceptor() {
10
+ }
11
+ GlobalDataLayerInterceptor.prototype.apply = function (json, persistMethod) {
12
+ var cookieDisabled = firefly_shared_ts_1.Browser.isCookiesDisabled();
13
+ var isNew = (0, identity_1.isNewGuest)();
14
+ var orientation = firefly_shared_ts_1.Browser.getScreenOrientation();
15
+ var os = firefly_shared_ts_1.Browser.getOperatingSystem();
16
+ var preferredLanguage = firefly_shared_ts_1.Browser.getPreferredLanguage();
17
+ var primaryDomain = firefly_shared_ts_1.Browser.getDomain();
18
+ var referrer = (0, browser_1.getReferrer)(persistMethod);
19
+ var screenColorDepth = firefly_shared_ts_1.Browser.getScreenColorDepth();
20
+ var screenSize = { height: firefly_shared_ts_1.Browser.getScreenHeight(), width: firefly_shared_ts_1.Browser.getScreenWidth() };
21
+ var sessionId = (0, identity_1.getSessionId)(persistMethod);
22
+ var size = { height: firefly_shared_ts_1.Browser.getBrowserHeight(), width: firefly_shared_ts_1.Browser.getBrowserWidth() };
23
+ var subDomain = firefly_shared_ts_1.Browser.getSubdomain();
24
+ var type = firefly_shared_ts_1.Browser.getDeviceType();
25
+ var url = (0, browser_1.sanitizeUrl)(firefly_shared_ts_1.Browser.getCurrentUrl());
26
+ var userAgent = firefly_shared_ts_1.Browser.getName();
27
+ var viewId = (0, event_1.getViewId)(persistMethod);
28
+ var fireflyId = (0, identity_1.getVisitorId)();
29
+ var oldInterceptorJSON = {
30
+ appState: { referrer: referrer, screenOrientation: orientation, url: url, viewId: viewId, windowSize: firefly_shared_ts_1.Browser.getBrowserSize() },
31
+ guest: { browser: userAgent, cookieDisabled: cookieDisabled, deviceType: type, newVisitor: isNew, os: os, preferredLanguage: preferredLanguage, primaryDomain: primaryDomain, screenColorDepth: screenColorDepth, screenSize: firefly_shared_ts_1.Browser.getScreenSize(), session: sessionId, subDomain: subDomain, visitorId: fireflyId }
32
+ };
33
+ var newInterceptorJSON = {
34
+ browser: { cookieDisabled: cookieDisabled, orientation: orientation, preferredLanguage: preferredLanguage, primaryDomain: primaryDomain, referrer: referrer, size: size, subDomain: subDomain, url: url, userAgent: userAgent },
35
+ device: { os: os, screenColorDepth: screenColorDepth, screenSize: screenSize, type: type },
36
+ identity: { fireflyId: fireflyId, isNew: isNew, sessionId: sessionId },
37
+ view: { id: viewId }
38
+ };
39
+ var interceptorJSON = firefly_utilities_ts_1.Utilities.extend(oldInterceptorJSON, newInterceptorJSON);
40
+ return firefly_utilities_ts_1.Utilities.extend(json, interceptorJSON);
41
+ };
42
+ return GlobalDataLayerInterceptor;
43
+ }());
44
+ exports.default = GlobalDataLayerInterceptor;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendEvent = void 0;
4
+ var firefly_utilities_ts_1 = require("firefly-utilities-ts");
5
+ var firefly_utilities_helper_ts_1 = require("firefly-utilities-helper-ts");
6
+ function sendEvent(json, apiKey, schemaId, url, retries) {
7
+ var payload = [json];
8
+ if ((0, firefly_utilities_helper_ts_1.isString)(url) && (url.indexOf('/v1') > -1 && url.indexOf('/consumers/v1/ingest') === -1)) {
9
+ payload = {
10
+ schema_id: schemaId,
11
+ records: [json]
12
+ };
13
+ }
14
+ var headers = {
15
+ 'x-api-key': apiKey
16
+ };
17
+ return firefly_utilities_ts_1.Request.postJSON(payload, headers, url, retries);
18
+ }
19
+ exports.sendEvent = sendEvent;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var ffApiNames = {
4
+ internalApps: "internal_app_analytics"
5
+ };
6
+ exports.default = ffApiNames;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var storageKeys = {
4
+ DATA_LAYER: '.dataLayer',
5
+ EVENT_CONFIGURATION: '.eventConfiguration',
6
+ REGISTERED_EVENT_MANAGERS: 'registeredEventManagers',
7
+ SCHEMA: '.schema'
8
+ };
9
+ exports.default = storageKeys;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var taskStatus = {
4
+ CANCELLED: 'cancelled',
5
+ FAIL: 'fail',
6
+ INIT: 'initiated',
7
+ SUCCESS: 'success'
8
+ };
9
+ exports.default = taskStatus;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var firefly_utilities_helper_ts_1 = require("firefly-utilities-helper-ts");
7
+ var firefly_utilities_ts_1 = require("firefly-utilities-ts");
8
+ var task_status_1 = __importDefault(require("./constants/task-status"));
9
+ var storage_keys_1 = __importDefault(require("./constants/storage-keys"));
10
+ var ff_api_names_1 = __importDefault(require("./constants/ff-api-names"));
11
+ var kafka_rest_proxy_request_1 = require("./requests/kafka-rest-proxy-request");
12
+ var storage_1 = require("./helpers/storage");
13
+ var EventManager = /** @class */ (function () {
14
+ function EventManager(eventConfiguration, dataLayerInterceptor, eventInterceptor) {
15
+ this.apiKey = eventConfiguration.apiKey;
16
+ this.persistMethod = eventConfiguration.persistMethod;
17
+ this.eventManagerKey = eventConfiguration.eventManagerKey;
18
+ this.retries = eventConfiguration.retries;
19
+ this.schemaId = eventConfiguration.schemaId;
20
+ this.url = eventConfiguration.url;
21
+ this.dataLayerInterceptor = dataLayerInterceptor;
22
+ this.eventInterceptor = eventInterceptor;
23
+ }
24
+ EventManager.prototype.addEvent = function (json) {
25
+ var isInternalApp = !!((0, firefly_utilities_helper_ts_1.isString)(this.url) && this.url.includes(ff_api_names_1.default.internalApps));
26
+ var result = appendToDataLayer(this.eventManagerKey, json, this.dataLayerInterceptor, this.persistMethod);
27
+ var decoratedJson = this.eventInterceptor.apply(result, this.persistMethod, isInternalApp);
28
+ return (0, kafka_rest_proxy_request_1.sendEvent)(decoratedJson, this.apiKey, this.schemaId, this.url, this.retries);
29
+ };
30
+ EventManager.prototype.addTaskCancelEvent = function (json) {
31
+ var taskInit = { task: { status: task_status_1.default.CANCELLED } };
32
+ var modifiedJSON = firefly_utilities_ts_1.Utilities.extend(json, taskInit);
33
+ this.addEvent(modifiedJSON);
34
+ };
35
+ EventManager.prototype.addTaskFailEvent = function (json) {
36
+ var taskInit = { task: { status: task_status_1.default.FAIL } };
37
+ var modifiedJSON = firefly_utilities_ts_1.Utilities.extend(json, taskInit);
38
+ this.addEvent(modifiedJSON);
39
+ };
40
+ EventManager.prototype.addTaskInitEvent = function (json) {
41
+ var taskInit = { task: { status: task_status_1.default.INIT } };
42
+ var modifiedJSON = firefly_utilities_ts_1.Utilities.extend(json, taskInit);
43
+ this.addEvent(modifiedJSON);
44
+ };
45
+ EventManager.prototype.addTaskSuccessEvent = function (json) {
46
+ var taskInit = { task: { status: task_status_1.default.SUCCESS } };
47
+ var modifiedJSON = firefly_utilities_ts_1.Utilities.extend(json, taskInit);
48
+ this.addEvent(modifiedJSON);
49
+ };
50
+ EventManager.prototype.appendToDataLayer = function (json) {
51
+ return appendToDataLayer(this.eventManagerKey, json, this.dataLayerInterceptor, this.persistMethod);
52
+ };
53
+ EventManager.prototype.clearDataLayer = function () {
54
+ firefly_utilities_ts_1.PersistenceManager.remove(this.eventManagerKey + storage_keys_1.default.DATA_LAYER, this.persistMethod);
55
+ };
56
+ EventManager.prototype.setDataLayer = function (json) {
57
+ var decoratedJson = this.dataLayerInterceptor.apply(json);
58
+ persistDataLayer(decoratedJson, this.eventManagerKey, this.persistMethod);
59
+ };
60
+ return EventManager;
61
+ }());
62
+ exports.default = EventManager;
63
+ function appendToDataLayer(eventManagerKey, json, interceptor, persistMethod) {
64
+ var dataLayer;
65
+ var persistedDataLayer = (0, storage_1.getDataFromStorage)(eventManagerKey, persistMethod, storage_keys_1.default.DATA_LAYER);
66
+ if ((0, firefly_utilities_helper_ts_1.isObject)(persistedDataLayer)) {
67
+ dataLayer = firefly_utilities_ts_1.Utilities.extend(persistedDataLayer, json);
68
+ }
69
+ else {
70
+ dataLayer = interceptor.apply(json);
71
+ }
72
+ persistDataLayer(dataLayer, eventManagerKey, persistMethod);
73
+ return dataLayer;
74
+ }
75
+ function persistDataLayer(json, eventManagerKey, persistMethod) {
76
+ (0, storage_1.setDataToStorage)(json, eventManagerKey, persistMethod, storage_keys_1.default.DATA_LAYER);
77
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.setLoggingLevel = exports.setGlobalDataLayer = exports.registerEventManagerWithConfig = exports.registerEventManager = exports.getEventManager = void 0;
30
+ var Helper = __importStar(require("firefly-utilities-helper-ts"));
31
+ var firefly_utilities_ts_1 = require("firefly-utilities-ts");
32
+ var event_manager_1 = __importDefault(require("./event-manager"));
33
+ var storage_keys_1 = __importDefault(require("./constants/storage-keys"));
34
+ var data_layer_interceptor_1 = __importDefault(require("./interceptors/data-layer-interceptor"));
35
+ var global_data_layer_interceptor_1 = __importDefault(require("./interceptors/global-data-layer-interceptor"));
36
+ var event_interceptor_1 = __importDefault(require("./interceptors/event-interceptor"));
37
+ function getEventManager(eventConfig) {
38
+ var eventManagerKey = eventConfig.eventManagerKey, persistMethod = eventConfig.persistMethod;
39
+ var eventConfiguration = firefly_utilities_ts_1.PersistenceManager.get(eventManagerKey + storage_keys_1.default.EVENT_CONFIGURATION, persistMethod);
40
+ return createEventManager(eventConfiguration);
41
+ }
42
+ exports.getEventManager = getEventManager;
43
+ function registerEventManager(eventManagerKey, apiKey, persistMethod, retries, schemaId, url) {
44
+ var eventConfiguration = { apiKey: apiKey, eventManagerKey: eventManagerKey, persistMethod: persistMethod, retries: retries, schemaId: schemaId, url: url };
45
+ return registerEventManagerWithConfig(eventConfiguration);
46
+ }
47
+ exports.registerEventManager = registerEventManager;
48
+ function registerEventManagerWithConfig(eventConfiguration) {
49
+ var eventManagerKey = eventConfiguration.eventManagerKey, persistMethod = eventConfiguration.persistMethod;
50
+ persistEventManagerKey(eventManagerKey, persistMethod);
51
+ resetPageLoadData(persistMethod);
52
+ firefly_utilities_ts_1.PersistenceManager.set(eventManagerKey + storage_keys_1.default.EVENT_CONFIGURATION, eventConfiguration, persistMethod);
53
+ return createEventManager(eventConfiguration);
54
+ }
55
+ exports.registerEventManagerWithConfig = registerEventManagerWithConfig;
56
+ function setGlobalDataLayer(json, persistMethod) {
57
+ var globalDataLayerInterceptor = new global_data_layer_interceptor_1.default();
58
+ var decoratedJson = globalDataLayerInterceptor.apply(json, persistMethod);
59
+ var eventManagerKeys = firefly_utilities_ts_1.PersistenceManager.get(storage_keys_1.default.REGISTERED_EVENT_MANAGERS, persistMethod);
60
+ if (Helper.isArray(eventManagerKeys)) {
61
+ eventManagerKeys.forEach(function (eventManagerKey) {
62
+ var eventManager = getEventManager({ eventManagerKey: eventManagerKey, persistMethod: persistMethod });
63
+ eventManager.setDataLayer(decoratedJson);
64
+ });
65
+ }
66
+ }
67
+ exports.setGlobalDataLayer = setGlobalDataLayer;
68
+ function setLoggingLevel(logLevel) {
69
+ firefly_utilities_ts_1.Logger.initialize(logLevel);
70
+ }
71
+ exports.setLoggingLevel = setLoggingLevel;
72
+ function createEventManager(eventConfiguration) {
73
+ return new event_manager_1.default(eventConfiguration, new data_layer_interceptor_1.default(), new event_interceptor_1.default());
74
+ }
75
+ function resetPageLoadData(persistMethod) {
76
+ firefly_utilities_ts_1.FFPersistenceManager.setSessionValue('viewId', '', persistMethod);
77
+ }
78
+ function persistEventManagerKey(eventManagerKey, persistMethod) {
79
+ var eventManagerKeys = firefly_utilities_ts_1.PersistenceManager.get(storage_keys_1.default.REGISTERED_EVENT_MANAGERS, persistMethod);
80
+ var eventManagerSet = new Set(eventManagerKeys);
81
+ eventManagerSet.add(eventManagerKey);
82
+ firefly_utilities_ts_1.PersistenceManager.set(storage_keys_1.default.REGISTERED_EVENT_MANAGERS, Array.from(eventManagerSet), persistMethod);
83
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitizeUrl = exports.setInternalAppSessionId = exports.getSourceValue = exports.getReferrer = exports.getQueryParams = void 0;
4
+ var firefly_utilities_helper_ts_1 = require("firefly-utilities-helper-ts");
5
+ var firefly_utilities_ts_1 = require("firefly-utilities-ts");
6
+ var firefly_shared_ts_1 = require("firefly-shared-ts");
7
+ function assignQueryParams(queryParamsDict, queryStringParts) {
8
+ var part;
9
+ for (var i = 0; i < queryStringParts.length; i += 1) {
10
+ part = queryStringParts[i].split("=");
11
+ if (part.length === 2) {
12
+ queryParamsDict[part[0].toLowerCase()] = part[1];
13
+ }
14
+ }
15
+ }
16
+ function setParam(url, key, val) {
17
+ return url.replace(new RegExp("&" + key + "=" + val), "");
18
+ }
19
+ function stripQueryParams(url) {
20
+ if ((0, firefly_utilities_helper_ts_1.isString)(url) && url.indexOf('?') !== -1) {
21
+ url = url.split('?')[0];
22
+ }
23
+ return url;
24
+ }
25
+ function getQueryParams(url) {
26
+ var queryParams, queryStringParts, queryParamsDict;
27
+ queryParamsDict = {};
28
+ if (url.indexOf("?") > -1) {
29
+ queryParams = url.split("?")[1];
30
+ if (queryParams.indexOf("#") > -1) {
31
+ queryStringParts = queryParams.split("#");
32
+ assignQueryParams(queryParamsDict, queryStringParts);
33
+ queryStringParts = queryStringParts[1].split("&");
34
+ }
35
+ if (queryStringParts === undefined) {
36
+ queryStringParts = queryParams.split("&");
37
+ }
38
+ assignQueryParams(queryParamsDict, queryStringParts);
39
+ }
40
+ else if (url.indexOf("#") > -1) {
41
+ queryParams = url.split("#")[1];
42
+ queryStringParts = queryParams.split("&");
43
+ assignQueryParams(queryParamsDict, queryStringParts);
44
+ }
45
+ return queryParamsDict;
46
+ }
47
+ exports.getQueryParams = getQueryParams;
48
+ function getReferrer(persistMethod) {
49
+ var referrer = "";
50
+ var prevPageUrl = firefly_utilities_ts_1.FFPersistenceManager.getSessionValue('prevPageUrl', persistMethod);
51
+ var currentReferrer = stripQueryParams(document.referrer);
52
+ var currentUrl = stripQueryParams(firefly_shared_ts_1.Browser.getCurrentUrl());
53
+ prevPageUrl = ((0, firefly_utilities_helper_ts_1.isNullOrUndefined)(prevPageUrl)) ? "" : prevPageUrl;
54
+ if (!(0, firefly_utilities_helper_ts_1.isEmptyString)(currentReferrer)) {
55
+ referrer = currentReferrer;
56
+ if (!(0, firefly_utilities_helper_ts_1.isEmptyString)(prevPageUrl) && prevPageUrl !== currentUrl) {
57
+ referrer = prevPageUrl;
58
+ }
59
+ }
60
+ else if (!(0, firefly_utilities_helper_ts_1.isEmptyString)(prevPageUrl)) {
61
+ referrer = prevPageUrl;
62
+ }
63
+ firefly_utilities_ts_1.FFPersistenceManager.setSessionValue('prevPageUrl', currentUrl, persistMethod);
64
+ return referrer;
65
+ }
66
+ exports.getReferrer = getReferrer;
67
+ function getSourceValue() {
68
+ var sourceValue;
69
+ var ipad = /iPad/i;
70
+ var mobile = /Android|BlackBerry|IEMobile|iPhone|iPod|Opera Mini|NokiaBrowser|Silk|webOs|Windows Phone/i;
71
+ var nonDesktop = /Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile|NokiaBrowser|Silk|mobile|tablet/i;
72
+ var userAgent = firefly_shared_ts_1.Browser.getName();
73
+ switch (true) {
74
+ case !nonDesktop.test(userAgent):
75
+ sourceValue = 1;
76
+ break;
77
+ case mobile.test(userAgent):
78
+ sourceValue = 2;
79
+ break;
80
+ case ipad.test(userAgent):
81
+ sourceValue = 3;
82
+ break;
83
+ default:
84
+ sourceValue = 0;
85
+ break;
86
+ }
87
+ return sourceValue;
88
+ }
89
+ exports.getSourceValue = getSourceValue;
90
+ function setInternalAppSessionId() {
91
+ var sessionId = firefly_utilities_ts_1.FFPersistenceManager.getSessionStorageValue('sessionId');
92
+ if ((0, firefly_utilities_helper_ts_1.isNullOrUndefined)(sessionId)) {
93
+ sessionId = firefly_shared_ts_1.Identity.createSessionId();
94
+ firefly_utilities_ts_1.FFPersistenceManager.setSessionStorageValue('sessionId', sessionId);
95
+ }
96
+ return sessionId;
97
+ }
98
+ exports.setInternalAppSessionId = setInternalAppSessionId;
99
+ function sanitizeUrl(url) {
100
+ if ((0, firefly_utilities_helper_ts_1.isString)(url)) {
101
+ var queryParams = getQueryParams(url);
102
+ for (var key in queryParams) {
103
+ var lowerCaseKey = key.toLowerCase();
104
+ if (lowerCaseKey === 'pass' || lowerCaseKey === 'password' || lowerCaseKey === 'pwd' || lowerCaseKey === 'passwd') {
105
+ url = setParam(url, key, queryParams[key]);
106
+ }
107
+ }
108
+ }
109
+ return url;
110
+ }
111
+ exports.sanitizeUrl = sanitizeUrl;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getViewId = exports.getSessionHit = exports.getSdkVersion = exports.setPrevPageType = exports.setPrevPageName = exports.getPrevPageType = exports.getPrevPageName = void 0;
4
+ var firefly_utilities_helper_ts_1 = require("firefly-utilities-helper-ts");
5
+ var firefly_utilities_ts_1 = require("firefly-utilities-ts");
6
+ var firefly_shared_ts_1 = require("firefly-shared-ts");
7
+ var pjson = require('../../version.json');
8
+ function getPrevPageName(persistMethod) {
9
+ return firefly_utilities_ts_1.FFPersistenceManager.getSessionValue('prevPageName', persistMethod);
10
+ }
11
+ exports.getPrevPageName = getPrevPageName;
12
+ function getPrevPageType(persistMethod) {
13
+ return firefly_utilities_ts_1.FFPersistenceManager.getSessionValue('prevPageType', persistMethod);
14
+ }
15
+ exports.getPrevPageType = getPrevPageType;
16
+ function setPrevPageName(json, persistMethod) {
17
+ var pageName = '';
18
+ if ((0, firefly_utilities_helper_ts_1.isObject)(json.appState) && (0, firefly_utilities_helper_ts_1.isDefined)(json.appState.pageName)) {
19
+ pageName = json.appState.pageName;
20
+ }
21
+ else if ((0, firefly_utilities_helper_ts_1.isObject)(json.view) && (0, firefly_utilities_helper_ts_1.isDefined)(json.view.name)) {
22
+ pageName = json.view.name;
23
+ }
24
+ firefly_utilities_ts_1.FFPersistenceManager.setSessionValue('prevPageName', pageName, persistMethod);
25
+ }
26
+ exports.setPrevPageName = setPrevPageName;
27
+ function setPrevPageType(json, persistMethod) {
28
+ var pageType = '';
29
+ if ((0, firefly_utilities_helper_ts_1.isObject)(json.appState) && (0, firefly_utilities_helper_ts_1.isDefined)(json.appState.pageType)) {
30
+ pageType = json.appState.pageType;
31
+ }
32
+ else if ((0, firefly_utilities_helper_ts_1.isObject)(json.view) && (0, firefly_utilities_helper_ts_1.isDefined)(json.view.type)) {
33
+ pageType = json.view.type;
34
+ }
35
+ firefly_utilities_ts_1.FFPersistenceManager.setSessionValue('prevPageType', pageType, persistMethod);
36
+ }
37
+ exports.setPrevPageType = setPrevPageType;
38
+ function getSdkVersion() {
39
+ var sdkVersion = '';
40
+ if ((0, firefly_utilities_helper_ts_1.isString)(pjson.version) && !(0, firefly_utilities_helper_ts_1.isEmptyString)(pjson.version)) {
41
+ sdkVersion = pjson.version;
42
+ }
43
+ return sdkVersion;
44
+ }
45
+ exports.getSdkVersion = getSdkVersion;
46
+ function getSessionHit(persistMethod) {
47
+ var sessionHit;
48
+ var sessionHitCookie = firefly_utilities_ts_1.FFPersistenceManager.getSessionValue('sessionHit', persistMethod);
49
+ sessionHit = firefly_utilities_ts_1.Utilities.getNumberOrDefault(sessionHitCookie);
50
+ sessionHit += 1;
51
+ firefly_utilities_ts_1.FFPersistenceManager.setSessionValue('sessionHit', sessionHit.toString(), persistMethod);
52
+ return sessionHit.toString();
53
+ }
54
+ exports.getSessionHit = getSessionHit;
55
+ function getViewId(persistMethod) {
56
+ var viewId = firefly_utilities_ts_1.FFPersistenceManager.getSessionValue('viewId', persistMethod);
57
+ if (!(0, firefly_utilities_helper_ts_1.isString)(viewId) || (0, firefly_utilities_helper_ts_1.isEmptyString)(viewId)) {
58
+ viewId = firefly_shared_ts_1.Event.createViewId();
59
+ firefly_utilities_ts_1.FFPersistenceManager.setSessionValue('viewId', viewId, persistMethod);
60
+ }
61
+ return viewId;
62
+ }
63
+ exports.getViewId = getViewId;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNewGuest = exports.getVisitorId = exports.getSessionId = void 0;
4
+ var firefly_utilities_helper_ts_1 = require("firefly-utilities-helper-ts");
5
+ var firefly_utilities_ts_1 = require("firefly-utilities-ts");
6
+ var firefly_shared_ts_1 = require("firefly-shared-ts");
7
+ var browser_1 = require("./browser");
8
+ function setVisitorId() {
9
+ var sourceValue = (0, browser_1.getSourceValue)();
10
+ var visitorId = firefly_shared_ts_1.Identity.createVisitorId(sourceValue);
11
+ firefly_utilities_ts_1.FFPersistenceManager.setVisitorId(visitorId, 'cookies');
12
+ }
13
+ function getSessionId(persistMethod) {
14
+ var sessionHash = firefly_utilities_ts_1.FFPersistenceManager.getSessionValue('sessionHash', persistMethod);
15
+ if ((0, firefly_utilities_helper_ts_1.isNullOrUndefined)(sessionHash)) {
16
+ sessionHash = firefly_shared_ts_1.Identity.createSessionId();
17
+ firefly_utilities_ts_1.FFPersistenceManager.setSessionValue('sessionHash', sessionHash, persistMethod);
18
+ }
19
+ return sessionHash;
20
+ }
21
+ exports.getSessionId = getSessionId;
22
+ function getVisitorId() {
23
+ var visitorId = firefly_utilities_ts_1.FFPersistenceManager.getVisitorId('cookies');
24
+ if (!(0, firefly_utilities_helper_ts_1.isNullOrUndefined)(visitorId)) {
25
+ firefly_utilities_ts_1.FFPersistenceManager.setVisitorId(visitorId, 'cookies');
26
+ }
27
+ return visitorId;
28
+ }
29
+ exports.getVisitorId = getVisitorId;
30
+ function isNewGuest() {
31
+ var newGuest = false;
32
+ if ((0, firefly_utilities_helper_ts_1.isNullOrUndefined)(firefly_utilities_ts_1.FFPersistenceManager.getVisitorId('cookies'))) {
33
+ setVisitorId();
34
+ newGuest = true;
35
+ }
36
+ return newGuest;
37
+ }
38
+ exports.isNewGuest = isNewGuest;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setDataToStorage = exports.getDataFromStorage = void 0;
4
+ var firefly_utilities_ts_1 = require("firefly-utilities-ts");
5
+ function getDataFromStorage(eventManagerKey, persistMethod, storageKey) {
6
+ var method = (persistMethod === 'cookies') ? 'window' : persistMethod;
7
+ return firefly_utilities_ts_1.PersistenceManager.get(eventManagerKey + storageKey, method);
8
+ }
9
+ exports.getDataFromStorage = getDataFromStorage;
10
+ function setDataToStorage(data, eventManagerKey, persistMethod, storageKey) {
11
+ var method = (persistMethod === 'cookies') ? 'window' : persistMethod;
12
+ firefly_utilities_ts_1.PersistenceManager.set(eventManagerKey + storageKey, data, method);
13
+ }
14
+ exports.setDataToStorage = setDataToStorage;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setInternalAppTaskNode = void 0;
7
+ var firefly_utilities_ts_1 = require("firefly-utilities-ts");
8
+ var firefly_utilities_helper_ts_1 = require("firefly-utilities-helper-ts");
9
+ var task_status_1 = __importDefault(require("../constants/task-status"));
10
+ var firefly_shared_ts_1 = require("firefly-shared-ts");
11
+ function setInternalAppTaskNode(json, systemTime) {
12
+ var id, initiatedTimestamp, name, sessionTaskObj, status, taskNode;
13
+ taskNode = firefly_utilities_ts_1.Utilities.getValueFromObject(json, "task", null);
14
+ if (!(0, firefly_utilities_helper_ts_1.isNullOrUndefined)(taskNode) && !firefly_utilities_ts_1.Utilities.isEmptyObject(taskNode)) {
15
+ sessionTaskObj = firefly_utilities_ts_1.FFPersistenceManager.getSessionStorageValue('task');
16
+ id = firefly_utilities_ts_1.Utilities.getValueFromObject(sessionTaskObj, 'id', null);
17
+ initiatedTimestamp = firefly_utilities_ts_1.Utilities.getValueFromObject(sessionTaskObj, 'initiatedTimestamp', null);
18
+ name = firefly_utilities_ts_1.Utilities.getValueFromObject(taskNode, 'name', null);
19
+ status = firefly_utilities_ts_1.Utilities.getValueFromObject(taskNode, 'status', null);
20
+ if ((0, firefly_utilities_helper_ts_1.isNullOrUndefined)(id)) {
21
+ id = firefly_shared_ts_1.Event.createEventId();
22
+ initiatedTimestamp = systemTime;
23
+ name = firefly_utilities_ts_1.Utilities.getValueFromObject(taskNode, 'name', null);
24
+ firefly_utilities_ts_1.FFPersistenceManager.setSessionStorageValue('task', { id: id, initiatedTimestamp: initiatedTimestamp, name: name });
25
+ }
26
+ taskNode = { id: id, initiatedTimestamp: initiatedTimestamp, name: name };
27
+ if (!(0, firefly_utilities_helper_ts_1.isNullOrUndefined)(status) && (status === task_status_1.default.SUCCESS || status === task_status_1.default.FAIL ||
28
+ status === task_status_1.default.CANCELLED)) {
29
+ firefly_utilities_ts_1.FFPersistenceManager.setSessionStorageValue('task', null);
30
+ }
31
+ }
32
+ return taskNode;
33
+ }
34
+ exports.setInternalAppTaskNode = setInternalAppTaskNode;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ var Firefly = __importStar(require("./firefly"));
27
+ exports.default = Firefly;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var firefly_utilities_ts_1 = require("firefly-utilities-ts");
4
+ var DataLayerInterceptor = /** @class */ (function () {
5
+ function DataLayerInterceptor() {
6
+ }
7
+ DataLayerInterceptor.prototype.apply = function (json) {
8
+ var interceptorJSON = {};
9
+ return firefly_utilities_ts_1.Utilities.extend(json, interceptorJSON);
10
+ };
11
+ return DataLayerInterceptor;
12
+ }());
13
+ exports.default = DataLayerInterceptor;