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