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