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