@cleartrip/ct-platform-utils 3.15.0 → 3.15.1-beta.1

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