@cleartrip/ct-platform-utils 3.5.1-beta.9 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,782 +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 secondsToDateString = 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
- var formatCurrency = function (value, withIcon) {
186
- if (withIcon === void 0) { withIcon = true; }
187
- var config = {
188
- currency: 'INR',
189
- minimumFractionDigits: 0,
190
- };
191
- if (withIcon) {
192
- config.style = 'currency';
193
- }
194
- if (typeof value !== 'string') {
195
- value = value === null || value === void 0 ? void 0 : value.toString();
196
- }
197
- value = value.replace(/,/g, '');
198
- return parseInt(value, 10).toLocaleString('en-IN', config);
199
- };
200
-
201
- var getDevicePlatform = function () {
202
- var _a;
203
- var userAgent = (_a = getNestedValue(window, [
204
- 'navigator',
205
- 'userAgent',
206
- ])) === null || _a === void 0 ? void 0 : _a.toLowerCase();
207
- var safariBrowser = /safari/.test(userAgent);
208
- var appleDevice = /iphone|ipod|ipad/.test(userAgent);
209
- if ((getNestedValue(window, ['androidData', 'app-agent']) &&
210
- getNestedValue(window, ['androidData', 'js-version'])) ||
211
- typeof getNestedValue(window, ['MobileApp', 'getAppSpecificData']) ===
212
- 'function') {
213
- return Platform.ANDROID;
214
- }
215
- else if ((getNestedValue(window, ['iosData', 'app-agent']) &&
216
- getNestedValue(window, ['iosData', 'js-version'])) ||
217
- (appleDevice && !safariBrowser)) {
218
- return Platform.IOS;
219
- }
220
- return Platform.PWA;
221
- };
222
- var getAppAgent = function () {
223
- var _a, _b;
224
- var platform = getDevicePlatform();
225
- if (platform === Platform.IOS) {
226
- return (_a = getNestedValue(window, ['iosData', 'app-agent'])) !== null && _a !== void 0 ? _a : AppAgent.IOS;
227
- }
228
- else if (platform === Platform.ANDROID) {
229
- return ((_b = getNestedValue(window, ['androidData', 'app-agent'])) !== null && _b !== void 0 ? _b : AppAgent.ANDROID);
230
- }
231
- return AppAgent.PWA;
232
- };
233
- var getJSVersion = function () {
234
- var jsVersion = '';
235
- if (isIOSApp()) {
236
- jsVersion = getNestedValue(window, ['iosData', 'js-version']);
237
- }
238
- else if (isAndroidApp()) {
239
- jsVersion = getNestedValue(window, ['androidData', 'js-version']);
240
- }
241
- if (jsVersion) {
242
- jsVersion = jsVersion.toString().split('.')[0];
243
- }
244
- return jsVersion;
245
- };
246
- var isPwa = function () {
247
- return getDevicePlatform() !== Platform.ANDROID &&
248
- getDevicePlatform() !== Platform.IOS;
249
- };
250
- var isAndroidApp = function () {
251
- return getDevicePlatform() === Platform.ANDROID;
252
- };
253
- var isJSVersionUpdated = function (compareVersion) {
254
- return parseInt(getJSVersion()) >= compareVersion;
255
- };
256
- var isIOSApp = function () { return getDevicePlatform() === Platform.IOS; };
257
-
258
- var API_BASE = getApiDomain();
259
- var getRequestUrl = function (path, params) {
260
- var url = API_ROUTES[path];
261
- if (!url || !url.trim().length) {
262
- return;
263
- }
264
- url = urlJoin(API_BASE, url);
265
- if (params === null || params === void 0 ? void 0 : params.pathParams) {
266
- for (var _i = 0, _a = Object.entries(params.pathParams); _i < _a.length; _i++) {
267
- var _b = _a[_i], key = _b[0], value = _b[1];
268
- url = url.replace(":".concat(key), value);
269
- }
270
- }
271
- if (params === null || params === void 0 ? void 0 : params.queryParams) {
272
- url += "?".concat(new URLSearchParams(params.queryParams).toString());
273
- }
274
- return url;
275
- };
276
- var createAPIRequest = function (path, method, payload, headers, params, useCustomErrorHandler) {
277
- if (method === void 0) { method = RequestMethods.GET; }
278
- if (headers === void 0) { headers = {}; }
279
- if (params === void 0) { params = {}; }
280
- if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
281
- return __awaiter(void 0, void 0, void 0, function () {
282
- var url, API_AUTHORITY, requestOptions, responseData, response, error, message, contentType;
283
- return __generator(this, function (_a) {
284
- switch (_a.label) {
285
- case 0:
286
- url = getRequestUrl(path, params);
287
- if (!url || !url.trim().length) {
288
- return [2, Promise.reject('URL parameter missing')];
289
- }
290
- API_AUTHORITY = getApiDomain();
291
- requestOptions = {
292
- method: method,
293
- 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),
294
- };
295
- if (payload) {
296
- requestOptions.body = JSON.stringify(payload);
297
- }
298
- return [4, fetch(url, requestOptions)];
299
- case 1:
300
- response = _a.sent();
301
- error = {
302
- name: 'API_FAILURE',
303
- status: response.status,
304
- message: 'UNKNOWN_ERROR',
305
- statusText: response.statusText,
306
- };
307
- if (!!(response === null || response === void 0 ? void 0 : response.ok)) return [3, 3];
308
- if (useCustomErrorHandler) {
309
- return [2, Promise.reject(error)];
310
- }
311
- return [4, response.json()];
312
- case 2:
313
- message = (_a.sent()).message;
314
- error.message = message;
315
- throw error;
316
- case 3:
317
- contentType = response.headers.get('content-type');
318
- if (!(contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json'))) return [3, 5];
319
- return [4, response.json()];
320
- case 4:
321
- responseData = _a.sent();
322
- return [3, 9];
323
- case 5:
324
- if (!(contentType === null || contentType === void 0 ? void 0 : contentType.includes('text'))) return [3, 7];
325
- return [4, response.text()];
326
- case 6:
327
- responseData = _a.sent();
328
- return [3, 9];
329
- case 7:
330
- if (!(response.status !== 204)) return [3, 9];
331
- return [4, response.blob()];
332
- case 8:
333
- responseData = _a.sent();
334
- _a.label = 9;
335
- case 9: return [2, {
336
- data: responseData,
337
- status: response.status,
338
- }];
339
- }
340
- });
341
- });
342
- };
343
- var createGetRequest = function (path, headers, params, useCustomErrorHandler) {
344
- if (headers === void 0) { headers = {}; }
345
- if (params === void 0) { params = {}; }
346
- if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
347
- return __awaiter(void 0, void 0, void 0, function () {
348
- return __generator(this, function (_a) {
349
- return [2, createAPIRequest(path, RequestMethods.GET, null, __assign({ expires: '0', accept: 'application/json', 'cache-control': 'no-cache' }, headers), params, useCustomErrorHandler)];
350
- });
351
- });
352
- };
353
- var createPostOrPutRequest = function (path, method, payload, headers, params, useCustomErrorHandler) {
354
- if (method === void 0) { method = RequestMethods.POST; }
355
- if (payload === void 0) { payload = {}; }
356
- if (headers === void 0) { headers = {}; }
357
- if (params === void 0) { params = {}; }
358
- if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
359
- return __awaiter(void 0, void 0, void 0, function () {
360
- return __generator(this, function (_a) {
361
- return [2, createAPIRequest(path, method, payload, __assign({ expires: '0', accept: 'application/json', 'cache-control': 'no-cache' }, headers), params, useCustomErrorHandler)];
362
- });
363
- });
364
- };
365
-
366
- var showMobileNumberHint = function () {
367
- var _a;
368
- if (typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onRequestMobileNumber) === 'function') {
369
- window.MobileApp.onRequestMobileNumber();
370
- var promiseResolver_1;
371
- var mobileNoPromise = new Promise(function (resolve) {
372
- promiseResolver_1 = resolve;
373
- });
374
- window.sendSelectedMobileNumber = function (mobileNum) {
375
- return promiseResolver_1(getAutoDetectedMobile(mobileNum));
376
- };
377
- return mobileNoPromise;
378
- }
379
- return Promise.resolve('');
380
- };
381
- var getAutoDetectedMobile = function (mobileNumber) {
382
- var formattedMobileNo = '';
383
- var matches = mobileNumber.match(MOBILE_CONSTANTS.REGEX);
384
- if (matches) {
385
- formattedMobileNo = matches[0].replace(/\D/g, '');
386
- }
387
- return formattedMobileNo;
388
- };
389
- var autoReadOtp = function () { return __awaiter(void 0, void 0, void 0, function () {
390
- return __generator(this, function (_a) {
391
- return [2, isAndroidApp() ? readOtpAndroid() : readOtpPWA()];
392
- });
393
- }); };
394
- var updateNativeIOSOnSignIn = function () {
395
- var _a, _b, _c;
396
- (_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({
397
- isSignIn: true,
398
- });
399
- };
400
- var updateNativeAndroidOnSignIn = function () {
401
- var _a;
402
- (_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onPWALoginStatus(JSON.stringify({
403
- isSignIn: true,
404
- }));
405
- };
406
- var triggerOTPListener = function () {
407
- var _a;
408
- if (isAndroidApp()) {
409
- (_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onPageStart('OTP_SCREEN');
410
- }
411
- };
412
- var readOtpPWA = function () { return __awaiter(void 0, void 0, void 0, function () {
413
- var abortController;
414
- var _a;
415
- return __generator(this, function (_b) {
416
- if (!((_a = navigator === null || navigator === void 0 ? void 0 : navigator.credentials) === null || _a === void 0 ? void 0 : _a.get) || !('OTPCredential' in window)) {
417
- return [2, Promise.reject('NOT_SUPPORTED')];
418
- }
419
- abortController = new AbortController();
420
- setTimeout(function () {
421
- abortController.abort();
422
- }, 60000);
423
- return [2, navigator.credentials
424
- .get({
425
- otp: { transport: ['sms'] },
426
- signal: abortController.signal,
427
- })
428
- .then(function (content) { return content === null || content === void 0 ? void 0 : content.code; })];
429
- });
430
- }); };
431
- var readOtpAndroid = function () { return __awaiter(void 0, void 0, void 0, function () {
432
- var promiseResolver, otpPromise;
433
- return __generator(this, function (_a) {
434
- otpPromise = new Promise(function (resolve) {
435
- promiseResolver = resolve;
436
- });
437
- window.sendOtpValue = function (otp) {
438
- promiseResolver(otp);
439
- };
440
- return [2, otpPromise];
441
- });
442
- }); };
443
-
444
- var sendLoginOtp = function (mobile, personalizationHeaders) { return __awaiter(void 0, void 0, void 0, function () {
445
- var response;
446
- return __generator(this, function (_a) {
447
- switch (_a.label) {
448
- case 0: return [4, createPostOrPutRequest('SEND_OTP', RequestMethods.POST, {
449
- value: mobile,
450
- type: 'MOBILE',
451
- action: 'SIGNIN',
452
- countryCode: MOBILE_CONSTANTS.COUNTRY_CODE,
453
- }, {
454
- 'ab-otp': 'b',
455
- dvid_data: personalizationHeaders,
456
- })];
457
- case 1:
458
- response = _a.sent();
459
- return [2, response === null || response === void 0 ? void 0 : response.data];
460
- }
461
- });
462
- }); };
463
- var validateOtp = function (mobile, otp) { return __awaiter(void 0, void 0, void 0, function () {
464
- var response, data;
465
- return __generator(this, function (_a) {
466
- switch (_a.label) {
467
- case 0: return [4, createPostOrPutRequest('VALIDATE_OTP', RequestMethods.POST, {
468
- otp: otp,
469
- value: mobile,
470
- type: 'MOBILE',
471
- action: 'SIGNIN',
472
- countryCode: '+91',
473
- }, { 'ab-otp': 'b' })];
474
- case 1:
475
- response = _a.sent();
476
- data = response === null || response === void 0 ? void 0 : response.data;
477
- 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 })];
478
- }
479
- });
480
- }); };
481
- var handleFKSSO = function (fallbackUri, signupPageUri, currentPageUri) { return __awaiter(void 0, void 0, void 0, function () {
482
- var redirectionInfo;
483
- return __generator(this, function (_a) {
484
- switch (_a.label) {
485
- case 0:
486
- if (isIOSApp()) {
487
- return [2, Promise.reject()];
488
- }
489
- return [4, sendFKSSORedirectionInfo(fallbackUri, signupPageUri, currentPageUri)];
490
- case 1:
491
- redirectionInfo = _a.sent();
492
- if (isAndroidApp()) {
493
- return [2, handleFKSSOAndroid(redirectionInfo)];
494
- }
495
- else {
496
- return [2, handleFKSSOWeb(redirectionInfo)];
497
- }
498
- }
499
- });
500
- }); };
501
- var isValidMobileNumber = function (text) {
502
- return (text === null || text === void 0 ? void 0 : text.length) === MOBILE_CONSTANTS.LENGTH && /^\d{10}$/.test(text);
503
- };
504
- var updateNativeOnLogin = function () {
505
- if (isIOSApp()) {
506
- updateNativeIOSOnSignIn();
507
- }
508
- else if (isAndroidApp()) {
509
- updateNativeAndroidOnSignIn();
510
- }
511
- };
512
- var isFKSSOEnabled = function () {
513
- return isPwa() || (!isIOSApp() && isJSVersionUpdated(5));
514
- };
515
- var sendFKSSORedirectionInfo = function (fallbackUri, signupPageUri, currentPageUri) { return __awaiter(void 0, void 0, void 0, function () {
516
- var WEBSITE_BASE, response;
517
- return __generator(this, function (_a) {
518
- switch (_a.label) {
519
- case 0:
520
- WEBSITE_BASE = getApiDomain();
521
- return [4, createPostOrPutRequest('FK_REDIRECTION_INFO', RequestMethods.POST, {
522
- provider: 'flipkart',
523
- fallbackUri: urlJoin(WEBSITE_BASE, fallbackUri || getCurrentPathName()),
524
- signupPageUri: urlJoin(WEBSITE_BASE, signupPageUri || 'personal-details'),
525
- currentPageUri: urlJoin(WEBSITE_BASE, currentPageUri),
526
- })];
527
- case 1:
528
- response = _a.sent();
529
- return [2, response === null || response === void 0 ? void 0 : response.data];
530
- }
531
- });
532
- }); };
533
- var handleFKSSOWeb = function (redirectionInfo) {
534
- var _a;
535
- var params = (_a = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.params) !== null && _a !== void 0 ? _a : {};
536
- var redirectUri = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.redirectUri;
537
- if (redirectUri) {
538
- redirectUri += '?';
539
- for (var key in params) {
540
- redirectUri += key + '=' + params[key] + '&';
541
- }
542
- return Promise.resolve(redirectUri);
543
- }
544
- return Promise.reject();
545
- };
546
- var handleFKSSOAndroid = function (redirectionInfo) {
547
- var _a, _b;
548
- var params = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.params;
549
- if (isEmpty(params) ||
550
- typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onNavigationChange) !== 'function') {
551
- return Promise.reject();
552
- }
553
- else {
554
- var FK_REDIRECT_DL = urlJoin(getApiDomain(), 'dl/oauth2');
555
- (_b = window.MobileApp) === null || _b === void 0 ? void 0 : _b.onNavigationChange(JSON.stringify({
556
- type: 'FkSSO',
557
- miscData: __assign(__assign({}, params), { redirectURI: FK_REDIRECT_DL }),
558
- }));
559
- return Promise.resolve();
560
- }
561
- };
562
- function getUserAuthValues(customCookie) {
563
- try {
564
- var _a = decodeURIComponent(getCookie('userid', customCookie) || '').split('|'), email = _a[0], profileName = _a[1], gender = _a[2], photo = _a[3], userId = _a[4];
565
- return {
566
- email: email,
567
- profileName: profileName,
568
- gender: gender,
569
- photo: photo,
570
- userId: userId,
571
- };
572
- }
573
- catch (error) {
574
- return {};
575
- }
576
- }
577
- var isUserSignedIn = function (customCookie) {
578
- var userObject = getUserAuthValues(customCookie) || {};
579
- var usermiscVal = decodeURIComponent(getCookie('usermisc', customCookie) || '').split('|');
580
- var signedIn = usermiscVal.includes('SIGNED_IN') &&
581
- userObject.userId &&
582
- userObject.userId.length > 0
583
- ? true
584
- : false;
585
- return signedIn;
586
- };
587
-
588
- var getUserInsights = function (userId) { return __awaiter(void 0, void 0, void 0, function () {
589
- var response;
590
- return __generator(this, function (_a) {
591
- switch (_a.label) {
592
- case 0:
593
- _a.trys.push([0, 2, , 3]);
594
- return [4, createGetRequest('USER_INSIGHTS', {}, {
595
- pathParams: {
596
- userId: userId,
597
- },
598
- })];
599
- case 1:
600
- response = _a.sent();
601
- return [2, response === null || response === void 0 ? void 0 : response.data];
602
- case 2:
603
- _a.sent();
604
- return [2, Promise.resolve(null)];
605
- case 3: return [2];
606
- }
607
- });
608
- }); };
609
- var getUserInsightsData = function (userId) { return __awaiter(void 0, void 0, void 0, function () {
610
- var _userId, stringifiedData, sessionData, userInsights;
611
- var _a, _b, _c, _d;
612
- return __generator(this, function (_f) {
613
- switch (_f.label) {
614
- case 0:
615
- _f.trys.push([0, 2, , 3]);
616
- _userId = userId !== null && userId !== void 0 ? userId : getUserAuthValues().userId;
617
- if (!_userId) {
618
- (_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.removeItem('martech_user_attributes');
619
- return [2, null];
620
- }
621
- stringifiedData = (_b = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _b === void 0 ? void 0 : _b.getItem('martech_user_attributes');
622
- sessionData = void 0;
623
- if (typeof stringifiedData === 'string') {
624
- sessionData = JSON.parse(stringifiedData);
625
- }
626
- if (_userId !== (sessionData === null || sessionData === void 0 ? void 0 : sessionData.accountId)) {
627
- (_c = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _c === void 0 ? void 0 : _c.removeItem('martech_user_attributes');
628
- }
629
- return [4, getUserInsights(_userId)];
630
- case 1:
631
- userInsights = _f.sent();
632
- if (isEmpty(userInsights === null || userInsights === void 0 ? void 0 : userInsights.data)) {
633
- return [2, null];
634
- }
635
- (_d = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _d === void 0 ? void 0 : _d.setItem('martech_user_attributes', JSON.stringify(userInsights === null || userInsights === void 0 ? void 0 : userInsights.data));
636
- return [2, userInsights === null || userInsights === void 0 ? void 0 : userInsights.data];
637
- case 2:
638
- _f.sent();
639
- return [2, null];
640
- case 3: return [2];
641
- }
642
- });
643
- }); };
644
-
645
- var stringifyPayload = function (payload) {
646
- var keys = Object.keys(payload);
647
- keys.forEach(function (key) {
648
- if (key === 'a_fare_price' ||
649
- key === 'a_ct_discount' ||
650
- key === 'supercoin_balance' ||
651
- key === 'supercoin_earned' ||
652
- key === 'supercoin_burnt' ||
653
- key === 'wallet_balance_used' ||
654
- key === 'convenience_fee')
655
- payload[key] = Number(payload[key]);
656
- else
657
- payload[key] = '' + payload[key];
658
- });
659
- return payload;
660
- };
661
- var ravenSDKTrigger = function (eventName, ravenPayload) {
662
- var _a;
663
- if (window && window['ravenWebManager']) {
664
- var commonPayload = {
665
- platform: (_a = getDevicePlatform()) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
666
- login_status: isUserSignedIn() ? 'yes' : 'no',
667
- domain: window.location.host,
668
- };
669
- var newRavenPayload = stringifyPayload(ravenPayload);
670
- var RavenWebManager = window['ravenWebManager'];
671
- RavenWebManager === null || RavenWebManager === void 0 ? void 0 : RavenWebManager.triggerRaven(eventName, __assign(__assign({}, commonPayload), newRavenPayload));
672
- }
673
- };
674
- var isAirHomePage = function () {
675
- if (window && typeof window !== 'undefined') {
676
- var pathname = getNestedValue(window, ['location', 'pathname']);
677
- if (pathname === '/' || pathname === '/flights') {
678
- return true;
679
- }
680
- }
681
- return false;
682
- };
683
- var getRavenEventProps = function () {
684
- if (window && typeof window !== 'undefined') {
685
- var queryParams = new URLSearchParams(getNestedValue(window, ['location', 'search']));
686
- var pathUrl = window.location.pathname;
687
- var redirectionPath = decodeURIComponent(queryParams.get('service'));
688
- var loginForm = isAirHomePage() ? 'skippable_login' : 'account_login';
689
- var vertical = 'air';
690
- var pageName = pathUrl.includes('flights/itinerary') ||
691
- redirectionPath.includes('flights/itinerary')
692
- ? 'a_itinerary'
693
- : 'a_home';
694
- if (redirectionPath.includes('my-account')) {
695
- vertical = 'uar';
696
- pageName = 'account';
697
- }
698
- if (redirectionPath.includes('hotels')) {
699
- vertical = 'hotel';
700
- pageName = redirectionPath.includes('hotels/itinerary')
701
- ? 'h_itinerary'
702
- : 'h_home';
703
- }
704
- if (redirectionPath.includes('bus')) {
705
- vertical = 'bus';
706
- pageName = redirectionPath.includes('bus/itinerary')
707
- ? 'b_itinerary'
708
- : 'b_home';
709
- }
710
- return { loginForm: loginForm, vertical: vertical, pageName: pageName };
711
- }
712
- return {};
713
- };
714
- var sendEventWithUserInsights = function (eventName, ravenPayload, userId) { return __awaiter(void 0, void 0, void 0, function () {
715
- var userInsights, updatedPayload, loyaltyData, martechAttributes;
716
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
717
- return __generator(this, function (_s) {
718
- switch (_s.label) {
719
- case 0: return [4, getUserInsightsData(userId)];
720
- case 1:
721
- userInsights = _s.sent();
722
- updatedPayload = __assign(__assign({}, ravenPayload), { fk_loyalty_status: 'na', fk_loyalty_end_dt: 'na', ct_last_booking_dt: 'na', ct_lifetime_booking: 'na', fk_loyalty_start_dt: 'na', ct_first_booking_dt: 'na', myntra_loyalty_status: 'na', ct_postmerger_booking: 'na', ct_last_1year_booking: 'na', myntra_loyalty_end_dt: 'na', ct_2nd_last_booking_dt: 'na', myntra_loyalty_start_dt: 'na' });
723
- if (!isEmpty(userInsights)) {
724
- loyaltyData = ((_a = userInsights === null || userInsights === void 0 ? void 0 : userInsights.loyaltyStatus) !== null && _a !== void 0 ? _a : []).reduce(function (prev, curr) {
725
- return __assign(__assign({}, prev), curr);
726
- }, {});
727
- martechAttributes = {
728
- ct_lifetime_booking: ((_c = (_b = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _b === void 0 ? void 0 : _b.lifetimeBooking) !== null && _c !== void 0 ? _c : 'na').toString(),
729
- ct_postmerger_booking: ((_e = (_d = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _d === void 0 ? void 0 : _d.postmergerBooking) !== null && _e !== void 0 ? _e : 'na').toString(),
730
- ct_last_1year_booking: ((_g = (_f = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _f === void 0 ? void 0 : _f.lastOneYearBooking) !== null && _g !== void 0 ? _g : 'na').toString(),
731
- ct_first_booking_dt: secondsToDateString((_h = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _h === void 0 ? void 0 : _h.firstbookingDate) || 'na',
732
- ct_last_booking_dt: secondsToDateString((_j = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _j === void 0 ? void 0 : _j.lastbookingDate) || 'na',
733
- ct_2nd_last_booking_dt: secondsToDateString((_k = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _k === void 0 ? void 0 : _k.secondLastbookingDate) || 'na',
734
- fk_loyalty_status: ((_l = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _l === void 0 ? void 0 : _l.program) || 'na',
735
- myntra_loyalty_status: ((_m = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _m === void 0 ? void 0 : _m.program) || 'na',
736
- fk_loyalty_end_dt: secondsToDateString((_o = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _o === void 0 ? void 0 : _o.loyaltyEndDate) || '',
737
- fk_loyalty_start_dt: secondsToDateString((_p = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _p === void 0 ? void 0 : _p.loyaltyStartDate) || 'na',
738
- myntra_loyalty_start_dt: secondsToDateString((_q = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _q === void 0 ? void 0 : _q.loyaltyStartDate) ||
739
- 'na',
740
- myntra_loyalty_end_dt: secondsToDateString((_r = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _r === void 0 ? void 0 : _r.loyaltyEndDate) ||
741
- 'na',
742
- };
743
- updatedPayload = __assign(__assign({}, updatedPayload), martechAttributes);
744
- setMartechUserProperties(martechAttributes);
745
- }
746
- ravenSDKTrigger(eventName, updatedPayload);
747
- return [2];
748
- }
749
- });
750
- }); };
751
- var setMartechUserProperties = function (userProperties) {
752
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
753
- if (isEmpty(userProperties) ||
754
- ((_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem('martech_user_props_sent'))) {
755
- return;
756
- }
757
- 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)) {
758
- (_d = window.webkit.messageHandlers.SEND_ATTRIBUTES) === null || _d === void 0 ? void 0 : _d.postMessage({
759
- type: 'GA',
760
- params: userProperties,
761
- });
762
- (_e = window.webkit.messageHandlers.SEND_ATTRIBUTES) === null || _e === void 0 ? void 0 : _e.postMessage({
763
- type: 'Clevertap',
764
- params: userProperties,
765
- });
766
- (_f = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _f === void 0 ? void 0 : _f.setItem('martech_user_props_sent', 'true');
767
- }
768
- else if (isAndroidApp() && ((_g = window === null || window === void 0 ? void 0 : window.MobileApp) === null || _g === void 0 ? void 0 : _g.sendAttributes)) {
769
- window.MobileApp.sendAttributes('GA', JSON.stringify(userProperties));
770
- window.MobileApp.sendAttributes('Clevertap', JSON.stringify(userProperties));
771
- (_h = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _h === void 0 ? void 0 : _h.setItem('martech_user_props_sent', 'true');
772
- }
773
- else if (isPwa() && window.clevertap) {
774
- window.clevertap.profile.push({
775
- Site: userProperties,
776
- });
777
- (_j = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _j === void 0 ? void 0 : _j.setItem('martech_user_props_sent', 'true');
778
- }
779
- };
780
-
781
- export { MULTI_SPACE, autoReadOtp, createAPIRequest, createGetRequest, createPostOrPutRequest, formatCurrency, 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, path, ravenSDKTrigger, replacePlaceHolder, secondsToDateString, 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};
782
2
  //# sourceMappingURL=ct-platform-utils.esm.js.map