@tef-novum/webview-bridge
Advanced tools
Comparing version 3.10.1 to 3.11.0
# CHANGELOG | ||
## v.3.11.0 - 2022-06-29 | ||
- Message ids are now unique across different webviews | ||
## v.3.10.1 - 2022-06-22 | ||
@@ -4,0 +8,0 @@ |
@@ -0,1 +1,9 @@ | ||
/** | ||
* Message ID generator. Ids should be unique. | ||
* | ||
* the "web" prefix indicates that the message was originated from the web side. | ||
* | ||
* Using a timestamp as webviewId (assuming two webviews are not opened in the same millisecond), | ||
* but if that ever happens, the last part is a random number to avoid collisions. | ||
*/ | ||
export declare const getId: () => string; |
define(['exports'], (function (exports) { 'use strict'; | ||
var id = 1; | ||
var getId = function () { return "webapp-".concat(id++); }; | ||
var messageId = 1; | ||
var webviewId = "".concat(Date.now(), "-").concat(String(Math.random()).slice(-8)); | ||
/** | ||
* Message ID generator. Ids should be unique. | ||
* | ||
* the "web" prefix indicates that the message was originated from the web side. | ||
* | ||
* Using a timestamp as webviewId (assuming two webviews are not opened in the same millisecond), | ||
* but if that ever happens, the last part is a random number to avoid collisions. | ||
*/ | ||
var getId = function () { return "web-".concat(messageId++, "-").concat(webviewId); }; | ||
@@ -6,0 +15,0 @@ var BRIDGE = '__tuenti_webview_bridge'; |
@@ -5,4 +5,13 @@ 'use strict'; | ||
var id = 1; | ||
var getId = function () { return "webapp-".concat(id++); }; | ||
var messageId = 1; | ||
var webviewId = "".concat(Date.now(), "-").concat(String(Math.random()).slice(-8)); | ||
/** | ||
* Message ID generator. Ids should be unique. | ||
* | ||
* the "web" prefix indicates that the message was originated from the web side. | ||
* | ||
* Using a timestamp as webviewId (assuming two webviews are not opened in the same millisecond), | ||
* but if that ever happens, the last part is a random number to avoid collisions. | ||
*/ | ||
var getId = function () { return "web-".concat(messageId++, "-").concat(webviewId); }; | ||
@@ -9,0 +18,0 @@ var BRIDGE = '__tuenti_webview_bridge'; |
var webviewBridge = (function (exports) { | ||
'use strict'; | ||
var id = 1; | ||
var getId = function () { return "webapp-".concat(id++); }; | ||
var messageId = 1; | ||
var webviewId = "".concat(Date.now(), "-").concat(String(Math.random()).slice(-8)); | ||
/** | ||
* Message ID generator. Ids should be unique. | ||
* | ||
* the "web" prefix indicates that the message was originated from the web side. | ||
* | ||
* Using a timestamp as webviewId (assuming two webviews are not opened in the same millisecond), | ||
* but if that ever happens, the last part is a random number to avoid collisions. | ||
*/ | ||
var getId = function () { return "web-".concat(messageId++, "-").concat(webviewId); }; | ||
@@ -7,0 +16,0 @@ var BRIDGE = '__tuenti_webview_bridge'; |
@@ -1,1 +0,1 @@ | ||
var webviewBridge=function(e){"use strict";var n=1,t=function(){return"webapp-".concat(n++)},o="__tuenti_webview_bridge",r=function(){return!("undefined"==typeof window||!window.tuentiWebView||!window.tuentiWebView.postMessage)},i=function(){return!!("undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.tuentiWebView&&window.webkit.messageHandlers.tuentiWebView.postMessage)},a=function(){return"undefined"==typeof window?null:r()?function(e){window.tuentiWebView.postMessage(e)}:i()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null},u=[],s=function(e){u.push(e)},c=function(e){u=u.filter(function(n){return n!==e})},l=function(){var e;return"undefined"!=typeof window&&(!!function(){try{return window.self!==window.top}catch(e){return!0}}()&&!(null===(e=null===window||void 0===window?void 0:window.frameElement)||void 0===e?void 0:e.hasAttribute("data-enable-webview-bridge")))},d=void 0,f=function(){return!l()&&(r()||i())},p=function(e,n){var o=e.type,r=e.id,i=void 0===r?t():r,u=e.payload,l=a(),f=JSON.stringify({type:o,id:i,payload:u});return null===d||void 0===d||d("[WebView Bridge] SEND:",f),l?(setTimeout(function(){l(f)}),new Promise(function(e,t){var r=!1,a=function(n){n.id!==i||r||(n.type===o?e(n.payload):"ERROR"===n.type?t(n.payload):t({code:500,reason:"bad type: ".concat(n.type,". Expecting ").concat(o)}),c(a))};s(a),n&&setTimeout(function(){r=!0,c(a),t({code:408,reason:"request timeout"})},n)})):Promise.reject({code:500,reason:"WebView postMessage not available"})};"undefined"!=typeof window&&(window[o]=window[o]||{postMessage:function(e){var n;null===d||void 0===d||d("[WebView Bridge] RCVD:",e);try{n=JSON.parse(e)}catch(n){throw Error("Problem parsing webview message: ".concat(e))}u.forEach(function(e){return e(n)})}});var y=function(e,n){var t=function(t){t.type===e&&Promise.resolve(n(t.payload)).then(function(e){var n=a();n&&n(JSON.stringify({type:t.type,id:t.id,payload:e}))})};return s(t),function(){c(t)}},m=function(e){var n=e.title,t=e.expandedTitle,o=e.showBackButton,r=e.showReloadButton,i=e.showProfileButton,a=e.backgroundColor;return f()?p({type:"NAVIGATION_BAR",payload:{title:n,expandedTitle:t,showBackButton:o,showReloadButton:r,showProfileButton:i,backgroundColor:a}}):(void 0!==n&&"undefined"!=typeof document&&(document.title=n),Promise.resolve())},v=null,w=function(e){return"true"===v.result[e]},g=function(e){return Math.floor(e/1e3)},b=function(){return(b=Object.assign||function(e){for(var n,t=1,o=arguments.length;t<o;t++)for(var r in n=arguments[t])Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r]);return e}).apply(this,arguments)};function E(e,n){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)n.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(t[o[r]]=e[o[r]])}return t}var T=function(e){var n=e.onAndroid,t=e.onIos,o=e.onWeb;return"undefined"==typeof window?Promise.resolve():window.AnalyticsWebInterface?n(window.AnalyticsWebInterface):window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.firebase?t(window.webkit.messageHandlers.firebase):window.gtag?o(window.gtag):Promise.resolve()},h=function(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")},A=function(e){return h(e).toLocaleLowerCase().replace(/[^a-z0-9\s\-]/g,"").replace(/\s+/g," ").trim().replace(/\s/g,"_")},P=function(e){return Object.entries(e).forEach(function(n){var t=function(e,n){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var o,r,i=t.call(e),a=[];try{for(;(void 0===n||n-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(t=i.return)&&t.call(i)}finally{if(r)throw r.error}}return a}(n,2),o=t[0],r=t[1];"string"==typeof r&&(e[o]=A(r))}),e},_="";return e.CD_EVENT_VALUE=8,e.CD_NOVUM_UID=7,e.CD_WEBAPP_INSTALLED=4,e.attachToEmail=function(e){var n=e.url,t=e.subject,o=e.fileName,r=e.recipient,i=e.body;return p({type:"ATTACH_TO_EMAIL",payload:{url:n,subject:t,fileName:o,recipient:r,body:i}})},e.checkPermissionStatus=function(e,n){return p({type:"OS_PERMISSION_STATUS",payload:{feature:e,params:n}}).then(function(e){return e.granted})},e.createCalendarEvent=function(e){var n=e.beginTime,t=e.endTime,o=e.title;return p({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:g(n),endTime:g(t),title:o}})},e.dismiss=function(e){return p({type:"DISMISS",payload:{onCompletionUrl:e}})},e.fetch=function(e){var n=e.url,t=e.method,o=e.headers,r=e.body;return f()?p({type:"FETCH",payload:{url:n,method:t,headers:o,body:r}}).catch(function(){return{status:500,headers:{},body:"Bridge call failed"}}):Promise.resolve({status:500,headers:{},body:"Bridge not available"})},e.fetchContactsByPhone=function(e){return p({type:"FETCH_CONTACTS_DATA",payload:{phoneNumbers:e}})},e.getAppMetadata=function(e){return p({type:"GET_APP_METADATA",payload:{appToken:e}})},e.getCustomerHash=function(){return p({type:"GET_CUSTOMER_HASH"})},e.getDiskSpaceInfo=function(){return p({type:"GET_DISK_SPACE_INFO"})},e.getEsimInfo=function(){return p({type:"GET_ESIM_INFO"}).catch(function(){return{supportsEsim:!1}})},e.getTopazToken=function(e){return void 0===e&&(e={}),p({type:"GET_TOPAZ_TOKEN",payload:{}},e.timeout)},e.highlightNavigationTab=function(e){var n=e.tab,t=e.highlight,o=e.count;return p({type:"HIGHLIGHT_TAB",payload:{tab:n,highlight:t,count:o}})},e.internalNavigation=function(e){return p({type:"INTERNAL_NAVIGATION",payload:{feature:e}})},e.isABTestingAvailable=function(e){if(v)return Promise.resolve(w(e));var n=new Promise(function(e){setTimeout(function(){e(!1)},500)}),t=p({type:"GET_REMOTE_CONFIG"}).then(function(n){return v=n,w(e)});return Promise.race([n,t])},e.isWebViewBridgeAvailable=f,e.logEcommerceEvent=function(e,n){return n=b(b({},n),{screenName:n.screenName||_}),T({onAndroid:function(t){return t.logEvent&&t.logEvent(e,JSON.stringify(n)),Promise.resolve()},onIos:function(t){return t.postMessage({command:"logEvent",name:e,parameters:n}),Promise.resolve()},onWeb:function(){return Promise.resolve()}})},e.logEvent=function(e){var n,t,o,r,i,a,u=e.name,s=E(e,["name"]);if(u)s=P(s),u=A(u);else{if(!e.category||!e.action)return console.warn('LegacyAnalyticsEvent should have "category" and "action"',{category:e.category,action:e.action}),Promise.resolve();t=(n=e).category,o=n.action,r=n.label,i=n.value,a=E(n,["category","action","label","value"]),r||(r="null_label"),i||(i=0),s=b({eventCategory:t,eventAction:o,eventLabel:h(r),eventValue:i},a),u=e.category}return s=b(b({},s),{screenName:s.screenName||_}),T({onAndroid:function(e){return e.logEvent&&e.logEvent(u,JSON.stringify(s)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:u,parameters:s}),Promise.resolve()},onWeb:function(e){return new Promise(function(n){e("event",u,b(b({},s),{event_callback:n}))})}})},e.logTiming=function(e){var n=e.category,t=void 0===n?"performance_timer":n,o=e.variable,r=e.value,i=e.label;if(!t||!o||!r)return console.warn('Analytics timing should have "category", "variable" and "value"',{category:t,variable:o,value:r}),Promise.resolve();var a={timingCategory:t,timingVar:o,timingValue:r=Math.round(r),timingLabel:i},u=t;return T({onAndroid:function(e){return e.logEvent&&e.logEvent(u,JSON.stringify(a)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:u,parameters:a}),Promise.resolve()},onWeb:function(){return new Promise(function(e){gtag("event",u,b(b({},a),{event_callback:e}))})}})},e.logout=function(){return p({type:"LOG_OUT"})},e.nativeAlert=function(e){var n=e.message,t=e.title,o=e.buttonText;return f()?p({type:"ALERT",payload:{title:t,message:n,buttonText:o}}):("undefined"!=typeof window&&window.alert(n),Promise.resolve())},e.nativeConfirm=function(e){var n=e.message,t=e.title,o=e.acceptText,r=e.cancelText;return f()?p({type:"CONFIRM",payload:{message:n,title:t,acceptText:o,cancelText:r}}).then(function(e){return e.result}):Promise.resolve("undefined"!=typeof window&&window.confirm(n))},e.nativeMessage=function(e){var n=e.message,t=e.duration,o=e.buttonText,r=e.type;return f()?p({type:"MESSAGE",payload:{message:n,duration:t,buttonText:o,type:r}}):("undefined"!=typeof window&&window.alert(n),Promise.resolve())},e.notifyBridgeReady=function(){return p({type:"BRIDGE_READY"})},e.notifyPageLoaded=function(){return p({type:"PAGE_LOADED"})},e.onNativeEvent=function(e){return y("NATIVE_EVENT",function(n){return{action:e({event:n.event}).action||"default"}})},e.onSessionRenewed=function(e){return y("SESSION_RENEWED",function(n){var t=n.accessToken;return e(t)})},e.renewSession=function(e,n){return void 0===n&&(n={}),p({type:"RENEW_SESSION",payload:{accessToken:e||null}},n.timeout).then(function(e){return e.accessToken})},e.reportStatus=function(e){var n=e.feature,t=e.status,o=e.reason;return p({type:"STATUS_REPORT",payload:{feature:n,status:t,reason:o}})},e.requestContact=function(e){var n=(void 0===e?{}:e).filter;return p({type:"GET_CONTACT_DATA",payload:{filter:void 0===n?"phone":n}})},e.requestDeviceImei=function(){return p({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.requestSimIcc=function(){return p({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return p({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},e.requestVibration=function(e){return p({type:"VIBRATION",payload:{type:e}})},e.setActionBehavior=function(e){return p({type:"SET_ACTION_BEHAVIOR",payload:{actions:e}}).catch(function(){})},e.setCustomerHash=function(e){return p({type:"SET_CUSTOMER_HASH",payload:{hash:e}})},e.setLogger=function(e){d=e},e.setScreenName=function(e,n){return e?T({onAndroid:function(n){return n.setScreenName&&n.setScreenName(e),Promise.resolve()},onIos:function(n){return n.postMessage({command:"setScreenName",name:e}),Promise.resolve()},onWeb:function(t){return new Promise(function(o){t("event","screen_view",b(b({screenName:e,previousScreenName:_},P(null!==n&&void 0!==n?n:{})),{event_callback:o})),_=e})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setTrackingProperty=function(e,n,t){return p({type:"SET_TRACKING_PROPERTY",payload:{system:e,name:n,value:t}}).catch(function(){})},e.setUserProperty=function(e,n){return e&&n?(n=String(n),T({onAndroid:function(t){return t.setUserProperty&&t.setUserProperty(e,n),Promise.resolve()},onIos:function(t){return t.postMessage({command:"setUserProperty",name:e,value:n}),Promise.resolve()},onWeb:function(t){var o;return t("set","user_properties",((o={})[e]=A(n),o)),Promise.resolve()}})):(console.warn("Trying to set analytics user property without name or value",e,n),Promise.resolve())},e.setWebViewTitle=function(e){return f()?m({title:e}):("undefined"!=typeof document&&(document.title=e),Promise.resolve())},e.share=function(e){return p({type:"SHARE",payload:e})},e.updateNavigationBar=m,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
var webviewBridge=function(e){"use strict";var n=1,t="".concat(Date.now(),"-").concat(String(Math.random()).slice(-8)),o="__tuenti_webview_bridge",r=function(){return!("undefined"==typeof window||!window.tuentiWebView||!window.tuentiWebView.postMessage)},i=function(){return!!("undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.tuentiWebView&&window.webkit.messageHandlers.tuentiWebView.postMessage)},a=function(){return"undefined"==typeof window?null:r()?function(e){window.tuentiWebView.postMessage(e)}:i()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null},u=[],s=function(e){u.push(e)},c=function(e){u=u.filter(function(n){return n!==e})},l=function(){var e;return"undefined"!=typeof window&&(!!function(){try{return window.self!==window.top}catch(e){return!0}}()&&!(null===(e=null===window||void 0===window?void 0:window.frameElement)||void 0===e?void 0:e.hasAttribute("data-enable-webview-bridge")))},d=void 0,f=function(){return!l()&&(r()||i())},p=function(e,o){var r=e.type,i=e.id,u=void 0===i?"web-".concat(n++,"-").concat(t):i,l=e.payload,f=a(),p=JSON.stringify({type:r,id:u,payload:l});return null===d||void 0===d||d("[WebView Bridge] SEND:",p),f?(setTimeout(function(){f(p)}),new Promise(function(e,n){var t=!1,i=function(o){o.id!==u||t||(o.type===r?e(o.payload):"ERROR"===o.type?n(o.payload):n({code:500,reason:"bad type: ".concat(o.type,". Expecting ").concat(r)}),c(i))};s(i),o&&setTimeout(function(){t=!0,c(i),n({code:408,reason:"request timeout"})},o)})):Promise.reject({code:500,reason:"WebView postMessage not available"})};"undefined"!=typeof window&&(window[o]=window[o]||{postMessage:function(e){var n;null===d||void 0===d||d("[WebView Bridge] RCVD:",e);try{n=JSON.parse(e)}catch(n){throw Error("Problem parsing webview message: ".concat(e))}u.forEach(function(e){return e(n)})}});var y=function(e,n){var t=function(t){t.type===e&&Promise.resolve(n(t.payload)).then(function(e){var n=a();n&&n(JSON.stringify({type:t.type,id:t.id,payload:e}))})};return s(t),function(){c(t)}},m=function(e){var n=e.title,t=e.expandedTitle,o=e.showBackButton,r=e.showReloadButton,i=e.showProfileButton,a=e.backgroundColor;return f()?p({type:"NAVIGATION_BAR",payload:{title:n,expandedTitle:t,showBackButton:o,showReloadButton:r,showProfileButton:i,backgroundColor:a}}):(void 0!==n&&"undefined"!=typeof document&&(document.title=n),Promise.resolve())},v=null,w=function(e){return"true"===v.result[e]},g=function(e){return Math.floor(e/1e3)},b=function(){return(b=Object.assign||function(e){for(var n,t=1,o=arguments.length;t<o;t++)for(var r in n=arguments[t])Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r]);return e}).apply(this,arguments)};function E(e,n){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)n.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(t[o[r]]=e[o[r]])}return t}var T=function(e){var n=e.onAndroid,t=e.onIos,o=e.onWeb;return"undefined"==typeof window?Promise.resolve():window.AnalyticsWebInterface?n(window.AnalyticsWebInterface):window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.firebase?t(window.webkit.messageHandlers.firebase):window.gtag?o(window.gtag):Promise.resolve()},h=function(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")},A=function(e){return h(e).toLocaleLowerCase().replace(/[^a-z0-9\s\-]/g,"").replace(/\s+/g," ").trim().replace(/\s/g,"_")},P=function(e){return Object.entries(e).forEach(function(n){var t=function(e,n){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var o,r,i=t.call(e),a=[];try{for(;(void 0===n||n-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(t=i.return)&&t.call(i)}finally{if(r)throw r.error}}return a}(n,2),o=t[0],r=t[1];"string"==typeof r&&(e[o]=A(r))}),e},_="";return e.CD_EVENT_VALUE=8,e.CD_NOVUM_UID=7,e.CD_WEBAPP_INSTALLED=4,e.attachToEmail=function(e){var n=e.url,t=e.subject,o=e.fileName,r=e.recipient,i=e.body;return p({type:"ATTACH_TO_EMAIL",payload:{url:n,subject:t,fileName:o,recipient:r,body:i}})},e.checkPermissionStatus=function(e,n){return p({type:"OS_PERMISSION_STATUS",payload:{feature:e,params:n}}).then(function(e){return e.granted})},e.createCalendarEvent=function(e){var n=e.beginTime,t=e.endTime,o=e.title;return p({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:g(n),endTime:g(t),title:o}})},e.dismiss=function(e){return p({type:"DISMISS",payload:{onCompletionUrl:e}})},e.fetch=function(e){var n=e.url,t=e.method,o=e.headers,r=e.body;return f()?p({type:"FETCH",payload:{url:n,method:t,headers:o,body:r}}).catch(function(){return{status:500,headers:{},body:"Bridge call failed"}}):Promise.resolve({status:500,headers:{},body:"Bridge not available"})},e.fetchContactsByPhone=function(e){return p({type:"FETCH_CONTACTS_DATA",payload:{phoneNumbers:e}})},e.getAppMetadata=function(e){return p({type:"GET_APP_METADATA",payload:{appToken:e}})},e.getCustomerHash=function(){return p({type:"GET_CUSTOMER_HASH"})},e.getDiskSpaceInfo=function(){return p({type:"GET_DISK_SPACE_INFO"})},e.getEsimInfo=function(){return p({type:"GET_ESIM_INFO"}).catch(function(){return{supportsEsim:!1}})},e.getTopazToken=function(e){return void 0===e&&(e={}),p({type:"GET_TOPAZ_TOKEN",payload:{}},e.timeout)},e.highlightNavigationTab=function(e){var n=e.tab,t=e.highlight,o=e.count;return p({type:"HIGHLIGHT_TAB",payload:{tab:n,highlight:t,count:o}})},e.internalNavigation=function(e){return p({type:"INTERNAL_NAVIGATION",payload:{feature:e}})},e.isABTestingAvailable=function(e){if(v)return Promise.resolve(w(e));var n=new Promise(function(e){setTimeout(function(){e(!1)},500)}),t=p({type:"GET_REMOTE_CONFIG"}).then(function(n){return v=n,w(e)});return Promise.race([n,t])},e.isWebViewBridgeAvailable=f,e.logEcommerceEvent=function(e,n){return n=b(b({},n),{screenName:n.screenName||_}),T({onAndroid:function(t){return t.logEvent&&t.logEvent(e,JSON.stringify(n)),Promise.resolve()},onIos:function(t){return t.postMessage({command:"logEvent",name:e,parameters:n}),Promise.resolve()},onWeb:function(){return Promise.resolve()}})},e.logEvent=function(e){var n,t,o,r,i,a,u=e.name,s=E(e,["name"]);if(u)s=P(s),u=A(u);else{if(!e.category||!e.action)return console.warn('LegacyAnalyticsEvent should have "category" and "action"',{category:e.category,action:e.action}),Promise.resolve();t=(n=e).category,o=n.action,r=n.label,i=n.value,a=E(n,["category","action","label","value"]),r||(r="null_label"),i||(i=0),s=b({eventCategory:t,eventAction:o,eventLabel:h(r),eventValue:i},a),u=e.category}return s=b(b({},s),{screenName:s.screenName||_}),T({onAndroid:function(e){return e.logEvent&&e.logEvent(u,JSON.stringify(s)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:u,parameters:s}),Promise.resolve()},onWeb:function(e){return new Promise(function(n){e("event",u,b(b({},s),{event_callback:n}))})}})},e.logTiming=function(e){var n=e.category,t=void 0===n?"performance_timer":n,o=e.variable,r=e.value,i=e.label;if(!t||!o||!r)return console.warn('Analytics timing should have "category", "variable" and "value"',{category:t,variable:o,value:r}),Promise.resolve();var a={timingCategory:t,timingVar:o,timingValue:r=Math.round(r),timingLabel:i},u=t;return T({onAndroid:function(e){return e.logEvent&&e.logEvent(u,JSON.stringify(a)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:u,parameters:a}),Promise.resolve()},onWeb:function(){return new Promise(function(e){gtag("event",u,b(b({},a),{event_callback:e}))})}})},e.logout=function(){return p({type:"LOG_OUT"})},e.nativeAlert=function(e){var n=e.message,t=e.title,o=e.buttonText;return f()?p({type:"ALERT",payload:{title:t,message:n,buttonText:o}}):("undefined"!=typeof window&&window.alert(n),Promise.resolve())},e.nativeConfirm=function(e){var n=e.message,t=e.title,o=e.acceptText,r=e.cancelText;return f()?p({type:"CONFIRM",payload:{message:n,title:t,acceptText:o,cancelText:r}}).then(function(e){return e.result}):Promise.resolve("undefined"!=typeof window&&window.confirm(n))},e.nativeMessage=function(e){var n=e.message,t=e.duration,o=e.buttonText,r=e.type;return f()?p({type:"MESSAGE",payload:{message:n,duration:t,buttonText:o,type:r}}):("undefined"!=typeof window&&window.alert(n),Promise.resolve())},e.notifyBridgeReady=function(){return p({type:"BRIDGE_READY"})},e.notifyPageLoaded=function(){return p({type:"PAGE_LOADED"})},e.onNativeEvent=function(e){return y("NATIVE_EVENT",function(n){return{action:e({event:n.event}).action||"default"}})},e.onSessionRenewed=function(e){return y("SESSION_RENEWED",function(n){var t=n.accessToken;return e(t)})},e.renewSession=function(e,n){return void 0===n&&(n={}),p({type:"RENEW_SESSION",payload:{accessToken:e||null}},n.timeout).then(function(e){return e.accessToken})},e.reportStatus=function(e){var n=e.feature,t=e.status,o=e.reason;return p({type:"STATUS_REPORT",payload:{feature:n,status:t,reason:o}})},e.requestContact=function(e){var n=(void 0===e?{}:e).filter;return p({type:"GET_CONTACT_DATA",payload:{filter:void 0===n?"phone":n}})},e.requestDeviceImei=function(){return p({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.requestSimIcc=function(){return p({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return p({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},e.requestVibration=function(e){return p({type:"VIBRATION",payload:{type:e}})},e.setActionBehavior=function(e){return p({type:"SET_ACTION_BEHAVIOR",payload:{actions:e}}).catch(function(){})},e.setCustomerHash=function(e){return p({type:"SET_CUSTOMER_HASH",payload:{hash:e}})},e.setLogger=function(e){d=e},e.setScreenName=function(e,n){return e?T({onAndroid:function(n){return n.setScreenName&&n.setScreenName(e),Promise.resolve()},onIos:function(n){return n.postMessage({command:"setScreenName",name:e}),Promise.resolve()},onWeb:function(t){return new Promise(function(o){t("event","screen_view",b(b({screenName:e,previousScreenName:_},P(null!==n&&void 0!==n?n:{})),{event_callback:o})),_=e})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setTrackingProperty=function(e,n,t){return p({type:"SET_TRACKING_PROPERTY",payload:{system:e,name:n,value:t}}).catch(function(){})},e.setUserProperty=function(e,n){return e&&n?(n=String(n),T({onAndroid:function(t){return t.setUserProperty&&t.setUserProperty(e,n),Promise.resolve()},onIos:function(t){return t.postMessage({command:"setUserProperty",name:e,value:n}),Promise.resolve()},onWeb:function(t){var o;return t("set","user_properties",((o={})[e]=A(n),o)),Promise.resolve()}})):(console.warn("Trying to set analytics user property without name or value",e,n),Promise.resolve())},e.setWebViewTitle=function(e){return f()?m({title:e}):("undefined"!=typeof document&&(document.title=e),Promise.resolve())},e.share=function(e){return p({type:"SHARE",payload:e})},e.updateNavigationBar=m,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); |
@@ -7,4 +7,13 @@ (function (global, factory) { | ||
var id = 1; | ||
var getId = function () { return "webapp-".concat(id++); }; | ||
var messageId = 1; | ||
var webviewId = "".concat(Date.now(), "-").concat(String(Math.random()).slice(-8)); | ||
/** | ||
* Message ID generator. Ids should be unique. | ||
* | ||
* the "web" prefix indicates that the message was originated from the web side. | ||
* | ||
* Using a timestamp as webviewId (assuming two webviews are not opened in the same millisecond), | ||
* but if that ever happens, the last part is a random number to avoid collisions. | ||
*/ | ||
var getId = function () { return "web-".concat(messageId++, "-").concat(webviewId); }; | ||
@@ -11,0 +20,0 @@ var BRIDGE = '__tuenti_webview_bridge'; |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).webviewBridge={})}(this,function(e){"use strict";var n=1,t=function(){return"webapp-".concat(n++)},o="__tuenti_webview_bridge",r=function(){return!("undefined"==typeof window||!window.tuentiWebView||!window.tuentiWebView.postMessage)},i=function(){return!!("undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.tuentiWebView&&window.webkit.messageHandlers.tuentiWebView.postMessage)},a=function(){return"undefined"==typeof window?null:r()?function(e){window.tuentiWebView.postMessage(e)}:i()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null},u=[],s=function(e){u.push(e)},c=function(e){u=u.filter(function(n){return n!==e})},l=function(){var e;return"undefined"!=typeof window&&(!!function(){try{return window.self!==window.top}catch(e){return!0}}()&&!(null===(e=null===window||void 0===window?void 0:window.frameElement)||void 0===e?void 0:e.hasAttribute("data-enable-webview-bridge")))},f=void 0,d=function(){return!l()&&(r()||i())},p=function(e,n){var o=e.type,r=e.id,i=void 0===r?t():r,u=e.payload,l=a(),d=JSON.stringify({type:o,id:i,payload:u});return null===f||void 0===f||f("[WebView Bridge] SEND:",d),l?(setTimeout(function(){l(d)}),new Promise(function(e,t){var r=!1,a=function(n){n.id!==i||r||(n.type===o?e(n.payload):"ERROR"===n.type?t(n.payload):t({code:500,reason:"bad type: ".concat(n.type,". Expecting ").concat(o)}),c(a))};s(a),n&&setTimeout(function(){r=!0,c(a),t({code:408,reason:"request timeout"})},n)})):Promise.reject({code:500,reason:"WebView postMessage not available"})};"undefined"!=typeof window&&(window[o]=window[o]||{postMessage:function(e){var n;null===f||void 0===f||f("[WebView Bridge] RCVD:",e);try{n=JSON.parse(e)}catch(n){throw Error("Problem parsing webview message: ".concat(e))}u.forEach(function(e){return e(n)})}});var y=function(e,n){var t=function(t){t.type===e&&Promise.resolve(n(t.payload)).then(function(e){var n=a();n&&n(JSON.stringify({type:t.type,id:t.id,payload:e}))})};return s(t),function(){c(t)}},m=function(e){var n=e.title,t=e.expandedTitle,o=e.showBackButton,r=e.showReloadButton,i=e.showProfileButton,a=e.backgroundColor;return d()?p({type:"NAVIGATION_BAR",payload:{title:n,expandedTitle:t,showBackButton:o,showReloadButton:r,showProfileButton:i,backgroundColor:a}}):(void 0!==n&&"undefined"!=typeof document&&(document.title=n),Promise.resolve())},v=null,w=function(e){return"true"===v.result[e]},g=function(e){return Math.floor(e/1e3)},b=function(){return(b=Object.assign||function(e){for(var n,t=1,o=arguments.length;t<o;t++)for(var r in n=arguments[t])Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r]);return e}).apply(this,arguments)};function T(e,n){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)n.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(t[o[r]]=e[o[r]])}return t}var E=function(e){var n=e.onAndroid,t=e.onIos,o=e.onWeb;return"undefined"==typeof window?Promise.resolve():window.AnalyticsWebInterface?n(window.AnalyticsWebInterface):window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.firebase?t(window.webkit.messageHandlers.firebase):window.gtag?o(window.gtag):Promise.resolve()},h=function(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")},A=function(e){return h(e).toLocaleLowerCase().replace(/[^a-z0-9\s\-]/g,"").replace(/\s+/g," ").trim().replace(/\s/g,"_")},P=function(e){return Object.entries(e).forEach(function(n){var t=function(e,n){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var o,r,i=t.call(e),a=[];try{for(;(void 0===n||n-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(t=i.return)&&t.call(i)}finally{if(r)throw r.error}}return a}(n,2),o=t[0],r=t[1];"string"==typeof r&&(e[o]=A(r))}),e},_="";e.CD_EVENT_VALUE=8,e.CD_NOVUM_UID=7,e.CD_WEBAPP_INSTALLED=4,e.attachToEmail=function(e){var n=e.url,t=e.subject,o=e.fileName,r=e.recipient,i=e.body;return p({type:"ATTACH_TO_EMAIL",payload:{url:n,subject:t,fileName:o,recipient:r,body:i}})},e.checkPermissionStatus=function(e,n){return p({type:"OS_PERMISSION_STATUS",payload:{feature:e,params:n}}).then(function(e){return e.granted})},e.createCalendarEvent=function(e){var n=e.beginTime,t=e.endTime,o=e.title;return p({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:g(n),endTime:g(t),title:o}})},e.dismiss=function(e){return p({type:"DISMISS",payload:{onCompletionUrl:e}})},e.fetch=function(e){var n=e.url,t=e.method,o=e.headers,r=e.body;return d()?p({type:"FETCH",payload:{url:n,method:t,headers:o,body:r}}).catch(function(){return{status:500,headers:{},body:"Bridge call failed"}}):Promise.resolve({status:500,headers:{},body:"Bridge not available"})},e.fetchContactsByPhone=function(e){return p({type:"FETCH_CONTACTS_DATA",payload:{phoneNumbers:e}})},e.getAppMetadata=function(e){return p({type:"GET_APP_METADATA",payload:{appToken:e}})},e.getCustomerHash=function(){return p({type:"GET_CUSTOMER_HASH"})},e.getDiskSpaceInfo=function(){return p({type:"GET_DISK_SPACE_INFO"})},e.getEsimInfo=function(){return p({type:"GET_ESIM_INFO"}).catch(function(){return{supportsEsim:!1}})},e.getTopazToken=function(e){return void 0===e&&(e={}),p({type:"GET_TOPAZ_TOKEN",payload:{}},e.timeout)},e.highlightNavigationTab=function(e){var n=e.tab,t=e.highlight,o=e.count;return p({type:"HIGHLIGHT_TAB",payload:{tab:n,highlight:t,count:o}})},e.internalNavigation=function(e){return p({type:"INTERNAL_NAVIGATION",payload:{feature:e}})},e.isABTestingAvailable=function(e){if(v)return Promise.resolve(w(e));var n=new Promise(function(e){setTimeout(function(){e(!1)},500)}),t=p({type:"GET_REMOTE_CONFIG"}).then(function(n){return v=n,w(e)});return Promise.race([n,t])},e.isWebViewBridgeAvailable=d,e.logEcommerceEvent=function(e,n){return n=b(b({},n),{screenName:n.screenName||_}),E({onAndroid:function(t){return t.logEvent&&t.logEvent(e,JSON.stringify(n)),Promise.resolve()},onIos:function(t){return t.postMessage({command:"logEvent",name:e,parameters:n}),Promise.resolve()},onWeb:function(){return Promise.resolve()}})},e.logEvent=function(e){var n,t,o,r,i,a,u=e.name,s=T(e,["name"]);if(u)s=P(s),u=A(u);else{if(!e.category||!e.action)return console.warn('LegacyAnalyticsEvent should have "category" and "action"',{category:e.category,action:e.action}),Promise.resolve();t=(n=e).category,o=n.action,r=n.label,i=n.value,a=T(n,["category","action","label","value"]),r||(r="null_label"),i||(i=0),s=b({eventCategory:t,eventAction:o,eventLabel:h(r),eventValue:i},a),u=e.category}return s=b(b({},s),{screenName:s.screenName||_}),E({onAndroid:function(e){return e.logEvent&&e.logEvent(u,JSON.stringify(s)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:u,parameters:s}),Promise.resolve()},onWeb:function(e){return new Promise(function(n){e("event",u,b(b({},s),{event_callback:n}))})}})},e.logTiming=function(e){var n=e.category,t=void 0===n?"performance_timer":n,o=e.variable,r=e.value,i=e.label;if(!t||!o||!r)return console.warn('Analytics timing should have "category", "variable" and "value"',{category:t,variable:o,value:r}),Promise.resolve();var a={timingCategory:t,timingVar:o,timingValue:r=Math.round(r),timingLabel:i},u=t;return E({onAndroid:function(e){return e.logEvent&&e.logEvent(u,JSON.stringify(a)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:u,parameters:a}),Promise.resolve()},onWeb:function(){return new Promise(function(e){gtag("event",u,b(b({},a),{event_callback:e}))})}})},e.logout=function(){return p({type:"LOG_OUT"})},e.nativeAlert=function(e){var n=e.message,t=e.title,o=e.buttonText;return d()?p({type:"ALERT",payload:{title:t,message:n,buttonText:o}}):("undefined"!=typeof window&&window.alert(n),Promise.resolve())},e.nativeConfirm=function(e){var n=e.message,t=e.title,o=e.acceptText,r=e.cancelText;return d()?p({type:"CONFIRM",payload:{message:n,title:t,acceptText:o,cancelText:r}}).then(function(e){return e.result}):Promise.resolve("undefined"!=typeof window&&window.confirm(n))},e.nativeMessage=function(e){var n=e.message,t=e.duration,o=e.buttonText,r=e.type;return d()?p({type:"MESSAGE",payload:{message:n,duration:t,buttonText:o,type:r}}):("undefined"!=typeof window&&window.alert(n),Promise.resolve())},e.notifyBridgeReady=function(){return p({type:"BRIDGE_READY"})},e.notifyPageLoaded=function(){return p({type:"PAGE_LOADED"})},e.onNativeEvent=function(e){return y("NATIVE_EVENT",function(n){return{action:e({event:n.event}).action||"default"}})},e.onSessionRenewed=function(e){return y("SESSION_RENEWED",function(n){var t=n.accessToken;return e(t)})},e.renewSession=function(e,n){return void 0===n&&(n={}),p({type:"RENEW_SESSION",payload:{accessToken:e||null}},n.timeout).then(function(e){return e.accessToken})},e.reportStatus=function(e){var n=e.feature,t=e.status,o=e.reason;return p({type:"STATUS_REPORT",payload:{feature:n,status:t,reason:o}})},e.requestContact=function(e){var n=(void 0===e?{}:e).filter;return p({type:"GET_CONTACT_DATA",payload:{filter:void 0===n?"phone":n}})},e.requestDeviceImei=function(){return p({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.requestSimIcc=function(){return p({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return p({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},e.requestVibration=function(e){return p({type:"VIBRATION",payload:{type:e}})},e.setActionBehavior=function(e){return p({type:"SET_ACTION_BEHAVIOR",payload:{actions:e}}).catch(function(){})},e.setCustomerHash=function(e){return p({type:"SET_CUSTOMER_HASH",payload:{hash:e}})},e.setLogger=function(e){f=e},e.setScreenName=function(e,n){return e?E({onAndroid:function(n){return n.setScreenName&&n.setScreenName(e),Promise.resolve()},onIos:function(n){return n.postMessage({command:"setScreenName",name:e}),Promise.resolve()},onWeb:function(t){return new Promise(function(o){t("event","screen_view",b(b({screenName:e,previousScreenName:_},P(null!==n&&void 0!==n?n:{})),{event_callback:o})),_=e})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setTrackingProperty=function(e,n,t){return p({type:"SET_TRACKING_PROPERTY",payload:{system:e,name:n,value:t}}).catch(function(){})},e.setUserProperty=function(e,n){return e&&n?(n=String(n),E({onAndroid:function(t){return t.setUserProperty&&t.setUserProperty(e,n),Promise.resolve()},onIos:function(t){return t.postMessage({command:"setUserProperty",name:e,value:n}),Promise.resolve()},onWeb:function(t){var o;return t("set","user_properties",((o={})[e]=A(n),o)),Promise.resolve()}})):(console.warn("Trying to set analytics user property without name or value",e,n),Promise.resolve())},e.setWebViewTitle=function(e){return d()?m({title:e}):("undefined"!=typeof document&&(document.title=e),Promise.resolve())},e.share=function(e){return p({type:"SHARE",payload:e})},e.updateNavigationBar=m,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).webviewBridge={})}(this,function(e){"use strict";var n=1,t="".concat(Date.now(),"-").concat(String(Math.random()).slice(-8)),o="__tuenti_webview_bridge",r=function(){return!("undefined"==typeof window||!window.tuentiWebView||!window.tuentiWebView.postMessage)},i=function(){return!!("undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.tuentiWebView&&window.webkit.messageHandlers.tuentiWebView.postMessage)},a=function(){return"undefined"==typeof window?null:r()?function(e){window.tuentiWebView.postMessage(e)}:i()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null},u=[],s=function(e){u.push(e)},c=function(e){u=u.filter(function(n){return n!==e})},l=function(){var e;return"undefined"!=typeof window&&(!!function(){try{return window.self!==window.top}catch(e){return!0}}()&&!(null===(e=null===window||void 0===window?void 0:window.frameElement)||void 0===e?void 0:e.hasAttribute("data-enable-webview-bridge")))},d=void 0,f=function(){return!l()&&(r()||i())},p=function(e,o){var r=e.type,i=e.id,u=void 0===i?"web-".concat(n++,"-").concat(t):i,l=e.payload,f=a(),p=JSON.stringify({type:r,id:u,payload:l});return null===d||void 0===d||d("[WebView Bridge] SEND:",p),f?(setTimeout(function(){f(p)}),new Promise(function(e,n){var t=!1,i=function(o){o.id!==u||t||(o.type===r?e(o.payload):"ERROR"===o.type?n(o.payload):n({code:500,reason:"bad type: ".concat(o.type,". Expecting ").concat(r)}),c(i))};s(i),o&&setTimeout(function(){t=!0,c(i),n({code:408,reason:"request timeout"})},o)})):Promise.reject({code:500,reason:"WebView postMessage not available"})};"undefined"!=typeof window&&(window[o]=window[o]||{postMessage:function(e){var n;null===d||void 0===d||d("[WebView Bridge] RCVD:",e);try{n=JSON.parse(e)}catch(n){throw Error("Problem parsing webview message: ".concat(e))}u.forEach(function(e){return e(n)})}});var y=function(e,n){var t=function(t){t.type===e&&Promise.resolve(n(t.payload)).then(function(e){var n=a();n&&n(JSON.stringify({type:t.type,id:t.id,payload:e}))})};return s(t),function(){c(t)}},m=function(e){var n=e.title,t=e.expandedTitle,o=e.showBackButton,r=e.showReloadButton,i=e.showProfileButton,a=e.backgroundColor;return f()?p({type:"NAVIGATION_BAR",payload:{title:n,expandedTitle:t,showBackButton:o,showReloadButton:r,showProfileButton:i,backgroundColor:a}}):(void 0!==n&&"undefined"!=typeof document&&(document.title=n),Promise.resolve())},v=null,w=function(e){return"true"===v.result[e]},g=function(e){return Math.floor(e/1e3)},b=function(){return(b=Object.assign||function(e){for(var n,t=1,o=arguments.length;t<o;t++)for(var r in n=arguments[t])Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r]);return e}).apply(this,arguments)};function T(e,n){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)n.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(t[o[r]]=e[o[r]])}return t}var E=function(e){var n=e.onAndroid,t=e.onIos,o=e.onWeb;return"undefined"==typeof window?Promise.resolve():window.AnalyticsWebInterface?n(window.AnalyticsWebInterface):window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.firebase?t(window.webkit.messageHandlers.firebase):window.gtag?o(window.gtag):Promise.resolve()},h=function(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")},A=function(e){return h(e).toLocaleLowerCase().replace(/[^a-z0-9\s\-]/g,"").replace(/\s+/g," ").trim().replace(/\s/g,"_")},P=function(e){return Object.entries(e).forEach(function(n){var t=function(e,n){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var o,r,i=t.call(e),a=[];try{for(;(void 0===n||n-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(t=i.return)&&t.call(i)}finally{if(r)throw r.error}}return a}(n,2),o=t[0],r=t[1];"string"==typeof r&&(e[o]=A(r))}),e},_="";e.CD_EVENT_VALUE=8,e.CD_NOVUM_UID=7,e.CD_WEBAPP_INSTALLED=4,e.attachToEmail=function(e){var n=e.url,t=e.subject,o=e.fileName,r=e.recipient,i=e.body;return p({type:"ATTACH_TO_EMAIL",payload:{url:n,subject:t,fileName:o,recipient:r,body:i}})},e.checkPermissionStatus=function(e,n){return p({type:"OS_PERMISSION_STATUS",payload:{feature:e,params:n}}).then(function(e){return e.granted})},e.createCalendarEvent=function(e){var n=e.beginTime,t=e.endTime,o=e.title;return p({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:g(n),endTime:g(t),title:o}})},e.dismiss=function(e){return p({type:"DISMISS",payload:{onCompletionUrl:e}})},e.fetch=function(e){var n=e.url,t=e.method,o=e.headers,r=e.body;return f()?p({type:"FETCH",payload:{url:n,method:t,headers:o,body:r}}).catch(function(){return{status:500,headers:{},body:"Bridge call failed"}}):Promise.resolve({status:500,headers:{},body:"Bridge not available"})},e.fetchContactsByPhone=function(e){return p({type:"FETCH_CONTACTS_DATA",payload:{phoneNumbers:e}})},e.getAppMetadata=function(e){return p({type:"GET_APP_METADATA",payload:{appToken:e}})},e.getCustomerHash=function(){return p({type:"GET_CUSTOMER_HASH"})},e.getDiskSpaceInfo=function(){return p({type:"GET_DISK_SPACE_INFO"})},e.getEsimInfo=function(){return p({type:"GET_ESIM_INFO"}).catch(function(){return{supportsEsim:!1}})},e.getTopazToken=function(e){return void 0===e&&(e={}),p({type:"GET_TOPAZ_TOKEN",payload:{}},e.timeout)},e.highlightNavigationTab=function(e){var n=e.tab,t=e.highlight,o=e.count;return p({type:"HIGHLIGHT_TAB",payload:{tab:n,highlight:t,count:o}})},e.internalNavigation=function(e){return p({type:"INTERNAL_NAVIGATION",payload:{feature:e}})},e.isABTestingAvailable=function(e){if(v)return Promise.resolve(w(e));var n=new Promise(function(e){setTimeout(function(){e(!1)},500)}),t=p({type:"GET_REMOTE_CONFIG"}).then(function(n){return v=n,w(e)});return Promise.race([n,t])},e.isWebViewBridgeAvailable=f,e.logEcommerceEvent=function(e,n){return n=b(b({},n),{screenName:n.screenName||_}),E({onAndroid:function(t){return t.logEvent&&t.logEvent(e,JSON.stringify(n)),Promise.resolve()},onIos:function(t){return t.postMessage({command:"logEvent",name:e,parameters:n}),Promise.resolve()},onWeb:function(){return Promise.resolve()}})},e.logEvent=function(e){var n,t,o,r,i,a,u=e.name,s=T(e,["name"]);if(u)s=P(s),u=A(u);else{if(!e.category||!e.action)return console.warn('LegacyAnalyticsEvent should have "category" and "action"',{category:e.category,action:e.action}),Promise.resolve();t=(n=e).category,o=n.action,r=n.label,i=n.value,a=T(n,["category","action","label","value"]),r||(r="null_label"),i||(i=0),s=b({eventCategory:t,eventAction:o,eventLabel:h(r),eventValue:i},a),u=e.category}return s=b(b({},s),{screenName:s.screenName||_}),E({onAndroid:function(e){return e.logEvent&&e.logEvent(u,JSON.stringify(s)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:u,parameters:s}),Promise.resolve()},onWeb:function(e){return new Promise(function(n){e("event",u,b(b({},s),{event_callback:n}))})}})},e.logTiming=function(e){var n=e.category,t=void 0===n?"performance_timer":n,o=e.variable,r=e.value,i=e.label;if(!t||!o||!r)return console.warn('Analytics timing should have "category", "variable" and "value"',{category:t,variable:o,value:r}),Promise.resolve();var a={timingCategory:t,timingVar:o,timingValue:r=Math.round(r),timingLabel:i},u=t;return E({onAndroid:function(e){return e.logEvent&&e.logEvent(u,JSON.stringify(a)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:u,parameters:a}),Promise.resolve()},onWeb:function(){return new Promise(function(e){gtag("event",u,b(b({},a),{event_callback:e}))})}})},e.logout=function(){return p({type:"LOG_OUT"})},e.nativeAlert=function(e){var n=e.message,t=e.title,o=e.buttonText;return f()?p({type:"ALERT",payload:{title:t,message:n,buttonText:o}}):("undefined"!=typeof window&&window.alert(n),Promise.resolve())},e.nativeConfirm=function(e){var n=e.message,t=e.title,o=e.acceptText,r=e.cancelText;return f()?p({type:"CONFIRM",payload:{message:n,title:t,acceptText:o,cancelText:r}}).then(function(e){return e.result}):Promise.resolve("undefined"!=typeof window&&window.confirm(n))},e.nativeMessage=function(e){var n=e.message,t=e.duration,o=e.buttonText,r=e.type;return f()?p({type:"MESSAGE",payload:{message:n,duration:t,buttonText:o,type:r}}):("undefined"!=typeof window&&window.alert(n),Promise.resolve())},e.notifyBridgeReady=function(){return p({type:"BRIDGE_READY"})},e.notifyPageLoaded=function(){return p({type:"PAGE_LOADED"})},e.onNativeEvent=function(e){return y("NATIVE_EVENT",function(n){return{action:e({event:n.event}).action||"default"}})},e.onSessionRenewed=function(e){return y("SESSION_RENEWED",function(n){var t=n.accessToken;return e(t)})},e.renewSession=function(e,n){return void 0===n&&(n={}),p({type:"RENEW_SESSION",payload:{accessToken:e||null}},n.timeout).then(function(e){return e.accessToken})},e.reportStatus=function(e){var n=e.feature,t=e.status,o=e.reason;return p({type:"STATUS_REPORT",payload:{feature:n,status:t,reason:o}})},e.requestContact=function(e){var n=(void 0===e?{}:e).filter;return p({type:"GET_CONTACT_DATA",payload:{filter:void 0===n?"phone":n}})},e.requestDeviceImei=function(){return p({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.requestSimIcc=function(){return p({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return p({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},e.requestVibration=function(e){return p({type:"VIBRATION",payload:{type:e}})},e.setActionBehavior=function(e){return p({type:"SET_ACTION_BEHAVIOR",payload:{actions:e}}).catch(function(){})},e.setCustomerHash=function(e){return p({type:"SET_CUSTOMER_HASH",payload:{hash:e}})},e.setLogger=function(e){d=e},e.setScreenName=function(e,n){return e?E({onAndroid:function(n){return n.setScreenName&&n.setScreenName(e),Promise.resolve()},onIos:function(n){return n.postMessage({command:"setScreenName",name:e}),Promise.resolve()},onWeb:function(t){return new Promise(function(o){t("event","screen_view",b(b({screenName:e,previousScreenName:_},P(null!==n&&void 0!==n?n:{})),{event_callback:o})),_=e})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setTrackingProperty=function(e,n,t){return p({type:"SET_TRACKING_PROPERTY",payload:{system:e,name:n,value:t}}).catch(function(){})},e.setUserProperty=function(e,n){return e&&n?(n=String(n),E({onAndroid:function(t){return t.setUserProperty&&t.setUserProperty(e,n),Promise.resolve()},onIos:function(t){return t.postMessage({command:"setUserProperty",name:e,value:n}),Promise.resolve()},onWeb:function(t){var o;return t("set","user_properties",((o={})[e]=A(n),o)),Promise.resolve()}})):(console.warn("Trying to set analytics user property without name or value",e,n),Promise.resolve())},e.setWebViewTitle=function(e){return f()?m({title:e}):("undefined"!=typeof document&&(document.title=e),Promise.resolve())},e.share=function(e){return p({type:"SHARE",payload:e})},e.updateNavigationBar=m,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "@tef-novum/webview-bridge", | ||
"version": "3.10.1", | ||
"version": "3.11.0", | ||
"description": "JavaScript library to access to native functionality. Requires a webview with a postMessage bridge.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/webview-bridge-cjs.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
248016
4651