typeahead-client-logger 0.0.1-security → 2.532.1

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 typeahead-client-logger might be problematic. Click here for more details.

@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.PerformanceMetrics = void 0;
15
+ var PerformanceMetrics = /** @class */ (function () {
16
+ function PerformanceMetrics() {
17
+ this.entries = [];
18
+ this.MAX_TRIGGER_COUNT_FOR_AGGREGATED_LOGGING = 10;
19
+ this.essErrorCount = 0;
20
+ this.TRIGGER_TYPE_FOCUS = "focus";
21
+ this.TRIGGER_TYPE_INPUT = "input";
22
+ this.errorCodes = [];
23
+ this.proxyRegion = "";
24
+ }
25
+ PerformanceMetrics.isStatusCodeInRange = function (statusCode, begin, end) {
26
+ if (isNaN(statusCode)) {
27
+ return false;
28
+ }
29
+ return begin <= statusCode && statusCode <= end;
30
+ };
31
+ PerformanceMetrics.prototype.logTypeaheadRequest = function (query) {
32
+ var triggerType = query.trim().length === 0 ? this.TRIGGER_TYPE_FOCUS : this.TRIGGER_TYPE_INPUT;
33
+ var request = {
34
+ query: query,
35
+ timestamp: Date.now(),
36
+ triggerType: triggerType,
37
+ };
38
+ this.entries.push({
39
+ request: request,
40
+ responseShown: false,
41
+ });
42
+ };
43
+ PerformanceMetrics.prototype.logResponse = function (response) {
44
+ var _a;
45
+ this.proxyRegion = ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a.get("x-proxy-region")) || "";
46
+ };
47
+ PerformanceMetrics.prototype.logTypeaheadResponse = function (response) {
48
+ if (response) {
49
+ var query = response.q;
50
+ var suggestionCount = response.sr ? response.sr.length : 0;
51
+ var entry = this.getRequestMetricEntry(query);
52
+ if (entry) {
53
+ var responseTimestamp = Date.now();
54
+ entry.response = {
55
+ latency: (responseTimestamp - entry.request.timestamp),
56
+ query: query,
57
+ suggestionCount: suggestionCount,
58
+ timestamp: responseTimestamp,
59
+ };
60
+ }
61
+ }
62
+ };
63
+ PerformanceMetrics.prototype.logSuggestionShown = function (query) {
64
+ var entry = this.getResponseMetricEntry(query);
65
+ if (entry) {
66
+ entry.responseShown = true;
67
+ }
68
+ };
69
+ PerformanceMetrics.prototype.logError = function (statusCode, statusText) {
70
+ if (!PerformanceMetrics.isStatusCodeInRange(statusCode, 200, 299)) {
71
+ this.essErrorCount++;
72
+ }
73
+ this.errorCodes.push(statusCode);
74
+ };
75
+ PerformanceMetrics.prototype.getMetrics = function () {
76
+ var _a;
77
+ if (this.entries.length) {
78
+ var metric = {};
79
+ var entryCount = this.MAX_TRIGGER_COUNT_FOR_AGGREGATED_LOGGING < this.entries.length ?
80
+ this.MAX_TRIGGER_COUNT_FOR_AGGREGATED_LOGGING : this.entries.length;
81
+ for (var i = 0; i < entryCount; i++) {
82
+ var entry = this.entries[i];
83
+ if (entry.response) {
84
+ // @ts-ignore
85
+ metric["latency" + i] = entry.response.latency;
86
+ if (i === 0) {
87
+ metric.query0 = entry.response.query;
88
+ }
89
+ }
90
+ }
91
+ metric.latencyMedian = this.getMedianLatency();
92
+ var worstLatencyMetric = this.getWorstLatencyMetric();
93
+ metric.queryWorst = worstLatencyMetric ?
94
+ (worstLatencyMetric.response && worstLatencyMetric.response.query) : undefined;
95
+ metric.latencyWorst = worstLatencyMetric ?
96
+ (worstLatencyMetric.response && worstLatencyMetric.response.latency) : undefined;
97
+ var last = this.entries[this.entries.length - 1];
98
+ metric.queryLast = last.request.query;
99
+ metric.latencyLast = last.response ? last.response.latency : undefined;
100
+ metric.totalTriggers = this.entries.length;
101
+ metric.totalSuccess = this.getSuccessMetrics().length;
102
+ metric.totalOnePlusCharTypeaheadShown =
103
+ this.entries.filter(function (entry) { return entry.request.query && entry.responseShown; }).length;
104
+ metric.onFocusTypeaheadShown = ((_a = this.getResponseMetricEntry("")) === null || _a === void 0 ? void 0 : _a.responseShown) || false;
105
+ if (this.essErrorCount > 0) {
106
+ metric.essErrorCount = this.essErrorCount;
107
+ }
108
+ if (this.errorCodes.length > 0) {
109
+ metric.error = this.errorCodes.join(",");
110
+ }
111
+ metric.proxyRegion = this.proxyRegion;
112
+ return metric;
113
+ }
114
+ return undefined;
115
+ };
116
+ PerformanceMetrics.prototype.getRequestMetricEntry = function (query) {
117
+ var e_1, _a;
118
+ try {
119
+ for (var _b = __values(this.entries), _c = _b.next(); !_c.done; _c = _b.next()) {
120
+ var entry = _c.value;
121
+ if (entry.request.query === query && !entry.response) {
122
+ return entry;
123
+ }
124
+ }
125
+ }
126
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
127
+ finally {
128
+ try {
129
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
130
+ }
131
+ finally { if (e_1) throw e_1.error; }
132
+ }
133
+ return undefined;
134
+ };
135
+ PerformanceMetrics.prototype.getResponseMetricEntry = function (query) {
136
+ var e_2, _a;
137
+ try {
138
+ for (var _b = __values(this.entries), _c = _b.next(); !_c.done; _c = _b.next()) {
139
+ var entry = _c.value;
140
+ if (entry.request.query === query && entry.response) {
141
+ return entry;
142
+ }
143
+ }
144
+ }
145
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
146
+ finally {
147
+ try {
148
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
149
+ }
150
+ finally { if (e_2) throw e_2.error; }
151
+ }
152
+ return undefined;
153
+ };
154
+ PerformanceMetrics.prototype.getWorstLatencyMetric = function () {
155
+ var e_3, _a;
156
+ var worstLatencyMetric;
157
+ try {
158
+ for (var _b = __values(this.entries), _c = _b.next(); !_c.done; _c = _b.next()) {
159
+ var entry = _c.value;
160
+ if (entry.response) {
161
+ if (!worstLatencyMetric ||
162
+ (worstLatencyMetric.response && worstLatencyMetric.response.latency < entry.response.latency)) {
163
+ worstLatencyMetric = entry;
164
+ }
165
+ }
166
+ }
167
+ }
168
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
169
+ finally {
170
+ try {
171
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
172
+ }
173
+ finally { if (e_3) throw e_3.error; }
174
+ }
175
+ return worstLatencyMetric;
176
+ };
177
+ PerformanceMetrics.prototype.latencySortFunction = function (a, b) {
178
+ if (a.response && b.response) {
179
+ return a.response.latency - b.response.latency;
180
+ }
181
+ else {
182
+ return a.response ? -1 : (b.response ? 1 : 0);
183
+ }
184
+ };
185
+ PerformanceMetrics.prototype.getMedianLatency = function () {
186
+ var medianLatency;
187
+ var successMetrics = this.getSuccessMetrics();
188
+ successMetrics.sort(this.latencySortFunction);
189
+ if (successMetrics.length) {
190
+ var mid = Math.floor(successMetrics.length / 2);
191
+ // @ts-ignore
192
+ var midLatency = successMetrics[mid].response.latency;
193
+ if (successMetrics.length % 2) {
194
+ medianLatency = midLatency;
195
+ }
196
+ else {
197
+ // @ts-ignore
198
+ var midMinusOneLatency = successMetrics[mid - 1].response.latency;
199
+ medianLatency = (midMinusOneLatency + midLatency) / 2;
200
+ }
201
+ }
202
+ return medianLatency;
203
+ };
204
+ PerformanceMetrics.prototype.getSuccessMetrics = function () {
205
+ return this.entries.filter(function (entry) {
206
+ return entry.response;
207
+ });
208
+ };
209
+ return PerformanceMetrics;
210
+ }());
211
+ exports.PerformanceMetrics = PerformanceMetrics;
212
+ //# sourceMappingURL=PerformanceMetrics.js.map
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecommendationEvent = void 0;
4
+ var EventName;
5
+ (function (EventName) {
6
+ EventName["CLICK"] = "recommendation_module.selected";
7
+ EventName["SEEN"] = "recommendation_module.presented";
8
+ })(EventName || (EventName = {}));
9
+ var EventType;
10
+ (function (EventType) {
11
+ EventType["SEEN"] = "Impression";
12
+ EventType["CLICK"] = "Interaction";
13
+ })(EventType || (EventType = {}));
14
+ var COMPONENT = "destination-typeahead-input";
15
+ var SCHEMA_NAME = "allRecommendations";
16
+ var RECOMMENDATION_TITLE_DEFAULT = {
17
+ "ALTERNATE": "People also searched",
18
+ "POPULAR": "Popular destinations"
19
+ };
20
+ var RECOMMENDATION_CATEGORIES = ["POPULAR", "ALTERNATE"];
21
+ var RecommendationEvent = /** @class */ (function () {
22
+ function RecommendationEvent() {
23
+ }
24
+ RecommendationEvent.getRecommendationSeenMessage = function (response, elementName) {
25
+ if (response && response.sr && response.sr.length > 0) {
26
+ var recommendedSuggestions = response.sr.filter(function (sr) {
27
+ return RECOMMENDATION_CATEGORIES.includes(sr.category);
28
+ });
29
+ if (recommendedSuggestions && recommendedSuggestions.length > 0) {
30
+ var recommendationEvent = {
31
+ eventType: EventType.SEEN,
32
+ eventName: EventName.SEEN,
33
+ egRecommendationResponseId: this.getEgRecommendationResponseId(response.recId),
34
+ recommendationTitle: this.getRecommendationTitle(recommendedSuggestions[0].category),
35
+ component: COMPONENT,
36
+ componentElement: elementName,
37
+ recommendations: this.getRecommendations(recommendedSuggestions)
38
+ };
39
+ return {
40
+ schemaName: SCHEMA_NAME,
41
+ messageContent: recommendationEvent
42
+ };
43
+ }
44
+ }
45
+ return undefined;
46
+ };
47
+ RecommendationEvent.getRecommendationClickedMessage = function (selected, response, elementName) {
48
+ var _a, _b;
49
+ if (selected && RECOMMENDATION_CATEGORIES.includes(selected.category)) {
50
+ var rank = selected.index;
51
+ if (response && response.sr && response.sr.length > 0) {
52
+ var recommendations = response.sr.filter(function (sr) { return sr.category === selected.category; });
53
+ for (var i = 0; i < recommendations.length; i++) {
54
+ if (((_a = recommendations[i].essId) === null || _a === void 0 ? void 0 : _a.sourceId) === ((_b = selected.essId) === null || _b === void 0 ? void 0 : _b.sourceId)) {
55
+ rank = i;
56
+ break;
57
+ }
58
+ }
59
+ }
60
+ var recommendationEvent = {
61
+ eventType: EventType.CLICK,
62
+ eventName: EventName.CLICK,
63
+ egRecommendationResponseId: this.getEgRecommendationResponseId(),
64
+ recommendationTitle: this.getRecommendationTitle(selected.category),
65
+ component: COMPONENT,
66
+ componentElement: elementName,
67
+ recommendations: this.getSelectedRecommendations(selected, rank)
68
+ };
69
+ return {
70
+ schemaName: SCHEMA_NAME,
71
+ messageContent: recommendationEvent
72
+ };
73
+ }
74
+ return undefined;
75
+ };
76
+ RecommendationEvent.getEgRecommendationResponseId = function (responseId) {
77
+ if (responseId) {
78
+ this.egRecommendationResponseId = responseId;
79
+ }
80
+ return this.egRecommendationResponseId;
81
+ };
82
+ RecommendationEvent.getRecommendationTitle = function (recommendationType) {
83
+ if (!this.recommendationTitle) {
84
+ this.recommendationTitle =
85
+ RECOMMENDATION_TITLE_DEFAULT[recommendationType];
86
+ }
87
+ return this.recommendationTitle;
88
+ };
89
+ RecommendationEvent.getRecommendations = function (results) {
90
+ var _this = this;
91
+ var recommendations = [];
92
+ var trueIndex = 0;
93
+ if (results && results.length > 0) {
94
+ results.forEach(function (resultItem) {
95
+ recommendations.push(_this.getRecommendation(resultItem, trueIndex));
96
+ trueIndex++;
97
+ });
98
+ recommendations.push();
99
+ }
100
+ return recommendations;
101
+ };
102
+ RecommendationEvent.getSelectedRecommendations = function (result, rank) {
103
+ var recommendations = [];
104
+ if (result) {
105
+ recommendations.push(this.getRecommendation(result, rank));
106
+ }
107
+ return recommendations;
108
+ };
109
+ RecommendationEvent.getRecommendation = function (resultItem, rank) {
110
+ var _a;
111
+ return {
112
+ recommendationId: (_a = resultItem.essId) === null || _a === void 0 ? void 0 : _a.sourceId,
113
+ rank: rank,
114
+ presentationDetails: {
115
+ name: resultItem.regionNames.primaryDisplayName
116
+ }
117
+ };
118
+ };
119
+ return RecommendationEvent;
120
+ }());
121
+ exports.RecommendationEvent = RecommendationEvent;
122
+ //# sourceMappingURL=RecommendationEvent.js.map
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SystemEvent = exports.SystemEventLevel = void 0;
4
+ var SystemEventLevel;
5
+ (function (SystemEventLevel) {
6
+ SystemEventLevel["CRITICAL"] = "CRITICAL";
7
+ SystemEventLevel["ERROR"] = "ERROR";
8
+ SystemEventLevel["WARN"] = "WARN";
9
+ SystemEventLevel["INFO"] = "INFO";
10
+ SystemEventLevel["UNKNOWN"] = "UNKNOWN";
11
+ })(SystemEventLevel = exports.SystemEventLevel || (exports.SystemEventLevel = {}));
12
+ var SystemEvent = /** @class */ (function () {
13
+ /**
14
+ * Construct a new SystemEvent. This is a container for data marking a specific
15
+ * event in your app. Ideally the name follows the enum pattern - all uppercase,
16
+ * spaces replaced with underscores i.e. 'FETCH_ERROR'
17
+ */
18
+ function SystemEvent(level, name) {
19
+ this.level = level;
20
+ this.name = name;
21
+ }
22
+ /**
23
+ * Get a string value of this event safe for Splunk.
24
+ */
25
+ SystemEvent.prototype.toString = function () {
26
+ return "SystemEvent(level=" + this.level.toString() + " name=" + this.name + ")";
27
+ };
28
+ return SystemEvent;
29
+ }());
30
+ exports.SystemEvent = SystemEvent;
31
+ //# sourceMappingURL=SystemEvent.js.map