@cleartrip/ct-platform-utils 3.5.1-beta.6 → 3.5.1

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