@cleartrip/ct-platform-utils 3.11.3-beta.1 → 3.11.3

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,959 +1,2 @@
1
- 'use strict';
2
-
3
- var tslib = require('tslib');
4
- var ctPlatformConstants = require('@cleartrip/ct-platform-constants');
5
- var ctPlatformTypes = require('@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
-
209
- var getDevicePlatform = function () {
210
- var _a;
211
- var userAgent = (_a = getNestedValue(window, [
212
- 'navigator',
213
- 'userAgent',
214
- ])) === null || _a === void 0 ? void 0 : _a.toLowerCase();
215
- var safariBrowser = /safari/.test(userAgent);
216
- var appleDevice = /iphone|ipod|ipad/.test(userAgent);
217
- if ((getNestedValue(window, ['androidData', 'app-agent']) &&
218
- getNestedValue(window, ['androidData', 'js-version'])) ||
219
- typeof getNestedValue(window, ['MobileApp', 'getAppSpecificData']) ===
220
- 'function') {
221
- return ctPlatformConstants.Platform.ANDROID;
222
- }
223
- else if ((getNestedValue(window, ['iosData', 'app-agent']) &&
224
- getNestedValue(window, ['iosData', 'js-version'])) ||
225
- (appleDevice && !safariBrowser)) {
226
- return ctPlatformConstants.Platform.IOS;
227
- }
228
- return ctPlatformConstants.Platform.PWA;
229
- };
230
- var getAppAgent = function () {
231
- var _a, _b;
232
- var platform = getDevicePlatform();
233
- if (platform === ctPlatformConstants.Platform.IOS) {
234
- return (_a = getNestedValue(window, ['iosData', 'app-agent'])) !== null && _a !== void 0 ? _a : ctPlatformConstants.AppAgent.IOS;
235
- }
236
- else if (platform === ctPlatformConstants.Platform.ANDROID) {
237
- return ((_b = getNestedValue(window, ['androidData', 'app-agent'])) !== null && _b !== void 0 ? _b : ctPlatformConstants.AppAgent.ANDROID);
238
- }
239
- return ctPlatformConstants.AppAgent.PWA;
240
- };
241
- var getJSVersion = function () {
242
- var jsVersion = '';
243
- if (isIOSApp()) {
244
- jsVersion = getNestedValue(window, ['iosData', 'js-version']);
245
- }
246
- else if (isAndroidApp()) {
247
- jsVersion = getNestedValue(window, ['androidData', 'js-version']);
248
- }
249
- if (jsVersion) {
250
- jsVersion = jsVersion.toString().split('.')[0];
251
- }
252
- return jsVersion;
253
- };
254
- var isPwa = function () {
255
- return getDevicePlatform() !== ctPlatformConstants.Platform.ANDROID &&
256
- getDevicePlatform() !== ctPlatformConstants.Platform.IOS;
257
- };
258
- var isAndroidApp = function () {
259
- return getDevicePlatform() === ctPlatformConstants.Platform.ANDROID;
260
- };
261
- var isJSVersionUpdated = function (compareVersion) {
262
- return parseInt(getJSVersion()) >= compareVersion;
263
- };
264
- var isIOSApp = function () { return getDevicePlatform() === ctPlatformConstants.Platform.IOS; };
265
-
266
- var API_BASE = getApiDomain();
267
- var getRequestUrl = function (path, params) {
268
- var url = ctPlatformConstants.API_ROUTES[path];
269
- if (!url || !url.trim().length) {
270
- return;
271
- }
272
- url = urlJoin(API_BASE, url);
273
- if (params === null || params === void 0 ? void 0 : params.pathParams) {
274
- for (var _i = 0, _a = Object.entries(params.pathParams); _i < _a.length; _i++) {
275
- var _b = _a[_i], key = _b[0], value = _b[1];
276
- url = url.replace(":".concat(key), value);
277
- }
278
- }
279
- if (params === null || params === void 0 ? void 0 : params.queryParams) {
280
- url += "?".concat(new URLSearchParams(params.queryParams).toString());
281
- }
282
- return url;
283
- };
284
- var createAPIRequest = function (path, method, payload, headers, params, useCustomErrorHandler) {
285
- if (method === void 0) { method = ctPlatformConstants.RequestMethods.GET; }
286
- if (headers === void 0) { headers = {}; }
287
- if (params === void 0) { params = {}; }
288
- if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
289
- return tslib.__awaiter(void 0, void 0, void 0, function () {
290
- var url, API_AUTHORITY, requestOptions, responseData, response, error, message, contentType;
291
- return tslib.__generator(this, function (_a) {
292
- switch (_a.label) {
293
- case 0:
294
- url = getRequestUrl(path, params);
295
- if (!url || !url.trim().length) {
296
- return [2, Promise.reject('URL parameter missing')];
297
- }
298
- API_AUTHORITY = getApiDomain();
299
- requestOptions = {
300
- method: method,
301
- headers: tslib.__assign({ Caller: API_BASE, Origin: API_BASE, Referer: API_BASE, Authority: API_AUTHORITY, x_ct_sourcetype: 'MOBILE', 'app-agent': getAppAgent(), 'Content-Type': 'application/json' }, headers),
302
- };
303
- if (payload) {
304
- requestOptions.body = JSON.stringify(payload);
305
- }
306
- return [4, fetch(url, requestOptions)];
307
- case 1:
308
- response = _a.sent();
309
- error = {
310
- name: 'API_FAILURE',
311
- status: response.status,
312
- message: 'UNKNOWN_ERROR',
313
- statusText: response.statusText,
314
- };
315
- if (!!(response === null || response === void 0 ? void 0 : response.ok)) return [3, 3];
316
- if (useCustomErrorHandler) {
317
- return [2, Promise.reject(error)];
318
- }
319
- return [4, response.json()];
320
- case 2:
321
- message = (_a.sent()).message;
322
- error.message = message;
323
- throw error;
324
- case 3:
325
- contentType = response.headers.get('content-type');
326
- if (!(contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json'))) return [3, 5];
327
- return [4, response.json()];
328
- case 4:
329
- responseData = _a.sent();
330
- return [3, 9];
331
- case 5:
332
- if (!(contentType === null || contentType === void 0 ? void 0 : contentType.includes('text'))) return [3, 7];
333
- return [4, response.text()];
334
- case 6:
335
- responseData = _a.sent();
336
- return [3, 9];
337
- case 7:
338
- if (!(response.status !== 204)) return [3, 9];
339
- return [4, response.blob()];
340
- case 8:
341
- responseData = _a.sent();
342
- _a.label = 9;
343
- case 9: return [2, {
344
- data: responseData,
345
- status: response.status,
346
- }];
347
- }
348
- });
349
- });
350
- };
351
- var createGetRequest = function (path, headers, params, useCustomErrorHandler) {
352
- if (headers === void 0) { headers = {}; }
353
- if (params === void 0) { params = {}; }
354
- if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
355
- return tslib.__awaiter(void 0, void 0, void 0, function () {
356
- return tslib.__generator(this, function (_a) {
357
- return [2, createAPIRequest(path, ctPlatformConstants.RequestMethods.GET, null, tslib.__assign({ expires: '0', accept: 'application/json', 'cache-control': 'no-cache' }, headers), params, useCustomErrorHandler)];
358
- });
359
- });
360
- };
361
- var createPostOrPutRequest = function (path, method, payload, headers, params, useCustomErrorHandler) {
362
- if (method === void 0) { method = ctPlatformConstants.RequestMethods.POST; }
363
- if (payload === void 0) { payload = {}; }
364
- if (headers === void 0) { headers = {}; }
365
- if (params === void 0) { params = {}; }
366
- if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
367
- return tslib.__awaiter(void 0, void 0, void 0, function () {
368
- return tslib.__generator(this, function (_a) {
369
- return [2, createAPIRequest(path, method, payload, tslib.__assign({ expires: '0', accept: 'application/json', 'cache-control': 'no-cache' }, headers), params, useCustomErrorHandler)];
370
- });
371
- });
372
- };
373
-
374
- var showMobileNumberHint = function () {
375
- var _a;
376
- if (typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onRequestMobileNumber) === 'function') {
377
- window.MobileApp.onRequestMobileNumber();
378
- var promiseResolver_1;
379
- var mobileNoPromise = new Promise(function (resolve) {
380
- promiseResolver_1 = resolve;
381
- });
382
- window.sendSelectedMobileNumber = function (mobileNum) {
383
- return promiseResolver_1(getAutoDetectedMobile(mobileNum));
384
- };
385
- return mobileNoPromise;
386
- }
387
- return Promise.resolve('');
388
- };
389
- var getAutoDetectedMobile = function (mobileNumber) {
390
- var formattedMobileNo = '';
391
- var matches = mobileNumber.match(ctPlatformConstants.MOBILE_CONSTANTS.REGEX);
392
- if (matches) {
393
- formattedMobileNo = matches[0].replace(/\D/g, '');
394
- }
395
- return formattedMobileNo;
396
- };
397
- var autoReadOtp = function () { return tslib.__awaiter(void 0, void 0, void 0, function () {
398
- return tslib.__generator(this, function (_a) {
399
- return [2, isAndroidApp() ? readOtpAndroid() : readOtpPWA()];
400
- });
401
- }); };
402
- var updateNativeIOSOnSignIn = function () {
403
- var _a, _b, _c;
404
- (_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({
405
- isSignIn: true,
406
- });
407
- };
408
- var updateNativeAndroidOnSignIn = function () {
409
- var _a;
410
- (_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onPWALoginStatus(JSON.stringify({
411
- isSignIn: true,
412
- }));
413
- };
414
- var triggerOTPListener = function () {
415
- var _a;
416
- if (isAndroidApp()) {
417
- (_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onPageStart('OTP_SCREEN');
418
- }
419
- };
420
- var readOtpPWA = function () { return tslib.__awaiter(void 0, void 0, void 0, function () {
421
- var abortController;
422
- var _a;
423
- return tslib.__generator(this, function (_b) {
424
- if (!((_a = navigator === null || navigator === void 0 ? void 0 : navigator.credentials) === null || _a === void 0 ? void 0 : _a.get) || !('OTPCredential' in window)) {
425
- return [2, Promise.reject('NOT_SUPPORTED')];
426
- }
427
- abortController = new AbortController();
428
- setTimeout(function () {
429
- abortController.abort();
430
- }, 60000);
431
- return [2, navigator.credentials
432
- .get({
433
- otp: { transport: ['sms'] },
434
- signal: abortController.signal,
435
- })
436
- .then(function (content) { return content === null || content === void 0 ? void 0 : content.code; })];
437
- });
438
- }); };
439
- var readOtpAndroid = function () { return tslib.__awaiter(void 0, void 0, void 0, function () {
440
- var promiseResolver, otpPromise;
441
- return tslib.__generator(this, function (_a) {
442
- otpPromise = new Promise(function (resolve) {
443
- promiseResolver = resolve;
444
- });
445
- window.sendOtpValue = function (otp) {
446
- promiseResolver(otp);
447
- };
448
- return [2, otpPromise];
449
- });
450
- }); };
451
- var shouldShowPushPrimer = function () { return tslib.__awaiter(void 0, void 0, void 0, function () {
452
- var getValue_1, value_1, interval_1;
453
- var _a, _b, _c;
454
- return tslib.__generator(this, function (_d) {
455
- switch (_d.label) {
456
- case 0:
457
- if (!(isIOSApp() &&
458
- typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.IS_PN_PERMISSION_ENABLED) === 'function')) return [3, 2];
459
- getValue_1 = function () {
460
- var _a;
461
- return (_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.IS_PN_PERMISSION_ENABLED();
462
- };
463
- return [4, getValue_1()];
464
- case 1:
465
- value_1 = _d.sent();
466
- interval_1 = setInterval(function () { return tslib.__awaiter(void 0, void 0, void 0, function () {
467
- return tslib.__generator(this, function (_a) {
468
- switch (_a.label) {
469
- case 0: return [4, getValue_1()];
470
- case 1:
471
- value_1 = _a.sent();
472
- if (value_1 !== null) {
473
- clearInterval(interval_1);
474
- }
475
- return [2];
476
- }
477
- });
478
- }); }, 1000);
479
- return [2, value_1];
480
- case 2:
481
- if (isAndroidApp() &&
482
- typeof ((_b = window.MobileApp) === null || _b === void 0 ? void 0 : _b.isPNPermissionEnabled) === 'function') {
483
- return [2, (_c = window.MobileApp) === null || _c === void 0 ? void 0 : _c.isPNPermissionEnabled()];
484
- }
485
- _d.label = 3;
486
- case 3: return [2, false];
487
- }
488
- });
489
- }); };
490
- var handlePushPrimerCTA = function (type) {
491
- var _a, _b, _c, _d;
492
- if (isAndroidApp() &&
493
- typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.handlePNPermission) === 'function') {
494
- (_b = window.MobileApp) === null || _b === void 0 ? void 0 : _b.handlePNPermission(JSON.stringify({
495
- type: type,
496
- }));
497
- }
498
- else if (isIOSApp() &&
499
- typeof ((_c = window.MobileApp) === null || _c === void 0 ? void 0 : _c.HANDLE_PN_PERMISSION) === 'function') {
500
- (_d = window.MobileApp) === null || _d === void 0 ? void 0 : _d.HANDLE_PN_PERMISSION(JSON.stringify({
501
- type: type,
502
- }));
503
- }
504
- return '';
505
- };
506
-
507
- var sendLoginOtp = function (mobile, personalizationHeaders) { return tslib.__awaiter(void 0, void 0, void 0, function () {
508
- var response;
509
- return tslib.__generator(this, function (_a) {
510
- switch (_a.label) {
511
- case 0: return [4, createPostOrPutRequest('SEND_OTP', ctPlatformConstants.RequestMethods.POST, {
512
- value: mobile,
513
- type: 'MOBILE',
514
- action: 'SIGNIN',
515
- countryCode: ctPlatformConstants.MOBILE_CONSTANTS.COUNTRY_CODE,
516
- }, {
517
- 'ab-otp': 'b',
518
- dvid_data: personalizationHeaders,
519
- })];
520
- case 1:
521
- response = _a.sent();
522
- return [2, response === null || response === void 0 ? void 0 : response.data];
523
- }
524
- });
525
- }); };
526
- var validateOtp = function (mobile, otp) { return tslib.__awaiter(void 0, void 0, void 0, function () {
527
- var response, data;
528
- return tslib.__generator(this, function (_a) {
529
- switch (_a.label) {
530
- case 0: return [4, createPostOrPutRequest('VALIDATE_OTP', ctPlatformConstants.RequestMethods.POST, {
531
- otp: otp,
532
- value: mobile,
533
- type: 'MOBILE',
534
- action: 'SIGNIN',
535
- countryCode: '+91',
536
- }, { 'ab-otp': 'b' })];
537
- case 1:
538
- response = _a.sent();
539
- data = response === null || response === void 0 ? void 0 : response.data;
540
- 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 })];
541
- }
542
- });
543
- }); };
544
- var handleFKSSO = function (fallbackUri, signupPageUri, currentPageUri) { return tslib.__awaiter(void 0, void 0, void 0, function () {
545
- var redirectionInfo;
546
- return tslib.__generator(this, function (_a) {
547
- switch (_a.label) {
548
- case 0:
549
- if (isIOSApp()) {
550
- return [2, Promise.reject()];
551
- }
552
- return [4, sendFKSSORedirectionInfo(fallbackUri, signupPageUri, currentPageUri)];
553
- case 1:
554
- redirectionInfo = _a.sent();
555
- if (isAndroidApp()) {
556
- return [2, handleFKSSOAndroid(redirectionInfo)];
557
- }
558
- else {
559
- return [2, handleFKSSOWeb(redirectionInfo)];
560
- }
561
- }
562
- });
563
- }); };
564
- var isValidMobileNumber = function (text) {
565
- return (text === null || text === void 0 ? void 0 : text.length) === ctPlatformConstants.MOBILE_CONSTANTS.LENGTH && /^\d{10}$/.test(text);
566
- };
567
- var updateNativeOnLogin = function () {
568
- if (isIOSApp()) {
569
- updateNativeIOSOnSignIn();
570
- }
571
- else if (isAndroidApp()) {
572
- updateNativeAndroidOnSignIn();
573
- }
574
- };
575
- var isFKSSOEnabled = function () {
576
- return isPwa() || (!isIOSApp() && isJSVersionUpdated(5));
577
- };
578
- var sendFKSSORedirectionInfo = function (fallbackUri, signupPageUri, currentPageUri) { return tslib.__awaiter(void 0, void 0, void 0, function () {
579
- var WEBSITE_BASE, response;
580
- return tslib.__generator(this, function (_a) {
581
- switch (_a.label) {
582
- case 0:
583
- WEBSITE_BASE = getApiDomain();
584
- return [4, createPostOrPutRequest('FK_REDIRECTION_INFO', ctPlatformConstants.RequestMethods.POST, {
585
- provider: 'flipkart',
586
- fallbackUri: urlJoin(WEBSITE_BASE, fallbackUri || getCurrentPathName()),
587
- signupPageUri: urlJoin(WEBSITE_BASE, signupPageUri || 'personal-details'),
588
- currentPageUri: urlJoin(WEBSITE_BASE, currentPageUri),
589
- })];
590
- case 1:
591
- response = _a.sent();
592
- return [2, response === null || response === void 0 ? void 0 : response.data];
593
- }
594
- });
595
- }); };
596
- var handleFKSSOWeb = function (redirectionInfo) {
597
- var _a;
598
- var params = (_a = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.params) !== null && _a !== void 0 ? _a : {};
599
- var redirectUri = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.redirectUri;
600
- if (redirectUri) {
601
- redirectUri += '?';
602
- for (var key in params) {
603
- redirectUri += key + '=' + params[key] + '&';
604
- }
605
- return Promise.resolve(redirectUri);
606
- }
607
- return Promise.reject();
608
- };
609
- var handleFKSSOAndroid = function (redirectionInfo) {
610
- var _a, _b;
611
- var params = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.params;
612
- if (isEmpty(params) ||
613
- typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onNavigationChange) !== 'function') {
614
- return Promise.reject();
615
- }
616
- else {
617
- var FK_REDIRECT_DL = urlJoin(getApiDomain(), 'dl/oauth2');
618
- (_b = window.MobileApp) === null || _b === void 0 ? void 0 : _b.onNavigationChange(JSON.stringify({
619
- type: 'FkSSO',
620
- miscData: tslib.__assign(tslib.__assign({}, params), { redirectURI: FK_REDIRECT_DL }),
621
- }));
622
- return Promise.resolve();
623
- }
624
- };
625
- function getUserAuthValues(customCookie) {
626
- try {
627
- var _a = decodeURIComponent(getCookie('userid', customCookie) || '').split('|'), email = _a[0], profileName = _a[1], gender = _a[2], photo = _a[3], userId = _a[4];
628
- return {
629
- email: email,
630
- profileName: profileName,
631
- gender: gender,
632
- photo: photo,
633
- userId: userId,
634
- };
635
- }
636
- catch (error) {
637
- return {};
638
- }
639
- }
640
- var isUserSignedIn = function (customCookie) {
641
- var userObject = getUserAuthValues(customCookie) || {};
642
- var usermiscVal = decodeURIComponent(getCookie('usermisc', customCookie) || '').split('|');
643
- var signedIn = usermiscVal.includes('SIGNED_IN') &&
644
- userObject.userId &&
645
- userObject.userId.length > 0
646
- ? true
647
- : false;
648
- return signedIn;
649
- };
650
-
651
- var getUserInsights = function (userId) { return tslib.__awaiter(void 0, void 0, void 0, function () {
652
- var response;
653
- return tslib.__generator(this, function (_a) {
654
- switch (_a.label) {
655
- case 0:
656
- _a.trys.push([0, 2, , 3]);
657
- return [4, createGetRequest('USER_INSIGHTS', {}, {
658
- pathParams: {
659
- userId: userId,
660
- },
661
- })];
662
- case 1:
663
- response = _a.sent();
664
- return [2, response === null || response === void 0 ? void 0 : response.data];
665
- case 2:
666
- _a.sent();
667
- return [2, Promise.resolve(null)];
668
- case 3: return [2];
669
- }
670
- });
671
- }); };
672
- var getUserInsightsData = function (userId) { return tslib.__awaiter(void 0, void 0, void 0, function () {
673
- var _userId, stringifiedData, sessionData, userInsights;
674
- var _a, _b, _c, _d;
675
- return tslib.__generator(this, function (_f) {
676
- switch (_f.label) {
677
- case 0:
678
- _f.trys.push([0, 2, , 3]);
679
- _userId = userId !== null && userId !== void 0 ? userId : getUserAuthValues().userId;
680
- if (!_userId) {
681
- (_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.removeItem('martech_user_attributes');
682
- return [2, null];
683
- }
684
- stringifiedData = (_b = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _b === void 0 ? void 0 : _b.getItem('martech_user_attributes');
685
- sessionData = void 0;
686
- if (typeof stringifiedData === 'string') {
687
- sessionData = JSON.parse(stringifiedData);
688
- }
689
- if (_userId !== (sessionData === null || sessionData === void 0 ? void 0 : sessionData.accountId)) {
690
- (_c = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _c === void 0 ? void 0 : _c.removeItem('martech_user_attributes');
691
- }
692
- return [4, getUserInsights(_userId)];
693
- case 1:
694
- userInsights = _f.sent();
695
- if (isEmpty(userInsights === null || userInsights === void 0 ? void 0 : userInsights.data)) {
696
- return [2, null];
697
- }
698
- (_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));
699
- return [2, userInsights === null || userInsights === void 0 ? void 0 : userInsights.data];
700
- case 2:
701
- _f.sent();
702
- return [2, null];
703
- case 3: return [2];
704
- }
705
- });
706
- }); };
707
-
708
- var stringifyPayload = function (payload) {
709
- var keys = Object.keys(payload);
710
- keys.forEach(function (key) {
711
- if (key === 'a_fare_price' ||
712
- key === 'a_ct_discount' ||
713
- key === 'supercoin_balance' ||
714
- key === 'supercoin_earned' ||
715
- key === 'supercoin_burnt' ||
716
- key === 'wallet_balance_used' ||
717
- key === 'convenience_fee')
718
- payload[key] = Number(payload[key]);
719
- else
720
- payload[key] = '' + payload[key];
721
- });
722
- return payload;
723
- };
724
- var ravenSDKTrigger = function (eventName, ravenPayload) {
725
- var _a;
726
- if (window && window['ravenWebManager']) {
727
- var _b = getRavenEventProps(), pageName = _b.pageName, utmSource = _b.utmSource;
728
- var commonPayload = {
729
- page_name: pageName,
730
- u_utm_source: utmSource,
731
- domain: window.location.host,
732
- platform: (_a = getDevicePlatform()) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
733
- login_status: isUserSignedIn() ? 'yes' : 'no',
734
- };
735
- var newRavenPayload = stringifyPayload(ravenPayload);
736
- var RavenWebManager = window['ravenWebManager'];
737
- RavenWebManager === null || RavenWebManager === void 0 ? void 0 : RavenWebManager.triggerRaven(eventName, tslib.__assign(tslib.__assign({}, commonPayload), newRavenPayload));
738
- }
739
- };
740
- var isAirHomePage = function () {
741
- if (window && typeof window !== 'undefined') {
742
- var pathname = getNestedValue(window, ['location', 'pathname']);
743
- if (pathname === '/' || pathname === '/flights') {
744
- return true;
745
- }
746
- }
747
- return false;
748
- };
749
- var getRavenEventProps = function () {
750
- var _a, _b;
751
- if (window && typeof window !== 'undefined') {
752
- var pathUrl = window.location.pathname;
753
- var redirectionPath = (_a = getQueryParam('service')) !== null && _a !== void 0 ? _a : '';
754
- var utmSource = (_b = getQueryParam('utm_source')) !== null && _b !== void 0 ? _b : 'organic';
755
- var loginForm = isAirHomePage() ? 'skippable_login' : 'account_login';
756
- var vertical = 'air';
757
- var pageName = pathUrl.includes('flights/itinerary') ||
758
- redirectionPath.includes('flights/itinerary')
759
- ? 'a_itinerary'
760
- : 'a_home';
761
- if (redirectionPath.includes('my-account')) {
762
- vertical = 'uar';
763
- pageName = 'account';
764
- }
765
- if (redirectionPath.includes('hotels')) {
766
- vertical = 'hotel';
767
- pageName = redirectionPath.includes('hotels/itinerary')
768
- ? 'h_itinerary'
769
- : 'h_home';
770
- }
771
- if (redirectionPath.includes('bus')) {
772
- vertical = 'bus';
773
- pageName = redirectionPath.includes('bus/itinerary')
774
- ? 'b_itinerary'
775
- : 'b_home';
776
- }
777
- return { loginForm: loginForm, vertical: vertical, pageName: pageName, utmSource: utmSource };
778
- }
779
- return {};
780
- };
781
- var sendEventWithUserInsights = function (eventName, ravenPayload, userId) { return tslib.__awaiter(void 0, void 0, void 0, function () {
782
- var userInsights, updatedPayload, loyaltyData, martechAttributes;
783
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
784
- return tslib.__generator(this, function (_s) {
785
- switch (_s.label) {
786
- case 0: return [4, getUserInsightsData(userId)];
787
- case 1:
788
- userInsights = _s.sent();
789
- 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' });
790
- if (!isEmpty(userInsights)) {
791
- loyaltyData = ((_a = userInsights === null || userInsights === void 0 ? void 0 : userInsights.loyaltyStatus) !== null && _a !== void 0 ? _a : []).reduce(function (prev, curr) {
792
- return tslib.__assign(tslib.__assign({}, prev), curr);
793
- }, {});
794
- martechAttributes = {
795
- 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(),
796
- ct_postmerger_booking: ((_e = (_d = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _d === void 0 ? void 0 : _d.postmergerBooking) !== null && _e !== void 0 ? _e : 'na').toString(),
797
- ct_last_1year_booking: ((_g = (_f = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _f === void 0 ? void 0 : _f.lastOneYearBooking) !== null && _g !== void 0 ? _g : 'na').toString(),
798
- ct_first_booking_dt: secondsToDateString((_h = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _h === void 0 ? void 0 : _h.firstbookingDate) || 'na',
799
- ct_last_booking_dt: secondsToDateString((_j = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _j === void 0 ? void 0 : _j.lastbookingDate) || 'na',
800
- ct_2nd_last_booking_dt: secondsToDateString((_k = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _k === void 0 ? void 0 : _k.secondLastbookingDate) || 'na',
801
- fk_loyalty_status: ((_l = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _l === void 0 ? void 0 : _l.program) || 'na',
802
- myntra_loyalty_status: ((_m = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _m === void 0 ? void 0 : _m.program) || 'na',
803
- fk_loyalty_end_dt: secondsToDateString((_o = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _o === void 0 ? void 0 : _o.loyaltyEndDate) || '',
804
- fk_loyalty_start_dt: secondsToDateString((_p = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _p === void 0 ? void 0 : _p.loyaltyStartDate) || 'na',
805
- myntra_loyalty_start_dt: secondsToDateString((_q = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _q === void 0 ? void 0 : _q.loyaltyStartDate) ||
806
- 'na',
807
- myntra_loyalty_end_dt: secondsToDateString((_r = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _r === void 0 ? void 0 : _r.loyaltyEndDate) ||
808
- 'na',
809
- };
810
- updatedPayload = tslib.__assign(tslib.__assign({}, updatedPayload), martechAttributes);
811
- setMartechUserProperties(martechAttributes);
812
- }
813
- ravenSDKTrigger(eventName, updatedPayload);
814
- return [2];
815
- }
816
- });
817
- }); };
818
- var setMartechUserProperties = function (userProperties) {
819
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
820
- if (isEmpty(userProperties) ||
821
- ((_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem('martech_user_props_sent'))) {
822
- return;
823
- }
824
- 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)) {
825
- (_d = window.webkit.messageHandlers.SEND_ATTRIBUTES) === null || _d === void 0 ? void 0 : _d.postMessage({
826
- type: 'GA',
827
- params: userProperties,
828
- });
829
- (_e = window.webkit.messageHandlers.SEND_ATTRIBUTES) === null || _e === void 0 ? void 0 : _e.postMessage({
830
- type: 'Clevertap',
831
- params: userProperties,
832
- });
833
- (_f = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _f === void 0 ? void 0 : _f.setItem('martech_user_props_sent', 'true');
834
- }
835
- else if (isAndroidApp() && ((_g = window === null || window === void 0 ? void 0 : window.MobileApp) === null || _g === void 0 ? void 0 : _g.sendAttributes)) {
836
- window.MobileApp.sendAttributes('GA', JSON.stringify(userProperties));
837
- window.MobileApp.sendAttributes('Clevertap', JSON.stringify(userProperties));
838
- (_h = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _h === void 0 ? void 0 : _h.setItem('martech_user_props_sent', 'true');
839
- }
840
- else if (isPwa() && window.clevertap) {
841
- window.clevertap.profile.push({
842
- Site: userProperties,
843
- });
844
- (_j = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _j === void 0 ? void 0 : _j.setItem('martech_user_props_sent', 'true');
845
- }
846
- };
847
- var batchRavenEvent = function (eventName, ravenPayload) {
848
- if (typeof window !== 'undefined' &&
849
- typeof window.requestIdleCallback === 'function') {
850
- requestIdleCallback(function () {
851
- ravenSDKTrigger(eventName, ravenPayload);
852
- });
853
- }
854
- else {
855
- setTimeout(function () {
856
- ravenSDKTrigger(eventName, ravenPayload);
857
- }, 0);
858
- }
859
- };
860
-
861
- var getHotelCrossSellRecos = function (vertical, fallbackPageLandingURL, cutoff) {
862
- if (cutoff === void 0) { cutoff = 450; }
863
- return tslib.__awaiter(void 0, void 0, void 0, function () {
864
- var userId, fallbackData, timeoutPromise, fetchRecommendationsPromise, result;
865
- var _a, _b;
866
- return tslib.__generator(this, function (_c) {
867
- switch (_c.label) {
868
- case 0:
869
- userId = (_b = (_a = getUserAuthValues()) === null || _a === void 0 ? void 0 : _a.userId) !== null && _b !== void 0 ? _b : '';
870
- fallbackData = {
871
- couponCode: '',
872
- offerCallOut: 'FLYER EXCLUSIVE COUPON UNLOCKED FOR YOU',
873
- couponCallOut: 'Offer applied on hotels',
874
- pageLandingUrl: fallbackPageLandingURL,
875
- };
876
- _c.label = 1;
877
- case 1:
878
- _c.trys.push([1, 3, , 4]);
879
- timeoutPromise = new Promise(function (resolve) {
880
- setTimeout(function () {
881
- resolve(fallbackData);
882
- }, cutoff);
883
- });
884
- fetchRecommendationsPromise = createGetRequest('HOTEL_RECOMMENDATIONS', {}, {
885
- queryParams: {
886
- userId: userId,
887
- vertical: vertical,
888
- },
889
- }).then(function (res) { return res.data; });
890
- return [4, Promise.race([
891
- fetchRecommendationsPromise,
892
- timeoutPromise,
893
- ])];
894
- case 2:
895
- result = _c.sent();
896
- return [2, result];
897
- case 3:
898
- _c.sent();
899
- return [2, fallbackData];
900
- case 4: return [2];
901
- }
902
- });
903
- });
904
- };
905
-
906
- exports.MULTI_SPACE = MULTI_SPACE;
907
- exports.autoReadOtp = autoReadOtp;
908
- exports.batchRavenEvent = batchRavenEvent;
909
- exports.createAPIRequest = createAPIRequest;
910
- exports.createGetRequest = createGetRequest;
911
- exports.createPostOrPutRequest = createPostOrPutRequest;
912
- exports.formatCurrency = formatCurrency;
913
- exports.formatFullDateString = formatFullDateString;
914
- exports.getApiDomain = getApiDomain;
915
- exports.getAppAgent = getAppAgent;
916
- exports.getAutoDetectedMobile = getAutoDetectedMobile;
917
- exports.getCookie = getCookie;
918
- exports.getCurrentPathName = getCurrentPathName;
919
- exports.getCurrentUrl = getCurrentUrl;
920
- exports.getDevicePlatform = getDevicePlatform;
921
- exports.getDimensionFromImageUrl = getDimensionFromImageUrl;
922
- exports.getHeightFromImgUrl = getHeightFromImgUrl;
923
- exports.getHotelCrossSellRecos = getHotelCrossSellRecos;
924
- exports.getJSVersion = getJSVersion;
925
- exports.getNestedValue = getNestedValue;
926
- exports.getQueryParam = getQueryParam;
927
- exports.getRavenEventProps = getRavenEventProps;
928
- exports.getUserAuthValues = getUserAuthValues;
929
- exports.getWidthFromImgUrl = getWidthFromImgUrl;
930
- exports.handleFKSSO = handleFKSSO;
931
- exports.handlePushPrimerCTA = handlePushPrimerCTA;
932
- exports.isAirHomePage = isAirHomePage;
933
- exports.isAndroidApp = isAndroidApp;
934
- exports.isEmpty = isEmpty;
935
- exports.isFKSSOEnabled = isFKSSOEnabled;
936
- exports.isHTMLInputElement = isHTMLInputElement;
937
- exports.isIOSApp = isIOSApp;
938
- exports.isJSVersionUpdated = isJSVersionUpdated;
939
- exports.isNumeric = isNumeric;
940
- exports.isPwa = isPwa;
941
- exports.isServer = isServer;
942
- exports.isUserSignedIn = isUserSignedIn;
943
- exports.isValidMobileNumber = isValidMobileNumber;
944
- exports.path = path;
945
- exports.ravenSDKTrigger = ravenSDKTrigger;
946
- exports.secondsToDateString = secondsToDateString;
947
- exports.sendEventWithUserInsights = sendEventWithUserInsights;
948
- exports.sendLoginOtp = sendLoginOtp;
949
- exports.setMartechUserProperties = setMartechUserProperties;
950
- exports.shouldShowPushPrimer = shouldShowPushPrimer;
951
- exports.showMobileNumberHint = showMobileNumberHint;
952
- exports.stringifyPayload = stringifyPayload;
953
- exports.triggerOTPListener = triggerOTPListener;
954
- exports.updateNativeAndroidOnSignIn = updateNativeAndroidOnSignIn;
955
- exports.updateNativeIOSOnSignIn = updateNativeIOSOnSignIn;
956
- exports.updateNativeOnLogin = updateNativeOnLogin;
957
- exports.urlJoin = urlJoin;
958
- exports.validateOtp = validateOtp;
1
+ "use strict";var t=require("tslib"),e=require("@cleartrip/ct-platform-constants"),n=require("@cleartrip/ct-platform-types"),o=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t.map((function(t){return t.trim().replace(/^[/]+/,"")})).join("/");return n=n.replace(/\/\?/g,"?")},r=function(){var t="undefined"!=typeof window?window.location.hostname:"";switch(console.log("API_BASE domain",t),t){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"}},i=function(t,e){return e.reduce((function(t,e){return t&&t[e]?t[e]:null}),t)},a=function(t){if(t instanceof Date)return!1;if(null==t)return!0;var e,n=function(t){return"[object Number]"===Object.prototype.toString.call(t)};if(n(t))return n(e=t)&&"NaN"===e.toString();if(t.length>0)return!1;if(0===t.length)return!0;if("object"!=typeof t)return!0;for(var o=Object.keys(t),r=0,i=o[r];r<o.length;r+=1)if(Object.prototype.hasOwnProperty.call(t,i))return!1;return!0},s="undefined"!=typeof window?window.location.href:"",u=function(t){return v()?"":new URLSearchParams(window.location.search).get(t)},l=function(){return"undefined"!=typeof window?(window.location.pathname+window.location.search).slice(1):""},d=function(t){if(t){var e=t.match(/h_(\d+)[,\/]/);return e&&e[1]?parseInt(e[1],10):void 0}},c=function(t){if(t){var e=t.match(/w_(\d+)[,\/]/);return e&&e[1]?parseInt(e[1],10):void 0}},v=function(){return"undefined"==typeof window||!window};function p(t,e){var n=e||i(document,["cookie"]);if(n){for(var o=t+"=",r=n.split(";"),a=0;a<r.length;a++){for(var s=r[a];" "==s.charAt(0);)s=s.substring(1,s.length);if(0==s.indexOf(o))return s.substring(o.length,s.length)}return""}return""}var _=function(t){try{if(!t||Number.isNaN(Number(t)))return"";var e=new Date(1e3*t),n=e.getFullYear(),o=String(e.getDate()).padStart(2,"0"),r=String(e.getMonth()+1).padStart(2,"0");return"".concat(n,"-").concat(r,"-").concat(o)}catch(t){return""}},g=function(){var t,n=null===(t=i(window,["navigator","userAgent"]))||void 0===t?void 0:t.toLowerCase(),o=/safari/.test(n),r=/iphone|ipod|ipad/.test(n);return i(window,["androidData","app-agent"])&&i(window,["androidData","js-version"])||"function"==typeof i(window,["MobileApp","getAppSpecificData"])?e.Platform.ANDROID:i(window,["iosData","app-agent"])&&i(window,["iosData","js-version"])||r&&!o?e.Platform.IOS:e.Platform.PWA},f=function(){var t,n,o=g();return o===e.Platform.IOS?null!==(t=i(window,["iosData","app-agent"]))&&void 0!==t?t:e.AppAgent.IOS:o===e.Platform.ANDROID?null!==(n=i(window,["androidData","app-agent"]))&&void 0!==n?n:e.AppAgent.ANDROID:e.AppAgent.PWA},w=function(){var t="";return S()?t=i(window,["iosData","js-version"]):h()&&(t=i(window,["androidData","js-version"])),t&&(t=t.toString().split(".")[0]),t},m=function(){return g()!==e.Platform.ANDROID&&g()!==e.Platform.IOS},h=function(){return g()===e.Platform.ANDROID},y=function(t){return parseInt(w())>=t},S=function(){return g()===e.Platform.IOS},b=r(),I=function(n,i,a,s,u,l){return void 0===i&&(i=e.RequestMethods.GET),void 0===s&&(s={}),void 0===u&&(u={}),void 0===l&&(l=!1),t.__awaiter(void 0,void 0,void 0,(function(){var d,c,v,p,_,g,w,m;return t.__generator(this,(function(h){switch(h.label){case 0:return d=function(t,n){var r=e.API_ROUTES[t];if(r&&r.trim().length){if(r=o(b,r),null==n?void 0:n.pathParams)for(var i=0,a=Object.entries(n.pathParams);i<a.length;i++){var s=a[i],u=s[0],l=s[1];r=r.replace(":".concat(u),l)}return(null==n?void 0:n.queryParams)&&(r+="?".concat(new URLSearchParams(n.queryParams).toString())),r}}(n,u),d&&d.trim().length?(c=r(),v={method:i,headers:t.__assign({Caller:b,Origin:b,Referer:b,Authority:c,x_ct_sourcetype:"MOBILE","app-agent":f(),"Content-Type":"application/json"},s)},a&&(v.body=JSON.stringify(a)),[4,fetch(d,v)]):[2,Promise.reject("URL parameter missing")];case 1:return _=h.sent(),g={name:"API_FAILURE",status:_.status,message:"UNKNOWN_ERROR",statusText:_.statusText},(null==_?void 0:_.ok)?[3,3]:l?[2,Promise.reject(g)]:[4,_.json()];case 2:throw w=h.sent().message,g.message=w,g;case 3:return(null==(m=_.headers.get("content-type"))?void 0:m.includes("application/json"))?[4,_.json()]:[3,5];case 4:return p=h.sent(),[3,9];case 5:return(null==m?void 0:m.includes("text"))?[4,_.text()]:[3,7];case 6:return p=h.sent(),[3,9];case 7:return 204===_.status?[3,9]:[4,_.blob()];case 8:p=h.sent(),h.label=9;case 9:return[2,{data:p,status:_.status}]}}))}))},O=function(n,o,r,i){return void 0===o&&(o={}),void 0===r&&(r={}),void 0===i&&(i=!1),t.__awaiter(void 0,void 0,void 0,(function(){return t.__generator(this,(function(a){return[2,I(n,e.RequestMethods.GET,null,t.__assign({expires:"0",accept:"application/json","cache-control":"no-cache"},o),r,i)]}))}))},N=function(n,o,r,i,a,s){return void 0===o&&(o=e.RequestMethods.POST),void 0===r&&(r={}),void 0===i&&(i={}),void 0===a&&(a={}),void 0===s&&(s=!1),t.__awaiter(void 0,void 0,void 0,(function(){return t.__generator(this,(function(e){return[2,I(n,o,r,t.__assign({expires:"0",accept:"application/json","cache-control":"no-cache"},i),a,s)]}))}))},P=function(t){var n="",o=t.match(e.MOBILE_CONSTANTS.REGEX);return o&&(n=o[0].replace(/\D/g,"")),n},A=function(){var t,e,n;null===(n=null===(e=null===(t=window.webkit)||void 0===t?void 0:t.messageHandlers)||void 0===e?void 0:e.PWA_IS_SIGNIN)||void 0===n||n.postMessage({isSignIn:!0})},x=function(){var t;null===(t=window.MobileApp)||void 0===t||t.onPWALoginStatus(JSON.stringify({isSignIn:!0}))},D=function(){return t.__awaiter(void 0,void 0,void 0,(function(){var e,n;return t.__generator(this,(function(t){return(null===(n=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===n?void 0:n.get)&&"OTPCredential"in window?(e=new AbortController,setTimeout((function(){e.abort()}),6e4),[2,navigator.credentials.get({otp:{transport:["sms"]},signal:e.signal}).then((function(t){return null==t?void 0:t.code}))]):[2,Promise.reject("NOT_SUPPORTED")]}))}))},E=function(){return t.__awaiter(void 0,void 0,void 0,(function(){var e,n;return t.__generator(this,(function(t){return n=new Promise((function(t){e=t})),window.sendOtpValue=function(t){e(t)},[2,n]}))}))},k=function(n,i,a){return t.__awaiter(void 0,void 0,void 0,(function(){var s,u;return t.__generator(this,(function(t){switch(t.label){case 0:return s=r(),[4,N("FK_REDIRECTION_INFO",e.RequestMethods.POST,{provider:"flipkart",fallbackUri:o(s,n||l()),signupPageUri:o(s,i||"personal-details"),currentPageUri:o(s,a)})];case 1:return[2,null==(u=t.sent())?void 0:u.data]}}))}))},T=function(t){var e,n=null!==(e=null==t?void 0:t.params)&&void 0!==e?e:{},o=null==t?void 0:t.redirectUri;if(o){for(var r in o+="?",n)o+=r+"="+n[r]+"&";return Promise.resolve(o)}return Promise.reject()},R=function(e){var n,i,s=null==e?void 0:e.params;if(a(s)||"function"!=typeof(null===(n=window.MobileApp)||void 0===n?void 0:n.onNavigationChange))return Promise.reject();var u=o(r(),"dl/oauth2");return null===(i=window.MobileApp)||void 0===i||i.onNavigationChange(JSON.stringify({type:"FkSSO",miscData:t.__assign(t.__assign({},s),{redirectURI:u})})),Promise.resolve()};function M(t){try{var e=decodeURIComponent(p("userid",t)||"").split("|");return{email:e[0],profileName:e[1],gender:e[2],photo:e[3],userId:e[4]}}catch(t){return{}}}var C=function(t){var e=M(t)||{};return!!(decodeURIComponent(p("usermisc",t)||"").split("|").includes("SIGNED_IN")&&e.userId&&e.userId.length>0)},U=function(e){return t.__awaiter(void 0,void 0,void 0,(function(){var n;return t.__generator(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,O("USER_INSIGHTS",{},{pathParams:{userId:e}})];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]}}))}))},L=function(e){return t.__awaiter(void 0,void 0,void 0,(function(){var n,o,r,i,s,u,l,d;return t.__generator(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),(n=null!=e?e:M().userId)?(o=null===(u=null===window||void 0===window?void 0:window.sessionStorage)||void 0===u?void 0:u.getItem("martech_user_attributes"),r=void 0,"string"==typeof o&&(r=JSON.parse(o)),n!==(null==r?void 0:r.accountId)&&(null===(l=null===window||void 0===window?void 0:window.sessionStorage)||void 0===l||l.removeItem("martech_user_attributes")),[4,U(n)]):(null===(s=null===window||void 0===window?void 0:window.sessionStorage)||void 0===s||s.removeItem("martech_user_attributes"),[2,null]);case 1:return i=t.sent(),a(null==i?void 0:i.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==i?void 0:i.data)),[2,null==i?void 0:i.data]);case 2:return t.sent(),[2,null];case 3:return[2]}}))}))},j=function(t){return Object.keys(t).forEach((function(e){t[e]="a_fare_price"===e||"a_ct_discount"===e||"supercoin_balance"===e||"supercoin_earned"===e||"supercoin_burnt"===e||"wallet_balance_used"===e||"convenience_fee"===e?Number(t[e]):""+t[e]})),t},q=function(e,n){var o;if(window&&window.ravenWebManager){var r=B(),i={page_name:r.pageName,u_utm_source:r.utmSource,domain:window.location.host,platform:null===(o=g())||void 0===o?void 0:o.toLowerCase(),login_status:C()?"yes":"no"},a=j(n),s=window.ravenWebManager;null==s||s.triggerRaven(e,t.__assign(t.__assign({},i),a))}},F=function(){if(window&&"undefined"!=typeof window){var t=i(window,["location","pathname"]);if("/"===t||"/flights"===t)return!0}return!1},B=function(){var t,e;if(window&&"undefined"!=typeof window){var n=window.location.pathname,o=null!==(t=u("service"))&&void 0!==t?t:"",r=null!==(e=u("utm_source"))&&void 0!==e?e:"organic",i=F()?"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:i,vertical:a,pageName:s,utmSource:r}}return{}},G=function(t){var e,n,o,r,i,s,u,l,d;a(t)||(null===(e=null===window||void 0===window?void 0:window.sessionStorage)||void 0===e?void 0:e.getItem("martech_user_props_sent"))||(S()&&(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===(r=window.webkit.messageHandlers.SEND_ATTRIBUTES)||void 0===r||r.postMessage({type:"GA",params:t}),null===(i=window.webkit.messageHandlers.SEND_ATTRIBUTES)||void 0===i||i.postMessage({type:"Clevertap",params:t}),null===(s=null===window||void 0===window?void 0:window.sessionStorage)||void 0===s||s.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(t)),window.MobileApp.sendAttributes("Clevertap",JSON.stringify(t)),null===(l=null===window||void 0===window?void 0:window.sessionStorage)||void 0===l||l.setItem("martech_user_props_sent","true")):m()&&window.clevertap&&(window.clevertap.profile.push({Site:t}),null===(d=null===window||void 0===window?void 0:window.sessionStorage)||void 0===d||d.setItem("martech_user_props_sent","true")))};exports.MULTI_SPACE=/\s\s+/g,exports.autoReadOtp=function(){return t.__awaiter(void 0,void 0,void 0,(function(){return t.__generator(this,(function(t){return[2,h()?E():D()]}))}))},exports.batchRavenEvent=function(t,e){"undefined"!=typeof window&&"function"==typeof window.requestIdleCallback?requestIdleCallback((function(){q(t,e)})):setTimeout((function(){q(t,e)}),0)},exports.createAPIRequest=I,exports.createGetRequest=O,exports.createPostOrPutRequest=N,exports.formatCurrency=function(t,e){void 0===e&&(e=!0);try{var n={currency:"INR",minimumFractionDigits:0};return e&&(n.style="currency"),"string"!=typeof t&&(t=null==t?void 0:t.toString()),t=t.replace(/,/g,""),parseInt(t,10).toLocaleString("en-IN",n)}catch(t){return""}},exports.formatFullDateString=function(t,e,n){void 0===e&&(e="dd-mm-yyyy"),void 0===n&&(n="");try{var o=new Date(t),r=o.getFullYear(),i=String(o.getDate()).padStart(2,"0"),a=String(o.getMonth()+1).padStart(2,"0");return"yyyy-mm-dd"===e?"".concat(r,"-").concat(a,"-").concat(i):"".concat(i,"-").concat(a,"-").concat(r)}catch(t){return n}},exports.getApiDomain=r,exports.getAppAgent=f,exports.getAutoDetectedMobile=P,exports.getCookie=p,exports.getCurrentPathName=l,exports.getCurrentUrl=s,exports.getDevicePlatform=g,exports.getDimensionFromImageUrl=function(t){void 0===t&&(t="");var e=d(t)||0,n=c(t)||0;return{height:"".concat(e,"px"),width:"".concat(n,"px"),heightInNumber:e,widthInNumber:n}},exports.getHeightFromImgUrl=d,exports.getHotelCrossSellRecos=function(e,n,o){return void 0===o&&(o=450),t.__awaiter(void 0,void 0,void 0,(function(){var r,i,a,s,u,l;return t.__generator(this,(function(t){switch(t.label){case 0:r=null!==(l=null===(u=M())||void 0===u?void 0:u.userId)&&void 0!==l?l:"",i={couponCode:"",offerCallOut:"FLYER EXCLUSIVE COUPON UNLOCKED FOR YOU",couponCallOut:"Offer applied on hotels",pageLandingUrl:n},t.label=1;case 1:return t.trys.push([1,3,,4]),a=new Promise((function(t){setTimeout((function(){t(i)}),o)})),s=O("HOTEL_RECOMMENDATIONS",{},{queryParams:{userId:r,vertical:e}}).then((function(t){return t.data})),[4,Promise.race([s,a])];case 2:return[2,t.sent()];case 3:return t.sent(),[2,i];case 4:return[2]}}))}))},exports.getJSVersion=w,exports.getNestedValue=i,exports.getQueryParam=u,exports.getRavenEventProps=B,exports.getUserAuthValues=M,exports.getWidthFromImgUrl=c,exports.handleFKSSO=function(e,n,o){return t.__awaiter(void 0,void 0,void 0,(function(){var r;return t.__generator(this,(function(t){switch(t.label){case 0:return S()?[2,Promise.reject()]:[4,k(e,n,o)];case 1:return r=t.sent(),h()?[2,R(r)]:[2,T(r)]}}))}))},exports.isAirHomePage=F,exports.isAndroidApp=h,exports.isEmpty=a,exports.isFKSSOEnabled=function(){return m()||!S()&&y(5)},exports.isHTMLInputElement=function(t){return"object"==typeof t&&null!==t&&"value"in t&&t instanceof HTMLInputElement},exports.isIOSApp=S,exports.isJSVersionUpdated=y,exports.isNumeric=function(t){return/^[0-9]*$/.test(t)},exports.isPwa=m,exports.isServer=v,exports.isUserSignedIn=C,exports.isValidMobileNumber=function(t){return(null==t?void 0:t.length)===e.MOBILE_CONSTANTS.LENGTH&&/^\d{10}$/.test(t)},exports.path=function(t,e){return t.reduce((function(t,e){return t&&t[e]?t[e]:null}),e)},exports.ravenSDKTrigger=q,exports.secondsToDateString=_,exports.sendEventWithUserInsights=function(e,n,o){return t.__awaiter(void 0,void 0,void 0,(function(){var r,i,s,u,l,d,c,v,p,g,f,w,m,h,y,S,b,I,O,N;return t.__generator(this,(function(P){switch(P.label){case 0:return[4,L(o)];case 1:return r=P.sent(),i=t.__assign(t.__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"}),a(r)||(s=(null!==(l=null==r?void 0:r.loyaltyStatus)&&void 0!==l?l:[]).reduce((function(e,n){return t.__assign(t.__assign({},e),n)}),{}),u={ct_lifetime_booking:(null!==(c=null===(d=null==r?void 0:r.bookingStatus)||void 0===d?void 0:d.lifetimeBooking)&&void 0!==c?c:"na").toString(),ct_postmerger_booking:(null!==(p=null===(v=null==r?void 0:r.bookingStatus)||void 0===v?void 0:v.postmergerBooking)&&void 0!==p?p:"na").toString(),ct_last_1year_booking:(null!==(f=null===(g=null==r?void 0:r.bookingStatus)||void 0===g?void 0:g.lastOneYearBooking)&&void 0!==f?f:"na").toString(),ct_first_booking_dt:_(null===(w=null==r?void 0:r.bookingStatus)||void 0===w?void 0:w.firstbookingDate)||"na",ct_last_booking_dt:_(null===(m=null==r?void 0:r.bookingStatus)||void 0===m?void 0:m.lastbookingDate)||"na",ct_2nd_last_booking_dt:_(null===(h=null==r?void 0:r.bookingStatus)||void 0===h?void 0:h.secondLastbookingDate)||"na",fk_loyalty_status:(null===(y=null==s?void 0:s.fk)||void 0===y?void 0:y.program)||"na",myntra_loyalty_status:(null===(S=null==s?void 0:s.myntra)||void 0===S?void 0:S.program)||"na",fk_loyalty_end_dt:_(null===(b=null==s?void 0:s.fk)||void 0===b?void 0:b.loyaltyEndDate)||"",fk_loyalty_start_dt:_(null===(I=null==s?void 0:s.fk)||void 0===I?void 0:I.loyaltyStartDate)||"na",myntra_loyalty_start_dt:_(null===(O=null==s?void 0:s.myntra)||void 0===O?void 0:O.loyaltyStartDate)||"na",myntra_loyalty_end_dt:_(null===(N=null==s?void 0:s.myntra)||void 0===N?void 0:N.loyaltyEndDate)||"na"},i=t.__assign(t.__assign({},i),u),G(u)),q(e,i),[2]}}))}))},exports.sendLoginOtp=function(n,o){return t.__awaiter(void 0,void 0,void 0,(function(){var r;return t.__generator(this,(function(t){switch(t.label){case 0:return[4,N("SEND_OTP",e.RequestMethods.POST,{value:n,type:"MOBILE",action:"SIGNIN",countryCode:e.MOBILE_CONSTANTS.COUNTRY_CODE},{"ab-otp":"b",dvid_data:o})];case 1:return[2,null==(r=t.sent())?void 0:r.data]}}))}))},exports.setMartechUserProperties=G,exports.showMobileNumberHint=function(){var t;if("function"==typeof(null===(t=window.MobileApp)||void 0===t?void 0:t.onRequestMobileNumber)){var e;window.MobileApp.onRequestMobileNumber();var n=new Promise((function(t){e=t}));return window.sendSelectedMobileNumber=function(t){return e(P(t))},n}return Promise.resolve("")},exports.stringifyPayload=j,exports.triggerOTPListener=function(){var t;h()&&(null===(t=window.MobileApp)||void 0===t||t.onPageStart("OTP_SCREEN"))},exports.updateNativeAndroidOnSignIn=x,exports.updateNativeIOSOnSignIn=A,exports.updateNativeOnLogin=function(){S()?A():h()&&x()},exports.urlJoin=o,exports.validateOtp=function(o,r){return t.__awaiter(void 0,void 0,void 0,(function(){var i,a;return t.__generator(this,(function(s){switch(s.label){case 0:return[4,N("VALIDATE_OTP",e.RequestMethods.POST,{otp:r,value:o,type:"MOBILE",action:"SIGNIN",countryCode:"+91"},{"ab-otp":"b"})];case 1:return i=s.sent(),a=null==i?void 0:i.data,[2,t.__assign(t.__assign({},i),{signup:(null==a?void 0:a.action)===n.ValidateOTPAction.SIGNUP,action:null==a?void 0:a.action,status:null==i?void 0:i.status})]}}))}))};
959
2
  //# sourceMappingURL=ct-platform-utils.cjs.js.map