@cleartrip/ct-platform-utils 3.15.1-beta.5 → 3.17.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,1132 +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({ type: type }));
558
- }
559
- else if (isIOSApp() &&
560
- ((_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)) {
561
- (_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 }));
562
- }
563
- return;
564
- };
565
-
566
- var getProfileDetails = function () { return tslib.__awaiter(void 0, void 0, void 0, function () {
567
- var response, error_1;
568
- return tslib.__generator(this, function (_a) {
569
- switch (_a.label) {
570
- case 0:
571
- _a.trys.push([0, 2, , 3]);
572
- return [4, createGetRequest('GET_PROFILE_DETAILS', {
573
- caller: getApiDomain(),
574
- 'app-agent': getAppAgent(),
575
- }, {})];
576
- case 1:
577
- response = _a.sent();
578
- return [2, response === null || response === void 0 ? void 0 : response.data];
579
- case 2:
580
- error_1 = _a.sent();
581
- console.error('Failed to fetch user details. Error: ', error_1);
582
- return [2, Promise.resolve(null)];
583
- case 3: return [2];
584
- }
585
- });
586
- }); };
587
- var sendLoginOtp = function (mobile, personalizationHeaders) { return tslib.__awaiter(void 0, void 0, void 0, function () {
588
- var response;
589
- return tslib.__generator(this, function (_a) {
590
- switch (_a.label) {
591
- case 0: return [4, createPostOrPutRequest('SEND_OTP', ctPlatformConstants.RequestMethods.POST, {
592
- value: mobile,
593
- type: 'MOBILE',
594
- action: 'SIGNIN',
595
- countryCode: ctPlatformConstants.MOBILE_CONSTANTS.COUNTRY_CODE,
596
- }, {
597
- 'ab-otp': 'b',
598
- dvid_data: personalizationHeaders,
599
- })];
600
- case 1:
601
- response = _a.sent();
602
- return [2, response === null || response === void 0 ? void 0 : response.data];
603
- }
604
- });
605
- }); };
606
- var validateOtp = function (mobile, otp) { return tslib.__awaiter(void 0, void 0, void 0, function () {
607
- var response, data;
608
- return tslib.__generator(this, function (_a) {
609
- switch (_a.label) {
610
- case 0: return [4, createPostOrPutRequest('VALIDATE_OTP', ctPlatformConstants.RequestMethods.POST, {
611
- otp: otp,
612
- value: mobile,
613
- type: 'MOBILE',
614
- action: 'SIGNIN',
615
- countryCode: '+91',
616
- }, { 'ab-otp': 'b' })];
617
- case 1:
618
- response = _a.sent();
619
- data = response === null || response === void 0 ? void 0 : response.data;
620
- 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 })];
621
- }
622
- });
623
- }); };
624
- var handleFKSSO = function (fallbackUri, skipProfileFlow) { return tslib.__awaiter(void 0, void 0, void 0, function () {
625
- var currentPageUri, redirectionInfo;
626
- return tslib.__generator(this, function (_a) {
627
- switch (_a.label) {
628
- case 0:
629
- if (isIOSApp()) {
630
- return [2, Promise.reject()];
631
- }
632
- currentPageUri = getCurrentPathName();
633
- return [4, sendFKSSORedirectionInfo(fallbackUri, skipProfileFlow
634
- ? currentPageUri
635
- : ctPlatformConstants.NAVIGATION_ROUTES.PERSONAL_DETAILS + '?onboardingFlow=true', currentPageUri)];
636
- case 1:
637
- redirectionInfo = _a.sent();
638
- if (isAndroidApp()) {
639
- return [2, handleFKSSOAndroid(redirectionInfo)];
640
- }
641
- else {
642
- return [2, handleFKSSOWeb(redirectionInfo)];
643
- }
644
- }
645
- });
646
- }); };
647
- var isValidMobileNumber = function (text) {
648
- return (text === null || text === void 0 ? void 0 : text.length) === ctPlatformConstants.MOBILE_CONSTANTS.LENGTH && /^\d{10}$/.test(text);
649
- };
650
- var updateNativeOnLogin = function () {
651
- if (isIOSApp()) {
652
- updateNativeIOSOnSignIn();
653
- }
654
- else if (isAndroidApp()) {
655
- updateNativeAndroidOnSignIn();
656
- }
657
- };
658
- var isFKSSOEnabled = function () {
659
- return isPwa() || (!isIOSApp() && isJSVersionUpdated(5));
660
- };
661
- var sendFKSSORedirectionInfo = function (fallbackUri, signupPageUri, currentPageUri) { return tslib.__awaiter(void 0, void 0, void 0, function () {
662
- var WEBSITE_BASE, response;
663
- return tslib.__generator(this, function (_a) {
664
- switch (_a.label) {
665
- case 0:
666
- WEBSITE_BASE = getApiDomain();
667
- return [4, createPostOrPutRequest('FK_REDIRECTION_INFO', ctPlatformConstants.RequestMethods.POST, {
668
- provider: 'flipkart',
669
- fallbackUri: urlJoin(WEBSITE_BASE, fallbackUri || currentPageUri),
670
- signupPageUri: urlJoin(WEBSITE_BASE, signupPageUri || 'personal-details'),
671
- currentPageUri: urlJoin(WEBSITE_BASE, currentPageUri),
672
- })];
673
- case 1:
674
- response = _a.sent();
675
- return [2, response === null || response === void 0 ? void 0 : response.data];
676
- }
677
- });
678
- }); };
679
- var handleFKSSOWeb = function (redirectionInfo) {
680
- var _a;
681
- var params = (_a = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.params) !== null && _a !== void 0 ? _a : {};
682
- var redirectUri = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.redirectUri;
683
- if (redirectUri) {
684
- redirectUri += '?';
685
- for (var key in params) {
686
- redirectUri += key + '=' + params[key] + '&';
687
- }
688
- return Promise.resolve(redirectUri);
689
- }
690
- return Promise.reject();
691
- };
692
- var handleFKSSOAndroid = function (redirectionInfo) {
693
- var _a, _b;
694
- var params = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.params;
695
- if (isEmpty(params) ||
696
- typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onNavigationChange) !== 'function') {
697
- return Promise.reject();
698
- }
699
- else {
700
- var FK_REDIRECT_DL = urlJoin(getApiDomain(), 'dl/oauth2');
701
- (_b = window.MobileApp) === null || _b === void 0 ? void 0 : _b.onNavigationChange(JSON.stringify({
702
- type: 'FkSSO',
703
- miscData: tslib.__assign(tslib.__assign({}, params), { redirectURI: FK_REDIRECT_DL }),
704
- }));
705
- return Promise.resolve();
706
- }
707
- };
708
- function getUserAuthValues(customCookie) {
709
- try {
710
- var _a = decodeURIComponent(getCookie('userid', customCookie) || '').split('|'), email = _a[0], profileName = _a[1], gender = _a[2], photo = _a[3], userId = _a[4];
711
- return {
712
- email: email,
713
- profileName: profileName,
714
- gender: gender,
715
- photo: photo,
716
- userId: userId,
717
- };
718
- }
719
- catch (error) {
720
- return {};
721
- }
722
- }
723
- var isUserSignedIn = function (customCookie) {
724
- var userObject = getUserAuthValues(customCookie) || {};
725
- var usermiscVal = decodeURIComponent(getCookie('usermisc', customCookie) || '').split('|');
726
- var signedIn = usermiscVal.includes('SIGNED_IN') &&
727
- userObject.userId &&
728
- userObject.userId.length > 0
729
- ? true
730
- : false;
731
- return signedIn;
732
- };
733
- var sendClevertapProfileDetails = function (profileDetails) {
734
- var _a, _b, _c, _d, _e, _f;
735
- try {
736
- if (isServer() || !(window === null || window === void 0 ? void 0 : window.clevertap) || isEmpty(profileDetails)) {
737
- return;
738
- }
739
- var Site = {
740
- Identity: (_a = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.id) !== null && _a !== void 0 ? _a : '',
741
- Gender: (_b = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.gender) !== null && _b !== void 0 ? _b : '',
742
- Email: (_c = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.username) !== null && _c !== void 0 ? _c : '',
743
- Phone: "".concat(profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.countryCode).concat(profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.mobile),
744
- 'MSG-sms': true,
745
- 'MSG-push': true,
746
- 'MSG-email': false,
747
- 'MSG-whatsapp': true,
748
- };
749
- if ((_d = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.travellerDetails) === null || _d === void 0 ? void 0 : _d.length) {
750
- for (var i = 0; i < ((_e = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.travellerDetails) === null || _e === void 0 ? void 0 : _e.length); i++) {
751
- var traveller = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.travellerDetails[i];
752
- if (traveller.isRegistered) {
753
- var dateOfBirth = traveller.personalDetails.dateOfBirth;
754
- Site.Name = "".concat(traveller.personalDetails.firstName, " ").concat(traveller.personalDetails.lastName);
755
- if (!isNaN(dateOfBirth)) {
756
- Site.DOB = new Date(dateOfBirth);
757
- }
758
- break;
759
- }
760
- }
761
- }
762
- (_f = window === null || window === void 0 ? void 0 : window.clevertap) === null || _f === void 0 ? void 0 : _f.onUserLogin.push({ Site: Site });
763
- }
764
- catch (error) {
765
- console.log('Error pushing clevertap profile information. Error: ', error);
766
- }
767
- };
768
- var handleProfileFetch = function (updateClevertap) {
769
- if (updateClevertap === void 0) { updateClevertap = true; }
770
- return tslib.__awaiter(void 0, void 0, void 0, function () {
771
- var response;
772
- return tslib.__generator(this, function (_a) {
773
- switch (_a.label) {
774
- case 0: return [4, getProfileDetails()];
775
- case 1:
776
- response = _a.sent();
777
- if (response) {
778
- if (updateClevertap) {
779
- sendClevertapProfileDetails(response);
780
- }
781
- }
782
- return [2];
783
- }
784
- });
785
- });
786
- };
787
-
788
- var getUserInsights = function (userId) { return tslib.__awaiter(void 0, void 0, void 0, function () {
789
- var response;
790
- return tslib.__generator(this, function (_a) {
791
- switch (_a.label) {
792
- case 0:
793
- _a.trys.push([0, 2, , 3]);
794
- return [4, createGetRequest('USER_INSIGHTS', {}, {
795
- pathParams: {
796
- userId: userId,
797
- },
798
- })];
799
- case 1:
800
- response = _a.sent();
801
- return [2, response === null || response === void 0 ? void 0 : response.data];
802
- case 2:
803
- _a.sent();
804
- return [2, Promise.resolve(null)];
805
- case 3: return [2];
806
- }
807
- });
808
- }); };
809
- var getUserInsightsData = function (userId) { return tslib.__awaiter(void 0, void 0, void 0, function () {
810
- var _userId, stringifiedData, sessionData, userInsights;
811
- var _a, _b, _c, _d;
812
- return tslib.__generator(this, function (_f) {
813
- switch (_f.label) {
814
- case 0:
815
- _f.trys.push([0, 2, , 3]);
816
- _userId = userId !== null && userId !== void 0 ? userId : getUserAuthValues().userId;
817
- if (!_userId) {
818
- (_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.removeItem('martech_user_attributes');
819
- return [2, null];
820
- }
821
- stringifiedData = (_b = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _b === void 0 ? void 0 : _b.getItem('martech_user_attributes');
822
- sessionData = void 0;
823
- if (typeof stringifiedData === 'string') {
824
- sessionData = JSON.parse(stringifiedData);
825
- }
826
- if (_userId !== (sessionData === null || sessionData === void 0 ? void 0 : sessionData.accountId)) {
827
- (_c = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _c === void 0 ? void 0 : _c.removeItem('martech_user_attributes');
828
- }
829
- return [4, getUserInsights(_userId)];
830
- case 1:
831
- userInsights = _f.sent();
832
- if (isEmpty(userInsights === null || userInsights === void 0 ? void 0 : userInsights.data)) {
833
- return [2, null];
834
- }
835
- (_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));
836
- return [2, userInsights === null || userInsights === void 0 ? void 0 : userInsights.data];
837
- case 2:
838
- _f.sent();
839
- return [2, null];
840
- case 3: return [2];
841
- }
842
- });
843
- }); };
844
-
845
- var stringifyPayload = function (payload) {
846
- var keys = Object.keys(payload);
847
- keys.forEach(function (key) {
848
- if (key === 'a_fare_price' ||
849
- key === 'a_ct_discount' ||
850
- key === 'supercoin_balance' ||
851
- key === 'supercoin_earned' ||
852
- key === 'supercoin_burnt' ||
853
- key === 'wallet_balance_used' ||
854
- key === 'convenience_fee')
855
- payload[key] = Number(payload[key]);
856
- else
857
- payload[key] = '' + payload[key];
858
- });
859
- return payload;
860
- };
861
- var getCTStatsigExpForRaven = function () {
862
- try {
863
- if (isServer()) {
864
- return '';
865
- }
866
- var cookie = getCookie('ct_statsig_experiments') || '{}';
867
- var parsedCookie_1 = cookie
868
- ? JSON.parse(decodeURIComponent(cookie))
869
- : {};
870
- return Object.keys(parsedCookie_1)
871
- .map(function (key) {
872
- if (key && parsedCookie_1[key]) {
873
- return "".concat(key, ":").concat(parsedCookie_1[key]);
874
- }
875
- return '';
876
- })
877
- .filter(function (value) { return !!value; })
878
- .join('|');
879
- }
880
- catch (_e) {
881
- return '';
882
- }
883
- };
884
- var ravenSDKTrigger = function (eventName, ravenPayload) {
885
- var _a;
886
- if (window && window['ravenWebManager']) {
887
- var _b = getRavenEventProps(), pageName = _b.pageName, utmSource = _b.utmSource;
888
- var commonPayload = {
889
- page_name: pageName,
890
- u_utm_source: utmSource,
891
- domain: window.location.host,
892
- u_ab_key: getCTStatsigExpForRaven(),
893
- platform: (_a = getDevicePlatform()) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
894
- login_status: isUserSignedIn() ? 'yes' : 'no',
895
- };
896
- var newRavenPayload = stringifyPayload(ravenPayload);
897
- var RavenWebManager = window['ravenWebManager'];
898
- RavenWebManager === null || RavenWebManager === void 0 ? void 0 : RavenWebManager.triggerRaven(eventName, tslib.__assign(tslib.__assign({}, commonPayload), newRavenPayload));
899
- }
900
- };
901
- var isAirHomePage = function () {
902
- if (window && typeof window !== 'undefined') {
903
- var pathname = getNestedValue(window, ['location', 'pathname']);
904
- if (pathname === '/' || pathname === '/flights') {
905
- return true;
906
- }
907
- }
908
- return false;
909
- };
910
- var getRavenEventProps = function () {
911
- var _a, _b;
912
- if (window && typeof window !== 'undefined') {
913
- var pathUrl = window.location.pathname;
914
- var redirectionPath = (_a = getQueryParam('service')) !== null && _a !== void 0 ? _a : '';
915
- var utmSource = (_b = getQueryParam('utm_source')) !== null && _b !== void 0 ? _b : 'organic';
916
- var loginForm = isAirHomePage() ? 'skippable_login' : 'account_login';
917
- var vertical = 'air';
918
- var pageName = pathUrl.includes('flights/itinerary') ||
919
- redirectionPath.includes('flights/itinerary')
920
- ? 'a_itinerary'
921
- : 'a_home';
922
- if (redirectionPath.includes('my-account')) {
923
- vertical = 'uar';
924
- pageName = 'account';
925
- }
926
- if (redirectionPath.includes('hotels')) {
927
- vertical = 'hotel';
928
- pageName = redirectionPath.includes('hotels/itinerary')
929
- ? 'h_itinerary'
930
- : 'h_home';
931
- }
932
- if (redirectionPath.includes('bus')) {
933
- vertical = 'bus';
934
- pageName = redirectionPath.includes('bus/itinerary')
935
- ? 'b_itinerary'
936
- : 'b_home';
937
- }
938
- return { loginForm: loginForm, vertical: vertical, pageName: pageName, utmSource: utmSource };
939
- }
940
- return {};
941
- };
942
- var sendEventWithUserInsights = function (eventName, ravenPayload, userId) { return tslib.__awaiter(void 0, void 0, void 0, function () {
943
- var userInsights, updatedPayload, loyaltyData, martechAttributes;
944
- var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
945
- return tslib.__generator(this, function (_t) {
946
- switch (_t.label) {
947
- case 0: return [4, getUserInsightsData(userId)];
948
- case 1:
949
- userInsights = _t.sent();
950
- 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' });
951
- if (!isEmpty(userInsights)) {
952
- loyaltyData = ((_a = userInsights === null || userInsights === void 0 ? void 0 : userInsights.loyaltyStatus) !== null && _a !== void 0 ? _a : []).reduce(function (prev, curr) {
953
- return tslib.__assign(tslib.__assign({}, prev), curr);
954
- }, {});
955
- martechAttributes = {
956
- 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(),
957
- 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(),
958
- 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(),
959
- ct_first_booking_dt: secondsToDateString((_j = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _j === void 0 ? void 0 : _j.firstbookingDate) || 'na',
960
- ct_last_booking_dt: secondsToDateString((_k = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _k === void 0 ? void 0 : _k.lastbookingDate) || 'na',
961
- 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',
962
- fk_loyalty_status: ((_m = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _m === void 0 ? void 0 : _m.program) || 'na',
963
- myntra_loyalty_status: ((_o = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _o === void 0 ? void 0 : _o.program) || 'na',
964
- fk_loyalty_end_dt: secondsToDateString((_p = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _p === void 0 ? void 0 : _p.loyaltyEndDate) || '',
965
- fk_loyalty_start_dt: secondsToDateString((_q = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _q === void 0 ? void 0 : _q.loyaltyStartDate) || 'na',
966
- myntra_loyalty_start_dt: secondsToDateString((_r = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _r === void 0 ? void 0 : _r.loyaltyStartDate) ||
967
- 'na',
968
- myntra_loyalty_end_dt: secondsToDateString((_s = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _s === void 0 ? void 0 : _s.loyaltyEndDate) ||
969
- 'na',
970
- };
971
- updatedPayload = tslib.__assign(tslib.__assign({}, updatedPayload), martechAttributes);
972
- setMartechUserProperties(martechAttributes);
973
- }
974
- ravenSDKTrigger(eventName, updatedPayload);
975
- return [2];
976
- }
977
- });
978
- }); };
979
- var setMartechUserProperties = function (userProperties) {
980
- var _a, _b, _c, _d, _f, _g, _h, _j, _k;
981
- if (isEmpty(userProperties) ||
982
- ((_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem('martech_user_props_sent'))) {
983
- return;
984
- }
985
- 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)) {
986
- (_d = window.webkit.messageHandlers.SEND_ATTRIBUTES) === null || _d === void 0 ? void 0 : _d.postMessage({
987
- type: 'GA',
988
- params: userProperties,
989
- });
990
- (_f = window.webkit.messageHandlers.SEND_ATTRIBUTES) === null || _f === void 0 ? void 0 : _f.postMessage({
991
- type: 'Clevertap',
992
- params: userProperties,
993
- });
994
- (_g = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _g === void 0 ? void 0 : _g.setItem('martech_user_props_sent', 'true');
995
- }
996
- else if (isAndroidApp() && ((_h = window === null || window === void 0 ? void 0 : window.MobileApp) === null || _h === void 0 ? void 0 : _h.sendAttributes)) {
997
- window.MobileApp.sendAttributes('GA', JSON.stringify(userProperties));
998
- window.MobileApp.sendAttributes('Clevertap', JSON.stringify(userProperties));
999
- (_j = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _j === void 0 ? void 0 : _j.setItem('martech_user_props_sent', 'true');
1000
- }
1001
- else if (isPwa() && window.clevertap) {
1002
- window.clevertap.profile.push({
1003
- Site: userProperties,
1004
- });
1005
- (_k = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _k === void 0 ? void 0 : _k.setItem('martech_user_props_sent', 'true');
1006
- }
1007
- };
1008
- var batchRavenEvent = function (eventName, ravenPayload) {
1009
- if (typeof window !== 'undefined' &&
1010
- typeof window.requestIdleCallback === 'function') {
1011
- requestIdleCallback(function () {
1012
- ravenSDKTrigger(eventName, ravenPayload);
1013
- });
1014
- }
1015
- else {
1016
- setTimeout(function () {
1017
- ravenSDKTrigger(eventName, ravenPayload);
1018
- }, 0);
1019
- }
1020
- };
1021
-
1022
- var getHotelCrossSellRecos = function (vertical, fallbackPageLandingURL, cutoff, couponCallOutPrefix, couponCallOutSuffix, offerCallOut, additionalHeaders, additionalParams) {
1023
- if (cutoff === void 0) { cutoff = 450; }
1024
- if (couponCallOutPrefix === void 0) { couponCallOutPrefix = 'Discounts'; }
1025
- if (couponCallOutSuffix === void 0) { couponCallOutSuffix = 'on hotels'; }
1026
- if (offerCallOut === void 0) { offerCallOut = 'CTBEST - Exclusive coupon applied for you!'; }
1027
- if (additionalHeaders === void 0) { additionalHeaders = {}; }
1028
- if (additionalParams === void 0) { additionalParams = {}; }
1029
- return tslib.__awaiter(void 0, void 0, void 0, function () {
1030
- var userId, fallbackData, timeoutPromise, fetchRecommendationsPromise, result;
1031
- var _a, _b;
1032
- return tslib.__generator(this, function (_c) {
1033
- switch (_c.label) {
1034
- case 0:
1035
- userId = (_b = (_a = getUserAuthValues()) === null || _a === void 0 ? void 0 : _a.userId) !== null && _b !== void 0 ? _b : '';
1036
- fallbackData = {
1037
- couponCode: '',
1038
- couponCallOut: '',
1039
- couponCallOutPrefix: couponCallOutPrefix,
1040
- couponCallOutSuffix: couponCallOutSuffix,
1041
- offerCallOut: offerCallOut,
1042
- pageLandingUrl: fallbackPageLandingURL,
1043
- };
1044
- _c.label = 1;
1045
- case 1:
1046
- _c.trys.push([1, 3, , 4]);
1047
- timeoutPromise = new Promise(function (resolve) {
1048
- setTimeout(function () {
1049
- resolve(fallbackData);
1050
- }, cutoff);
1051
- });
1052
- fetchRecommendationsPromise = createGetRequest('HOTEL_RECOMMENDATIONS', additionalHeaders, {
1053
- queryParams: tslib.__assign({ userId: userId, vertical: vertical }, additionalParams),
1054
- }, false, {
1055
- userBuckets: { 'x-cross-sell': 'true' },
1056
- }).then(function (res) { return res.data; });
1057
- return [4, Promise.race([
1058
- fetchRecommendationsPromise,
1059
- timeoutPromise,
1060
- ])];
1061
- case 2:
1062
- result = _c.sent();
1063
- return [2, result];
1064
- case 3:
1065
- _c.sent();
1066
- return [2, fallbackData];
1067
- case 4: return [2];
1068
- }
1069
- });
1070
- });
1071
- };
1072
-
1073
- exports.MULTI_SPACE = MULTI_SPACE;
1074
- exports.autoReadOtp = autoReadOtp;
1075
- exports.batchRavenEvent = batchRavenEvent;
1076
- exports.createAPIRequest = createAPIRequest;
1077
- exports.createGetRequest = createGetRequest;
1078
- exports.createPostOrPutRequest = createPostOrPutRequest;
1079
- exports.extractQueryParamsAsObj = extractQueryParamsAsObj;
1080
- exports.formatCurrency = formatCurrency;
1081
- exports.formatFullDateString = formatFullDateString;
1082
- exports.getApiDomain = getApiDomain;
1083
- exports.getAppAgent = getAppAgent;
1084
- exports.getAutoDetectedMobile = getAutoDetectedMobile;
1085
- exports.getCTStatsigExpForRaven = getCTStatsigExpForRaven;
1086
- exports.getCookie = getCookie;
1087
- exports.getCurrentPathName = getCurrentPathName;
1088
- exports.getCurrentUrl = getCurrentUrl;
1089
- exports.getDeviceModel = getDeviceModel;
1090
- exports.getDevicePlatform = getDevicePlatform;
1091
- exports.getDimensionFromImageUrl = getDimensionFromImageUrl;
1092
- exports.getHeightFromImgUrl = getHeightFromImgUrl;
1093
- exports.getHotelCrossSellRecos = getHotelCrossSellRecos;
1094
- exports.getJSVersion = getJSVersion;
1095
- exports.getNestedValue = getNestedValue;
1096
- exports.getNoOfDaysFromToday = getNoOfDaysFromToday;
1097
- exports.getQueryParam = getQueryParam;
1098
- exports.getRavenEventProps = getRavenEventProps;
1099
- exports.getUserAuthValues = getUserAuthValues;
1100
- exports.getWidthFromImgUrl = getWidthFromImgUrl;
1101
- exports.handleFKSSO = handleFKSSO;
1102
- exports.handleProfileFetch = handleProfileFetch;
1103
- exports.handlePushPrimerCTA = handlePushPrimerCTA;
1104
- exports.isAirHomePage = isAirHomePage;
1105
- exports.isAndroidApp = isAndroidApp;
1106
- exports.isEmpty = isEmpty;
1107
- exports.isFKSSOEnabled = isFKSSOEnabled;
1108
- exports.isHTMLInputElement = isHTMLInputElement;
1109
- exports.isIOSApp = isIOSApp;
1110
- exports.isJSVersionUpdated = isJSVersionUpdated;
1111
- exports.isNumeric = isNumeric;
1112
- exports.isPwa = isPwa;
1113
- exports.isServer = isServer;
1114
- exports.isUserSignedIn = isUserSignedIn;
1115
- exports.isValidMobileNumber = isValidMobileNumber;
1116
- exports.path = path;
1117
- exports.ravenSDKTrigger = ravenSDKTrigger;
1118
- exports.secondsToDateString = secondsToDateString;
1119
- exports.sendEventWithUserInsights = sendEventWithUserInsights;
1120
- exports.sendLoginOtp = sendLoginOtp;
1121
- exports.setCookie = setCookie;
1122
- exports.setMartechUserProperties = setMartechUserProperties;
1123
- exports.shouldShowPushPrimer = shouldShowPushPrimer;
1124
- exports.showMobileNumberHint = showMobileNumberHint;
1125
- exports.stringifyPayload = stringifyPayload;
1126
- exports.triggerOTPListener = triggerOTPListener;
1127
- exports.updateNativeAndroidOnSignIn = updateNativeAndroidOnSignIn;
1128
- exports.updateNativeIOSOnSignIn = updateNativeIOSOnSignIn;
1129
- exports.updateNativeOnLogin = updateNativeOnLogin;
1130
- exports.urlJoin = urlJoin;
1131
- 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})]}}))}))};
1132
2
  //# sourceMappingURL=ct-platform-utils.cjs.js.map