@cleartrip/ct-platform-utils 3.15.1-beta.4 → 3.16.0

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