@cleartrip/ct-platform-utils 3.2.1-beta.2 → 3.2.1-beta.4

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