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