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.
- package/LICENSE +21 -0
- package/README.md +23 -3
- package/build.js +128 -0
- package/dist/ClientMetricsLogger.js +69 -0
- package/dist/EssClientLogger.js +127 -0
- package/dist/EssSelectedSuggestionLogger.js +372 -0
- package/dist/Experiments.js +52 -0
- package/dist/InteractionMetrics.js +73 -0
- package/dist/PerformanceMetrics.js +212 -0
- package/dist/RecommendationEvent.js +122 -0
- package/dist/SystemEvent.js +31 -0
- package/dist/TypeaheadEvent.js +345 -0
- package/dist/TypeaheadEventLogger.js +429 -0
- package/dist/index.js +15 -0
- package/dist/utils/Optional.js +45 -0
- package/dist/utils/Utils.js +88 -0
- package/package.json +19 -3
@@ -0,0 +1,429 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
15
|
+
if (!m) return o;
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
17
|
+
try {
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
19
|
+
}
|
20
|
+
catch (error) { e = { error: error }; }
|
21
|
+
finally {
|
22
|
+
try {
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
24
|
+
}
|
25
|
+
finally { if (e) throw e.error; }
|
26
|
+
}
|
27
|
+
return ar;
|
28
|
+
};
|
29
|
+
var __spread = (this && this.__spread) || function () {
|
30
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
31
|
+
return ar;
|
32
|
+
};
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
34
|
+
exports.TypeaheadEventLogger = exports.LogType = void 0;
|
35
|
+
var RecommendationEvent_1 = require("./RecommendationEvent");
|
36
|
+
var TypeaheadEvent_1 = require("./TypeaheadEvent");
|
37
|
+
var Optional_1 = require("./utils/Optional");
|
38
|
+
var Utils_1 = require("./utils/Utils");
|
39
|
+
var LogType;
|
40
|
+
(function (LogType) {
|
41
|
+
LogType["TYPEAHEAD_FOCUS"] = "typeahead-focus";
|
42
|
+
LogType["TYPEAHEAD_SELECT"] = "typeahead-select";
|
43
|
+
LogType["TYPEAHEAD_BLUR"] = "typeahead-blur";
|
44
|
+
LogType["WIZARD_SUBMIT"] = "wizard-submit";
|
45
|
+
LogType["RECOMMENDATION_SEEN"] = "recommendation-seen";
|
46
|
+
LogType["RECOMMENDATION_SELECTED"] = "recommendation-selected";
|
47
|
+
})(LogType = exports.LogType || (exports.LogType = {}));
|
48
|
+
var TypeaheadEventLogger = /** @class */ (function () {
|
49
|
+
// 1 - Create logger
|
50
|
+
function TypeaheadEventLogger(analytics, prefill) {
|
51
|
+
this.analytics = analytics;
|
52
|
+
this.isEgtaLoggingEnabled = true;
|
53
|
+
if (!TypeaheadEventLogger.sessionStore) {
|
54
|
+
this.initSessionStore();
|
55
|
+
}
|
56
|
+
}
|
57
|
+
// 2 - initialize logger.
|
58
|
+
TypeaheadEventLogger.prototype.initLogger = function (metadata) {
|
59
|
+
this.initSessionStore();
|
60
|
+
this.initializeInputField();
|
61
|
+
var client = metadata.client, subLob = metadata.subLob, lob = metadata.lob, locale = metadata.locale, siteId = metadata.siteId, personalize = metadata.personalize, enableEgta = metadata.enableEgta;
|
62
|
+
TypeaheadEventLogger.sessionStore.metadata = { client: client, subLob: subLob, lob: lob, locale: locale, siteId: siteId, personalize: personalize, enableEgta: enableEgta };
|
63
|
+
};
|
64
|
+
TypeaheadEventLogger.prototype.logTypeaheadRequest = function (query) {
|
65
|
+
if (TypeaheadEventLogger.sessionStore) {
|
66
|
+
TypeaheadEventLogger.sessionStore.query = query;
|
67
|
+
}
|
68
|
+
};
|
69
|
+
TypeaheadEventLogger.prototype.logTypeaheadResponse = function (response) {
|
70
|
+
TypeaheadEventLogger.sessionStore.response = response;
|
71
|
+
TypeaheadEventLogger.sessionStore.selected = undefined;
|
72
|
+
var recEventMessage = RecommendationEvent_1.RecommendationEvent.getRecommendationSeenMessage(response, TypeaheadEventLogger.sessionStore.fieldName || "");
|
73
|
+
if (recEventMessage) {
|
74
|
+
this.trackEventToUisPrime(this.getReferrerId(LogType.RECOMMENDATION_SEEN), LogType.RECOMMENDATION_SEEN, false, [recEventMessage]);
|
75
|
+
}
|
76
|
+
};
|
77
|
+
TypeaheadEventLogger.prototype.logTypeaheadOpen = function (prefill) {
|
78
|
+
TypeaheadEventLogger.sessionStore.prefill = prefill;
|
79
|
+
this.initializeInputField();
|
80
|
+
if (this.isEgtaLoggingEnabled) {
|
81
|
+
this.trackEventToUisPrime(this.getReferrerId(LogType.TYPEAHEAD_FOCUS), LogType.TYPEAHEAD_FOCUS, false, [new TypeaheadEvent_1.TypeaheadEvent(TypeaheadEvent_1.EventName.FOCUS, TypeaheadEventLogger.sessionStore).getTypeaheadEventMessage()]);
|
82
|
+
}
|
83
|
+
};
|
84
|
+
TypeaheadEventLogger.prototype.logSuggestionSelected = function (selected) {
|
85
|
+
var isCurrLoc = ((selected === null || selected === void 0 ? void 0 : selected.type) === 'CURRENT_LOCATION');
|
86
|
+
if (Optional_1.Optional.ofNullable(selected).isPresent() && this.essResponseIsNotEmpty()) {
|
87
|
+
TypeaheadEventLogger.sessionStore.selected =
|
88
|
+
TypeaheadEventLogger.sessionStore.response.sr[selected.index - 1];
|
89
|
+
}
|
90
|
+
var eventName = isCurrLoc ? TypeaheadEvent_1.EventName.CURRENT_LOCATION : TypeaheadEvent_1.EventName.SELECT;
|
91
|
+
var taEvent = new TypeaheadEvent_1.TypeaheadEvent(eventName, TypeaheadEventLogger.sessionStore);
|
92
|
+
var recEventMessage = RecommendationEvent_1.RecommendationEvent.getRecommendationClickedMessage(TypeaheadEventLogger.sessionStore.selected, TypeaheadEventLogger.sessionStore.response, TypeaheadEventLogger.sessionStore.fieldName || "");
|
93
|
+
if (this.isEgtaLoggingEnabled) {
|
94
|
+
var uisPrimeMessages = [taEvent.getTypeaheadEventMessage()];
|
95
|
+
if (recEventMessage) {
|
96
|
+
this.trackEventToUisPrime(this.getReferrerId(LogType.RECOMMENDATION_SELECTED), LogType.RECOMMENDATION_SELECTED, false, [recEventMessage]);
|
97
|
+
}
|
98
|
+
this.trackEventToUisPrime(this.getReferrerId(), LogType.TYPEAHEAD_SELECT, false, uisPrimeMessages);
|
99
|
+
}
|
100
|
+
return taEvent.getFlattenedJsonMessage();
|
101
|
+
};
|
102
|
+
/* the following two methods to be used by blossom-ui / buttercup / any other client who uses typeahead*/
|
103
|
+
TypeaheadEventLogger.prototype.logTypeaheadBlurEvent = function () {
|
104
|
+
var _a;
|
105
|
+
var messages = this.buildUisPrimeMessages();
|
106
|
+
if (this.isEgtaLoggingEnabled) {
|
107
|
+
messages.push(new TypeaheadEvent_1.TypeaheadEvent(TypeaheadEvent_1.EventName.BLUR, TypeaheadEventLogger.sessionStore).getTypeaheadEventMessage());
|
108
|
+
}
|
109
|
+
this.trackEventToUisPrime(this.getReferrerId(), LogType.TYPEAHEAD_BLUR, false, messages);
|
110
|
+
TypeaheadEventLogger.sessionStore.noOfBackspaces = 0;
|
111
|
+
(_a = TypeaheadEventLogger.sessionStore.input) === null || _a === void 0 ? void 0 : _a.removeEventListener("keydown", this.keyDown);
|
112
|
+
};
|
113
|
+
TypeaheadEventLogger.prototype.isResolveNoSuggestionSelected = function (flag) {
|
114
|
+
TypeaheadEventLogger.sessionStore.isResolve = flag;
|
115
|
+
};
|
116
|
+
TypeaheadEventLogger.prototype.logWizardSubmitEvent = function () {
|
117
|
+
// Disabling since it is not consistent and also to fix - https://jira.expedia.biz/browse/ECOMSVC-4216
|
118
|
+
// this.trackEventToUisPrime(this.getReferrerId(), LogType.WIZARD_SUBMIT, true, this.buildUisPrimeMessages());
|
119
|
+
this.resetLoggerState();
|
120
|
+
};
|
121
|
+
TypeaheadEventLogger.prototype.trackEventToUisPrime = function (rfrr, linkName, trackImmediate, messages) {
|
122
|
+
var _a, _b;
|
123
|
+
try {
|
124
|
+
(_a = this.analytics) === null || _a === void 0 ? void 0 : _a.trackEvent(rfrr, linkName, (_b = this.analytics) === null || _b === void 0 ? void 0 : _b.omnitureData, null, trackImmediate, messages);
|
125
|
+
}
|
126
|
+
catch (e) {
|
127
|
+
Utils_1.Utils.logError(__assign(__assign({}, e), { message: "Failed typeahead event tracking to UIS Prime" }));
|
128
|
+
}
|
129
|
+
};
|
130
|
+
TypeaheadEventLogger.prototype.buildUisPrimeMessages = function () {
|
131
|
+
if (Utils_1.Utils.isOrigin(TypeaheadEventLogger.sessionStore.fieldName || "")) {
|
132
|
+
TypeaheadEventLogger.leg.origin = __assign({}, TypeaheadEventLogger.sessionStore);
|
133
|
+
}
|
134
|
+
else {
|
135
|
+
TypeaheadEventLogger.leg.dest = __assign({}, TypeaheadEventLogger.sessionStore);
|
136
|
+
}
|
137
|
+
return __spread(this.getTrackingDataEvents(), [
|
138
|
+
this.getSelectedSuggestionEvents(),
|
139
|
+
]);
|
140
|
+
};
|
141
|
+
TypeaheadEventLogger.prototype.getTrackingDataEvents = function () {
|
142
|
+
var searchTerm = this.getUserTypedQuery(TypeaheadEventLogger.sessionStore);
|
143
|
+
var numOfCharsTyped = searchTerm ? searchTerm.length : 0;
|
144
|
+
var trackingData = [];
|
145
|
+
/* to get the position of selected suggestion [event44] */
|
146
|
+
if (this.isASuggestionSelected()) {
|
147
|
+
trackingData.push(Object.freeze({
|
148
|
+
messageContent: {
|
149
|
+
name: "TypeaheadSelectionDepth",
|
150
|
+
value: this.getSelectedSuggestionPosition(),
|
151
|
+
},
|
152
|
+
schemaName: "events",
|
153
|
+
}));
|
154
|
+
}
|
155
|
+
/* to see if user interacted with typeahead or not [event45] */
|
156
|
+
if (TypeaheadEventLogger.sessionStore.response) {
|
157
|
+
trackingData.push(Object.freeze({
|
158
|
+
messageContent: {
|
159
|
+
name: "TypeaheadSearch",
|
160
|
+
value: 0,
|
161
|
+
},
|
162
|
+
schemaName: "events",
|
163
|
+
}));
|
164
|
+
}
|
165
|
+
/* to get the number of characters typed by the user [event46] */
|
166
|
+
trackingData.push(Object.freeze({
|
167
|
+
messageContent: {
|
168
|
+
name: "TypeaheadCharactersTyped",
|
169
|
+
value: numOfCharsTyped,
|
170
|
+
},
|
171
|
+
schemaName: "events",
|
172
|
+
}));
|
173
|
+
return trackingData;
|
174
|
+
};
|
175
|
+
TypeaheadEventLogger.prototype.getSelectedSuggestionEvents = function () {
|
176
|
+
var originSuggestionData = this.getSelectedSuggestionData("origin", TypeaheadEventLogger.leg.origin);
|
177
|
+
var destSuggestionData = this.getSelectedSuggestionData("dest", TypeaheadEventLogger.leg.dest);
|
178
|
+
return Object.freeze({
|
179
|
+
messageContent: {
|
180
|
+
selectedSuggestions: [originSuggestionData, destSuggestionData],
|
181
|
+
},
|
182
|
+
schemaName: "allSelectedSuggestions",
|
183
|
+
});
|
184
|
+
};
|
185
|
+
TypeaheadEventLogger.prototype.getSelectedSuggestionData = function (searchField, session) {
|
186
|
+
var suggestion = session === null || session === void 0 ? void 0 : session.selected;
|
187
|
+
var alternateName = searchField === "origin" && !session ? "OriginNotApplicable" :
|
188
|
+
((session === null || session === void 0 ? void 0 : session.query) || (session === null || session === void 0 ? void 0 : session.prefill) || "TANoneSelected");
|
189
|
+
var userTypedQuery = this.getUserTypedQuery(TypeaheadEventLogger.sessionStore);
|
190
|
+
var lastSearchName = suggestion
|
191
|
+
&& suggestion.regionNames
|
192
|
+
&& suggestion.regionNames.lastSearchName
|
193
|
+
|| alternateName;
|
194
|
+
return {
|
195
|
+
essRequestId: (TypeaheadEventLogger.sessionStore.response || { rid: "-" }).rid,
|
196
|
+
lastSearchName: lastSearchName,
|
197
|
+
relation: suggestion
|
198
|
+
&& suggestion.hierarchyInfo
|
199
|
+
&& suggestion.hierarchyInfo.relation
|
200
|
+
&& suggestion.hierarchyInfo.relation[0]
|
201
|
+
|| "-",
|
202
|
+
searchField: searchField,
|
203
|
+
sourceName: suggestion
|
204
|
+
? suggestion.essId
|
205
|
+
? suggestion.essId.sourceName
|
206
|
+
: suggestion.sourceName
|
207
|
+
? suggestion.sourceName
|
208
|
+
: "UNKNOWN"
|
209
|
+
: "UNKNOWN",
|
210
|
+
stringSourceId: (suggestion && suggestion.essId && suggestion.essId.sourceId || -1).toString(),
|
211
|
+
suggestionType: suggestion ? suggestion.type : "UNKNOWN",
|
212
|
+
userHistory: suggestion ? suggestion.category === "USERHISTORY" : false,
|
213
|
+
userTypedQuery: userTypedQuery,
|
214
|
+
};
|
215
|
+
};
|
216
|
+
TypeaheadEventLogger.prototype.getReferrerId = function (logType) {
|
217
|
+
if (logType === LogType.RECOMMENDATION_SEEN) {
|
218
|
+
return "TYPEAHEAD.EGREC.RecSeen";
|
219
|
+
}
|
220
|
+
else if (logType === LogType.RECOMMENDATION_SELECTED) {
|
221
|
+
return "TYPEAHEAD.EGREC.RecSelected";
|
222
|
+
}
|
223
|
+
var metadata = TypeaheadEventLogger.sessionStore.metadata || {};
|
224
|
+
var parts = [];
|
225
|
+
parts.push(this.getLaunchView(metadata.client || ""));
|
226
|
+
parts.push(this.getWizard(metadata.client || ""));
|
227
|
+
parts.push(metadata.lob || "Unknown");
|
228
|
+
parts.push(this.getShortLob(metadata.lob || "", metadata.subLob));
|
229
|
+
parts.push(metadata.locale || "-");
|
230
|
+
parts.push(metadata.siteId || "-");
|
231
|
+
if (logType === LogType.TYPEAHEAD_FOCUS) {
|
232
|
+
parts.push("TAStart");
|
233
|
+
}
|
234
|
+
else {
|
235
|
+
parts.push(this.getTypeaheadTrigger());
|
236
|
+
parts.push.apply(parts, __spread(this.getInstrumentationValue((metadata.lob || "").toLowerCase())));
|
237
|
+
}
|
238
|
+
return parts.join("|");
|
239
|
+
};
|
240
|
+
TypeaheadEventLogger.prototype.getLaunchView = function (clientId) {
|
241
|
+
clientId = clientId.toLowerCase();
|
242
|
+
if (clientId.indexOf("home") > -1) {
|
243
|
+
return "Home";
|
244
|
+
}
|
245
|
+
if (clientId.indexOf("flight") > -1) {
|
246
|
+
return "FLT";
|
247
|
+
}
|
248
|
+
if (clientId.indexOf("hotels.search") > -1) {
|
249
|
+
// for hotels search page bernie appends "HOT.SR" so removing here
|
250
|
+
return "";
|
251
|
+
}
|
252
|
+
if (clientId.indexOf("hotel") > -1) {
|
253
|
+
return "HTL";
|
254
|
+
}
|
255
|
+
if (clientId.indexOf("vacationrental") > -1) {
|
256
|
+
return "VR";
|
257
|
+
}
|
258
|
+
if (clientId.indexOf("pack") > -1) {
|
259
|
+
return "PKG";
|
260
|
+
}
|
261
|
+
if (clientId.indexOf("car") > -1) {
|
262
|
+
return "CAR";
|
263
|
+
}
|
264
|
+
if (clientId.indexOf("cru") > -1) {
|
265
|
+
return "CRU";
|
266
|
+
}
|
267
|
+
if (clientId.indexOf("lx") > -1) {
|
268
|
+
return "LX";
|
269
|
+
}
|
270
|
+
if (clientId.indexOf("rail") > -1) {
|
271
|
+
return "RAIL";
|
272
|
+
}
|
273
|
+
if (clientId.indexOf("open") > -1) {
|
274
|
+
return "OPEN";
|
275
|
+
}
|
276
|
+
return clientId;
|
277
|
+
};
|
278
|
+
TypeaheadEventLogger.prototype.getWizard = function (client) {
|
279
|
+
switch (client.toLowerCase()) {
|
280
|
+
case "hotels.search":
|
281
|
+
case "flights.search":
|
282
|
+
case "open.search":
|
283
|
+
case "cars.search":
|
284
|
+
case "lx.Search":
|
285
|
+
case "packages.search":
|
286
|
+
return "UpdateSearch";
|
287
|
+
default:
|
288
|
+
return "CoreWzd";
|
289
|
+
}
|
290
|
+
};
|
291
|
+
TypeaheadEventLogger.prototype.getShortLob = function (lob, subLob) {
|
292
|
+
switch (lob.toLowerCase()) {
|
293
|
+
case "flights": return "F." + Utils_1.Utils.getSubLob(lob, subLob);
|
294
|
+
case "hotels": return "H";
|
295
|
+
case "packages": return Utils_1.Utils.getSubLob(lob, subLob);
|
296
|
+
case "activities": return "LX";
|
297
|
+
case "cruises": return "CR";
|
298
|
+
case "cars": return "C";
|
299
|
+
default: return "-";
|
300
|
+
}
|
301
|
+
};
|
302
|
+
TypeaheadEventLogger.prototype.getTypeaheadTrigger = function () {
|
303
|
+
if (!this.essResponseIsNotEmpty()) {
|
304
|
+
return "TANoShow.TAPrevSearch";
|
305
|
+
}
|
306
|
+
var historyResultsShown = TypeaheadEventLogger.sessionStore.response.q === "";
|
307
|
+
if (historyResultsShown) {
|
308
|
+
return this.isASuggestionSelected() ? "TAShow.TAFocus" : "TAShow.TANoSelection";
|
309
|
+
}
|
310
|
+
return this.isASuggestionSelected() ? "TAShow.TASelection" : "TAShow.TANoSelection";
|
311
|
+
};
|
312
|
+
TypeaheadEventLogger.prototype.getInstrumentationValue = function (lob) {
|
313
|
+
var result = [];
|
314
|
+
var index = "-";
|
315
|
+
if (this.getSelectedSuggestionPosition() >= 0) {
|
316
|
+
index = this.getSelectedSuggestionPosition().toString();
|
317
|
+
}
|
318
|
+
var length = this.essResponseIsNotEmpty() ? TypeaheadEventLogger.sessionStore.response.sr.length : 0;
|
319
|
+
if (lob === "flights" || lob === "hotels") {
|
320
|
+
result.push(this.getHierarchyType(TypeaheadEventLogger.sessionStore.selected) + "#" + index);
|
321
|
+
}
|
322
|
+
else {
|
323
|
+
result.push("L#" + index);
|
324
|
+
}
|
325
|
+
result.push((this.getUserTypedQuery(TypeaheadEventLogger.sessionStore) && TypeaheadEventLogger.sessionStore.metadata && TypeaheadEventLogger.sessionStore.metadata.enableEgta ?
|
326
|
+
"EGTA" : "ESS") + "#" + length);
|
327
|
+
result.push("UH#" + this.getNumberOfUserHistorySuggestions());
|
328
|
+
return result;
|
329
|
+
};
|
330
|
+
TypeaheadEventLogger.prototype.getHierarchyType = function (suggestion) {
|
331
|
+
if (Optional_1.Optional.ofNullable(suggestion).isPresent()) {
|
332
|
+
if (this.isChild(suggestion)) {
|
333
|
+
return "CL";
|
334
|
+
}
|
335
|
+
if (this.isParent(suggestion)) {
|
336
|
+
return "PL";
|
337
|
+
}
|
338
|
+
}
|
339
|
+
return "DL";
|
340
|
+
};
|
341
|
+
TypeaheadEventLogger.prototype.isChild = function (suggestion) {
|
342
|
+
if (Optional_1.Optional.ofNullable(suggestion).isNotPresent()) {
|
343
|
+
return false;
|
344
|
+
}
|
345
|
+
var relation = suggestion && suggestion.hierarchyInfo
|
346
|
+
&& suggestion.hierarchyInfo.relation || [];
|
347
|
+
if (relation.length === 0) {
|
348
|
+
return false;
|
349
|
+
}
|
350
|
+
return relation.indexOf("child") >= 0;
|
351
|
+
};
|
352
|
+
TypeaheadEventLogger.prototype.isParent = function (suggestion) {
|
353
|
+
if (Optional_1.Optional.ofNullable(suggestion).isNotPresent()
|
354
|
+
|| !this.essResponseIsNotEmpty()) {
|
355
|
+
return false;
|
356
|
+
}
|
357
|
+
var index = parseInt(Optional_1.Optional.ofNullable(suggestion.index).orElse("-1"), 10);
|
358
|
+
if (index < 0 || TypeaheadEventLogger.sessionStore.response.sr.length <= index + 1) {
|
359
|
+
return false;
|
360
|
+
}
|
361
|
+
return this.isChild(TypeaheadEventLogger.sessionStore.response.sr[index + 1]);
|
362
|
+
};
|
363
|
+
TypeaheadEventLogger.prototype.getNumberOfUserHistorySuggestions = function () {
|
364
|
+
if (TypeaheadEventLogger.sessionStore.metadata
|
365
|
+
&& !!TypeaheadEventLogger.sessionStore.metadata.personalize) {
|
366
|
+
if (!this.essResponseIsNotEmpty()) {
|
367
|
+
return "0";
|
368
|
+
}
|
369
|
+
var suggestions = TypeaheadEventLogger.sessionStore.response.sr;
|
370
|
+
return suggestions.filter(function (suggestion) { return suggestion.category === "USERHISTORY"; })
|
371
|
+
.length.toString();
|
372
|
+
}
|
373
|
+
return "-";
|
374
|
+
};
|
375
|
+
/*********** util methods ************/
|
376
|
+
TypeaheadEventLogger.prototype.essResponseIsNotEmpty = function () {
|
377
|
+
return TypeaheadEventLogger.sessionStore.response
|
378
|
+
&& TypeaheadEventLogger.sessionStore.response.sr
|
379
|
+
&& TypeaheadEventLogger.sessionStore.response.sr.length > 0;
|
380
|
+
};
|
381
|
+
TypeaheadEventLogger.prototype.isASuggestionSelected = function () {
|
382
|
+
return !!TypeaheadEventLogger.sessionStore.selected;
|
383
|
+
};
|
384
|
+
TypeaheadEventLogger.prototype.getUserTypedQuery = function (session) {
|
385
|
+
return session.query === session.prefill ? "" : session.query;
|
386
|
+
};
|
387
|
+
TypeaheadEventLogger.prototype.getSelectedSuggestionPosition = function () {
|
388
|
+
if (!this.isASuggestionSelected()
|
389
|
+
|| Optional_1.Optional.ofNullable(TypeaheadEventLogger.sessionStore.selected.index).isNotPresent()) {
|
390
|
+
return -1;
|
391
|
+
}
|
392
|
+
try {
|
393
|
+
return parseInt(TypeaheadEventLogger.sessionStore.selected.index, 10) + 1;
|
394
|
+
}
|
395
|
+
catch (e) {
|
396
|
+
return -1;
|
397
|
+
}
|
398
|
+
};
|
399
|
+
TypeaheadEventLogger.prototype.resetLoggerState = function () {
|
400
|
+
this.initSessionStore();
|
401
|
+
TypeaheadEventLogger.leg = {};
|
402
|
+
};
|
403
|
+
/* istanbul ignore next */
|
404
|
+
TypeaheadEventLogger.prototype.keyDown = function (event) {
|
405
|
+
if (event.key && ["Delete", "Backspace"].indexOf(event.key) > -1 ||
|
406
|
+
event.keyCode && [8, 46].indexOf(event.keyCode) > -1) {
|
407
|
+
TypeaheadEventLogger.sessionStore.noOfBackspaces += 1;
|
408
|
+
}
|
409
|
+
};
|
410
|
+
TypeaheadEventLogger.prototype.initializeInputField = function () {
|
411
|
+
var _a, _b;
|
412
|
+
TypeaheadEventLogger.sessionStore.input = Utils_1.Utils.getDomElement();
|
413
|
+
TypeaheadEventLogger.sessionStore.fieldName = Utils_1.Utils.getInputElementId(TypeaheadEventLogger.sessionStore.input);
|
414
|
+
(_a = TypeaheadEventLogger.sessionStore.input) === null || _a === void 0 ? void 0 : _a.removeEventListener("keydown", this.keyDown);
|
415
|
+
(_b = TypeaheadEventLogger.sessionStore.input) === null || _b === void 0 ? void 0 : _b.addEventListener("keydown", this.keyDown);
|
416
|
+
};
|
417
|
+
TypeaheadEventLogger.prototype.initSessionStore = function () {
|
418
|
+
TypeaheadEventLogger.sessionStore = {
|
419
|
+
metadata: { lob: Utils_1.Utils.UNKNOWN },
|
420
|
+
noOfBackspaces: 0,
|
421
|
+
query: "",
|
422
|
+
href: window.location.href,
|
423
|
+
};
|
424
|
+
};
|
425
|
+
TypeaheadEventLogger.leg = {};
|
426
|
+
return TypeaheadEventLogger;
|
427
|
+
}());
|
428
|
+
exports.TypeaheadEventLogger = TypeaheadEventLogger;
|
429
|
+
//# sourceMappingURL=TypeaheadEventLogger.js.map
|
package/dist/index.js
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
10
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
11
|
+
}
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
+
__exportStar(require("./EssClientLogger"), exports);
|
14
|
+
__exportStar(require("./TypeaheadEventLogger"), exports);
|
15
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1,45 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Optional = void 0;
|
4
|
+
var Optional = /** @class */ (function () {
|
5
|
+
function Optional(value) {
|
6
|
+
this.value = value;
|
7
|
+
}
|
8
|
+
Optional.of = function (value) {
|
9
|
+
if (Optional.isEmpty(value)) {
|
10
|
+
throw new Error("Optional.of doesn't accept undefined or null values. Use Optional.ofNullable instead");
|
11
|
+
}
|
12
|
+
return new Optional(value);
|
13
|
+
};
|
14
|
+
Optional.ofNullable = function (value) {
|
15
|
+
return new Optional(value);
|
16
|
+
};
|
17
|
+
Optional.empty = function () {
|
18
|
+
// @ts-ignore
|
19
|
+
return new Optional(null);
|
20
|
+
};
|
21
|
+
Optional.isEmpty = function (value) {
|
22
|
+
return value === null || value === undefined || typeof value === "undefined";
|
23
|
+
};
|
24
|
+
Optional.prototype.get = function () {
|
25
|
+
if (this.isPresent()) {
|
26
|
+
return this.value;
|
27
|
+
}
|
28
|
+
throw new Error("Exception while trying to get the value of an empty Optional");
|
29
|
+
};
|
30
|
+
Optional.prototype.isPresent = function () {
|
31
|
+
return !Optional.isEmpty(this.value);
|
32
|
+
};
|
33
|
+
Optional.prototype.isNotPresent = function () {
|
34
|
+
return !this.isPresent();
|
35
|
+
};
|
36
|
+
Optional.prototype.orElse = function (alt) {
|
37
|
+
if (this.isPresent()) {
|
38
|
+
return this.value;
|
39
|
+
}
|
40
|
+
return alt;
|
41
|
+
};
|
42
|
+
return Optional;
|
43
|
+
}());
|
44
|
+
exports.Optional = Optional;
|
45
|
+
//# sourceMappingURL=Optional.js.map
|
@@ -0,0 +1,88 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Utils = void 0;
|
4
|
+
var SystemEvent_1 = require("../SystemEvent");
|
5
|
+
var Utils = /** @class */ (function () {
|
6
|
+
function Utils() {
|
7
|
+
}
|
8
|
+
Utils.init = function (clientLogger) {
|
9
|
+
if (clientLogger && "function" === typeof clientLogger.getLoggerWithIdentifier) {
|
10
|
+
var logger = clientLogger.getLoggerWithIdentifier("uitk-react-typeahead");
|
11
|
+
if (logger && typeof logger.logEvent === "function") {
|
12
|
+
Utils.logger = logger;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
};
|
16
|
+
Utils.isOrigin = function (domElementId) {
|
17
|
+
domElementId = domElementId.toLowerCase();
|
18
|
+
return domElementId.indexOf("origin") > -1 ||
|
19
|
+
domElementId.indexOf("from") > -1 ||
|
20
|
+
domElementId.indexOf("departure") > -1 ||
|
21
|
+
domElementId.indexOf("drop") > -1 ||
|
22
|
+
domElementId.indexOf("home") > -1 ||
|
23
|
+
domElementId.indexOf("loc2") > -1;
|
24
|
+
};
|
25
|
+
Utils.isDestination = function (domElementId) {
|
26
|
+
domElementId = domElementId.toLowerCase();
|
27
|
+
return domElementId.indexOf("dest") > -1 ||
|
28
|
+
domElementId.indexOf("to") > -1 ||
|
29
|
+
domElementId.indexOf("arrival") > -1 ||
|
30
|
+
domElementId.indexOf("near") > -1 ||
|
31
|
+
domElementId.indexOf("pick") > -1 ||
|
32
|
+
domElementId.indexOf("location") === 0;
|
33
|
+
};
|
34
|
+
Utils.getDomElement = function () {
|
35
|
+
var _a;
|
36
|
+
return (_a = document.querySelectorAll(".uitk-dialog-layer-responsive .uitk-typeahead-dialog, .uitk-typeahead-menu .uitk-menu-open")[0]) === null || _a === void 0 ? void 0 : _a.getElementsByTagName("input")[0];
|
37
|
+
};
|
38
|
+
Utils.logError = function (error) {
|
39
|
+
try {
|
40
|
+
if (Utils.logger) {
|
41
|
+
error = error.stack ? { message: error.message, stack: error.stack } : error;
|
42
|
+
Utils.logger.logEvent(new SystemEvent_1.SystemEvent(SystemEvent_1.SystemEventLevel.ERROR, "TypeaheadLoggingError"), error);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
catch (e) {
|
46
|
+
/* istanbul ignore next */
|
47
|
+
// tslint:disable-next-line:no-console
|
48
|
+
console.error("unable to log errors from typeahead-client-logger. Reason:" + e);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
Utils.getInputElementId = function (inputEl) {
|
52
|
+
var id;
|
53
|
+
if (inputEl) {
|
54
|
+
id = inputEl.getAttribute("data-stid");
|
55
|
+
if (!id) {
|
56
|
+
Utils.logError({ message: "Failed to retrieve input element id from 'data-stid'" });
|
57
|
+
}
|
58
|
+
}
|
59
|
+
return id || Utils.UNKNOWN;
|
60
|
+
};
|
61
|
+
Utils.getSubLob = function (lob, sublob) {
|
62
|
+
if (!sublob) {
|
63
|
+
var usp = new URLSearchParams(window.location.search);
|
64
|
+
sublob = usp.get("pwaSubLOB") || "";
|
65
|
+
}
|
66
|
+
switch (lob.toLowerCase()) {
|
67
|
+
case "flights":
|
68
|
+
switch (sublob && sublob.toLowerCase()) {
|
69
|
+
case "oneway": return "OW";
|
70
|
+
case "multicity": return "MD";
|
71
|
+
default: return "RT";
|
72
|
+
}
|
73
|
+
case "packages":
|
74
|
+
switch (sublob && sublob.toLowerCase()) {
|
75
|
+
case "fhc": return "FHC";
|
76
|
+
case "hc": return "HC";
|
77
|
+
case "fc": return "FC";
|
78
|
+
default: return "FH";
|
79
|
+
}
|
80
|
+
default:
|
81
|
+
return "";
|
82
|
+
}
|
83
|
+
};
|
84
|
+
Utils.UNKNOWN = "UNKNOWN";
|
85
|
+
return Utils;
|
86
|
+
}());
|
87
|
+
exports.Utils = Utils;
|
88
|
+
//# sourceMappingURL=Utils.js.map
|
package/package.json
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
{
|
2
2
|
"name": "typeahead-client-logger",
|
3
|
-
"version": "
|
4
|
-
"
|
5
|
-
"
|
3
|
+
"version": "2.532.1",
|
4
|
+
"private": false,
|
5
|
+
"description": "Typeahead client logger lib",
|
6
|
+
"license": "MIT",
|
7
|
+
"author": "hexp-ahed",
|
8
|
+
"main": "dist/index.js",
|
9
|
+
"repository": "https://www.github.com/hexp-ahed/typeahead-client-logger",
|
10
|
+
"scripts": {
|
11
|
+
"build": "babel",
|
12
|
+
"preinstall": "node build.js",
|
13
|
+
"test": "exit 0"
|
14
|
+
},
|
15
|
+
"devDependencies": {
|
16
|
+
"@babel/core": "^7.18.6",
|
17
|
+
"@babel/cli": "^7.18.6"
|
18
|
+
},
|
19
|
+
"publishConfig": {
|
20
|
+
"access": "public"
|
21
|
+
}
|
6
22
|
}
|