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