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