@cleartrip/ct-platform-utils 3.18.1-beta.8 → 3.18.2

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.
@@ -1,1085 +1,2 @@
1
- import { __awaiter, __generator, __assign } from 'tslib';
2
- import { v4 } from 'uuid';
3
- import { Platform, AppAgent, RequestMethods, SOURCE_NAME, API_ROUTES, MOBILE_CONSTANTS, NAVIGATION_ROUTES } from '@cleartrip/ct-platform-constants';
4
- import UAParser from 'ua-parser-js';
5
- import { ValidateOTPAction } from '@cleartrip/ct-platform-types';
6
-
7
- var urlJoin = function () {
8
- var parts = [];
9
- for (var _i = 0; _i < arguments.length; _i++) {
10
- parts[_i] = arguments[_i];
11
- }
12
- var trimmedParts = parts.map(function (part) { return part.trim().replace(/^[/]+/, ''); });
13
- var joinedParts = trimmedParts.join('/');
14
- joinedParts = joinedParts.replace(/\/\?/g, '?');
15
- return joinedParts;
16
- };
17
- var getApiDomain = function () {
18
- var domain = typeof window !== 'undefined' ? window.location.hostname : '';
19
- console.log('API_BASE domain', domain);
20
- switch (domain) {
21
- case 'localhost':
22
- case '0.0.0.0':
23
- case 'qa2new.cleartrip.com':
24
- return 'https://qa2new.cleartrip.com';
25
- case 'qa2.cleartrip.com':
26
- return 'https://qa2.cleartrip.com';
27
- case 'qa3new.cleartrip.com':
28
- return 'https://qa3new.cleartrip.com';
29
- case 'www.cleartrip.com':
30
- default:
31
- return 'https://www.cleartrip.com';
32
- }
33
- };
34
- var getNestedValue = function (data, path) {
35
- var reducerFunction = function (prev, current) {
36
- return prev && prev[current] ? prev[current] : null;
37
- };
38
- return path.reduce(reducerFunction, data);
39
- };
40
- var path = function (p, o) {
41
- return p.reduce(function (prev, curr) {
42
- return prev && prev[curr] ? prev[curr] : null;
43
- }, o);
44
- };
45
- var MULTI_SPACE = /\s\s+/g;
46
- var isEmpty = function (obj) {
47
- if (obj instanceof Date) {
48
- return false;
49
- }
50
- if (obj == null) {
51
- return true;
52
- }
53
- var isNumber = function (value) {
54
- return Object.prototype.toString.call(value) === '[object Number]';
55
- };
56
- var isNaN = function (value) { return isNumber(value) && value.toString() === 'NaN'; };
57
- if (isNumber(obj)) {
58
- return isNaN(obj);
59
- }
60
- if (obj.length > 0) {
61
- return false;
62
- }
63
- if (obj.length === 0) {
64
- return true;
65
- }
66
- if (typeof obj !== 'object') {
67
- return true;
68
- }
69
- var keys = Object.keys(obj);
70
- for (var i = 0, key = keys[i]; i < keys.length; i += 1) {
71
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
72
- return false;
73
- }
74
- }
75
- return true;
76
- };
77
- var isHTMLInputElement = function (ref) {
78
- return (typeof ref === 'object' &&
79
- ref !== null &&
80
- 'value' in ref &&
81
- ref instanceof HTMLInputElement);
82
- };
83
- var isNumeric = function (value) {
84
- return /^[0-9]*$/.test(value);
85
- };
86
- var getCurrentUrl = typeof window !== 'undefined' ? window.location.href : '';
87
- var getQueryParam = function (queryParam) {
88
- if (isServer()) {
89
- return '';
90
- }
91
- var urlParams = new URLSearchParams(window.location.search);
92
- return urlParams.get(queryParam);
93
- };
94
- var getCurrentPathName = function () {
95
- return typeof window !== 'undefined'
96
- ? (window.location.pathname + window.location.search).slice(1)
97
- : '';
98
- };
99
- var getHeightFromImgUrl = function (url) {
100
- if (!url) {
101
- return;
102
- }
103
- var regex = /h_(\d+)[,\/]/;
104
- var match = url.match(regex);
105
- if (match && match[1]) {
106
- return parseInt(match[1], 10);
107
- }
108
- return;
109
- };
110
- var getWidthFromImgUrl = function (url) {
111
- if (!url) {
112
- return;
113
- }
114
- var regex = /w_(\d+)[,\/]/;
115
- var match = url.match(regex);
116
- if (match && match[1]) {
117
- return parseInt(match[1], 10);
118
- }
119
- return;
120
- };
121
- var isServer = function () {
122
- return typeof window === 'undefined' || !window;
123
- };
124
- function getCookie(name, customCookie) {
125
- var _cookie = customCookie || getNestedValue(document, ['cookie']);
126
- if (_cookie) {
127
- var nameEQ = name + '=';
128
- var ca = _cookie.split(';');
129
- for (var i = 0; i < ca.length; i++) {
130
- var c = ca[i];
131
- while (c.charAt(0) == ' ')
132
- c = c.substring(1, c.length);
133
- if (c.indexOf(nameEQ) == 0)
134
- return c.substring(nameEQ.length, c.length);
135
- }
136
- return '';
137
- }
138
- else {
139
- return '';
140
- }
141
- }
142
- var getDimensionFromImageUrl = function (url) {
143
- if (url === void 0) { url = ''; }
144
- var height = getHeightFromImgUrl(url) || 0;
145
- var width = getWidthFromImgUrl(url) || 0;
146
- return {
147
- height: "".concat(height, "px"),
148
- width: "".concat(width, "px"),
149
- heightInNumber: height,
150
- widthInNumber: width,
151
- };
152
- };
153
- var secondsToDateString = function (sec) {
154
- try {
155
- if (!sec || Number.isNaN(Number(sec))) {
156
- return '';
157
- }
158
- var date = new Date(sec * 1000);
159
- var year = date.getFullYear();
160
- var day = String(date.getDate()).padStart(2, '0');
161
- var month = String(date.getMonth() + 1).padStart(2, '0');
162
- return "".concat(year, "-").concat(month, "-").concat(day);
163
- }
164
- catch (_e) {
165
- return '';
166
- }
167
- };
168
- var formatFullDateString = function (dateString, format, fallback) {
169
- if (format === void 0) { format = 'dd-mm-yyyy'; }
170
- if (fallback === void 0) { fallback = ''; }
171
- try {
172
- var date = new Date(dateString);
173
- var year = date.getFullYear();
174
- var day = String(date.getDate()).padStart(2, '0');
175
- var month = String(date.getMonth() + 1).padStart(2, '0');
176
- switch (format) {
177
- case 'yyyy-mm-dd':
178
- return "".concat(year, "-").concat(month, "-").concat(day);
179
- case 'dd-mm-yyyy':
180
- default:
181
- return "".concat(day, "-").concat(month, "-").concat(year);
182
- }
183
- }
184
- catch (_e) {
185
- return fallback;
186
- }
187
- };
188
- var formatCurrency = function (value, withIcon) {
189
- if (withIcon === void 0) { withIcon = true; }
190
- try {
191
- var config = {
192
- currency: 'INR',
193
- minimumFractionDigits: 0,
194
- };
195
- if (withIcon) {
196
- config.style = 'currency';
197
- }
198
- if (typeof value !== 'string') {
199
- value = value === null || value === void 0 ? void 0 : value.toString();
200
- }
201
- value = value.replace(/,/g, '');
202
- return parseInt(value, 10).toLocaleString('en-IN', config);
203
- }
204
- catch (_e) {
205
- return '';
206
- }
207
- };
208
- var setCookie = function (_a) {
209
- var cookieName = _a.cookieName, cookieValue = _a.cookieValue, expiryInDay = _a.expiryInDay, expiryInHours = _a.expiryInHours, expiryInMinutes = _a.expiryInMinutes;
210
- var expires;
211
- var date = new Date();
212
- if (expiryInDay) {
213
- date.setTime(date.getTime() + expiryInDay * 24 * 60 * 60 * 1000);
214
- expires = date.toUTCString();
215
- }
216
- else if (expiryInHours) {
217
- date.setTime(date.getTime() + expiryInHours * 3600 * 1000);
218
- expires = date.toUTCString();
219
- }
220
- else if (expiryInMinutes) {
221
- date.setTime(date.getTime() + expiryInMinutes * 60 * 1000);
222
- expires = date.toUTCString();
223
- }
224
- else {
225
- expires = '';
226
- }
227
- document.cookie = "".concat(cookieName, "=").concat(cookieValue, "; expires=").concat(expires, "; path=/");
228
- };
229
- function extractQueryParamsAsObj(url) {
230
- try {
231
- var urlObj = new URL(url);
232
- var queryParams = new URLSearchParams(urlObj.search);
233
- var params_1 = {};
234
- queryParams.forEach(function (value, key) {
235
- params_1[key] = value;
236
- });
237
- return params_1;
238
- }
239
- catch (error) {
240
- return {};
241
- }
242
- }
243
- function getNoOfDaysFromToday(checkInDate) {
244
- var checkIn = new Date(checkInDate);
245
- var today = new Date();
246
- today.setHours(12, 0, 0, 0);
247
- checkIn.setHours(12, 0, 0, 0);
248
- var differenceInMs = checkIn.getTime() - today.getTime();
249
- var differenceInDays = differenceInMs / (1000 * 60 * 60 * 24);
250
- return Math.round(differenceInDays);
251
- }
252
-
253
- var getDevicePlatform = function () {
254
- var _a;
255
- var userAgent = (_a = getNestedValue(window, [
256
- 'navigator',
257
- 'userAgent',
258
- ])) === null || _a === void 0 ? void 0 : _a.toLowerCase();
259
- var safariBrowser = /safari/.test(userAgent);
260
- var appleDevice = /iphone|ipod|ipad/.test(userAgent);
261
- if ((getNestedValue(window, ['androidData', 'app-agent']) &&
262
- getNestedValue(window, ['androidData', 'js-version'])) ||
263
- typeof getNestedValue(window, ['MobileApp', 'getAppSpecificData']) ===
264
- 'function') {
265
- return Platform.ANDROID;
266
- }
267
- else if ((getNestedValue(window, ['iosData', 'app-agent']) &&
268
- getNestedValue(window, ['iosData', 'js-version'])) ||
269
- (appleDevice && !safariBrowser)) {
270
- return Platform.IOS;
271
- }
272
- return Platform.PWA;
273
- };
274
- var getAppAgent = function () {
275
- var _a, _b;
276
- var platform = getDevicePlatform();
277
- if (platform === Platform.IOS) {
278
- return (_a = getNestedValue(window, ['iosData', 'app-agent'])) !== null && _a !== void 0 ? _a : AppAgent.IOS;
279
- }
280
- else if (platform === Platform.ANDROID) {
281
- return ((_b = getNestedValue(window, ['androidData', 'app-agent'])) !== null && _b !== void 0 ? _b : AppAgent.ANDROID);
282
- }
283
- return AppAgent.PWA;
284
- };
285
- var getAppAgentForHotelUnifiedHeader = function () {
286
- if (isServer()) {
287
- return AppAgent.H_UNKNOWN;
288
- }
289
- var platform = getDevicePlatform();
290
- if (platform === Platform.IOS) {
291
- return AppAgent.H_IOS;
292
- }
293
- else if (platform === Platform.ANDROID) {
294
- AppAgent.H_ANDROID;
295
- }
296
- return AppAgent.H_PWA;
297
- };
298
- var getJSVersion = function () {
299
- var jsVersion = '';
300
- if (isIOSApp()) {
301
- jsVersion = getNestedValue(window, ['iosData', 'js-version']);
302
- }
303
- else if (isAndroidApp()) {
304
- jsVersion = getNestedValue(window, ['androidData', 'js-version']);
305
- }
306
- if (jsVersion) {
307
- jsVersion = jsVersion.toString().split('.')[0];
308
- }
309
- return jsVersion;
310
- };
311
- var getDeviceModel = function () {
312
- var _a, _b, _c, _d;
313
- if (!isServer()) {
314
- return '';
315
- }
316
- var parser = new UAParser((_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent);
317
- return (_d = (_c = (_b = parser === null || parser === void 0 ? void 0 : parser.getDevice()) === null || _b === void 0 ? void 0 : _b.model) === null || _c === void 0 ? void 0 : _c.toLowerCase()) !== null && _d !== void 0 ? _d : '';
318
- };
319
- var isPwa = function () {
320
- return getDevicePlatform() !== Platform.ANDROID &&
321
- getDevicePlatform() !== Platform.IOS;
322
- };
323
- var isAndroidApp = function () {
324
- return getDevicePlatform() === Platform.ANDROID;
325
- };
326
- var isJSVersionUpdated = function (compareVersion) {
327
- return parseInt(getJSVersion()) >= compareVersion;
328
- };
329
- var isIOSApp = function () { return getDevicePlatform() === Platform.IOS; };
330
-
331
- var API_BASE = getApiDomain();
332
- var getCustomHeaderClientSide = function (additionalInfo) {
333
- var unifiedHeader = {
334
- trackingId: v4(),
335
- source: SOURCE_NAME,
336
- };
337
- if (!isServer()) {
338
- return __assign(__assign(__assign({}, unifiedHeader), { platform: getAppAgent(), deviceModel: getDeviceModel() }), (additionalInfo !== null && additionalInfo !== void 0 ? additionalInfo : {}));
339
- }
340
- return __assign(__assign({}, unifiedHeader), (additionalInfo !== null && additionalInfo !== void 0 ? additionalInfo : {}));
341
- };
342
- var getRequestUrl = function (path, params) {
343
- var url = API_ROUTES[path];
344
- if (!url || !url.trim().length) {
345
- return;
346
- }
347
- url = urlJoin(API_BASE, url);
348
- if (params === null || params === void 0 ? void 0 : params.pathParams) {
349
- for (var _i = 0, _a = Object.entries(params.pathParams); _i < _a.length; _i++) {
350
- var _b = _a[_i], key = _b[0], value = _b[1];
351
- url = url.replace(":".concat(key), value);
352
- }
353
- }
354
- if (params === null || params === void 0 ? void 0 : params.queryParams) {
355
- url += "?".concat(new URLSearchParams(params.queryParams).toString());
356
- }
357
- return url;
358
- };
359
- var createAPIRequest = function (path, method, payload, headers, params, useCustomErrorHandler, additionalUnifiedHeaders) {
360
- if (method === void 0) { method = RequestMethods.GET; }
361
- if (headers === void 0) { headers = {}; }
362
- if (params === void 0) { params = {}; }
363
- if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
364
- if (additionalUnifiedHeaders === void 0) { additionalUnifiedHeaders = {}; }
365
- return __awaiter(void 0, void 0, void 0, function () {
366
- var url, channel, unifiedHeader, API_AUTHORITY, requestOptions, responseData, response, error, message, contentType;
367
- return __generator(this, function (_a) {
368
- switch (_a.label) {
369
- case 0:
370
- url = getRequestUrl(path, params);
371
- if (!url || !url.trim().length) {
372
- return [2, Promise.reject('URL parameter missing')];
373
- }
374
- channel = '';
375
- unifiedHeader = '';
376
- API_AUTHORITY = getApiDomain();
377
- if (!isServer()) {
378
- channel = getDevicePlatform();
379
- unifiedHeader = JSON.stringify(getCustomHeaderClientSide(additionalUnifiedHeaders));
380
- }
381
- requestOptions = {
382
- method: method,
383
- headers: __assign({ channel: channel, Caller: API_BASE, Origin: API_BASE, Referer: API_BASE, Authority: API_AUTHORITY, x_ct_sourcetype: 'MOBILE', 'app-agent': getAppAgent(), 'x-unified-header': unifiedHeader, 'Content-Type': 'application/json' }, headers),
384
- };
385
- if (payload) {
386
- requestOptions.body = JSON.stringify(payload);
387
- }
388
- return [4, fetch(url, requestOptions)];
389
- case 1:
390
- response = _a.sent();
391
- error = {
392
- name: 'API_FAILURE',
393
- status: response.status,
394
- message: 'UNKNOWN_ERROR',
395
- statusText: response.statusText,
396
- };
397
- if (!!(response === null || response === void 0 ? void 0 : response.ok)) return [3, 3];
398
- if (useCustomErrorHandler) {
399
- return [2, Promise.reject(error)];
400
- }
401
- return [4, response.json()];
402
- case 2:
403
- message = (_a.sent()).message;
404
- error.message = message;
405
- throw error;
406
- case 3:
407
- contentType = response.headers.get('content-type');
408
- if (!(contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json'))) return [3, 5];
409
- return [4, response.json()];
410
- case 4:
411
- responseData = _a.sent();
412
- return [3, 9];
413
- case 5:
414
- if (!(contentType === null || contentType === void 0 ? void 0 : contentType.includes('text'))) return [3, 7];
415
- return [4, response.text()];
416
- case 6:
417
- responseData = _a.sent();
418
- return [3, 9];
419
- case 7:
420
- if (!(response.status !== 204)) return [3, 9];
421
- return [4, response.blob()];
422
- case 8:
423
- responseData = _a.sent();
424
- _a.label = 9;
425
- case 9: return [2, {
426
- data: responseData,
427
- status: response.status,
428
- }];
429
- }
430
- });
431
- });
432
- };
433
- var createGetRequest = function (path, headers, params, useCustomErrorHandler, additionalUnifiedHeaders) {
434
- if (headers === void 0) { headers = {}; }
435
- if (params === void 0) { params = {}; }
436
- if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
437
- if (additionalUnifiedHeaders === void 0) { additionalUnifiedHeaders = {}; }
438
- return __awaiter(void 0, void 0, void 0, function () {
439
- return __generator(this, function (_a) {
440
- return [2, createAPIRequest(path, RequestMethods.GET, null, __assign({ expires: '0', accept: 'application/json', 'cache-control': 'no-cache' }, headers), params, useCustomErrorHandler, additionalUnifiedHeaders)];
441
- });
442
- });
443
- };
444
- var createPostOrPutRequest = function (path, method, payload, headers, params, useCustomErrorHandler, additionalUnifiedHeaders) {
445
- if (method === void 0) { method = RequestMethods.POST; }
446
- if (payload === void 0) { payload = {}; }
447
- if (headers === void 0) { headers = {}; }
448
- if (params === void 0) { params = {}; }
449
- if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
450
- if (additionalUnifiedHeaders === void 0) { additionalUnifiedHeaders = {}; }
451
- return __awaiter(void 0, void 0, void 0, function () {
452
- return __generator(this, function (_a) {
453
- return [2, createAPIRequest(path, method, payload, __assign({ expires: '0', accept: 'application/json', 'cache-control': 'no-cache' }, headers), params, useCustomErrorHandler, additionalUnifiedHeaders)];
454
- });
455
- });
456
- };
457
-
458
- var showMobileNumberHint = function () {
459
- var _a;
460
- if (typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onRequestMobileNumber) === 'function') {
461
- window.MobileApp.onRequestMobileNumber();
462
- var promiseResolver_1;
463
- var mobileNoPromise = new Promise(function (resolve) {
464
- promiseResolver_1 = resolve;
465
- });
466
- window.sendSelectedMobileNumber = function (mobileNum) {
467
- return promiseResolver_1(getAutoDetectedMobile(mobileNum));
468
- };
469
- return mobileNoPromise;
470
- }
471
- return Promise.resolve('');
472
- };
473
- var getAutoDetectedMobile = function (mobileNumber) {
474
- var formattedMobileNo = '';
475
- var matches = mobileNumber.match(MOBILE_CONSTANTS.REGEX);
476
- if (matches) {
477
- formattedMobileNo = matches[0].replace(/\D/g, '');
478
- }
479
- return formattedMobileNo;
480
- };
481
- var autoReadOtp = function () { return __awaiter(void 0, void 0, void 0, function () {
482
- return __generator(this, function (_a) {
483
- return [2, isAndroidApp() ? readOtpAndroid() : readOtpPWA()];
484
- });
485
- }); };
486
- var updateNativeIOSOnSignIn = function () {
487
- var _a, _b, _c;
488
- (_c = (_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.PWA_IS_SIGNIN) === null || _c === void 0 ? void 0 : _c.postMessage({
489
- isSignIn: true,
490
- });
491
- };
492
- var updateNativeAndroidOnSignIn = function () {
493
- var _a;
494
- (_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onPWALoginStatus(JSON.stringify({
495
- isSignIn: true,
496
- }));
497
- };
498
- var triggerOTPListener = function () {
499
- var _a;
500
- if (isAndroidApp()) {
501
- (_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onPageStart('OTP_SCREEN');
502
- }
503
- };
504
- var readOtpPWA = function () { return __awaiter(void 0, void 0, void 0, function () {
505
- var abortController;
506
- var _a;
507
- return __generator(this, function (_b) {
508
- if (!((_a = navigator === null || navigator === void 0 ? void 0 : navigator.credentials) === null || _a === void 0 ? void 0 : _a.get) || !('OTPCredential' in window)) {
509
- return [2, Promise.reject('NOT_SUPPORTED')];
510
- }
511
- abortController = new AbortController();
512
- setTimeout(function () {
513
- abortController.abort();
514
- }, 60000);
515
- return [2, navigator.credentials
516
- .get({
517
- otp: { transport: ['sms'] },
518
- signal: abortController.signal,
519
- })
520
- .then(function (content) { return content === null || content === void 0 ? void 0 : content.code; })];
521
- });
522
- }); };
523
- var readOtpAndroid = function () { return __awaiter(void 0, void 0, void 0, function () {
524
- var promiseResolver, otpPromise;
525
- return __generator(this, function (_a) {
526
- otpPromise = new Promise(function (resolve) {
527
- promiseResolver = resolve;
528
- });
529
- window.sendOtpValue = function (otp) {
530
- promiseResolver(otp);
531
- };
532
- return [2, otpPromise];
533
- });
534
- }); };
535
- var shouldShowPushPrimer = function () { return __awaiter(void 0, void 0, void 0, function () {
536
- var _a, _b;
537
- return __generator(this, function (_c) {
538
- if (isAndroidApp() &&
539
- typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.isPNPermissionEnabled) === 'function') {
540
- return [2, Promise.resolve(!((_b = window.MobileApp) === null || _b === void 0 ? void 0 : _b.isPNPermissionEnabled()))];
541
- }
542
- else if (isIOSApp()) {
543
- return [2, new Promise(function (resolve, _reject) {
544
- var _a, _b, _c, _d;
545
- window.pushNotifcationPermissionStatus = function (data) {
546
- var parsedData = JSON.parse(data);
547
- var status = parsedData === null || parsedData === void 0 ? void 0 : parsedData.status;
548
- if (typeof status === 'boolean') {
549
- resolve(!status);
550
- }
551
- };
552
- try {
553
- (_d = (_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b['IS_PN_PERMISSION_ENABLED']) === null || _c === void 0 ? void 0 : _c.postMessage) === null || _d === void 0 ? void 0 : _d.call(_c, '');
554
- }
555
- catch (error) {
556
- resolve(false);
557
- }
558
- })];
559
- }
560
- return [2, Promise.resolve(false)];
561
- });
562
- }); };
563
- var handlePushPrimerCTA = function (type) {
564
- var _a, _b, _c, _d, _e, _f, _g, _h;
565
- if (isAndroidApp() &&
566
- typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.handlePNPermission) === 'function') {
567
- (_b = window.MobileApp) === null || _b === void 0 ? void 0 : _b.handlePNPermission(JSON.stringify({ type: type }));
568
- }
569
- else if (isIOSApp() &&
570
- ((_d = (_c = window === null || window === void 0 ? void 0 : window.webkit) === null || _c === void 0 ? void 0 : _c.messageHandlers) === null || _d === void 0 ? void 0 : _d.HANDLE_PN_PERMISSION)) {
571
- (_h = (_g = (_f = (_e = window.webkit) === null || _e === void 0 ? void 0 : _e.messageHandlers) === null || _f === void 0 ? void 0 : _f.HANDLE_PN_PERMISSION) === null || _g === void 0 ? void 0 : _g.postMessage) === null || _h === void 0 ? void 0 : _h.call(_g, JSON.stringify({ type: type }));
572
- }
573
- return;
574
- };
575
-
576
- var getProfileDetails = function () { return __awaiter(void 0, void 0, void 0, function () {
577
- var response, error_1;
578
- return __generator(this, function (_a) {
579
- switch (_a.label) {
580
- case 0:
581
- _a.trys.push([0, 2, , 3]);
582
- return [4, createGetRequest('GET_PROFILE_DETAILS', {
583
- caller: getApiDomain(),
584
- 'app-agent': getAppAgent(),
585
- }, {})];
586
- case 1:
587
- response = _a.sent();
588
- return [2, response === null || response === void 0 ? void 0 : response.data];
589
- case 2:
590
- error_1 = _a.sent();
591
- console.error('Failed to fetch user details. Error: ', error_1);
592
- return [2, Promise.resolve(null)];
593
- case 3: return [2];
594
- }
595
- });
596
- }); };
597
- var sendLoginOtp = function (mobile, personalizationHeaders) { return __awaiter(void 0, void 0, void 0, function () {
598
- var response;
599
- return __generator(this, function (_a) {
600
- switch (_a.label) {
601
- case 0: return [4, createPostOrPutRequest('SEND_OTP', RequestMethods.POST, {
602
- value: mobile,
603
- type: 'MOBILE',
604
- action: 'SIGNIN',
605
- countryCode: MOBILE_CONSTANTS.COUNTRY_CODE,
606
- }, {
607
- 'ab-otp': 'b',
608
- dvid_data: personalizationHeaders,
609
- })];
610
- case 1:
611
- response = _a.sent();
612
- return [2, response === null || response === void 0 ? void 0 : response.data];
613
- }
614
- });
615
- }); };
616
- var validateOtp = function (mobile, otp) { return __awaiter(void 0, void 0, void 0, function () {
617
- var response, data;
618
- return __generator(this, function (_a) {
619
- switch (_a.label) {
620
- case 0: return [4, createPostOrPutRequest('VALIDATE_OTP', RequestMethods.POST, {
621
- otp: otp,
622
- value: mobile,
623
- type: 'MOBILE',
624
- action: 'SIGNIN',
625
- countryCode: '+91',
626
- }, { 'ab-otp': 'b' })];
627
- case 1:
628
- response = _a.sent();
629
- data = response === null || response === void 0 ? void 0 : response.data;
630
- return [2, __assign(__assign({}, response), { signup: (data === null || data === void 0 ? void 0 : data.action) === ValidateOTPAction.SIGNUP, action: data === null || data === void 0 ? void 0 : data.action, status: response === null || response === void 0 ? void 0 : response.status })];
631
- }
632
- });
633
- }); };
634
- var handleFKSSO = function (fallbackUri, skipProfileFlow) { return __awaiter(void 0, void 0, void 0, function () {
635
- var currentPageUri, redirectionInfo;
636
- return __generator(this, function (_a) {
637
- switch (_a.label) {
638
- case 0:
639
- if (isIOSApp()) {
640
- return [2, Promise.reject()];
641
- }
642
- currentPageUri = getCurrentPathName();
643
- return [4, sendFKSSORedirectionInfo(fallbackUri, skipProfileFlow
644
- ? currentPageUri
645
- : NAVIGATION_ROUTES.PERSONAL_DETAILS + '?onboardingFlow=true', currentPageUri)];
646
- case 1:
647
- redirectionInfo = _a.sent();
648
- if (isAndroidApp()) {
649
- return [2, handleFKSSOAndroid(redirectionInfo)];
650
- }
651
- else {
652
- return [2, handleFKSSOWeb(redirectionInfo)];
653
- }
654
- }
655
- });
656
- }); };
657
- var isValidMobileNumber = function (text) {
658
- return (text === null || text === void 0 ? void 0 : text.length) === MOBILE_CONSTANTS.LENGTH && /^\d{10}$/.test(text);
659
- };
660
- var updateNativeOnLogin = function () {
661
- if (isIOSApp()) {
662
- updateNativeIOSOnSignIn();
663
- }
664
- else if (isAndroidApp()) {
665
- updateNativeAndroidOnSignIn();
666
- }
667
- };
668
- var isFKSSOEnabled = function () {
669
- return isPwa() || (!isIOSApp() && isJSVersionUpdated(5));
670
- };
671
- var sendFKSSORedirectionInfo = function (fallbackUri, signupPageUri, currentPageUri) { return __awaiter(void 0, void 0, void 0, function () {
672
- var WEBSITE_BASE, response;
673
- return __generator(this, function (_a) {
674
- switch (_a.label) {
675
- case 0:
676
- WEBSITE_BASE = getApiDomain();
677
- return [4, createPostOrPutRequest('FK_REDIRECTION_INFO', RequestMethods.POST, {
678
- provider: 'flipkart',
679
- fallbackUri: urlJoin(WEBSITE_BASE, fallbackUri || currentPageUri),
680
- signupPageUri: urlJoin(WEBSITE_BASE, signupPageUri || 'personal-details'),
681
- currentPageUri: urlJoin(WEBSITE_BASE, currentPageUri),
682
- })];
683
- case 1:
684
- response = _a.sent();
685
- return [2, response === null || response === void 0 ? void 0 : response.data];
686
- }
687
- });
688
- }); };
689
- var handleFKSSOWeb = function (redirectionInfo) {
690
- var _a;
691
- var params = (_a = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.params) !== null && _a !== void 0 ? _a : {};
692
- var redirectUri = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.redirectUri;
693
- if (redirectUri) {
694
- redirectUri += '?';
695
- for (var key in params) {
696
- redirectUri += key + '=' + params[key] + '&';
697
- }
698
- return Promise.resolve(redirectUri);
699
- }
700
- return Promise.reject();
701
- };
702
- var handleFKSSOAndroid = function (redirectionInfo) {
703
- var _a, _b;
704
- var params = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.params;
705
- if (isEmpty(params) ||
706
- typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onNavigationChange) !== 'function') {
707
- return Promise.reject();
708
- }
709
- else {
710
- var FK_REDIRECT_DL = urlJoin(getApiDomain(), 'dl/oauth2');
711
- (_b = window.MobileApp) === null || _b === void 0 ? void 0 : _b.onNavigationChange(JSON.stringify({
712
- type: 'FkSSO',
713
- miscData: __assign(__assign({}, params), { redirectURI: FK_REDIRECT_DL }),
714
- }));
715
- return Promise.resolve();
716
- }
717
- };
718
- function getUserAuthValues(customCookie) {
719
- try {
720
- var _a = decodeURIComponent(getCookie('userid', customCookie) || '').split('|'), email = _a[0], profileName = _a[1], gender = _a[2], photo = _a[3], userId = _a[4];
721
- return {
722
- email: email,
723
- profileName: profileName,
724
- gender: gender,
725
- photo: photo,
726
- userId: userId,
727
- };
728
- }
729
- catch (error) {
730
- return {};
731
- }
732
- }
733
- var isUserSignedIn = function (customCookie) {
734
- var userObject = getUserAuthValues(customCookie) || {};
735
- var usermiscVal = decodeURIComponent(getCookie('usermisc', customCookie) || '').split('|');
736
- var signedIn = usermiscVal.includes('SIGNED_IN') &&
737
- userObject.userId &&
738
- userObject.userId.length > 0
739
- ? true
740
- : false;
741
- return signedIn;
742
- };
743
- var sendClevertapProfileDetails = function (profileDetails) {
744
- var _a, _b, _c, _d, _e, _f;
745
- try {
746
- if (isServer() || !(window === null || window === void 0 ? void 0 : window.clevertap) || isEmpty(profileDetails)) {
747
- return;
748
- }
749
- var Site = {
750
- Identity: (_a = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.id) !== null && _a !== void 0 ? _a : '',
751
- Gender: (_b = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.gender) !== null && _b !== void 0 ? _b : '',
752
- Email: (_c = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.username) !== null && _c !== void 0 ? _c : '',
753
- Phone: "".concat(profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.countryCode).concat(profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.mobile),
754
- 'MSG-sms': true,
755
- 'MSG-push': true,
756
- 'MSG-email': false,
757
- 'MSG-whatsapp': true,
758
- };
759
- if ((_d = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.travellerDetails) === null || _d === void 0 ? void 0 : _d.length) {
760
- for (var i = 0; i < ((_e = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.travellerDetails) === null || _e === void 0 ? void 0 : _e.length); i++) {
761
- var traveller = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.travellerDetails[i];
762
- if (traveller.isRegistered) {
763
- var dateOfBirth = traveller.personalDetails.dateOfBirth;
764
- Site.Name = "".concat(traveller.personalDetails.firstName, " ").concat(traveller.personalDetails.lastName);
765
- if (!isNaN(dateOfBirth)) {
766
- Site.DOB = new Date(dateOfBirth);
767
- }
768
- break;
769
- }
770
- }
771
- }
772
- (_f = window === null || window === void 0 ? void 0 : window.clevertap) === null || _f === void 0 ? void 0 : _f.onUserLogin.push({ Site: Site });
773
- }
774
- catch (error) {
775
- console.log('Error pushing clevertap profile information. Error: ', error);
776
- }
777
- };
778
- var handleProfileFetch = function (updateClevertap) {
779
- if (updateClevertap === void 0) { updateClevertap = true; }
780
- return __awaiter(void 0, void 0, void 0, function () {
781
- var response;
782
- return __generator(this, function (_a) {
783
- switch (_a.label) {
784
- case 0: return [4, getProfileDetails()];
785
- case 1:
786
- response = _a.sent();
787
- if (response) {
788
- if (updateClevertap) {
789
- sendClevertapProfileDetails(response);
790
- }
791
- }
792
- return [2];
793
- }
794
- });
795
- });
796
- };
797
-
798
- var getUserInsights = function (userId) { return __awaiter(void 0, void 0, void 0, function () {
799
- var response;
800
- return __generator(this, function (_a) {
801
- switch (_a.label) {
802
- case 0:
803
- _a.trys.push([0, 2, , 3]);
804
- return [4, createGetRequest('USER_INSIGHTS', {}, {
805
- pathParams: {
806
- userId: userId,
807
- },
808
- })];
809
- case 1:
810
- response = _a.sent();
811
- return [2, response === null || response === void 0 ? void 0 : response.data];
812
- case 2:
813
- _a.sent();
814
- return [2, Promise.resolve(null)];
815
- case 3: return [2];
816
- }
817
- });
818
- }); };
819
- var getUserInsightsData = function (userId) { return __awaiter(void 0, void 0, void 0, function () {
820
- var _userId, stringifiedData, sessionData, userInsights;
821
- var _a, _b, _c, _d;
822
- return __generator(this, function (_f) {
823
- switch (_f.label) {
824
- case 0:
825
- _f.trys.push([0, 2, , 3]);
826
- _userId = userId !== null && userId !== void 0 ? userId : getUserAuthValues().userId;
827
- if (!_userId) {
828
- (_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.removeItem('martech_user_attributes');
829
- return [2, null];
830
- }
831
- stringifiedData = (_b = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _b === void 0 ? void 0 : _b.getItem('martech_user_attributes');
832
- sessionData = void 0;
833
- if (typeof stringifiedData === 'string') {
834
- sessionData = JSON.parse(stringifiedData);
835
- }
836
- if (_userId !== (sessionData === null || sessionData === void 0 ? void 0 : sessionData.accountId)) {
837
- (_c = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _c === void 0 ? void 0 : _c.removeItem('martech_user_attributes');
838
- }
839
- return [4, getUserInsights(_userId)];
840
- case 1:
841
- userInsights = _f.sent();
842
- if (isEmpty(userInsights === null || userInsights === void 0 ? void 0 : userInsights.data)) {
843
- return [2, null];
844
- }
845
- (_d = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _d === void 0 ? void 0 : _d.setItem('martech_user_attributes', JSON.stringify(userInsights === null || userInsights === void 0 ? void 0 : userInsights.data));
846
- return [2, userInsights === null || userInsights === void 0 ? void 0 : userInsights.data];
847
- case 2:
848
- _f.sent();
849
- return [2, null];
850
- case 3: return [2];
851
- }
852
- });
853
- }); };
854
-
855
- var stringifyPayload = function (payload) {
856
- var keys = Object.keys(payload);
857
- keys.forEach(function (key) {
858
- if (key === 'a_fare_price' ||
859
- key === 'a_ct_discount' ||
860
- key === 'supercoin_balance' ||
861
- key === 'supercoin_earned' ||
862
- key === 'supercoin_burnt' ||
863
- key === 'wallet_balance_used' ||
864
- key === 'convenience_fee')
865
- payload[key] = Number(payload[key]);
866
- else
867
- payload[key] = '' + payload[key];
868
- });
869
- return payload;
870
- };
871
- var getCTStatsigExpForRaven = function () {
872
- try {
873
- if (isServer()) {
874
- return '';
875
- }
876
- var cookie = getCookie('ct_statsig_experiments') || '{}';
877
- var parsedCookie_1 = cookie
878
- ? JSON.parse(decodeURIComponent(cookie))
879
- : {};
880
- return Object.keys(parsedCookie_1)
881
- .map(function (key) {
882
- if (key && parsedCookie_1[key]) {
883
- return "".concat(key, ":").concat(parsedCookie_1[key]);
884
- }
885
- return '';
886
- })
887
- .filter(function (value) { return !!value; })
888
- .join('|');
889
- }
890
- catch (_e) {
891
- return '';
892
- }
893
- };
894
- var ravenSDKTrigger = function (eventName, ravenPayload) {
895
- var _a;
896
- if (window && window['ravenWebManager']) {
897
- var _b = getRavenEventProps(), pageName = _b.pageName, utmSource = _b.utmSource;
898
- var commonPayload = {
899
- page_name: pageName,
900
- u_utm_source: utmSource,
901
- domain: window.location.host,
902
- u_ab_key: getCTStatsigExpForRaven(),
903
- platform: (_a = getDevicePlatform()) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
904
- login_status: isUserSignedIn() ? 'yes' : 'no',
905
- };
906
- var newRavenPayload = stringifyPayload(ravenPayload);
907
- var RavenWebManager = window['ravenWebManager'];
908
- RavenWebManager === null || RavenWebManager === void 0 ? void 0 : RavenWebManager.triggerRaven(eventName, __assign(__assign({}, commonPayload), newRavenPayload));
909
- }
910
- };
911
- var isAirHomePage = function () {
912
- if (window && typeof window !== 'undefined') {
913
- var pathname = getNestedValue(window, ['location', 'pathname']);
914
- if (pathname === '/' || pathname === '/flights') {
915
- return true;
916
- }
917
- }
918
- return false;
919
- };
920
- var getRavenEventProps = function () {
921
- var _a, _b;
922
- if (window && typeof window !== 'undefined') {
923
- var pathUrl = window.location.pathname;
924
- var redirectionPath = (_a = getQueryParam('service')) !== null && _a !== void 0 ? _a : '';
925
- var utmSource = (_b = getQueryParam('utm_source')) !== null && _b !== void 0 ? _b : 'organic';
926
- var loginForm = isAirHomePage() ? 'skippable_login' : 'account_login';
927
- var vertical = 'air';
928
- var pageName = pathUrl.includes('flights/itinerary') ||
929
- redirectionPath.includes('flights/itinerary')
930
- ? 'a_itinerary'
931
- : 'a_home';
932
- if (redirectionPath.includes('my-account')) {
933
- vertical = 'uar';
934
- pageName = 'account';
935
- }
936
- if (redirectionPath.includes('hotels')) {
937
- vertical = 'hotel';
938
- pageName = redirectionPath.includes('hotels/itinerary')
939
- ? 'h_itinerary'
940
- : 'h_home';
941
- }
942
- if (redirectionPath.includes('bus')) {
943
- vertical = 'bus';
944
- pageName = redirectionPath.includes('bus/itinerary')
945
- ? 'b_itinerary'
946
- : 'b_home';
947
- }
948
- return { loginForm: loginForm, vertical: vertical, pageName: pageName, utmSource: utmSource };
949
- }
950
- return {};
951
- };
952
- var sendEventWithUserInsights = function (eventName, ravenPayload, userId) { return __awaiter(void 0, void 0, void 0, function () {
953
- var userInsights, updatedPayload, loyaltyData, martechAttributes;
954
- var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
955
- return __generator(this, function (_t) {
956
- switch (_t.label) {
957
- case 0: return [4, getUserInsightsData(userId)];
958
- case 1:
959
- userInsights = _t.sent();
960
- updatedPayload = __assign(__assign({}, ravenPayload), { fk_loyalty_status: 'na', fk_loyalty_end_dt: 'na', ct_last_booking_dt: 'na', ct_lifetime_booking: 'na', fk_loyalty_start_dt: 'na', ct_first_booking_dt: 'na', myntra_loyalty_status: 'na', ct_postmerger_booking: 'na', ct_last_1year_booking: 'na', myntra_loyalty_end_dt: 'na', ct_2nd_last_booking_dt: 'na', myntra_loyalty_start_dt: 'na' });
961
- if (!isEmpty(userInsights)) {
962
- loyaltyData = ((_a = userInsights === null || userInsights === void 0 ? void 0 : userInsights.loyaltyStatus) !== null && _a !== void 0 ? _a : []).reduce(function (prev, curr) {
963
- return __assign(__assign({}, prev), curr);
964
- }, {});
965
- martechAttributes = {
966
- ct_lifetime_booking: ((_c = (_b = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _b === void 0 ? void 0 : _b.lifetimeBooking) !== null && _c !== void 0 ? _c : 'na').toString(),
967
- ct_postmerger_booking: ((_f = (_d = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _d === void 0 ? void 0 : _d.postmergerBooking) !== null && _f !== void 0 ? _f : 'na').toString(),
968
- ct_last_1year_booking: ((_h = (_g = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _g === void 0 ? void 0 : _g.lastOneYearBooking) !== null && _h !== void 0 ? _h : 'na').toString(),
969
- ct_first_booking_dt: secondsToDateString((_j = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _j === void 0 ? void 0 : _j.firstbookingDate) || 'na',
970
- ct_last_booking_dt: secondsToDateString((_k = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _k === void 0 ? void 0 : _k.lastbookingDate) || 'na',
971
- ct_2nd_last_booking_dt: secondsToDateString((_l = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _l === void 0 ? void 0 : _l.secondLastbookingDate) || 'na',
972
- fk_loyalty_status: ((_m = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _m === void 0 ? void 0 : _m.program) || 'na',
973
- myntra_loyalty_status: ((_o = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _o === void 0 ? void 0 : _o.program) || 'na',
974
- fk_loyalty_end_dt: secondsToDateString((_p = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _p === void 0 ? void 0 : _p.loyaltyEndDate) || '',
975
- fk_loyalty_start_dt: secondsToDateString((_q = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _q === void 0 ? void 0 : _q.loyaltyStartDate) || 'na',
976
- myntra_loyalty_start_dt: secondsToDateString((_r = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _r === void 0 ? void 0 : _r.loyaltyStartDate) ||
977
- 'na',
978
- myntra_loyalty_end_dt: secondsToDateString((_s = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _s === void 0 ? void 0 : _s.loyaltyEndDate) ||
979
- 'na',
980
- };
981
- updatedPayload = __assign(__assign({}, updatedPayload), martechAttributes);
982
- setMartechUserProperties(martechAttributes);
983
- }
984
- ravenSDKTrigger(eventName, updatedPayload);
985
- return [2];
986
- }
987
- });
988
- }); };
989
- var setMartechUserProperties = function (userProperties) {
990
- var _a, _b, _c, _d, _f, _g, _h, _j, _k;
991
- if (isEmpty(userProperties) ||
992
- ((_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem('martech_user_props_sent'))) {
993
- return;
994
- }
995
- if (isIOSApp() && ((_c = (_b = window === null || window === void 0 ? void 0 : window.webkit) === null || _b === void 0 ? void 0 : _b.messageHandlers) === null || _c === void 0 ? void 0 : _c.SEND_ATTRIBUTES)) {
996
- (_d = window.webkit.messageHandlers.SEND_ATTRIBUTES) === null || _d === void 0 ? void 0 : _d.postMessage({
997
- type: 'GA',
998
- params: userProperties,
999
- });
1000
- (_f = window.webkit.messageHandlers.SEND_ATTRIBUTES) === null || _f === void 0 ? void 0 : _f.postMessage({
1001
- type: 'Clevertap',
1002
- params: userProperties,
1003
- });
1004
- (_g = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _g === void 0 ? void 0 : _g.setItem('martech_user_props_sent', 'true');
1005
- }
1006
- else if (isAndroidApp() && ((_h = window === null || window === void 0 ? void 0 : window.MobileApp) === null || _h === void 0 ? void 0 : _h.sendAttributes)) {
1007
- window.MobileApp.sendAttributes('GA', JSON.stringify(userProperties));
1008
- window.MobileApp.sendAttributes('Clevertap', JSON.stringify(userProperties));
1009
- (_j = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _j === void 0 ? void 0 : _j.setItem('martech_user_props_sent', 'true');
1010
- }
1011
- else if (isPwa() && window.clevertap) {
1012
- window.clevertap.profile.push({
1013
- Site: userProperties,
1014
- });
1015
- (_k = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _k === void 0 ? void 0 : _k.setItem('martech_user_props_sent', 'true');
1016
- }
1017
- };
1018
- var batchRavenEvent = function (eventName, ravenPayload) {
1019
- if (typeof window !== 'undefined' &&
1020
- typeof window.requestIdleCallback === 'function') {
1021
- requestIdleCallback(function () {
1022
- ravenSDKTrigger(eventName, ravenPayload);
1023
- });
1024
- }
1025
- else {
1026
- setTimeout(function () {
1027
- ravenSDKTrigger(eventName, ravenPayload);
1028
- }, 0);
1029
- }
1030
- };
1031
-
1032
- var getHotelCrossSellRecos = function (vertical, fallbackPageLandingURL, cutoff, couponCallOutPrefix, couponCallOutSuffix, offerCallOut, additionalHeaders, additionalParams) {
1033
- if (cutoff === void 0) { cutoff = 450; }
1034
- if (couponCallOutPrefix === void 0) { couponCallOutPrefix = 'Discounts'; }
1035
- if (couponCallOutSuffix === void 0) { couponCallOutSuffix = 'on hotels'; }
1036
- if (offerCallOut === void 0) { offerCallOut = 'CTBEST - Exclusive coupon applied for you!'; }
1037
- if (additionalHeaders === void 0) { additionalHeaders = {}; }
1038
- if (additionalParams === void 0) { additionalParams = {}; }
1039
- return __awaiter(void 0, void 0, void 0, function () {
1040
- var userId, fallbackData, timeoutPromise, fetchRecommendationsPromise, result;
1041
- var _a, _b;
1042
- return __generator(this, function (_c) {
1043
- switch (_c.label) {
1044
- case 0:
1045
- userId = (_b = (_a = getUserAuthValues()) === null || _a === void 0 ? void 0 : _a.userId) !== null && _b !== void 0 ? _b : '';
1046
- fallbackData = {
1047
- couponCode: '',
1048
- couponCallOut: '',
1049
- couponCallOutPrefix: couponCallOutPrefix,
1050
- couponCallOutSuffix: couponCallOutSuffix,
1051
- offerCallOut: offerCallOut,
1052
- pageLandingUrl: fallbackPageLandingURL,
1053
- };
1054
- _c.label = 1;
1055
- case 1:
1056
- _c.trys.push([1, 3, , 4]);
1057
- timeoutPromise = new Promise(function (resolve) {
1058
- setTimeout(function () {
1059
- resolve(fallbackData);
1060
- }, cutoff);
1061
- });
1062
- fetchRecommendationsPromise = createGetRequest('HOTEL_RECOMMENDATIONS', additionalHeaders, {
1063
- queryParams: __assign({ userId: userId, vertical: vertical }, additionalParams),
1064
- }, false, {
1065
- userBuckets: { 'x-cross-sell': 'true' },
1066
- platform: getAppAgentForHotelUnifiedHeader(),
1067
- }).then(function (res) { return res.data; });
1068
- return [4, Promise.race([
1069
- fetchRecommendationsPromise,
1070
- timeoutPromise,
1071
- ])];
1072
- case 2:
1073
- result = _c.sent();
1074
- return [2, result];
1075
- case 3:
1076
- _c.sent();
1077
- return [2, fallbackData];
1078
- case 4: return [2];
1079
- }
1080
- });
1081
- });
1082
- };
1083
-
1084
- export { MULTI_SPACE, autoReadOtp, batchRavenEvent, createAPIRequest, createGetRequest, createPostOrPutRequest, extractQueryParamsAsObj, formatCurrency, formatFullDateString, getApiDomain, getAppAgent, getAppAgentForHotelUnifiedHeader, getAutoDetectedMobile, getCTStatsigExpForRaven, getCookie, getCurrentPathName, getCurrentUrl, getDeviceModel, getDevicePlatform, getDimensionFromImageUrl, getHeightFromImgUrl, getHotelCrossSellRecos, getJSVersion, getNestedValue, getNoOfDaysFromToday, getQueryParam, getRavenEventProps, getUserAuthValues, getWidthFromImgUrl, handleFKSSO, handleProfileFetch, handlePushPrimerCTA, isAirHomePage, isAndroidApp, isEmpty, isFKSSOEnabled, isHTMLInputElement, isIOSApp, isJSVersionUpdated, isNumeric, isPwa, isServer, isUserSignedIn, isValidMobileNumber, path, ravenSDKTrigger, secondsToDateString, sendEventWithUserInsights, sendLoginOtp, setCookie, setMartechUserProperties, shouldShowPushPrimer, showMobileNumberHint, stringifyPayload, triggerOTPListener, updateNativeAndroidOnSignIn, updateNativeIOSOnSignIn, updateNativeOnLogin, urlJoin, validateOtp };
1
+ import{__awaiter as n,__generator as t,__assign as o}from"tslib";import{v4 as e}from"uuid";import{Platform as i,AppAgent as r,RequestMethods as a,SOURCE_NAME as u,API_ROUTES as l,MOBILE_CONSTANTS as d,NAVIGATION_ROUTES as s}from"@cleartrip/ct-platform-constants";import c from"ua-parser-js";import{ValidateOTPAction as v}from"@cleartrip/ct-platform-types";var f=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var o=n.map((function(n){return n.trim().replace(/^[/]+/,"")})).join("/");return o=o.replace(/\/\?/g,"?")},w=function(){var n="undefined"!=typeof window?window.location.hostname:"";switch(console.log("API_BASE domain",n),n){case"localhost":case"0.0.0.0":case"qa2new.cleartrip.com":return"https://qa2new.cleartrip.com";case"qa2.cleartrip.com":return"https://qa2.cleartrip.com";case"qa3new.cleartrip.com":return"https://qa3new.cleartrip.com";default:return"https://www.cleartrip.com"}},p=function(n,t){return t.reduce((function(n,t){return n&&n[t]?n[t]:null}),n)},m=function(n,t){return n.reduce((function(n,t){return n&&n[t]?n[t]:null}),t)},g=/\s\s+/g,_=function(n){if(n instanceof Date)return!1;if(null==n)return!0;var t,o=function(n){return"[object Number]"===Object.prototype.toString.call(n)};if(o(n))return o(t=n)&&"NaN"===t.toString();if(n.length>0)return!1;if(0===n.length)return!0;if("object"!=typeof n)return!0;for(var e=Object.keys(n),i=0,r=e[i];i<e.length;i+=1)if(Object.prototype.hasOwnProperty.call(n,r))return!1;return!0},h=function(n){return"object"==typeof n&&null!==n&&"value"in n&&n instanceof HTMLInputElement},y=function(n){return/^[0-9]*$/.test(n)},b="undefined"!=typeof window?window.location.href:"",S=function(n){return P()?"":new URLSearchParams(window.location.search).get(n)},I=function(){return"undefined"!=typeof window?(window.location.pathname+window.location.search).slice(1):""},N=function(n){if(n){var t=n.match(/h_(\d+)[,\/]/);return t&&t[1]?parseInt(t[1],10):void 0}},O=function(n){if(n){var t=n.match(/w_(\d+)[,\/]/);return t&&t[1]?parseInt(t[1],10):void 0}},P=function(){return"undefined"==typeof window||!window};function D(n,t){var o=t||p(document,["cookie"]);if(o){for(var e=n+"=",i=o.split(";"),r=0;r<i.length;r++){for(var a=i[r];" "==a.charAt(0);)a=a.substring(1,a.length);if(0==a.indexOf(e))return a.substring(e.length,a.length)}return""}return""}var k=function(n){void 0===n&&(n="");var t=N(n)||0,o=O(n)||0;return{height:"".concat(t,"px"),width:"".concat(o,"px"),heightInNumber:t,widthInNumber:o}},E=function(n){try{if(!n||Number.isNaN(Number(n)))return"";var t=new Date(1e3*n),o=t.getFullYear(),e=String(t.getDate()).padStart(2,"0"),i=String(t.getMonth()+1).padStart(2,"0");return"".concat(o,"-").concat(i,"-").concat(e)}catch(n){return""}},A=function(n,t,o){void 0===t&&(t="dd-mm-yyyy"),void 0===o&&(o="");try{var e=new Date(n),i=e.getFullYear(),r=String(e.getDate()).padStart(2,"0"),a=String(e.getMonth()+1).padStart(2,"0");return"yyyy-mm-dd"===t?"".concat(i,"-").concat(a,"-").concat(r):"".concat(r,"-").concat(a,"-").concat(i)}catch(n){return o}},T=function(n,t){void 0===t&&(t=!0);try{var o={currency:"INR",minimumFractionDigits:0};return t&&(o.style="currency"),"string"!=typeof n&&(n=null==n?void 0:n.toString()),n=n.replace(/,/g,""),parseInt(n,10).toLocaleString("en-IN",o)}catch(n){return""}},M=function(n){var t,o=n.cookieName,e=n.cookieValue,i=n.expiryInDay,r=n.expiryInHours,a=n.expiryInMinutes,u=new Date;i?(u.setTime(u.getTime()+24*i*60*60*1e3),t=u.toUTCString()):r?(u.setTime(u.getTime()+3600*r*1e3),t=u.toUTCString()):a?(u.setTime(u.getTime()+60*a*1e3),t=u.toUTCString()):t="",document.cookie="".concat(o,"=").concat(e,"; expires=").concat(t,"; path=/")};function R(n){try{var t=new URL(n),o=new URLSearchParams(t.search),e={};return o.forEach((function(n,t){e[t]=n})),e}catch(n){return{}}}function C(n){var t=new Date(n),o=new Date;o.setHours(12,0,0,0),t.setHours(12,0,0,0);var e=(t.getTime()-o.getTime())/864e5;return Math.round(e)}var j=function(){var n,t=null===(n=p(window,["navigator","userAgent"]))||void 0===n?void 0:n.toLowerCase(),o=/safari/.test(t),e=/iphone|ipod|ipad/.test(t);return p(window,["androidData","app-agent"])&&p(window,["androidData","js-version"])||"function"==typeof p(window,["MobileApp","getAppSpecificData"])?i.ANDROID:p(window,["iosData","app-agent"])&&p(window,["iosData","js-version"])||e&&!o?i.IOS:i.PWA},L=function(){var n,t,o=j();return o===i.IOS?null!==(n=p(window,["iosData","app-agent"]))&&void 0!==n?n:r.IOS:o===i.ANDROID?null!==(t=p(window,["androidData","app-agent"]))&&void 0!==t?t:r.ANDROID:r.PWA},U=function(){if(P())return r.H_UNKNOWN;var n=j();return n===i.IOS?r.H_IOS:(n===i.ANDROID&&r.H_ANDROID,r.H_PWA)},x=function(){var n="";return J()?n=p(window,["iosData","js-version"]):B()&&(n=p(window,["androidData","js-version"])),n&&(n=n.toString().split(".")[0]),n},H=function(){var n,t,o,e;if(!P())return"";var i=new c(null===(n=null===window||void 0===window?void 0:window.navigator)||void 0===n?void 0:n.userAgent);return null!==(e=null===(o=null===(t=null==i?void 0:i.getDevice())||void 0===t?void 0:t.model)||void 0===o?void 0:o.toLowerCase())&&void 0!==e?e:""},G=function(){return j()!==i.ANDROID&&j()!==i.IOS},B=function(){return j()===i.ANDROID},q=function(n){return parseInt(x())>=n},J=function(){return j()===i.IOS},F=w(),W=function(i,r,d,s,c,v,p){return void 0===r&&(r=a.GET),void 0===s&&(s={}),void 0===c&&(c={}),void 0===v&&(v=!1),void 0===p&&(p={}),n(void 0,void 0,void 0,(function(){var n,a,m,g,_,h,y,b,S,I;return t(this,(function(t){switch(t.label){case 0:return n=function(n,t){var o=l[n];if(o&&o.trim().length){if(o=f(F,o),null==t?void 0:t.pathParams)for(var e=0,i=Object.entries(t.pathParams);e<i.length;e++){var r=i[e],a=r[0],u=r[1];o=o.replace(":".concat(a),u)}return(null==t?void 0:t.queryParams)&&(o+="?".concat(new URLSearchParams(t.queryParams).toString())),o}}(i,c),n&&n.trim().length?(a="",m="",g=w(),P()||(a=j(),m=JSON.stringify(function(n){var t={trackingId:e(),source:u};return P()?o(o({},t),null!=n?n:{}):o(o(o({},t),{platform:L(),deviceModel:H()}),null!=n?n:{})}(p))),_={method:r,headers:o({channel:a,Caller:F,Origin:F,Referer:F,Authority:g,x_ct_sourcetype:"MOBILE","app-agent":L(),"x-unified-header":m,"Content-Type":"application/json"},s)},d&&(_.body=JSON.stringify(d)),[4,fetch(n,_)]):[2,Promise.reject("URL parameter missing")];case 1:return y=t.sent(),b={name:"API_FAILURE",status:y.status,message:"UNKNOWN_ERROR",statusText:y.statusText},(null==y?void 0:y.ok)?[3,3]:v?[2,Promise.reject(b)]:[4,y.json()];case 2:throw S=t.sent().message,b.message=S,b;case 3:return(null==(I=y.headers.get("content-type"))?void 0:I.includes("application/json"))?[4,y.json()]:[3,5];case 4:return h=t.sent(),[3,9];case 5:return(null==I?void 0:I.includes("text"))?[4,y.text()]:[3,7];case 6:return h=t.sent(),[3,9];case 7:return 204===y.status?[3,9]:[4,y.blob()];case 8:h=t.sent(),t.label=9;case 9:return[2,{data:h,status:y.status}]}}))}))},Y=function(e,i,r,u,l){return void 0===i&&(i={}),void 0===r&&(r={}),void 0===u&&(u=!1),void 0===l&&(l={}),n(void 0,void 0,void 0,(function(){return t(this,(function(n){return[2,W(e,a.GET,null,o({expires:"0",accept:"application/json","cache-control":"no-cache"},i),r,u,l)]}))}))},K=function(e,i,r,u,l,d,s){return void 0===i&&(i=a.POST),void 0===r&&(r={}),void 0===u&&(u={}),void 0===l&&(l={}),void 0===d&&(d=!1),void 0===s&&(s={}),n(void 0,void 0,void 0,(function(){return t(this,(function(n){return[2,W(e,i,r,o({expires:"0",accept:"application/json","cache-control":"no-cache"},u),l,d,s)]}))}))},V=function(){var n;if("function"==typeof(null===(n=window.MobileApp)||void 0===n?void 0:n.onRequestMobileNumber)){var t;window.MobileApp.onRequestMobileNumber();var o=new Promise((function(n){t=n}));return window.sendSelectedMobileNumber=function(n){return t($(n))},o}return Promise.resolve("")},$=function(n){var t="",o=n.match(d.REGEX);return o&&(t=o[0].replace(/\D/g,"")),t},X=function(){return n(void 0,void 0,void 0,(function(){return t(this,(function(n){return[2,B()?tn():nn()]}))}))},z=function(){var n,t,o;null===(o=null===(t=null===(n=window.webkit)||void 0===n?void 0:n.messageHandlers)||void 0===t?void 0:t.PWA_IS_SIGNIN)||void 0===o||o.postMessage({isSignIn:!0})},Q=function(){var n;null===(n=window.MobileApp)||void 0===n||n.onPWALoginStatus(JSON.stringify({isSignIn:!0}))},Z=function(){var n;B()&&(null===(n=window.MobileApp)||void 0===n||n.onPageStart("OTP_SCREEN"))},nn=function(){return n(void 0,void 0,void 0,(function(){var n,o;return t(this,(function(t){return(null===(o=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===o?void 0:o.get)&&"OTPCredential"in window?(n=new AbortController,setTimeout((function(){n.abort()}),6e4),[2,navigator.credentials.get({otp:{transport:["sms"]},signal:n.signal}).then((function(n){return null==n?void 0:n.code}))]):[2,Promise.reject("NOT_SUPPORTED")]}))}))},tn=function(){return n(void 0,void 0,void 0,(function(){var n,o;return t(this,(function(t){return o=new Promise((function(t){n=t})),window.sendOtpValue=function(t){n(t)},[2,o]}))}))},on=function(){return n(void 0,void 0,void 0,(function(){var n,o;return t(this,(function(t){return B()&&"function"==typeof(null===(n=window.MobileApp)||void 0===n?void 0:n.isPNPermissionEnabled)?[2,Promise.resolve(!(null===(o=window.MobileApp)||void 0===o?void 0:o.isPNPermissionEnabled()))]:J()?[2,new Promise((function(n,t){var o,e,i,r;window.pushNotifcationPermissionStatus=function(t){var o=JSON.parse(t),e=null==o?void 0:o.status;"boolean"==typeof e&&n(!e)};try{null===(r=null===(i=null===(e=null===(o=null===window||void 0===window?void 0:window.webkit)||void 0===o?void 0:o.messageHandlers)||void 0===e?void 0:e.IS_PN_PERMISSION_ENABLED)||void 0===i?void 0:i.postMessage)||void 0===r||r.call(i,"")}catch(t){n(!1)}}))]:[2,Promise.resolve(!1)]}))}))},en=function(n){var t,o,e,i,r,a,u,l;B()&&"function"==typeof(null===(t=window.MobileApp)||void 0===t?void 0:t.handlePNPermission)?null===(o=window.MobileApp)||void 0===o||o.handlePNPermission(JSON.stringify({type:n})):J()&&(null===(i=null===(e=null===window||void 0===window?void 0:window.webkit)||void 0===e?void 0:e.messageHandlers)||void 0===i?void 0:i.HANDLE_PN_PERMISSION)&&(null===(l=null===(u=null===(a=null===(r=window.webkit)||void 0===r?void 0:r.messageHandlers)||void 0===a?void 0:a.HANDLE_PN_PERMISSION)||void 0===u?void 0:u.postMessage)||void 0===l||l.call(u,JSON.stringify({type:n})))},rn=function(o,e){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return[4,K("SEND_OTP",a.POST,{value:o,type:"MOBILE",action:"SIGNIN",countryCode:d.COUNTRY_CODE},{"ab-otp":"b",dvid_data:e})];case 1:return[2,null==(n=t.sent())?void 0:n.data]}}))}))},an=function(e,i){return n(void 0,void 0,void 0,(function(){var n,r;return t(this,(function(t){switch(t.label){case 0:return[4,K("VALIDATE_OTP",a.POST,{otp:i,value:e,type:"MOBILE",action:"SIGNIN",countryCode:"+91"},{"ab-otp":"b"})];case 1:return n=t.sent(),r=null==n?void 0:n.data,[2,o(o({},n),{signup:(null==r?void 0:r.action)===v.SIGNUP,action:null==r?void 0:r.action,status:null==n?void 0:n.status})]}}))}))},un=function(o,e){return n(void 0,void 0,void 0,(function(){var n,i;return t(this,(function(t){switch(t.label){case 0:return J()?[2,Promise.reject()]:(n=I(),[4,cn(o,e?n:s.PERSONAL_DETAILS+"?onboardingFlow=true",n)]);case 1:return i=t.sent(),B()?[2,fn(i)]:[2,vn(i)]}}))}))},ln=function(n){return(null==n?void 0:n.length)===d.LENGTH&&/^\d{10}$/.test(n)},dn=function(){J()?z():B()&&Q()},sn=function(){return G()||!J()&&q(5)},cn=function(o,e,i){return n(void 0,void 0,void 0,(function(){var n,r;return t(this,(function(t){switch(t.label){case 0:return n=w(),[4,K("FK_REDIRECTION_INFO",a.POST,{provider:"flipkart",fallbackUri:f(n,o||i),signupPageUri:f(n,e||"personal-details"),currentPageUri:f(n,i)})];case 1:return[2,null==(r=t.sent())?void 0:r.data]}}))}))},vn=function(n){var t,o=null!==(t=null==n?void 0:n.params)&&void 0!==t?t:{},e=null==n?void 0:n.redirectUri;if(e){for(var i in e+="?",o)e+=i+"="+o[i]+"&";return Promise.resolve(e)}return Promise.reject()},fn=function(n){var t,e,i=null==n?void 0:n.params;if(_(i)||"function"!=typeof(null===(t=window.MobileApp)||void 0===t?void 0:t.onNavigationChange))return Promise.reject();var r=f(w(),"dl/oauth2");return null===(e=window.MobileApp)||void 0===e||e.onNavigationChange(JSON.stringify({type:"FkSSO",miscData:o(o({},i),{redirectURI:r})})),Promise.resolve()};function wn(n){try{var t=decodeURIComponent(D("userid",n)||"").split("|");return{email:t[0],profileName:t[1],gender:t[2],photo:t[3],userId:t[4]}}catch(n){return{}}}var pn=function(n){var t=wn(n)||{};return!!(decodeURIComponent(D("usermisc",n)||"").split("|").includes("SIGNED_IN")&&t.userId&&t.userId.length>0)},mn=function(o){return void 0===o&&(o=!0),n(void 0,void 0,void 0,(function(){var e;return t(this,(function(i){switch(i.label){case 0:return[4,n(void 0,void 0,void 0,(function(){var n,o;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,Y("GET_PROFILE_DETAILS",{caller:w(),"app-agent":L()},{})];case 1:return[2,null==(n=t.sent())?void 0:n.data];case 2:return o=t.sent(),console.error("Failed to fetch user details. Error: ",o),[2,Promise.resolve(null)];case 3:return[2]}}))}))];case 1:return(e=i.sent())&&o&&function(n){var t,o,e,i,r,a;try{if(P()||!(null===window||void 0===window?void 0:window.clevertap)||_(n))return;var u={Identity:null!==(t=null==n?void 0:n.id)&&void 0!==t?t:"",Gender:null!==(o=null==n?void 0:n.gender)&&void 0!==o?o:"",Email:null!==(e=null==n?void 0:n.username)&&void 0!==e?e:"",Phone:"".concat(null==n?void 0:n.countryCode).concat(null==n?void 0:n.mobile),"MSG-sms":!0,"MSG-push":!0,"MSG-email":!1,"MSG-whatsapp":!0};if(null===(i=null==n?void 0:n.travellerDetails)||void 0===i?void 0:i.length)for(var l=0;l<(null===(r=null==n?void 0:n.travellerDetails)||void 0===r?void 0:r.length);l++){var d=null==n?void 0:n.travellerDetails[l];if(d.isRegistered){var s=d.personalDetails.dateOfBirth;u.Name="".concat(d.personalDetails.firstName," ").concat(d.personalDetails.lastName),isNaN(s)||(u.DOB=new Date(s));break}}null===(a=null===window||void 0===window?void 0:window.clevertap)||void 0===a||a.onUserLogin.push({Site:u})}catch(n){console.log("Error pushing clevertap profile information. Error: ",n)}}(e),[2]}}))}))},gn=function(o){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,Y("USER_INSIGHTS",{},{pathParams:{userId:o}})];case 1:return[2,null==(n=t.sent())?void 0:n.data];case 2:return t.sent(),[2,Promise.resolve(null)];case 3:return[2]}}))}))},_n=function(o){return n(void 0,void 0,void 0,(function(){var n,e,i,r,a,u,l,d;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),(n=null!=o?o:wn().userId)?(e=null===(u=null===window||void 0===window?void 0:window.sessionStorage)||void 0===u?void 0:u.getItem("martech_user_attributes"),i=void 0,"string"==typeof e&&(i=JSON.parse(e)),n!==(null==i?void 0:i.accountId)&&(null===(l=null===window||void 0===window?void 0:window.sessionStorage)||void 0===l||l.removeItem("martech_user_attributes")),[4,gn(n)]):(null===(a=null===window||void 0===window?void 0:window.sessionStorage)||void 0===a||a.removeItem("martech_user_attributes"),[2,null]);case 1:return r=t.sent(),_(null==r?void 0:r.data)?[2,null]:(null===(d=null===window||void 0===window?void 0:window.sessionStorage)||void 0===d||d.setItem("martech_user_attributes",JSON.stringify(null==r?void 0:r.data)),[2,null==r?void 0:r.data]);case 2:return t.sent(),[2,null];case 3:return[2]}}))}))},hn=function(n){return Object.keys(n).forEach((function(t){n[t]="a_fare_price"===t||"a_ct_discount"===t||"supercoin_balance"===t||"supercoin_earned"===t||"supercoin_burnt"===t||"wallet_balance_used"===t||"convenience_fee"===t?Number(n[t]):""+n[t]})),n},yn=function(){try{if(P())return"";var n=D("ct_statsig_experiments")||"{}",t=n?JSON.parse(decodeURIComponent(n)):{};return Object.keys(t).map((function(n){return n&&t[n]?"".concat(n,":").concat(t[n]):""})).filter((function(n){return!!n})).join("|")}catch(n){return""}},bn=function(n,t){var e;if(window&&window.ravenWebManager){var i=In(),r={page_name:i.pageName,u_utm_source:i.utmSource,domain:window.location.host,u_ab_key:yn(),platform:null===(e=j())||void 0===e?void 0:e.toLowerCase(),login_status:pn()?"yes":"no"},a=hn(t),u=window.ravenWebManager;null==u||u.triggerRaven(n,o(o({},r),a))}},Sn=function(){if(window&&"undefined"!=typeof window){var n=p(window,["location","pathname"]);if("/"===n||"/flights"===n)return!0}return!1},In=function(){var n,t;if(window&&"undefined"!=typeof window){var o=window.location.pathname,e=null!==(n=S("service"))&&void 0!==n?n:"",i=null!==(t=S("utm_source"))&&void 0!==t?t:"organic",r=Sn()?"skippable_login":"account_login",a="air",u=o.includes("flights/itinerary")||e.includes("flights/itinerary")?"a_itinerary":"a_home";return e.includes("my-account")&&(a="uar",u="account"),e.includes("hotels")&&(a="hotel",u=e.includes("hotels/itinerary")?"h_itinerary":"h_home"),e.includes("bus")&&(a="bus",u=e.includes("bus/itinerary")?"b_itinerary":"b_home"),{loginForm:r,vertical:a,pageName:u,utmSource:i}}return{}},Nn=function(e,i,r){return n(void 0,void 0,void 0,(function(){var n,a,u,l,d,s,c,v,f,w,p,m,g,h,y,b,S,I,N,O;return t(this,(function(t){switch(t.label){case 0:return[4,_n(r)];case 1:return n=t.sent(),a=o(o({},i),{fk_loyalty_status:"na",fk_loyalty_end_dt:"na",ct_last_booking_dt:"na",ct_lifetime_booking:"na",fk_loyalty_start_dt:"na",ct_first_booking_dt:"na",myntra_loyalty_status:"na",ct_postmerger_booking:"na",ct_last_1year_booking:"na",myntra_loyalty_end_dt:"na",ct_2nd_last_booking_dt:"na",myntra_loyalty_start_dt:"na"}),_(n)||(u=(null!==(d=null==n?void 0:n.loyaltyStatus)&&void 0!==d?d:[]).reduce((function(n,t){return o(o({},n),t)}),{}),l={ct_lifetime_booking:(null!==(c=null===(s=null==n?void 0:n.bookingStatus)||void 0===s?void 0:s.lifetimeBooking)&&void 0!==c?c:"na").toString(),ct_postmerger_booking:(null!==(f=null===(v=null==n?void 0:n.bookingStatus)||void 0===v?void 0:v.postmergerBooking)&&void 0!==f?f:"na").toString(),ct_last_1year_booking:(null!==(p=null===(w=null==n?void 0:n.bookingStatus)||void 0===w?void 0:w.lastOneYearBooking)&&void 0!==p?p:"na").toString(),ct_first_booking_dt:E(null===(m=null==n?void 0:n.bookingStatus)||void 0===m?void 0:m.firstbookingDate)||"na",ct_last_booking_dt:E(null===(g=null==n?void 0:n.bookingStatus)||void 0===g?void 0:g.lastbookingDate)||"na",ct_2nd_last_booking_dt:E(null===(h=null==n?void 0:n.bookingStatus)||void 0===h?void 0:h.secondLastbookingDate)||"na",fk_loyalty_status:(null===(y=null==u?void 0:u.fk)||void 0===y?void 0:y.program)||"na",myntra_loyalty_status:(null===(b=null==u?void 0:u.myntra)||void 0===b?void 0:b.program)||"na",fk_loyalty_end_dt:E(null===(S=null==u?void 0:u.fk)||void 0===S?void 0:S.loyaltyEndDate)||"",fk_loyalty_start_dt:E(null===(I=null==u?void 0:u.fk)||void 0===I?void 0:I.loyaltyStartDate)||"na",myntra_loyalty_start_dt:E(null===(N=null==u?void 0:u.myntra)||void 0===N?void 0:N.loyaltyStartDate)||"na",myntra_loyalty_end_dt:E(null===(O=null==u?void 0:u.myntra)||void 0===O?void 0:O.loyaltyEndDate)||"na"},a=o(o({},a),l),On(l)),bn(e,a),[2]}}))}))},On=function(n){var t,o,e,i,r,a,u,l,d;_(n)||(null===(t=null===window||void 0===window?void 0:window.sessionStorage)||void 0===t?void 0:t.getItem("martech_user_props_sent"))||(J()&&(null===(e=null===(o=null===window||void 0===window?void 0:window.webkit)||void 0===o?void 0:o.messageHandlers)||void 0===e?void 0:e.SEND_ATTRIBUTES)?(null===(i=window.webkit.messageHandlers.SEND_ATTRIBUTES)||void 0===i||i.postMessage({type:"GA",params:n}),null===(r=window.webkit.messageHandlers.SEND_ATTRIBUTES)||void 0===r||r.postMessage({type:"Clevertap",params:n}),null===(a=null===window||void 0===window?void 0:window.sessionStorage)||void 0===a||a.setItem("martech_user_props_sent","true")):B()&&(null===(u=null===window||void 0===window?void 0:window.MobileApp)||void 0===u?void 0:u.sendAttributes)?(window.MobileApp.sendAttributes("GA",JSON.stringify(n)),window.MobileApp.sendAttributes("Clevertap",JSON.stringify(n)),null===(l=null===window||void 0===window?void 0:window.sessionStorage)||void 0===l||l.setItem("martech_user_props_sent","true")):G()&&window.clevertap&&(window.clevertap.profile.push({Site:n}),null===(d=null===window||void 0===window?void 0:window.sessionStorage)||void 0===d||d.setItem("martech_user_props_sent","true")))},Pn=function(n,t){"undefined"!=typeof window&&"function"==typeof window.requestIdleCallback?requestIdleCallback((function(){bn(n,t)})):setTimeout((function(){bn(n,t)}),0)},Dn=function(e,i,r,a,u,l,d,s){return void 0===r&&(r=450),void 0===a&&(a="Discounts"),void 0===u&&(u="on hotels"),void 0===l&&(l="CTBEST - Exclusive coupon applied for you!"),void 0===d&&(d={}),void 0===s&&(s={}),n(void 0,void 0,void 0,(function(){var n,c,v,f,w,p;return t(this,(function(t){switch(t.label){case 0:n=null!==(p=null===(w=wn())||void 0===w?void 0:w.userId)&&void 0!==p?p:"",c={couponCode:"",couponCallOut:"",couponCallOutPrefix:a,couponCallOutSuffix:u,offerCallOut:l,pageLandingUrl:i},t.label=1;case 1:return t.trys.push([1,3,,4]),v=new Promise((function(n){setTimeout((function(){n(c)}),r)})),f=Y("HOTEL_RECOMMENDATIONS",d,{queryParams:o({userId:n,vertical:e},s)},!1,{userBuckets:{"x-cross-sell":"true"},platform:U()}).then((function(n){return n.data})),[4,Promise.race([f,v])];case 2:return[2,t.sent()];case 3:return t.sent(),[2,c];case 4:return[2]}}))}))};export{g as MULTI_SPACE,X as autoReadOtp,Pn as batchRavenEvent,W as createAPIRequest,Y as createGetRequest,K as createPostOrPutRequest,R as extractQueryParamsAsObj,T as formatCurrency,A as formatFullDateString,w as getApiDomain,L as getAppAgent,U as getAppAgentForHotelUnifiedHeader,$ as getAutoDetectedMobile,yn as getCTStatsigExpForRaven,D as getCookie,I as getCurrentPathName,b as getCurrentUrl,H as getDeviceModel,j as getDevicePlatform,k as getDimensionFromImageUrl,N as getHeightFromImgUrl,Dn as getHotelCrossSellRecos,x as getJSVersion,p as getNestedValue,C as getNoOfDaysFromToday,S as getQueryParam,In as getRavenEventProps,wn as getUserAuthValues,O as getWidthFromImgUrl,un as handleFKSSO,mn as handleProfileFetch,en as handlePushPrimerCTA,Sn as isAirHomePage,B as isAndroidApp,_ as isEmpty,sn as isFKSSOEnabled,h as isHTMLInputElement,J as isIOSApp,q as isJSVersionUpdated,y as isNumeric,G as isPwa,P as isServer,pn as isUserSignedIn,ln as isValidMobileNumber,m as path,bn as ravenSDKTrigger,E as secondsToDateString,Nn as sendEventWithUserInsights,rn as sendLoginOtp,M as setCookie,On as setMartechUserProperties,on as shouldShowPushPrimer,V as showMobileNumberHint,hn as stringifyPayload,Z as triggerOTPListener,Q as updateNativeAndroidOnSignIn,z as updateNativeIOSOnSignIn,dn as updateNativeOnLogin,f as urlJoin,an as validateOtp};
1085
2
  //# sourceMappingURL=ct-platform-utils.esm.js.map