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