@cleartrip/ct-platform-utils 3.16.0 → 3.17.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,1068 @@
1
- import{__awaiter as n,__generator as t,__assign as o}from"tslib";import{v4 as e}from"uuid";import{Platform as i,AppAgent as r,RequestMethods as a,SOURCE_NAME as u,API_ROUTES as l,MOBILE_CONSTANTS as d,NAVIGATION_ROUTES as s}from"@cleartrip/ct-platform-constants";import c from"ua-parser-js";import{ValidateOTPAction as v}from"@cleartrip/ct-platform-types";var f=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var o=n.map((function(n){return n.trim().replace(/^[/]+/,"")})).join("/");return o=o.replace(/\/\?/g,"?")},w=function(){var n="undefined"!=typeof window?window.location.hostname:"";switch(console.log("API_BASE domain",n),n){case"localhost":case"0.0.0.0":case"qa2new.cleartrip.com":return"https://qa2new.cleartrip.com";case"qa2.cleartrip.com":return"https://qa2.cleartrip.com";case"qa3new.cleartrip.com":return"https://qa3new.cleartrip.com";default:return"https://www.cleartrip.com"}},p=function(n,t){return t.reduce((function(n,t){return n&&n[t]?n[t]:null}),n)},m=function(n,t){return n.reduce((function(n,t){return n&&n[t]?n[t]:null}),t)},g=/\s\s+/g,_=function(n){if(n instanceof Date)return!1;if(null==n)return!0;var t,o=function(n){return"[object Number]"===Object.prototype.toString.call(n)};if(o(n))return o(t=n)&&"NaN"===t.toString();if(n.length>0)return!1;if(0===n.length)return!0;if("object"!=typeof n)return!0;for(var e=Object.keys(n),i=0,r=e[i];i<e.length;i+=1)if(Object.prototype.hasOwnProperty.call(n,r))return!1;return!0},h=function(n){return"object"==typeof n&&null!==n&&"value"in n&&n instanceof HTMLInputElement},y=function(n){return/^[0-9]*$/.test(n)},b="undefined"!=typeof window?window.location.href:"",S=function(n){return P()?"":new URLSearchParams(window.location.search).get(n)},I=function(){return"undefined"!=typeof window?(window.location.pathname+window.location.search).slice(1):""},N=function(n){if(n){var t=n.match(/h_(\d+)[,\/]/);return t&&t[1]?parseInt(t[1],10):void 0}},O=function(n){if(n){var t=n.match(/w_(\d+)[,\/]/);return t&&t[1]?parseInt(t[1],10):void 0}},P=function(){return"undefined"==typeof window||!window};function D(n,t){var o=t||p(document,["cookie"]);if(o){for(var e=n+"=",i=o.split(";"),r=0;r<i.length;r++){for(var a=i[r];" "==a.charAt(0);)a=a.substring(1,a.length);if(0==a.indexOf(e))return a.substring(e.length,a.length)}return""}return""}var k=function(n){void 0===n&&(n="");var t=N(n)||0,o=O(n)||0;return{height:"".concat(t,"px"),width:"".concat(o,"px"),heightInNumber:t,widthInNumber:o}},E=function(n){try{if(!n||Number.isNaN(Number(n)))return"";var t=new Date(1e3*n),o=t.getFullYear(),e=String(t.getDate()).padStart(2,"0"),i=String(t.getMonth()+1).padStart(2,"0");return"".concat(o,"-").concat(i,"-").concat(e)}catch(n){return""}},T=function(n,t,o){void 0===t&&(t="dd-mm-yyyy"),void 0===o&&(o="");try{var e=new Date(n),i=e.getFullYear(),r=String(e.getDate()).padStart(2,"0"),a=String(e.getMonth()+1).padStart(2,"0");return"yyyy-mm-dd"===t?"".concat(i,"-").concat(a,"-").concat(r):"".concat(r,"-").concat(a,"-").concat(i)}catch(n){return o}},A=function(n,t){void 0===t&&(t=!0);try{var o={currency:"INR",minimumFractionDigits:0};return t&&(o.style="currency"),"string"!=typeof n&&(n=null==n?void 0:n.toString()),n=n.replace(/,/g,""),parseInt(n,10).toLocaleString("en-IN",o)}catch(n){return""}},M=function(n){var t,o=n.cookieName,e=n.cookieValue,i=n.expiryInDay,r=n.expiryInHours,a=n.expiryInMinutes,u=new Date;i?(u.setTime(u.getTime()+24*i*60*60*1e3),t=u.toUTCString()):r?(u.setTime(u.getTime()+3600*r*1e3),t=u.toUTCString()):a?(u.setTime(u.getTime()+60*a*1e3),t=u.toUTCString()):t="",document.cookie="".concat(o,"=").concat(e,"; expires=").concat(t,"; path=/")};function R(n){try{var t=new URL(n),o=new URLSearchParams(t.search),e={};return o.forEach((function(n,t){e[t]=n})),e}catch(n){return{}}}function C(n){var t=new Date(n),o=new Date;o.setHours(12,0,0,0),t.setHours(12,0,0,0);var e=(t.getTime()-o.getTime())/864e5;return Math.round(e)}var j=function(){var n,t=null===(n=p(window,["navigator","userAgent"]))||void 0===n?void 0:n.toLowerCase(),o=/safari/.test(t),e=/iphone|ipod|ipad/.test(t);return p(window,["androidData","app-agent"])&&p(window,["androidData","js-version"])||"function"==typeof p(window,["MobileApp","getAppSpecificData"])?i.ANDROID:p(window,["iosData","app-agent"])&&p(window,["iosData","js-version"])||e&&!o?i.IOS:i.PWA},L=function(){var n,t,o=j();return o===i.IOS?null!==(n=p(window,["iosData","app-agent"]))&&void 0!==n?n:r.IOS:o===i.ANDROID?null!==(t=p(window,["androidData","app-agent"]))&&void 0!==t?t:r.ANDROID:r.PWA},U=function(){var n="";return q()?n=p(window,["iosData","js-version"]):H()&&(n=p(window,["androidData","js-version"])),n&&(n=n.toString().split(".")[0]),n},x=function(){var n,t,o,e;if(!P())return"";var i=new c(null===(n=null===window||void 0===window?void 0:window.navigator)||void 0===n?void 0:n.userAgent);return null!==(e=null===(o=null===(t=null==i?void 0:i.getDevice())||void 0===t?void 0:t.model)||void 0===o?void 0:o.toLowerCase())&&void 0!==e?e:""},G=function(){return j()!==i.ANDROID&&j()!==i.IOS},H=function(){return j()===i.ANDROID},B=function(n){return parseInt(U())>=n},q=function(){return j()===i.IOS},J=w(),F=function(i,r,d,s,c,v,p){return void 0===r&&(r=a.GET),void 0===s&&(s={}),void 0===c&&(c={}),void 0===v&&(v=!1),void 0===p&&(p={}),n(void 0,void 0,void 0,(function(){var n,a,m,g,_,h,y,b,S,I;return t(this,(function(t){switch(t.label){case 0:return n=function(n,t){var o=l[n];if(o&&o.trim().length){if(o=f(J,o),null==t?void 0:t.pathParams)for(var e=0,i=Object.entries(t.pathParams);e<i.length;e++){var r=i[e],a=r[0],u=r[1];o=o.replace(":".concat(a),u)}return(null==t?void 0:t.queryParams)&&(o+="?".concat(new URLSearchParams(t.queryParams).toString())),o}}(i,c),n&&n.trim().length?(a="",m="",g=w(),P()||(a=j(),m=JSON.stringify(function(n){var t=o({trackingId:e(),source:u},null!=n?n:{});return P()?t:o(o({},t),{platform:L(),deviceModel:x()})}(p))),_={method:r,headers:o({channel:a,Caller:J,Origin:J,Referer:J,Authority:g,x_ct_sourcetype:"MOBILE","app-agent":L(),"x-unified-header":m,"Content-Type":"application/json"},s)},d&&(_.body=JSON.stringify(d)),[4,fetch(n,_)]):[2,Promise.reject("URL parameter missing")];case 1:return y=t.sent(),b={name:"API_FAILURE",status:y.status,message:"UNKNOWN_ERROR",statusText:y.statusText},(null==y?void 0:y.ok)?[3,3]:v?[2,Promise.reject(b)]:[4,y.json()];case 2:throw S=t.sent().message,b.message=S,b;case 3:return(null==(I=y.headers.get("content-type"))?void 0:I.includes("application/json"))?[4,y.json()]:[3,5];case 4:return h=t.sent(),[3,9];case 5:return(null==I?void 0:I.includes("text"))?[4,y.text()]:[3,7];case 6:return h=t.sent(),[3,9];case 7:return 204===y.status?[3,9]:[4,y.blob()];case 8:h=t.sent(),t.label=9;case 9:return[2,{data:h,status:y.status}]}}))}))},W=function(e,i,r,u,l){return void 0===i&&(i={}),void 0===r&&(r={}),void 0===u&&(u=!1),void 0===l&&(l={}),n(void 0,void 0,void 0,(function(){return t(this,(function(n){return[2,F(e,a.GET,null,o({expires:"0",accept:"application/json","cache-control":"no-cache"},i),r,u,l)]}))}))},Y=function(e,i,r,u,l,d,s){return void 0===i&&(i=a.POST),void 0===r&&(r={}),void 0===u&&(u={}),void 0===l&&(l={}),void 0===d&&(d=!1),void 0===s&&(s={}),n(void 0,void 0,void 0,(function(){return t(this,(function(n){return[2,F(e,i,r,o({expires:"0",accept:"application/json","cache-control":"no-cache"},u),l,d,s)]}))}))},V=function(){var n;if("function"==typeof(null===(n=window.MobileApp)||void 0===n?void 0:n.onRequestMobileNumber)){var t;window.MobileApp.onRequestMobileNumber();var o=new Promise((function(n){t=n}));return window.sendSelectedMobileNumber=function(n){return t(K(n))},o}return Promise.resolve("")},K=function(n){var t="",o=n.match(d.REGEX);return o&&(t=o[0].replace(/\D/g,"")),t},$=function(){return n(void 0,void 0,void 0,(function(){return t(this,(function(n){return[2,H()?nn():Z()]}))}))},X=function(){var n,t,o;null===(o=null===(t=null===(n=window.webkit)||void 0===n?void 0:n.messageHandlers)||void 0===t?void 0:t.PWA_IS_SIGNIN)||void 0===o||o.postMessage({isSignIn:!0})},z=function(){var n;null===(n=window.MobileApp)||void 0===n||n.onPWALoginStatus(JSON.stringify({isSignIn:!0}))},Q=function(){var n;H()&&(null===(n=window.MobileApp)||void 0===n||n.onPageStart("OTP_SCREEN"))},Z=function(){return n(void 0,void 0,void 0,(function(){var n,o;return t(this,(function(t){return(null===(o=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===o?void 0:o.get)&&"OTPCredential"in window?(n=new AbortController,setTimeout((function(){n.abort()}),6e4),[2,navigator.credentials.get({otp:{transport:["sms"]},signal:n.signal}).then((function(n){return null==n?void 0:n.code}))]):[2,Promise.reject("NOT_SUPPORTED")]}))}))},nn=function(){return n(void 0,void 0,void 0,(function(){var n,o;return t(this,(function(t){return o=new Promise((function(t){n=t})),window.sendOtpValue=function(t){n(t)},[2,o]}))}))},tn=function(){return n(void 0,void 0,void 0,(function(){var n,o;return t(this,(function(t){return H()&&"function"==typeof(null===(n=window.MobileApp)||void 0===n?void 0:n.isPNPermissionEnabled)?[2,Promise.resolve(!(null===(o=window.MobileApp)||void 0===o?void 0:o.isPNPermissionEnabled()))]:q()?[2,new Promise((function(n,t){var o,e,i,r;window.pushNotifcationPermissionStatus=function(t){var o=JSON.parse(t),e=null==o?void 0:o.status;"boolean"==typeof e&&n(!e)};try{null===(r=null===(i=null===(e=null===(o=null===window||void 0===window?void 0:window.webkit)||void 0===o?void 0:o.messageHandlers)||void 0===e?void 0:e.IS_PN_PERMISSION_ENABLED)||void 0===i?void 0:i.postMessage)||void 0===r||r.call(i,"")}catch(t){n(!1)}}))]:[2,Promise.resolve(!1)]}))}))},on=function(n){var t,o,e,i,r,a,u,l;H()&&"function"==typeof(null===(t=window.MobileApp)||void 0===t?void 0:t.handlePNPermission)?null===(o=window.MobileApp)||void 0===o||o.handlePNPermission(JSON.stringify({type:n})):q()&&(null===(i=null===(e=null===window||void 0===window?void 0:window.webkit)||void 0===e?void 0:e.messageHandlers)||void 0===i?void 0:i.HANDLE_PN_PERMISSION)&&(null===(l=null===(u=null===(a=null===(r=window.webkit)||void 0===r?void 0:r.messageHandlers)||void 0===a?void 0:a.HANDLE_PN_PERMISSION)||void 0===u?void 0:u.postMessage)||void 0===l||l.call(u,JSON.stringify({type:n})))},en=function(o,e){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return[4,Y("SEND_OTP",a.POST,{value:o,type:"MOBILE",action:"SIGNIN",countryCode:d.COUNTRY_CODE},{"ab-otp":"b",dvid_data:e})];case 1:return[2,null==(n=t.sent())?void 0:n.data]}}))}))},rn=function(e,i){return n(void 0,void 0,void 0,(function(){var n,r;return t(this,(function(t){switch(t.label){case 0:return[4,Y("VALIDATE_OTP",a.POST,{otp:i,value:e,type:"MOBILE",action:"SIGNIN",countryCode:"+91"},{"ab-otp":"b"})];case 1:return n=t.sent(),r=null==n?void 0:n.data,[2,o(o({},n),{signup:(null==r?void 0:r.action)===v.SIGNUP,action:null==r?void 0:r.action,status:null==n?void 0:n.status})]}}))}))},an=function(o,e){return n(void 0,void 0,void 0,(function(){var n,i;return t(this,(function(t){switch(t.label){case 0:return q()?[2,Promise.reject()]:(n=I(),[4,sn(o,e?n:s.PERSONAL_DETAILS+"?onboardingFlow=true",n)]);case 1:return i=t.sent(),H()?[2,vn(i)]:[2,cn(i)]}}))}))},un=function(n){return(null==n?void 0:n.length)===d.LENGTH&&/^\d{10}$/.test(n)},ln=function(){q()?X():H()&&z()},dn=function(){return G()||!q()&&B(5)},sn=function(o,e,i){return n(void 0,void 0,void 0,(function(){var n,r;return t(this,(function(t){switch(t.label){case 0:return n=w(),[4,Y("FK_REDIRECTION_INFO",a.POST,{provider:"flipkart",fallbackUri:f(n,o||i),signupPageUri:f(n,e||"personal-details"),currentPageUri:f(n,i)})];case 1:return[2,null==(r=t.sent())?void 0:r.data]}}))}))},cn=function(n){var t,o=null!==(t=null==n?void 0:n.params)&&void 0!==t?t:{},e=null==n?void 0:n.redirectUri;if(e){for(var i in e+="?",o)e+=i+"="+o[i]+"&";return Promise.resolve(e)}return Promise.reject()},vn=function(n){var t,e,i=null==n?void 0:n.params;if(_(i)||"function"!=typeof(null===(t=window.MobileApp)||void 0===t?void 0:t.onNavigationChange))return Promise.reject();var r=f(w(),"dl/oauth2");return null===(e=window.MobileApp)||void 0===e||e.onNavigationChange(JSON.stringify({type:"FkSSO",miscData:o(o({},i),{redirectURI:r})})),Promise.resolve()};function fn(n){try{var t=decodeURIComponent(D("userid",n)||"").split("|");return{email:t[0],profileName:t[1],gender:t[2],photo:t[3],userId:t[4]}}catch(n){return{}}}var wn=function(n){var t=fn(n)||{};return!!(decodeURIComponent(D("usermisc",n)||"").split("|").includes("SIGNED_IN")&&t.userId&&t.userId.length>0)},pn=function(o){return void 0===o&&(o=!0),n(void 0,void 0,void 0,(function(){var e;return t(this,(function(i){switch(i.label){case 0:return[4,n(void 0,void 0,void 0,(function(){var n,o;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,W("GET_PROFILE_DETAILS",{caller:w(),"app-agent":L()},{})];case 1:return[2,null==(n=t.sent())?void 0:n.data];case 2:return o=t.sent(),console.error("Failed to fetch user details. Error: ",o),[2,Promise.resolve(null)];case 3:return[2]}}))}))];case 1:return(e=i.sent())&&o&&function(n){var t,o,e,i,r,a;try{if(P()||!(null===window||void 0===window?void 0:window.clevertap)||_(n))return;var u={Identity:null!==(t=null==n?void 0:n.id)&&void 0!==t?t:"",Gender:null!==(o=null==n?void 0:n.gender)&&void 0!==o?o:"",Email:null!==(e=null==n?void 0:n.username)&&void 0!==e?e:"",Phone:"".concat(null==n?void 0:n.countryCode).concat(null==n?void 0:n.mobile),"MSG-sms":!0,"MSG-push":!0,"MSG-email":!1,"MSG-whatsapp":!0};if(null===(i=null==n?void 0:n.travellerDetails)||void 0===i?void 0:i.length)for(var l=0;l<(null===(r=null==n?void 0:n.travellerDetails)||void 0===r?void 0:r.length);l++){var d=null==n?void 0:n.travellerDetails[l];if(d.isRegistered){var s=d.personalDetails.dateOfBirth;u.Name="".concat(d.personalDetails.firstName," ").concat(d.personalDetails.lastName),isNaN(s)||(u.DOB=new Date(s));break}}null===(a=null===window||void 0===window?void 0:window.clevertap)||void 0===a||a.onUserLogin.push({Site:u})}catch(n){console.log("Error pushing clevertap profile information. Error: ",n)}}(e),[2]}}))}))},mn=function(o){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,W("USER_INSIGHTS",{},{pathParams:{userId:o}})];case 1:return[2,null==(n=t.sent())?void 0:n.data];case 2:return t.sent(),[2,Promise.resolve(null)];case 3:return[2]}}))}))},gn=function(o){return n(void 0,void 0,void 0,(function(){var n,e,i,r,a,u,l,d;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),(n=null!=o?o:fn().userId)?(e=null===(u=null===window||void 0===window?void 0:window.sessionStorage)||void 0===u?void 0:u.getItem("martech_user_attributes"),i=void 0,"string"==typeof e&&(i=JSON.parse(e)),n!==(null==i?void 0:i.accountId)&&(null===(l=null===window||void 0===window?void 0:window.sessionStorage)||void 0===l||l.removeItem("martech_user_attributes")),[4,mn(n)]):(null===(a=null===window||void 0===window?void 0:window.sessionStorage)||void 0===a||a.removeItem("martech_user_attributes"),[2,null]);case 1:return r=t.sent(),_(null==r?void 0:r.data)?[2,null]:(null===(d=null===window||void 0===window?void 0:window.sessionStorage)||void 0===d||d.setItem("martech_user_attributes",JSON.stringify(null==r?void 0:r.data)),[2,null==r?void 0:r.data]);case 2:return t.sent(),[2,null];case 3:return[2]}}))}))},_n=function(n){return Object.keys(n).forEach((function(t){n[t]="a_fare_price"===t||"a_ct_discount"===t||"supercoin_balance"===t||"supercoin_earned"===t||"supercoin_burnt"===t||"wallet_balance_used"===t||"convenience_fee"===t?Number(n[t]):""+n[t]})),n},hn=function(){try{if(P())return"";var n=D("ct_statsig_experiments")||"{}",t=n?JSON.parse(decodeURIComponent(n)):{};return Object.keys(t).map((function(n){return n&&t[n]?"".concat(n,":").concat(t[n]):""})).filter((function(n){return!!n})).join("|")}catch(n){return""}},yn=function(n,t){var e;if(window&&window.ravenWebManager){var i=Sn(),r={page_name:i.pageName,u_utm_source:i.utmSource,domain:window.location.host,u_ab_key:hn(),platform:null===(e=j())||void 0===e?void 0:e.toLowerCase(),login_status:wn()?"yes":"no"},a=_n(t),u=window.ravenWebManager;null==u||u.triggerRaven(n,o(o({},r),a))}},bn=function(){if(window&&"undefined"!=typeof window){var n=p(window,["location","pathname"]);if("/"===n||"/flights"===n)return!0}return!1},Sn=function(){var n,t;if(window&&"undefined"!=typeof window){var o=window.location.pathname,e=null!==(n=S("service"))&&void 0!==n?n:"",i=null!==(t=S("utm_source"))&&void 0!==t?t:"organic",r=bn()?"skippable_login":"account_login",a="air",u=o.includes("flights/itinerary")||e.includes("flights/itinerary")?"a_itinerary":"a_home";return e.includes("my-account")&&(a="uar",u="account"),e.includes("hotels")&&(a="hotel",u=e.includes("hotels/itinerary")?"h_itinerary":"h_home"),e.includes("bus")&&(a="bus",u=e.includes("bus/itinerary")?"b_itinerary":"b_home"),{loginForm:r,vertical:a,pageName:u,utmSource:i}}return{}},In=function(e,i,r){return n(void 0,void 0,void 0,(function(){var n,a,u,l,d,s,c,v,f,w,p,m,g,h,y,b,S,I,N,O;return t(this,(function(t){switch(t.label){case 0:return[4,gn(r)];case 1:return n=t.sent(),a=o(o({},i),{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"}),_(n)||(u=(null!==(d=null==n?void 0:n.loyaltyStatus)&&void 0!==d?d:[]).reduce((function(n,t){return o(o({},n),t)}),{}),l={ct_lifetime_booking:(null!==(c=null===(s=null==n?void 0:n.bookingStatus)||void 0===s?void 0:s.lifetimeBooking)&&void 0!==c?c:"na").toString(),ct_postmerger_booking:(null!==(f=null===(v=null==n?void 0:n.bookingStatus)||void 0===v?void 0:v.postmergerBooking)&&void 0!==f?f:"na").toString(),ct_last_1year_booking:(null!==(p=null===(w=null==n?void 0:n.bookingStatus)||void 0===w?void 0:w.lastOneYearBooking)&&void 0!==p?p:"na").toString(),ct_first_booking_dt:E(null===(m=null==n?void 0:n.bookingStatus)||void 0===m?void 0:m.firstbookingDate)||"na",ct_last_booking_dt:E(null===(g=null==n?void 0:n.bookingStatus)||void 0===g?void 0:g.lastbookingDate)||"na",ct_2nd_last_booking_dt:E(null===(h=null==n?void 0:n.bookingStatus)||void 0===h?void 0:h.secondLastbookingDate)||"na",fk_loyalty_status:(null===(y=null==u?void 0:u.fk)||void 0===y?void 0:y.program)||"na",myntra_loyalty_status:(null===(b=null==u?void 0:u.myntra)||void 0===b?void 0:b.program)||"na",fk_loyalty_end_dt:E(null===(S=null==u?void 0:u.fk)||void 0===S?void 0:S.loyaltyEndDate)||"",fk_loyalty_start_dt:E(null===(I=null==u?void 0:u.fk)||void 0===I?void 0:I.loyaltyStartDate)||"na",myntra_loyalty_start_dt:E(null===(N=null==u?void 0:u.myntra)||void 0===N?void 0:N.loyaltyStartDate)||"na",myntra_loyalty_end_dt:E(null===(O=null==u?void 0:u.myntra)||void 0===O?void 0:O.loyaltyEndDate)||"na"},a=o(o({},a),l),Nn(l)),yn(e,a),[2]}}))}))},Nn=function(n){var t,o,e,i,r,a,u,l,d;_(n)||(null===(t=null===window||void 0===window?void 0:window.sessionStorage)||void 0===t?void 0:t.getItem("martech_user_props_sent"))||(q()&&(null===(e=null===(o=null===window||void 0===window?void 0:window.webkit)||void 0===o?void 0:o.messageHandlers)||void 0===e?void 0:e.SEND_ATTRIBUTES)?(null===(i=window.webkit.messageHandlers.SEND_ATTRIBUTES)||void 0===i||i.postMessage({type:"GA",params:n}),null===(r=window.webkit.messageHandlers.SEND_ATTRIBUTES)||void 0===r||r.postMessage({type:"Clevertap",params:n}),null===(a=null===window||void 0===window?void 0:window.sessionStorage)||void 0===a||a.setItem("martech_user_props_sent","true")):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(n)),window.MobileApp.sendAttributes("Clevertap",JSON.stringify(n)),null===(l=null===window||void 0===window?void 0:window.sessionStorage)||void 0===l||l.setItem("martech_user_props_sent","true")):G()&&window.clevertap&&(window.clevertap.profile.push({Site:n}),null===(d=null===window||void 0===window?void 0:window.sessionStorage)||void 0===d||d.setItem("martech_user_props_sent","true")))},On=function(n,t){"undefined"!=typeof window&&"function"==typeof window.requestIdleCallback?requestIdleCallback((function(){yn(n,t)})):setTimeout((function(){yn(n,t)}),0)},Pn=function(e,i,r,a,u,l,d,s){return void 0===r&&(r=450),void 0===a&&(a="Discounts"),void 0===u&&(u="on hotels"),void 0===l&&(l="CTBEST - Exclusive coupon applied for you!"),void 0===d&&(d={}),void 0===s&&(s={}),n(void 0,void 0,void 0,(function(){var n,c,v,f,w,p;return t(this,(function(t){switch(t.label){case 0:n=null!==(p=null===(w=fn())||void 0===w?void 0:w.userId)&&void 0!==p?p:"",c={couponCode:"",couponCallOut:"",couponCallOutPrefix:a,couponCallOutSuffix:u,offerCallOut:l,pageLandingUrl:i},t.label=1;case 1:return t.trys.push([1,3,,4]),v=new Promise((function(n){setTimeout((function(){n(c)}),r)})),f=W("HOTEL_RECOMMENDATIONS",d,{queryParams:o({userId:n,vertical:e},s)},!1,{userBuckets:{"x-cross-sell":"true"}}).then((function(n){return n.data})),[4,Promise.race([f,v])];case 2:return[2,t.sent()];case 3:return t.sent(),[2,c];case 4:return[2]}}))}))};export{g as MULTI_SPACE,$ as autoReadOtp,On as batchRavenEvent,F as createAPIRequest,W as createGetRequest,Y as createPostOrPutRequest,R as extractQueryParamsAsObj,A as formatCurrency,T as formatFullDateString,w as getApiDomain,L as getAppAgent,K as getAutoDetectedMobile,hn as getCTStatsigExpForRaven,D as getCookie,I as getCurrentPathName,b as getCurrentUrl,x as getDeviceModel,j as getDevicePlatform,k as getDimensionFromImageUrl,N as getHeightFromImgUrl,Pn as getHotelCrossSellRecos,U as getJSVersion,p as getNestedValue,C as getNoOfDaysFromToday,S as getQueryParam,Sn as getRavenEventProps,fn as getUserAuthValues,O as getWidthFromImgUrl,an as handleFKSSO,pn as handleProfileFetch,on as handlePushPrimerCTA,bn as isAirHomePage,H as isAndroidApp,_ as isEmpty,dn as isFKSSOEnabled,h as isHTMLInputElement,q as isIOSApp,B as isJSVersionUpdated,y as isNumeric,G as isPwa,P as isServer,wn as isUserSignedIn,un as isValidMobileNumber,m as path,yn as ravenSDKTrigger,E as secondsToDateString,In as sendEventWithUserInsights,en as sendLoginOtp,M as setCookie,Nn as setMartechUserProperties,tn as shouldShowPushPrimer,V as showMobileNumberHint,_n as stringifyPayload,Q as triggerOTPListener,z as updateNativeAndroidOnSignIn,X as updateNativeIOSOnSignIn,ln as updateNativeOnLogin,f as urlJoin,rn as validateOtp};
1
+ import { __awaiter, __generator, __assign } from 'tslib';
2
+ import { v4 } from 'uuid';
3
+ import { Platform, AppAgent, RequestMethods, SOURCE_NAME, API_ROUTES, MOBILE_CONSTANTS, NAVIGATION_ROUTES } from '@cleartrip/ct-platform-constants';
4
+ import UAParser from 'ua-parser-js';
5
+ import { ValidateOTPAction } from '@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 secondsToDateString = function (sec) {
154
+ try {
155
+ if (!sec || Number.isNaN(Number(sec))) {
156
+ return '';
157
+ }
158
+ var date = new Date(sec * 1000);
159
+ var year = date.getFullYear();
160
+ var day = String(date.getDate()).padStart(2, '0');
161
+ var month = String(date.getMonth() + 1).padStart(2, '0');
162
+ return "".concat(year, "-").concat(month, "-").concat(day);
163
+ }
164
+ catch (_e) {
165
+ return '';
166
+ }
167
+ };
168
+ var formatFullDateString = function (dateString, format, fallback) {
169
+ if (format === void 0) { format = 'dd-mm-yyyy'; }
170
+ if (fallback === void 0) { fallback = ''; }
171
+ try {
172
+ var date = new Date(dateString);
173
+ var year = date.getFullYear();
174
+ var day = String(date.getDate()).padStart(2, '0');
175
+ var month = String(date.getMonth() + 1).padStart(2, '0');
176
+ switch (format) {
177
+ case 'yyyy-mm-dd':
178
+ return "".concat(year, "-").concat(month, "-").concat(day);
179
+ case 'dd-mm-yyyy':
180
+ default:
181
+ return "".concat(day, "-").concat(month, "-").concat(year);
182
+ }
183
+ }
184
+ catch (_e) {
185
+ return fallback;
186
+ }
187
+ };
188
+ var formatCurrency = function (value, withIcon) {
189
+ if (withIcon === void 0) { withIcon = true; }
190
+ try {
191
+ var config = {
192
+ currency: 'INR',
193
+ minimumFractionDigits: 0,
194
+ };
195
+ if (withIcon) {
196
+ config.style = 'currency';
197
+ }
198
+ if (typeof value !== 'string') {
199
+ value = value === null || value === void 0 ? void 0 : value.toString();
200
+ }
201
+ value = value.replace(/,/g, '');
202
+ return parseInt(value, 10).toLocaleString('en-IN', config);
203
+ }
204
+ catch (_e) {
205
+ return '';
206
+ }
207
+ };
208
+ var setCookie = function (_a) {
209
+ var cookieName = _a.cookieName, cookieValue = _a.cookieValue, expiryInDay = _a.expiryInDay, expiryInHours = _a.expiryInHours, expiryInMinutes = _a.expiryInMinutes;
210
+ var expires;
211
+ var date = new Date();
212
+ if (expiryInDay) {
213
+ date.setTime(date.getTime() + expiryInDay * 24 * 60 * 60 * 1000);
214
+ expires = date.toUTCString();
215
+ }
216
+ else if (expiryInHours) {
217
+ date.setTime(date.getTime() + expiryInHours * 3600 * 1000);
218
+ expires = date.toUTCString();
219
+ }
220
+ else if (expiryInMinutes) {
221
+ date.setTime(date.getTime() + expiryInMinutes * 60 * 1000);
222
+ expires = date.toUTCString();
223
+ }
224
+ else {
225
+ expires = '';
226
+ }
227
+ document.cookie = "".concat(cookieName, "=").concat(cookieValue, "; expires=").concat(expires, "; path=/");
228
+ };
229
+ function extractQueryParamsAsObj(url) {
230
+ try {
231
+ var urlObj = new URL(url);
232
+ var queryParams = new URLSearchParams(urlObj.search);
233
+ var params_1 = {};
234
+ queryParams.forEach(function (value, key) {
235
+ params_1[key] = value;
236
+ });
237
+ return params_1;
238
+ }
239
+ catch (error) {
240
+ return {};
241
+ }
242
+ }
243
+ function getNoOfDaysFromToday(checkInDate) {
244
+ var checkIn = new Date(checkInDate);
245
+ var today = new Date();
246
+ today.setHours(12, 0, 0, 0);
247
+ checkIn.setHours(12, 0, 0, 0);
248
+ var differenceInMs = checkIn.getTime() - today.getTime();
249
+ var differenceInDays = differenceInMs / (1000 * 60 * 60 * 24);
250
+ return Math.round(differenceInDays);
251
+ }
252
+
253
+ var getDevicePlatform = function () {
254
+ var _a;
255
+ var userAgent = (_a = getNestedValue(window, [
256
+ 'navigator',
257
+ 'userAgent',
258
+ ])) === null || _a === void 0 ? void 0 : _a.toLowerCase();
259
+ var safariBrowser = /safari/.test(userAgent);
260
+ var appleDevice = /iphone|ipod|ipad/.test(userAgent);
261
+ if ((getNestedValue(window, ['androidData', 'app-agent']) &&
262
+ getNestedValue(window, ['androidData', 'js-version'])) ||
263
+ typeof getNestedValue(window, ['MobileApp', 'getAppSpecificData']) ===
264
+ 'function') {
265
+ return Platform.ANDROID;
266
+ }
267
+ else if ((getNestedValue(window, ['iosData', 'app-agent']) &&
268
+ getNestedValue(window, ['iosData', 'js-version'])) ||
269
+ (appleDevice && !safariBrowser)) {
270
+ return Platform.IOS;
271
+ }
272
+ return Platform.PWA;
273
+ };
274
+ var getAppAgent = function () {
275
+ var _a, _b;
276
+ var platform = getDevicePlatform();
277
+ if (platform === Platform.IOS) {
278
+ return (_a = getNestedValue(window, ['iosData', 'app-agent'])) !== null && _a !== void 0 ? _a : AppAgent.IOS;
279
+ }
280
+ else if (platform === Platform.ANDROID) {
281
+ return ((_b = getNestedValue(window, ['androidData', 'app-agent'])) !== null && _b !== void 0 ? _b : AppAgent.ANDROID);
282
+ }
283
+ return AppAgent.PWA;
284
+ };
285
+ var getJSVersion = function () {
286
+ var jsVersion = '';
287
+ if (isIOSApp()) {
288
+ jsVersion = getNestedValue(window, ['iosData', 'js-version']);
289
+ }
290
+ else if (isAndroidApp()) {
291
+ jsVersion = getNestedValue(window, ['androidData', 'js-version']);
292
+ }
293
+ if (jsVersion) {
294
+ jsVersion = jsVersion.toString().split('.')[0];
295
+ }
296
+ return jsVersion;
297
+ };
298
+ var getDeviceModel = function () {
299
+ var _a, _b, _c, _d;
300
+ if (!isServer()) {
301
+ return '';
302
+ }
303
+ var parser = new UAParser((_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent);
304
+ return (_d = (_c = (_b = parser === null || parser === void 0 ? void 0 : parser.getDevice()) === null || _b === void 0 ? void 0 : _b.model) === null || _c === void 0 ? void 0 : _c.toLowerCase()) !== null && _d !== void 0 ? _d : '';
305
+ };
306
+ var isPwa = function () {
307
+ return getDevicePlatform() !== Platform.ANDROID &&
308
+ getDevicePlatform() !== Platform.IOS;
309
+ };
310
+ var isAndroidApp = function () {
311
+ return getDevicePlatform() === Platform.ANDROID;
312
+ };
313
+ var isJSVersionUpdated = function (compareVersion) {
314
+ return parseInt(getJSVersion()) >= compareVersion;
315
+ };
316
+ var isIOSApp = function () { return getDevicePlatform() === Platform.IOS; };
317
+
318
+ var API_BASE = getApiDomain();
319
+ var getCustomHeaderClientSide = function (additionalInfo) {
320
+ var unifiedHeader = __assign({ trackingId: v4(), source: SOURCE_NAME }, (additionalInfo !== null && additionalInfo !== void 0 ? additionalInfo : {}));
321
+ if (!isServer()) {
322
+ return __assign(__assign({}, unifiedHeader), { platform: getAppAgent(), deviceModel: getDeviceModel() });
323
+ }
324
+ return unifiedHeader;
325
+ };
326
+ var getRequestUrl = function (path, params) {
327
+ var url = API_ROUTES[path];
328
+ if (!url || !url.trim().length) {
329
+ return;
330
+ }
331
+ url = urlJoin(API_BASE, url);
332
+ if (params === null || params === void 0 ? void 0 : params.pathParams) {
333
+ for (var _i = 0, _a = Object.entries(params.pathParams); _i < _a.length; _i++) {
334
+ var _b = _a[_i], key = _b[0], value = _b[1];
335
+ url = url.replace(":".concat(key), value);
336
+ }
337
+ }
338
+ if (params === null || params === void 0 ? void 0 : params.queryParams) {
339
+ url += "?".concat(new URLSearchParams(params.queryParams).toString());
340
+ }
341
+ return url;
342
+ };
343
+ var createAPIRequest = function (path, method, payload, headers, params, useCustomErrorHandler, additionalUnifiedHeaders) {
344
+ if (method === void 0) { method = RequestMethods.GET; }
345
+ if (headers === void 0) { headers = {}; }
346
+ if (params === void 0) { params = {}; }
347
+ if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
348
+ if (additionalUnifiedHeaders === void 0) { additionalUnifiedHeaders = {}; }
349
+ return __awaiter(void 0, void 0, void 0, function () {
350
+ var url, channel, unifiedHeader, API_AUTHORITY, requestOptions, responseData, response, error, message, contentType;
351
+ return __generator(this, function (_a) {
352
+ switch (_a.label) {
353
+ case 0:
354
+ url = getRequestUrl(path, params);
355
+ if (!url || !url.trim().length) {
356
+ return [2, Promise.reject('URL parameter missing')];
357
+ }
358
+ channel = '';
359
+ unifiedHeader = '';
360
+ API_AUTHORITY = getApiDomain();
361
+ if (!isServer()) {
362
+ channel = getDevicePlatform();
363
+ unifiedHeader = JSON.stringify(getCustomHeaderClientSide(additionalUnifiedHeaders));
364
+ }
365
+ requestOptions = {
366
+ method: method,
367
+ headers: __assign({ channel: channel, Caller: API_BASE, Origin: API_BASE, Referer: API_BASE, Authority: API_AUTHORITY, x_ct_sourcetype: 'MOBILE', 'app-agent': getAppAgent(), 'x-unified-header': unifiedHeader, 'Content-Type': 'application/json' }, headers),
368
+ };
369
+ if (payload) {
370
+ requestOptions.body = JSON.stringify(payload);
371
+ }
372
+ return [4, fetch(url, requestOptions)];
373
+ case 1:
374
+ response = _a.sent();
375
+ error = {
376
+ name: 'API_FAILURE',
377
+ status: response.status,
378
+ message: 'UNKNOWN_ERROR',
379
+ statusText: response.statusText,
380
+ };
381
+ if (!!(response === null || response === void 0 ? void 0 : response.ok)) return [3, 3];
382
+ if (useCustomErrorHandler) {
383
+ return [2, Promise.reject(error)];
384
+ }
385
+ return [4, response.json()];
386
+ case 2:
387
+ message = (_a.sent()).message;
388
+ error.message = message;
389
+ throw error;
390
+ case 3:
391
+ contentType = response.headers.get('content-type');
392
+ if (!(contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json'))) return [3, 5];
393
+ return [4, response.json()];
394
+ case 4:
395
+ responseData = _a.sent();
396
+ return [3, 9];
397
+ case 5:
398
+ if (!(contentType === null || contentType === void 0 ? void 0 : contentType.includes('text'))) return [3, 7];
399
+ return [4, response.text()];
400
+ case 6:
401
+ responseData = _a.sent();
402
+ return [3, 9];
403
+ case 7:
404
+ if (!(response.status !== 204)) return [3, 9];
405
+ return [4, response.blob()];
406
+ case 8:
407
+ responseData = _a.sent();
408
+ _a.label = 9;
409
+ case 9: return [2, {
410
+ data: responseData,
411
+ status: response.status,
412
+ }];
413
+ }
414
+ });
415
+ });
416
+ };
417
+ var createGetRequest = function (path, headers, params, useCustomErrorHandler, additionalUnifiedHeaders) {
418
+ if (headers === void 0) { headers = {}; }
419
+ if (params === void 0) { params = {}; }
420
+ if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
421
+ if (additionalUnifiedHeaders === void 0) { additionalUnifiedHeaders = {}; }
422
+ return __awaiter(void 0, void 0, void 0, function () {
423
+ return __generator(this, function (_a) {
424
+ return [2, createAPIRequest(path, RequestMethods.GET, null, __assign({ expires: '0', accept: 'application/json', 'cache-control': 'no-cache' }, headers), params, useCustomErrorHandler, additionalUnifiedHeaders)];
425
+ });
426
+ });
427
+ };
428
+ var createPostOrPutRequest = function (path, method, payload, headers, params, useCustomErrorHandler, additionalUnifiedHeaders) {
429
+ if (method === void 0) { method = RequestMethods.POST; }
430
+ if (payload === void 0) { payload = {}; }
431
+ if (headers === void 0) { headers = {}; }
432
+ if (params === void 0) { params = {}; }
433
+ if (useCustomErrorHandler === void 0) { useCustomErrorHandler = false; }
434
+ if (additionalUnifiedHeaders === void 0) { additionalUnifiedHeaders = {}; }
435
+ return __awaiter(void 0, void 0, void 0, function () {
436
+ return __generator(this, function (_a) {
437
+ return [2, createAPIRequest(path, method, payload, __assign({ expires: '0', accept: 'application/json', 'cache-control': 'no-cache' }, headers), params, useCustomErrorHandler, additionalUnifiedHeaders)];
438
+ });
439
+ });
440
+ };
441
+
442
+ var showMobileNumberHint = function () {
443
+ var _a;
444
+ if (typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onRequestMobileNumber) === 'function') {
445
+ window.MobileApp.onRequestMobileNumber();
446
+ var promiseResolver_1;
447
+ var mobileNoPromise = new Promise(function (resolve) {
448
+ promiseResolver_1 = resolve;
449
+ });
450
+ window.sendSelectedMobileNumber = function (mobileNum) {
451
+ return promiseResolver_1(getAutoDetectedMobile(mobileNum));
452
+ };
453
+ return mobileNoPromise;
454
+ }
455
+ return Promise.resolve('');
456
+ };
457
+ var getAutoDetectedMobile = function (mobileNumber) {
458
+ var formattedMobileNo = '';
459
+ var matches = mobileNumber.match(MOBILE_CONSTANTS.REGEX);
460
+ if (matches) {
461
+ formattedMobileNo = matches[0].replace(/\D/g, '');
462
+ }
463
+ return formattedMobileNo;
464
+ };
465
+ var autoReadOtp = function () { return __awaiter(void 0, void 0, void 0, function () {
466
+ return __generator(this, function (_a) {
467
+ return [2, isAndroidApp() ? readOtpAndroid() : readOtpPWA()];
468
+ });
469
+ }); };
470
+ var updateNativeIOSOnSignIn = function () {
471
+ var _a, _b, _c;
472
+ (_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({
473
+ isSignIn: true,
474
+ });
475
+ };
476
+ var updateNativeAndroidOnSignIn = function () {
477
+ var _a;
478
+ (_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onPWALoginStatus(JSON.stringify({
479
+ isSignIn: true,
480
+ }));
481
+ };
482
+ var triggerOTPListener = function () {
483
+ var _a;
484
+ if (isAndroidApp()) {
485
+ (_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onPageStart('OTP_SCREEN');
486
+ }
487
+ };
488
+ var readOtpPWA = function () { return __awaiter(void 0, void 0, void 0, function () {
489
+ var abortController;
490
+ var _a;
491
+ return __generator(this, function (_b) {
492
+ if (!((_a = navigator === null || navigator === void 0 ? void 0 : navigator.credentials) === null || _a === void 0 ? void 0 : _a.get) || !('OTPCredential' in window)) {
493
+ return [2, Promise.reject('NOT_SUPPORTED')];
494
+ }
495
+ abortController = new AbortController();
496
+ setTimeout(function () {
497
+ abortController.abort();
498
+ }, 60000);
499
+ return [2, navigator.credentials
500
+ .get({
501
+ otp: { transport: ['sms'] },
502
+ signal: abortController.signal,
503
+ })
504
+ .then(function (content) { return content === null || content === void 0 ? void 0 : content.code; })];
505
+ });
506
+ }); };
507
+ var readOtpAndroid = function () { return __awaiter(void 0, void 0, void 0, function () {
508
+ var promiseResolver, otpPromise;
509
+ return __generator(this, function (_a) {
510
+ otpPromise = new Promise(function (resolve) {
511
+ promiseResolver = resolve;
512
+ });
513
+ window.sendOtpValue = function (otp) {
514
+ promiseResolver(otp);
515
+ };
516
+ return [2, otpPromise];
517
+ });
518
+ }); };
519
+ var shouldShowPushPrimer = function () { return __awaiter(void 0, void 0, void 0, function () {
520
+ var _a, _b;
521
+ return __generator(this, function (_c) {
522
+ if (isAndroidApp() &&
523
+ typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.isPNPermissionEnabled) === 'function') {
524
+ return [2, Promise.resolve(!((_b = window.MobileApp) === null || _b === void 0 ? void 0 : _b.isPNPermissionEnabled()))];
525
+ }
526
+ else if (isIOSApp()) {
527
+ return [2, new Promise(function (resolve, _reject) {
528
+ var _a, _b, _c, _d;
529
+ window.pushNotifcationPermissionStatus = function (data) {
530
+ var parsedData = JSON.parse(data);
531
+ var status = parsedData === null || parsedData === void 0 ? void 0 : parsedData.status;
532
+ if (typeof status === 'boolean') {
533
+ resolve(!status);
534
+ }
535
+ };
536
+ try {
537
+ (_d = (_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b['IS_PN_PERMISSION_ENABLED']) === null || _c === void 0 ? void 0 : _c.postMessage) === null || _d === void 0 ? void 0 : _d.call(_c, '');
538
+ }
539
+ catch (error) {
540
+ resolve(false);
541
+ }
542
+ })];
543
+ }
544
+ return [2, Promise.resolve(false)];
545
+ });
546
+ }); };
547
+ var handlePushPrimerCTA = function (type) {
548
+ var _a, _b, _c, _d, _e, _f, _g, _h;
549
+ if (isAndroidApp() &&
550
+ typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.handlePNPermission) === 'function') {
551
+ (_b = window.MobileApp) === null || _b === void 0 ? void 0 : _b.handlePNPermission(JSON.stringify({ type: type }));
552
+ }
553
+ else if (isIOSApp() &&
554
+ ((_d = (_c = window === null || window === void 0 ? void 0 : window.webkit) === null || _c === void 0 ? void 0 : _c.messageHandlers) === null || _d === void 0 ? void 0 : _d.HANDLE_PN_PERMISSION)) {
555
+ (_h = (_g = (_f = (_e = window.webkit) === null || _e === void 0 ? void 0 : _e.messageHandlers) === null || _f === void 0 ? void 0 : _f.HANDLE_PN_PERMISSION) === null || _g === void 0 ? void 0 : _g.postMessage) === null || _h === void 0 ? void 0 : _h.call(_g, JSON.stringify({ type: type }));
556
+ }
557
+ return;
558
+ };
559
+
560
+ var getProfileDetails = function () { return __awaiter(void 0, void 0, void 0, function () {
561
+ var response, error_1;
562
+ return __generator(this, function (_a) {
563
+ switch (_a.label) {
564
+ case 0:
565
+ _a.trys.push([0, 2, , 3]);
566
+ return [4, createGetRequest('GET_PROFILE_DETAILS', {
567
+ caller: getApiDomain(),
568
+ 'app-agent': getAppAgent(),
569
+ }, {})];
570
+ case 1:
571
+ response = _a.sent();
572
+ return [2, response === null || response === void 0 ? void 0 : response.data];
573
+ case 2:
574
+ error_1 = _a.sent();
575
+ console.error('Failed to fetch user details. Error: ', error_1);
576
+ return [2, Promise.resolve(null)];
577
+ case 3: return [2];
578
+ }
579
+ });
580
+ }); };
581
+ var sendLoginOtp = function (mobile, personalizationHeaders) { return __awaiter(void 0, void 0, void 0, function () {
582
+ var response;
583
+ return __generator(this, function (_a) {
584
+ switch (_a.label) {
585
+ case 0: return [4, createPostOrPutRequest('SEND_OTP', RequestMethods.POST, {
586
+ value: mobile,
587
+ type: 'MOBILE',
588
+ action: 'SIGNIN',
589
+ countryCode: MOBILE_CONSTANTS.COUNTRY_CODE,
590
+ }, {
591
+ 'ab-otp': 'b',
592
+ dvid_data: personalizationHeaders,
593
+ })];
594
+ case 1:
595
+ response = _a.sent();
596
+ return [2, response === null || response === void 0 ? void 0 : response.data];
597
+ }
598
+ });
599
+ }); };
600
+ var validateOtp = function (mobile, otp) { return __awaiter(void 0, void 0, void 0, function () {
601
+ var response, data;
602
+ return __generator(this, function (_a) {
603
+ switch (_a.label) {
604
+ case 0: return [4, createPostOrPutRequest('VALIDATE_OTP', RequestMethods.POST, {
605
+ otp: otp,
606
+ value: mobile,
607
+ type: 'MOBILE',
608
+ action: 'SIGNIN',
609
+ countryCode: '+91',
610
+ }, { 'ab-otp': 'b' })];
611
+ case 1:
612
+ response = _a.sent();
613
+ data = response === null || response === void 0 ? void 0 : response.data;
614
+ return [2, __assign(__assign({}, response), { signup: (data === null || data === void 0 ? void 0 : data.action) === ValidateOTPAction.SIGNUP, action: data === null || data === void 0 ? void 0 : data.action, status: response === null || response === void 0 ? void 0 : response.status })];
615
+ }
616
+ });
617
+ }); };
618
+ var handleFKSSO = function (fallbackUri, skipProfileFlow) { return __awaiter(void 0, void 0, void 0, function () {
619
+ var currentPageUri, redirectionInfo;
620
+ return __generator(this, function (_a) {
621
+ switch (_a.label) {
622
+ case 0:
623
+ if (isIOSApp()) {
624
+ return [2, Promise.reject()];
625
+ }
626
+ currentPageUri = getCurrentPathName();
627
+ return [4, sendFKSSORedirectionInfo(fallbackUri, skipProfileFlow
628
+ ? currentPageUri
629
+ : NAVIGATION_ROUTES.PERSONAL_DETAILS + '?onboardingFlow=true', currentPageUri)];
630
+ case 1:
631
+ redirectionInfo = _a.sent();
632
+ if (isAndroidApp()) {
633
+ return [2, handleFKSSOAndroid(redirectionInfo)];
634
+ }
635
+ else {
636
+ return [2, handleFKSSOWeb(redirectionInfo)];
637
+ }
638
+ }
639
+ });
640
+ }); };
641
+ var isValidMobileNumber = function (text) {
642
+ return (text === null || text === void 0 ? void 0 : text.length) === MOBILE_CONSTANTS.LENGTH && /^\d{10}$/.test(text);
643
+ };
644
+ var updateNativeOnLogin = function () {
645
+ if (isIOSApp()) {
646
+ updateNativeIOSOnSignIn();
647
+ }
648
+ else if (isAndroidApp()) {
649
+ updateNativeAndroidOnSignIn();
650
+ }
651
+ };
652
+ var isFKSSOEnabled = function () {
653
+ return isPwa() || (!isIOSApp() && isJSVersionUpdated(5));
654
+ };
655
+ var sendFKSSORedirectionInfo = function (fallbackUri, signupPageUri, currentPageUri) { return __awaiter(void 0, void 0, void 0, function () {
656
+ var WEBSITE_BASE, response;
657
+ return __generator(this, function (_a) {
658
+ switch (_a.label) {
659
+ case 0:
660
+ WEBSITE_BASE = getApiDomain();
661
+ return [4, createPostOrPutRequest('FK_REDIRECTION_INFO', RequestMethods.POST, {
662
+ provider: 'flipkart',
663
+ fallbackUri: urlJoin(WEBSITE_BASE, fallbackUri || currentPageUri),
664
+ signupPageUri: urlJoin(WEBSITE_BASE, signupPageUri || 'personal-details'),
665
+ currentPageUri: urlJoin(WEBSITE_BASE, currentPageUri),
666
+ })];
667
+ case 1:
668
+ response = _a.sent();
669
+ return [2, response === null || response === void 0 ? void 0 : response.data];
670
+ }
671
+ });
672
+ }); };
673
+ var handleFKSSOWeb = function (redirectionInfo) {
674
+ var _a;
675
+ var params = (_a = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.params) !== null && _a !== void 0 ? _a : {};
676
+ var redirectUri = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.redirectUri;
677
+ if (redirectUri) {
678
+ redirectUri += '?';
679
+ for (var key in params) {
680
+ redirectUri += key + '=' + params[key] + '&';
681
+ }
682
+ return Promise.resolve(redirectUri);
683
+ }
684
+ return Promise.reject();
685
+ };
686
+ var handleFKSSOAndroid = function (redirectionInfo) {
687
+ var _a, _b;
688
+ var params = redirectionInfo === null || redirectionInfo === void 0 ? void 0 : redirectionInfo.params;
689
+ if (isEmpty(params) ||
690
+ typeof ((_a = window.MobileApp) === null || _a === void 0 ? void 0 : _a.onNavigationChange) !== 'function') {
691
+ return Promise.reject();
692
+ }
693
+ else {
694
+ var FK_REDIRECT_DL = urlJoin(getApiDomain(), 'dl/oauth2');
695
+ (_b = window.MobileApp) === null || _b === void 0 ? void 0 : _b.onNavigationChange(JSON.stringify({
696
+ type: 'FkSSO',
697
+ miscData: __assign(__assign({}, params), { redirectURI: FK_REDIRECT_DL }),
698
+ }));
699
+ return Promise.resolve();
700
+ }
701
+ };
702
+ function getUserAuthValues(customCookie) {
703
+ try {
704
+ var _a = decodeURIComponent(getCookie('userid', customCookie) || '').split('|'), email = _a[0], profileName = _a[1], gender = _a[2], photo = _a[3], userId = _a[4];
705
+ return {
706
+ email: email,
707
+ profileName: profileName,
708
+ gender: gender,
709
+ photo: photo,
710
+ userId: userId,
711
+ };
712
+ }
713
+ catch (error) {
714
+ return {};
715
+ }
716
+ }
717
+ var isUserSignedIn = function (customCookie) {
718
+ var userObject = getUserAuthValues(customCookie) || {};
719
+ var usermiscVal = decodeURIComponent(getCookie('usermisc', customCookie) || '').split('|');
720
+ var signedIn = usermiscVal.includes('SIGNED_IN') &&
721
+ userObject.userId &&
722
+ userObject.userId.length > 0
723
+ ? true
724
+ : false;
725
+ return signedIn;
726
+ };
727
+ var sendClevertapProfileDetails = function (profileDetails) {
728
+ var _a, _b, _c, _d, _e, _f;
729
+ try {
730
+ if (isServer() || !(window === null || window === void 0 ? void 0 : window.clevertap) || isEmpty(profileDetails)) {
731
+ return;
732
+ }
733
+ var Site = {
734
+ Identity: (_a = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.id) !== null && _a !== void 0 ? _a : '',
735
+ Gender: (_b = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.gender) !== null && _b !== void 0 ? _b : '',
736
+ Email: (_c = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.username) !== null && _c !== void 0 ? _c : '',
737
+ Phone: "".concat(profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.countryCode).concat(profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.mobile),
738
+ 'MSG-sms': true,
739
+ 'MSG-push': true,
740
+ 'MSG-email': false,
741
+ 'MSG-whatsapp': true,
742
+ };
743
+ if ((_d = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.travellerDetails) === null || _d === void 0 ? void 0 : _d.length) {
744
+ for (var i = 0; i < ((_e = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.travellerDetails) === null || _e === void 0 ? void 0 : _e.length); i++) {
745
+ var traveller = profileDetails === null || profileDetails === void 0 ? void 0 : profileDetails.travellerDetails[i];
746
+ if (traveller.isRegistered) {
747
+ var dateOfBirth = traveller.personalDetails.dateOfBirth;
748
+ Site.Name = "".concat(traveller.personalDetails.firstName, " ").concat(traveller.personalDetails.lastName);
749
+ if (!isNaN(dateOfBirth)) {
750
+ Site.DOB = new Date(dateOfBirth);
751
+ }
752
+ break;
753
+ }
754
+ }
755
+ }
756
+ (_f = window === null || window === void 0 ? void 0 : window.clevertap) === null || _f === void 0 ? void 0 : _f.onUserLogin.push({ Site: Site });
757
+ }
758
+ catch (error) {
759
+ console.log('Error pushing clevertap profile information. Error: ', error);
760
+ }
761
+ };
762
+ var handleProfileFetch = function (updateClevertap) {
763
+ if (updateClevertap === void 0) { updateClevertap = true; }
764
+ return __awaiter(void 0, void 0, void 0, function () {
765
+ var response;
766
+ return __generator(this, function (_a) {
767
+ switch (_a.label) {
768
+ case 0: return [4, getProfileDetails()];
769
+ case 1:
770
+ response = _a.sent();
771
+ if (response) {
772
+ if (updateClevertap) {
773
+ sendClevertapProfileDetails(response);
774
+ }
775
+ }
776
+ return [2];
777
+ }
778
+ });
779
+ });
780
+ };
781
+
782
+ var getUserInsights = function (userId) { return __awaiter(void 0, void 0, void 0, function () {
783
+ var response;
784
+ return __generator(this, function (_a) {
785
+ switch (_a.label) {
786
+ case 0:
787
+ _a.trys.push([0, 2, , 3]);
788
+ return [4, createGetRequest('USER_INSIGHTS', {}, {
789
+ pathParams: {
790
+ userId: userId,
791
+ },
792
+ })];
793
+ case 1:
794
+ response = _a.sent();
795
+ return [2, response === null || response === void 0 ? void 0 : response.data];
796
+ case 2:
797
+ _a.sent();
798
+ return [2, Promise.resolve(null)];
799
+ case 3: return [2];
800
+ }
801
+ });
802
+ }); };
803
+ var getUserInsightsData = function (userId) { return __awaiter(void 0, void 0, void 0, function () {
804
+ var _userId, stringifiedData, sessionData, userInsights;
805
+ var _a, _b, _c, _d;
806
+ return __generator(this, function (_f) {
807
+ switch (_f.label) {
808
+ case 0:
809
+ _f.trys.push([0, 2, , 3]);
810
+ _userId = userId !== null && userId !== void 0 ? userId : getUserAuthValues().userId;
811
+ if (!_userId) {
812
+ (_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.removeItem('martech_user_attributes');
813
+ return [2, null];
814
+ }
815
+ stringifiedData = (_b = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _b === void 0 ? void 0 : _b.getItem('martech_user_attributes');
816
+ sessionData = void 0;
817
+ if (typeof stringifiedData === 'string') {
818
+ sessionData = JSON.parse(stringifiedData);
819
+ }
820
+ if (_userId !== (sessionData === null || sessionData === void 0 ? void 0 : sessionData.accountId)) {
821
+ (_c = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _c === void 0 ? void 0 : _c.removeItem('martech_user_attributes');
822
+ }
823
+ return [4, getUserInsights(_userId)];
824
+ case 1:
825
+ userInsights = _f.sent();
826
+ if (isEmpty(userInsights === null || userInsights === void 0 ? void 0 : userInsights.data)) {
827
+ return [2, null];
828
+ }
829
+ (_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));
830
+ return [2, userInsights === null || userInsights === void 0 ? void 0 : userInsights.data];
831
+ case 2:
832
+ _f.sent();
833
+ return [2, null];
834
+ case 3: return [2];
835
+ }
836
+ });
837
+ }); };
838
+
839
+ var stringifyPayload = function (payload) {
840
+ var keys = Object.keys(payload);
841
+ keys.forEach(function (key) {
842
+ if (key === 'a_fare_price' ||
843
+ key === 'a_ct_discount' ||
844
+ key === 'supercoin_balance' ||
845
+ key === 'supercoin_earned' ||
846
+ key === 'supercoin_burnt' ||
847
+ key === 'wallet_balance_used' ||
848
+ key === 'convenience_fee')
849
+ payload[key] = Number(payload[key]);
850
+ else
851
+ payload[key] = '' + payload[key];
852
+ });
853
+ return payload;
854
+ };
855
+ var getCTStatsigExpForRaven = function () {
856
+ try {
857
+ if (isServer()) {
858
+ return '';
859
+ }
860
+ var cookie = getCookie('ct_statsig_experiments') || '{}';
861
+ var parsedCookie_1 = cookie
862
+ ? JSON.parse(decodeURIComponent(cookie))
863
+ : {};
864
+ return Object.keys(parsedCookie_1)
865
+ .map(function (key) {
866
+ if (key && parsedCookie_1[key]) {
867
+ return "".concat(key, ":").concat(parsedCookie_1[key]);
868
+ }
869
+ return '';
870
+ })
871
+ .filter(function (value) { return !!value; })
872
+ .join('|');
873
+ }
874
+ catch (_e) {
875
+ return '';
876
+ }
877
+ };
878
+ var ravenSDKTrigger = function (eventName, ravenPayload) {
879
+ var _a;
880
+ if (window && window['ravenWebManager']) {
881
+ var _b = getRavenEventProps(), pageName = _b.pageName, utmSource = _b.utmSource;
882
+ var commonPayload = {
883
+ page_name: pageName,
884
+ u_utm_source: utmSource,
885
+ domain: window.location.host,
886
+ u_ab_key: getCTStatsigExpForRaven(),
887
+ platform: (_a = getDevicePlatform()) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
888
+ login_status: isUserSignedIn() ? 'yes' : 'no',
889
+ };
890
+ var newRavenPayload = stringifyPayload(ravenPayload);
891
+ var RavenWebManager = window['ravenWebManager'];
892
+ RavenWebManager === null || RavenWebManager === void 0 ? void 0 : RavenWebManager.triggerRaven(eventName, __assign(__assign({}, commonPayload), newRavenPayload));
893
+ }
894
+ };
895
+ var isAirHomePage = function () {
896
+ if (window && typeof window !== 'undefined') {
897
+ var pathname = getNestedValue(window, ['location', 'pathname']);
898
+ if (pathname === '/' || pathname === '/flights') {
899
+ return true;
900
+ }
901
+ }
902
+ return false;
903
+ };
904
+ var getRavenEventProps = function () {
905
+ var _a, _b;
906
+ if (window && typeof window !== 'undefined') {
907
+ var pathUrl = window.location.pathname;
908
+ var redirectionPath = (_a = getQueryParam('service')) !== null && _a !== void 0 ? _a : '';
909
+ var utmSource = (_b = getQueryParam('utm_source')) !== null && _b !== void 0 ? _b : 'organic';
910
+ var loginForm = isAirHomePage() ? 'skippable_login' : 'account_login';
911
+ var vertical = 'air';
912
+ var pageName = pathUrl.includes('flights/itinerary') ||
913
+ redirectionPath.includes('flights/itinerary')
914
+ ? 'a_itinerary'
915
+ : 'a_home';
916
+ if (redirectionPath.includes('my-account')) {
917
+ vertical = 'uar';
918
+ pageName = 'account';
919
+ }
920
+ if (redirectionPath.includes('hotels')) {
921
+ vertical = 'hotel';
922
+ pageName = redirectionPath.includes('hotels/itinerary')
923
+ ? 'h_itinerary'
924
+ : 'h_home';
925
+ }
926
+ if (redirectionPath.includes('bus')) {
927
+ vertical = 'bus';
928
+ pageName = redirectionPath.includes('bus/itinerary')
929
+ ? 'b_itinerary'
930
+ : 'b_home';
931
+ }
932
+ return { loginForm: loginForm, vertical: vertical, pageName: pageName, utmSource: utmSource };
933
+ }
934
+ return {};
935
+ };
936
+ var sendEventWithUserInsights = function (eventName, ravenPayload, userId) { return __awaiter(void 0, void 0, void 0, function () {
937
+ var userInsights, updatedPayload, loyaltyData, martechAttributes;
938
+ var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
939
+ return __generator(this, function (_t) {
940
+ switch (_t.label) {
941
+ case 0: return [4, getUserInsightsData(userId)];
942
+ case 1:
943
+ userInsights = _t.sent();
944
+ updatedPayload = __assign(__assign({}, ravenPayload), { fk_loyalty_status: 'na', fk_loyalty_end_dt: 'na', ct_last_booking_dt: 'na', ct_lifetime_booking: 'na', fk_loyalty_start_dt: 'na', ct_first_booking_dt: 'na', myntra_loyalty_status: 'na', ct_postmerger_booking: 'na', ct_last_1year_booking: 'na', myntra_loyalty_end_dt: 'na', ct_2nd_last_booking_dt: 'na', myntra_loyalty_start_dt: 'na' });
945
+ if (!isEmpty(userInsights)) {
946
+ loyaltyData = ((_a = userInsights === null || userInsights === void 0 ? void 0 : userInsights.loyaltyStatus) !== null && _a !== void 0 ? _a : []).reduce(function (prev, curr) {
947
+ return __assign(__assign({}, prev), curr);
948
+ }, {});
949
+ martechAttributes = {
950
+ 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(),
951
+ ct_postmerger_booking: ((_f = (_d = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _d === void 0 ? void 0 : _d.postmergerBooking) !== null && _f !== void 0 ? _f : 'na').toString(),
952
+ ct_last_1year_booking: ((_h = (_g = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _g === void 0 ? void 0 : _g.lastOneYearBooking) !== null && _h !== void 0 ? _h : 'na').toString(),
953
+ ct_first_booking_dt: secondsToDateString((_j = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _j === void 0 ? void 0 : _j.firstbookingDate) || 'na',
954
+ ct_last_booking_dt: secondsToDateString((_k = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _k === void 0 ? void 0 : _k.lastbookingDate) || 'na',
955
+ ct_2nd_last_booking_dt: secondsToDateString((_l = userInsights === null || userInsights === void 0 ? void 0 : userInsights.bookingStatus) === null || _l === void 0 ? void 0 : _l.secondLastbookingDate) || 'na',
956
+ fk_loyalty_status: ((_m = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _m === void 0 ? void 0 : _m.program) || 'na',
957
+ myntra_loyalty_status: ((_o = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _o === void 0 ? void 0 : _o.program) || 'na',
958
+ fk_loyalty_end_dt: secondsToDateString((_p = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _p === void 0 ? void 0 : _p.loyaltyEndDate) || '',
959
+ fk_loyalty_start_dt: secondsToDateString((_q = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.fk) === null || _q === void 0 ? void 0 : _q.loyaltyStartDate) || 'na',
960
+ myntra_loyalty_start_dt: secondsToDateString((_r = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _r === void 0 ? void 0 : _r.loyaltyStartDate) ||
961
+ 'na',
962
+ myntra_loyalty_end_dt: secondsToDateString((_s = loyaltyData === null || loyaltyData === void 0 ? void 0 : loyaltyData.myntra) === null || _s === void 0 ? void 0 : _s.loyaltyEndDate) ||
963
+ 'na',
964
+ };
965
+ updatedPayload = __assign(__assign({}, updatedPayload), martechAttributes);
966
+ setMartechUserProperties(martechAttributes);
967
+ }
968
+ ravenSDKTrigger(eventName, updatedPayload);
969
+ return [2];
970
+ }
971
+ });
972
+ }); };
973
+ var setMartechUserProperties = function (userProperties) {
974
+ var _a, _b, _c, _d, _f, _g, _h, _j, _k;
975
+ if (isEmpty(userProperties) ||
976
+ ((_a = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem('martech_user_props_sent'))) {
977
+ return;
978
+ }
979
+ 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)) {
980
+ (_d = window.webkit.messageHandlers.SEND_ATTRIBUTES) === null || _d === void 0 ? void 0 : _d.postMessage({
981
+ type: 'GA',
982
+ params: userProperties,
983
+ });
984
+ (_f = window.webkit.messageHandlers.SEND_ATTRIBUTES) === null || _f === void 0 ? void 0 : _f.postMessage({
985
+ type: 'Clevertap',
986
+ params: userProperties,
987
+ });
988
+ (_g = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _g === void 0 ? void 0 : _g.setItem('martech_user_props_sent', 'true');
989
+ }
990
+ else if (isAndroidApp() && ((_h = window === null || window === void 0 ? void 0 : window.MobileApp) === null || _h === void 0 ? void 0 : _h.sendAttributes)) {
991
+ window.MobileApp.sendAttributes('GA', JSON.stringify(userProperties));
992
+ window.MobileApp.sendAttributes('Clevertap', JSON.stringify(userProperties));
993
+ (_j = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _j === void 0 ? void 0 : _j.setItem('martech_user_props_sent', 'true');
994
+ }
995
+ else if (isPwa() && window.clevertap) {
996
+ window.clevertap.profile.push({
997
+ Site: userProperties,
998
+ });
999
+ (_k = window === null || window === void 0 ? void 0 : window.sessionStorage) === null || _k === void 0 ? void 0 : _k.setItem('martech_user_props_sent', 'true');
1000
+ }
1001
+ };
1002
+ var batchRavenEvent = function (eventName, ravenPayload) {
1003
+ if (typeof window !== 'undefined' &&
1004
+ typeof window.requestIdleCallback === 'function') {
1005
+ requestIdleCallback(function () {
1006
+ ravenSDKTrigger(eventName, ravenPayload);
1007
+ });
1008
+ }
1009
+ else {
1010
+ setTimeout(function () {
1011
+ ravenSDKTrigger(eventName, ravenPayload);
1012
+ }, 0);
1013
+ }
1014
+ };
1015
+
1016
+ var getHotelCrossSellRecos = function (vertical, fallbackPageLandingURL, cutoff, couponCallOutPrefix, couponCallOutSuffix, offerCallOut, additionalHeaders, additionalParams) {
1017
+ if (cutoff === void 0) { cutoff = 450; }
1018
+ if (couponCallOutPrefix === void 0) { couponCallOutPrefix = 'Discounts'; }
1019
+ if (couponCallOutSuffix === void 0) { couponCallOutSuffix = 'on hotels'; }
1020
+ if (offerCallOut === void 0) { offerCallOut = 'CTBEST - Exclusive coupon applied for you!'; }
1021
+ if (additionalHeaders === void 0) { additionalHeaders = {}; }
1022
+ if (additionalParams === void 0) { additionalParams = {}; }
1023
+ return __awaiter(void 0, void 0, void 0, function () {
1024
+ var userId, fallbackData, timeoutPromise, fetchRecommendationsPromise, result;
1025
+ var _a, _b;
1026
+ return __generator(this, function (_c) {
1027
+ switch (_c.label) {
1028
+ case 0:
1029
+ userId = (_b = (_a = getUserAuthValues()) === null || _a === void 0 ? void 0 : _a.userId) !== null && _b !== void 0 ? _b : '';
1030
+ fallbackData = {
1031
+ couponCode: '',
1032
+ couponCallOut: '',
1033
+ couponCallOutPrefix: couponCallOutPrefix,
1034
+ couponCallOutSuffix: couponCallOutSuffix,
1035
+ offerCallOut: offerCallOut,
1036
+ pageLandingUrl: fallbackPageLandingURL,
1037
+ };
1038
+ _c.label = 1;
1039
+ case 1:
1040
+ _c.trys.push([1, 3, , 4]);
1041
+ timeoutPromise = new Promise(function (resolve) {
1042
+ setTimeout(function () {
1043
+ resolve(fallbackData);
1044
+ }, cutoff);
1045
+ });
1046
+ fetchRecommendationsPromise = createGetRequest('HOTEL_RECOMMENDATIONS', additionalHeaders, {
1047
+ queryParams: __assign({ userId: userId, vertical: vertical }, additionalParams),
1048
+ }, false, {
1049
+ userBuckets: { 'x-cross-sell': 'true' },
1050
+ }).then(function (res) { return res.data; });
1051
+ return [4, Promise.race([
1052
+ fetchRecommendationsPromise,
1053
+ timeoutPromise,
1054
+ ])];
1055
+ case 2:
1056
+ result = _c.sent();
1057
+ return [2, result];
1058
+ case 3:
1059
+ _c.sent();
1060
+ return [2, fallbackData];
1061
+ case 4: return [2];
1062
+ }
1063
+ });
1064
+ });
1065
+ };
1066
+
1067
+ export { MULTI_SPACE, autoReadOtp, batchRavenEvent, createAPIRequest, createGetRequest, createPostOrPutRequest, extractQueryParamsAsObj, formatCurrency, formatFullDateString, getApiDomain, getAppAgent, getAutoDetectedMobile, getCTStatsigExpForRaven, getCookie, getCurrentPathName, getCurrentUrl, getDeviceModel, getDevicePlatform, getDimensionFromImageUrl, getHeightFromImgUrl, getHotelCrossSellRecos, getJSVersion, getNestedValue, getNoOfDaysFromToday, getQueryParam, getRavenEventProps, getUserAuthValues, getWidthFromImgUrl, handleFKSSO, handleProfileFetch, handlePushPrimerCTA, isAirHomePage, isAndroidApp, isEmpty, isFKSSOEnabled, isHTMLInputElement, isIOSApp, isJSVersionUpdated, isNumeric, isPwa, isServer, isUserSignedIn, isValidMobileNumber, path, ravenSDKTrigger, secondsToDateString, sendEventWithUserInsights, sendLoginOtp, setCookie, setMartechUserProperties, shouldShowPushPrimer, showMobileNumberHint, stringifyPayload, triggerOTPListener, updateNativeAndroidOnSignIn, updateNativeIOSOnSignIn, updateNativeOnLogin, urlJoin, validateOtp };
2
1068
  //# sourceMappingURL=ct-platform-utils.esm.js.map