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