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