@tef-novum/webview-bridge
Advanced tools
Comparing version 3.13.1 to 3.14.0
@@ -13,1 +13,2 @@ export { isWebViewBridgeAvailable, onNativeEvent, NativeEventHandler, setLogger, } from './src/post-message'; | ||
export { showAppRating } from './src/app-rating'; | ||
export { bottomSheet, bottomSheetSingleSelector } from './src/bottom-sheet'; |
@@ -22,2 +22,9 @@ /** | ||
}; | ||
export declare type SheetResponse = { | ||
action: 'SUBMIT' | 'DISMISS'; | ||
result: Array<{ | ||
id: string; | ||
selectedIds: Array<string>; | ||
}>; | ||
}; | ||
export declare type ResponsesFromNativeApp = { | ||
@@ -253,2 +260,7 @@ SIM_ICC: { | ||
}; | ||
SHEET: { | ||
type: 'SHEET'; | ||
id: string; | ||
payload: SheetResponse; | ||
}; | ||
}; | ||
@@ -255,0 +267,0 @@ export declare type NativeAppResponsePayload<Type extends keyof ResponsesFromNativeApp> = ResponsesFromNativeApp[Type]['payload']; |
@@ -854,2 +854,30 @@ define(['exports'], (function (exports) { 'use strict'; | ||
var bottomSheet = function (payload) { | ||
return postMessageToNativeApp({ type: 'SHEET', payload: payload }); | ||
}; | ||
var bottomSheetSingleSelector = function (_a) { | ||
var title = _a.title, subtitle = _a.subtitle, description = _a.description, selectedId = _a.selectedId, items = _a.items; | ||
return bottomSheet({ | ||
title: title, | ||
subtitle: subtitle, | ||
description: description, | ||
content: [ | ||
{ | ||
type: 'LIST', | ||
id: 'list-0', | ||
listType: 'SINGLE_SELECTION', | ||
autoSubmit: true, | ||
selectedIds: typeof selectedId === 'string' ? [selectedId] : [], | ||
items: items, | ||
}, | ||
], | ||
}).then(function (_a) { | ||
var action = _a.action, result = _a.result; | ||
return ({ | ||
action: action, | ||
selectedId: result[0].selectedIds[0], | ||
}); | ||
}); | ||
}; | ||
exports.CD_EVENT_VALUE = CD_EVENT_VALUE; | ||
@@ -859,2 +887,4 @@ exports.CD_NOVUM_UID = CD_NOVUM_UID; | ||
exports.attachToEmail = attachToEmail; | ||
exports.bottomSheet = bottomSheet; | ||
exports.bottomSheetSingleSelector = bottomSheetSingleSelector; | ||
exports.checkPermissionStatus = checkPermissionStatus; | ||
@@ -861,0 +891,0 @@ exports.createCalendarEvent = createCalendarEvent; |
@@ -856,2 +856,30 @@ 'use strict'; | ||
var bottomSheet = function (payload) { | ||
return postMessageToNativeApp({ type: 'SHEET', payload: payload }); | ||
}; | ||
var bottomSheetSingleSelector = function (_a) { | ||
var title = _a.title, subtitle = _a.subtitle, description = _a.description, selectedId = _a.selectedId, items = _a.items; | ||
return bottomSheet({ | ||
title: title, | ||
subtitle: subtitle, | ||
description: description, | ||
content: [ | ||
{ | ||
type: 'LIST', | ||
id: 'list-0', | ||
listType: 'SINGLE_SELECTION', | ||
autoSubmit: true, | ||
selectedIds: typeof selectedId === 'string' ? [selectedId] : [], | ||
items: items, | ||
}, | ||
], | ||
}).then(function (_a) { | ||
var action = _a.action, result = _a.result; | ||
return ({ | ||
action: action, | ||
selectedId: result[0].selectedIds[0], | ||
}); | ||
}); | ||
}; | ||
exports.CD_EVENT_VALUE = CD_EVENT_VALUE; | ||
@@ -861,2 +889,4 @@ exports.CD_NOVUM_UID = CD_NOVUM_UID; | ||
exports.attachToEmail = attachToEmail; | ||
exports.bottomSheet = bottomSheet; | ||
exports.bottomSheetSingleSelector = bottomSheetSingleSelector; | ||
exports.checkPermissionStatus = checkPermissionStatus; | ||
@@ -863,0 +893,0 @@ exports.createCalendarEvent = createCalendarEvent; |
@@ -855,2 +855,30 @@ var webviewBridge = (function (exports) { | ||
var bottomSheet = function (payload) { | ||
return postMessageToNativeApp({ type: 'SHEET', payload: payload }); | ||
}; | ||
var bottomSheetSingleSelector = function (_a) { | ||
var title = _a.title, subtitle = _a.subtitle, description = _a.description, selectedId = _a.selectedId, items = _a.items; | ||
return bottomSheet({ | ||
title: title, | ||
subtitle: subtitle, | ||
description: description, | ||
content: [ | ||
{ | ||
type: 'LIST', | ||
id: 'list-0', | ||
listType: 'SINGLE_SELECTION', | ||
autoSubmit: true, | ||
selectedIds: typeof selectedId === 'string' ? [selectedId] : [], | ||
items: items, | ||
}, | ||
], | ||
}).then(function (_a) { | ||
var action = _a.action, result = _a.result; | ||
return ({ | ||
action: action, | ||
selectedId: result[0].selectedIds[0], | ||
}); | ||
}); | ||
}; | ||
exports.CD_EVENT_VALUE = CD_EVENT_VALUE; | ||
@@ -860,2 +888,4 @@ exports.CD_NOVUM_UID = CD_NOVUM_UID; | ||
exports.attachToEmail = attachToEmail; | ||
exports.bottomSheet = bottomSheet; | ||
exports.bottomSheetSingleSelector = bottomSheetSingleSelector; | ||
exports.checkPermissionStatus = checkPermissionStatus; | ||
@@ -862,0 +892,0 @@ exports.createCalendarEvent = createCalendarEvent; |
@@ -1,1 +0,1 @@ | ||
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")))},f=void 0,d=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,d=a(),p=JSON.stringify({type:r,id:u,payload:l});return null===f||void 0===f||f("[WebView Bridge] SEND:",p),d?(setTimeout(function(){d(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===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=0,h=function(e){var n=setTimeout(function(){e(),E++},500);return function(){clearTimeout(n),E=0,e()}},A=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&&E<3?o(window.gtag):Promise.resolve()},P=function(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")},_=function(e){return P(e).toLocaleLowerCase().replace(/[^a-z0-9\s\-\_\/\|\:]/g,"").replace(/\s+/g," ").trim().replace(/\s/g,"_").slice(0,100)},S=function(e){var n={};return Object.entries(e).forEach(function(e){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}(e,2),o=t[0],r=t[1],i=r,a=o.slice(0,40);"string"==typeof r&&(i=_(r)),n[a]=i}),n},N={sanitize:!0},I="";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 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||I}),A({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,n){var t,o,r,i,a,u,s=b(b({},N),n).sanitize,c=e.name,l=T(e,["name"]);if(c)Object.keys(l).length>25&&console.warn("Trying to log FirebaseEvent with name ".concat(c," exceeding the limit of ").concat(25," params")),s&&(l=S(l),c=_(c));else{if(!e.category||!e.action)return console.warn('LegacyAnalyticsEvent should have "category" and "action"',{category:e.category,action:e.action}),Promise.resolve();o=(t=e).category,r=t.action,i=t.label,a=t.value,u=T(t,["category","action","label","value"]),i||(i="null_label"),a||(a=0),l=b({eventCategory:o,eventAction:r,eventLabel:P(i),eventValue:a},u),c=e.category}return l=b(b({},l),{screenName:l.screenName||I}),A({onAndroid:function(e){return e.logEvent&&e.logEvent(c,JSON.stringify(l)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:c,parameters:l}),Promise.resolve()},onWeb:function(e){return new Promise(function(n){e("event",c,b(b({},l),{event_callback:h(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 A({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:h(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.sanitizeAnalyticsParam=_,e.sanitizeAnalyticsParams=S,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){if(!e)return console.warn("Missing analytics screenName"),Promise.resolve();var t=I;return I=e,A({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(o){return new Promise(function(r){o("event","page_view",b(b({screenName:e,page_title:e,previousScreenName:t},S(null!==n&&void 0!==n?n:{})),{event_callback:h(r)}))})}})},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),A({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]=_(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.showAppRating=function(){return p({type:"SHOW_APP_RATING"})},e.updateNavigationBar=m,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
var webviewBridge=function(e){"use strict";var t=1,n="".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(t){return t!==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(t++,"-").concat(n):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,t){var n=!1,i=function(o){o.id!==u||n||(o.type===r?e(o.payload):"ERROR"===o.type?t(o.payload):t({code:500,reason:"bad type: ".concat(o.type,". Expecting ").concat(r)}),c(i))};s(i),o&&setTimeout(function(){n=!0,c(i),t({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 t;null===d||void 0===d||d("[WebView Bridge] RCVD:",e);try{t=JSON.parse(e)}catch(t){throw Error("Problem parsing webview message: ".concat(e))}u.forEach(function(e){return e(t)})}});var y=function(e,t){var n=function(n){n.type===e&&Promise.resolve(t(n.payload)).then(function(e){var t=a();t&&t(JSON.stringify({type:n.type,id:n.id,payload:e}))})};return s(n),function(){c(n)}},m=function(e){var t=e.title,n=e.expandedTitle,o=e.showBackButton,r=e.showReloadButton,i=e.showProfileButton,a=e.backgroundColor;return f()?p({type:"NAVIGATION_BAR",payload:{title:t,expandedTitle:n,showBackButton:o,showReloadButton:r,showProfileButton:i,backgroundColor:a}}):(void 0!==t&&"undefined"!=typeof document&&(document.title=t),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 t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function T(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}var E=0,h=function(e){var t=setTimeout(function(){e(),E++},500);return function(){clearTimeout(t),E=0,e()}},S=function(e){var t=e.onAndroid,n=e.onIos,o=e.onWeb;return"undefined"==typeof window?Promise.resolve():window.AnalyticsWebInterface?t(window.AnalyticsWebInterface):window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.firebase?n(window.webkit.messageHandlers.firebase):window.gtag&&E<3?o(window.gtag):Promise.resolve()},A=function(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")},_=function(e){return A(e).toLocaleLowerCase().replace(/[^a-z0-9\s\-\_\/\|\:]/g,"").replace(/\s+/g," ").trim().replace(/\s/g,"_").slice(0,100)},P=function(e){var t={};return Object.entries(e).forEach(function(e){var n=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a}(e,2),o=n[0],r=n[1],i=r,a=o.slice(0,40);"string"==typeof r&&(i=_(r)),t[a]=i}),t},I={sanitize:!0},N="",O=function(e){return p({type:"SHEET",payload:e})};return e.CD_EVENT_VALUE=8,e.CD_NOVUM_UID=7,e.CD_WEBAPP_INSTALLED=4,e.attachToEmail=function(e){var t=e.url,n=e.subject,o=e.fileName,r=e.recipient,i=e.body;return p({type:"ATTACH_TO_EMAIL",payload:{url:t,subject:n,fileName:o,recipient:r,body:i}})},e.bottomSheet=O,e.bottomSheetSingleSelector=function(e){var t=e.title,n=e.subtitle,o=e.description,r=e.selectedId,i=e.items;return O({title:t,subtitle:n,description:o,content:[{type:"LIST",id:"list-0",listType:"SINGLE_SELECTION",autoSubmit:!0,selectedIds:"string"==typeof r?[r]:[],items:i}]}).then(function(e){return{action:e.action,selectedId:e.result[0].selectedIds[0]}})},e.checkPermissionStatus=function(e,t){return p({type:"OS_PERMISSION_STATUS",payload:{feature:e,params:t}}).then(function(e){return e.granted})},e.createCalendarEvent=function(e){var t=e.beginTime,n=e.endTime,o=e.title;return p({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:g(t),endTime:g(n),title:o}})},e.dismiss=function(e){return p({type:"DISMISS",payload:{onCompletionUrl:e}})},e.fetch=function(e){var t=e.url,n=e.method,o=e.headers,r=e.body;return f()?p({type:"FETCH",payload:{url:t,method:n,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 t=e.tab,n=e.highlight,o=e.count;return p({type:"HIGHLIGHT_TAB",payload:{tab:t,highlight:n,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 t=new Promise(function(e){setTimeout(function(){e(!1)},500)}),n=p({type:"GET_REMOTE_CONFIG"}).then(function(t){return v=t,w(e)});return Promise.race([t,n])},e.isWebViewBridgeAvailable=f,e.logEcommerceEvent=function(e,t){return t=b(b({},t),{screenName:t.screenName||N}),S({onAndroid:function(n){return n.logEvent&&n.logEvent(e,JSON.stringify(t)),Promise.resolve()},onIos:function(n){return n.postMessage({command:"logEvent",name:e,parameters:t}),Promise.resolve()},onWeb:function(){return Promise.resolve()}})},e.logEvent=function(e,t){var n,o,r,i,a,u,s=b(b({},I),t).sanitize,c=e.name,l=T(e,["name"]);if(c)Object.keys(l).length>25&&console.warn("Trying to log FirebaseEvent with name ".concat(c," exceeding the limit of ").concat(25," params")),s&&(l=P(l),c=_(c));else{if(!e.category||!e.action)return console.warn('LegacyAnalyticsEvent should have "category" and "action"',{category:e.category,action:e.action}),Promise.resolve();o=(n=e).category,r=n.action,i=n.label,a=n.value,u=T(n,["category","action","label","value"]),i||(i="null_label"),a||(a=0),l=b({eventCategory:o,eventAction:r,eventLabel:A(i),eventValue:a},u),c=e.category}return l=b(b({},l),{screenName:l.screenName||N}),S({onAndroid:function(e){return e.logEvent&&e.logEvent(c,JSON.stringify(l)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:c,parameters:l}),Promise.resolve()},onWeb:function(e){return new Promise(function(t){e("event",c,b(b({},l),{event_callback:h(t)}))})}})},e.logTiming=function(e){var t=e.category,n=void 0===t?"performance_timer":t,o=e.variable,r=e.value,i=e.label;if(!n||!o||!r)return console.warn('Analytics timing should have "category", "variable" and "value"',{category:n,variable:o,value:r}),Promise.resolve();var a={timingCategory:n,timingVar:o,timingValue:r=Math.round(r),timingLabel:i},u=n;return S({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:h(e)}))})}})},e.logout=function(){return p({type:"LOG_OUT"})},e.nativeAlert=function(e){var t=e.message,n=e.title,o=e.buttonText;return f()?p({type:"ALERT",payload:{title:n,message:t,buttonText:o}}):("undefined"!=typeof window&&window.alert(t),Promise.resolve())},e.nativeConfirm=function(e){var t=e.message,n=e.title,o=e.acceptText,r=e.cancelText;return f()?p({type:"CONFIRM",payload:{message:t,title:n,acceptText:o,cancelText:r}}).then(function(e){return e.result}):Promise.resolve("undefined"!=typeof window&&window.confirm(t))},e.nativeMessage=function(e){var t=e.message,n=e.duration,o=e.buttonText,r=e.type;return f()?p({type:"MESSAGE",payload:{message:t,duration:n,buttonText:o,type:r}}):("undefined"!=typeof window&&window.alert(t),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(t){return{action:e({event:t.event}).action||"default"}})},e.onSessionRenewed=function(e){return y("SESSION_RENEWED",function(t){var n=t.accessToken;return e(n)})},e.renewSession=function(e,t){return void 0===t&&(t={}),p({type:"RENEW_SESSION",payload:{accessToken:e||null}},t.timeout).then(function(e){return e.accessToken})},e.reportStatus=function(e){var t=e.feature,n=e.status,o=e.reason;return p({type:"STATUS_REPORT",payload:{feature:t,status:n,reason:o}})},e.requestContact=function(e){var t=(void 0===e?{}:e).filter;return p({type:"GET_CONTACT_DATA",payload:{filter:void 0===t?"phone":t}})},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.sanitizeAnalyticsParam=_,e.sanitizeAnalyticsParams=P,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,t){if(!e)return console.warn("Missing analytics screenName"),Promise.resolve();var n=N;return N=e,S({onAndroid:function(t){return t.setScreenName&&t.setScreenName(e),Promise.resolve()},onIos:function(t){return t.postMessage({command:"setScreenName",name:e}),Promise.resolve()},onWeb:function(o){return new Promise(function(r){o("event","page_view",b(b({screenName:e,page_title:e,previousScreenName:n},P(null!==t&&void 0!==t?t:{})),{event_callback:h(r)}))})}})},e.setTrackingProperty=function(e,t,n){return p({type:"SET_TRACKING_PROPERTY",payload:{system:e,name:t,value:n}}).catch(function(){})},e.setUserProperty=function(e,t){return e&&t?(t=String(t),S({onAndroid:function(n){return n.setUserProperty&&n.setUserProperty(e,t),Promise.resolve()},onIos:function(n){return n.postMessage({command:"setUserProperty",name:e,value:t}),Promise.resolve()},onWeb:function(n){var o;return n("set","user_properties",((o={})[e]=_(t),o)),Promise.resolve()}})):(console.warn("Trying to set analytics user property without name or value",e,t),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.showAppRating=function(){return p({type:"SHOW_APP_RATING"})},e.updateNavigationBar=m,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); |
@@ -858,2 +858,30 @@ (function (global, factory) { | ||
var bottomSheet = function (payload) { | ||
return postMessageToNativeApp({ type: 'SHEET', payload: payload }); | ||
}; | ||
var bottomSheetSingleSelector = function (_a) { | ||
var title = _a.title, subtitle = _a.subtitle, description = _a.description, selectedId = _a.selectedId, items = _a.items; | ||
return bottomSheet({ | ||
title: title, | ||
subtitle: subtitle, | ||
description: description, | ||
content: [ | ||
{ | ||
type: 'LIST', | ||
id: 'list-0', | ||
listType: 'SINGLE_SELECTION', | ||
autoSubmit: true, | ||
selectedIds: typeof selectedId === 'string' ? [selectedId] : [], | ||
items: items, | ||
}, | ||
], | ||
}).then(function (_a) { | ||
var action = _a.action, result = _a.result; | ||
return ({ | ||
action: action, | ||
selectedId: result[0].selectedIds[0], | ||
}); | ||
}); | ||
}; | ||
exports.CD_EVENT_VALUE = CD_EVENT_VALUE; | ||
@@ -863,2 +891,4 @@ exports.CD_NOVUM_UID = CD_NOVUM_UID; | ||
exports.attachToEmail = attachToEmail; | ||
exports.bottomSheet = bottomSheet; | ||
exports.bottomSheetSingleSelector = bottomSheetSingleSelector; | ||
exports.checkPermissionStatus = checkPermissionStatus; | ||
@@ -865,0 +895,0 @@ exports.createCalendarEvent = createCalendarEvent; |
@@ -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="".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")))},f=void 0,d=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,d=a(),p=JSON.stringify({type:r,id:u,payload:l});return null===f||void 0===f||f("[WebView Bridge] SEND:",p),d?(setTimeout(function(){d(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===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=0,h=function(e){var n=setTimeout(function(){e(),E++},500);return function(){clearTimeout(n),E=0,e()}},A=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&&E<3?o(window.gtag):Promise.resolve()},P=function(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")},_=function(e){return P(e).toLocaleLowerCase().replace(/[^a-z0-9\s\-\_\/\|\:]/g,"").replace(/\s+/g," ").trim().replace(/\s/g,"_").slice(0,100)},S=function(e){var n={};return Object.entries(e).forEach(function(e){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}(e,2),o=t[0],r=t[1],i=r,a=o.slice(0,40);"string"==typeof r&&(i=_(r)),n[a]=i}),n},N={sanitize:!0},I="";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||I}),A({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,n){var t,o,r,i,a,u,s=b(b({},N),n).sanitize,c=e.name,l=T(e,["name"]);if(c)Object.keys(l).length>25&&console.warn("Trying to log FirebaseEvent with name ".concat(c," exceeding the limit of ").concat(25," params")),s&&(l=S(l),c=_(c));else{if(!e.category||!e.action)return console.warn('LegacyAnalyticsEvent should have "category" and "action"',{category:e.category,action:e.action}),Promise.resolve();o=(t=e).category,r=t.action,i=t.label,a=t.value,u=T(t,["category","action","label","value"]),i||(i="null_label"),a||(a=0),l=b({eventCategory:o,eventAction:r,eventLabel:P(i),eventValue:a},u),c=e.category}return l=b(b({},l),{screenName:l.screenName||I}),A({onAndroid:function(e){return e.logEvent&&e.logEvent(c,JSON.stringify(l)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:c,parameters:l}),Promise.resolve()},onWeb:function(e){return new Promise(function(n){e("event",c,b(b({},l),{event_callback:h(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 A({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:h(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.sanitizeAnalyticsParam=_,e.sanitizeAnalyticsParams=S,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){if(!e)return console.warn("Missing analytics screenName"),Promise.resolve();var t=I;return I=e,A({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(o){return new Promise(function(r){o("event","page_view",b(b({screenName:e,page_title:e,previousScreenName:t},S(null!==n&&void 0!==n?n:{})),{event_callback:h(r)}))})}})},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),A({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]=_(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.showAppRating=function(){return p({type:"SHOW_APP_RATING"})},e.updateNavigationBar=m,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).webviewBridge={})}(this,function(e){"use strict";var t=1,n="".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(t){return t!==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(t++,"-").concat(n):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,t){var n=!1,i=function(o){o.id!==u||n||(o.type===r?e(o.payload):"ERROR"===o.type?t(o.payload):t({code:500,reason:"bad type: ".concat(o.type,". Expecting ").concat(r)}),c(i))};s(i),o&&setTimeout(function(){n=!0,c(i),t({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 t;null===d||void 0===d||d("[WebView Bridge] RCVD:",e);try{t=JSON.parse(e)}catch(t){throw Error("Problem parsing webview message: ".concat(e))}u.forEach(function(e){return e(t)})}});var y=function(e,t){var n=function(n){n.type===e&&Promise.resolve(t(n.payload)).then(function(e){var t=a();t&&t(JSON.stringify({type:n.type,id:n.id,payload:e}))})};return s(n),function(){c(n)}},m=function(e){var t=e.title,n=e.expandedTitle,o=e.showBackButton,r=e.showReloadButton,i=e.showProfileButton,a=e.backgroundColor;return f()?p({type:"NAVIGATION_BAR",payload:{title:t,expandedTitle:n,showBackButton:o,showReloadButton:r,showProfileButton:i,backgroundColor:a}}):(void 0!==t&&"undefined"!=typeof document&&(document.title=t),Promise.resolve())},v=null,g=function(e){return"true"===v.result[e]},w=function(e){return Math.floor(e/1e3)},b=function(){return(b=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function T(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}var E=0,h=function(e){var t=setTimeout(function(){e(),E++},500);return function(){clearTimeout(t),E=0,e()}},S=function(e){var t=e.onAndroid,n=e.onIos,o=e.onWeb;return"undefined"==typeof window?Promise.resolve():window.AnalyticsWebInterface?t(window.AnalyticsWebInterface):window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.firebase?n(window.webkit.messageHandlers.firebase):window.gtag&&E<3?o(window.gtag):Promise.resolve()},A=function(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")},_=function(e){return A(e).toLocaleLowerCase().replace(/[^a-z0-9\s\-\_\/\|\:]/g,"").replace(/\s+/g," ").trim().replace(/\s/g,"_").slice(0,100)},P=function(e){var t={};return Object.entries(e).forEach(function(e){var n=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a}(e,2),o=n[0],r=n[1],i=r,a=o.slice(0,40);"string"==typeof r&&(i=_(r)),t[a]=i}),t},I={sanitize:!0},N="",O=function(e){return p({type:"SHEET",payload:e})};e.CD_EVENT_VALUE=8,e.CD_NOVUM_UID=7,e.CD_WEBAPP_INSTALLED=4,e.attachToEmail=function(e){var t=e.url,n=e.subject,o=e.fileName,r=e.recipient,i=e.body;return p({type:"ATTACH_TO_EMAIL",payload:{url:t,subject:n,fileName:o,recipient:r,body:i}})},e.bottomSheet=O,e.bottomSheetSingleSelector=function(e){var t=e.title,n=e.subtitle,o=e.description,r=e.selectedId,i=e.items;return O({title:t,subtitle:n,description:o,content:[{type:"LIST",id:"list-0",listType:"SINGLE_SELECTION",autoSubmit:!0,selectedIds:"string"==typeof r?[r]:[],items:i}]}).then(function(e){return{action:e.action,selectedId:e.result[0].selectedIds[0]}})},e.checkPermissionStatus=function(e,t){return p({type:"OS_PERMISSION_STATUS",payload:{feature:e,params:t}}).then(function(e){return e.granted})},e.createCalendarEvent=function(e){var t=e.beginTime,n=e.endTime,o=e.title;return p({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:w(t),endTime:w(n),title:o}})},e.dismiss=function(e){return p({type:"DISMISS",payload:{onCompletionUrl:e}})},e.fetch=function(e){var t=e.url,n=e.method,o=e.headers,r=e.body;return f()?p({type:"FETCH",payload:{url:t,method:n,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 t=e.tab,n=e.highlight,o=e.count;return p({type:"HIGHLIGHT_TAB",payload:{tab:t,highlight:n,count:o}})},e.internalNavigation=function(e){return p({type:"INTERNAL_NAVIGATION",payload:{feature:e}})},e.isABTestingAvailable=function(e){if(v)return Promise.resolve(g(e));var t=new Promise(function(e){setTimeout(function(){e(!1)},500)}),n=p({type:"GET_REMOTE_CONFIG"}).then(function(t){return v=t,g(e)});return Promise.race([t,n])},e.isWebViewBridgeAvailable=f,e.logEcommerceEvent=function(e,t){return t=b(b({},t),{screenName:t.screenName||N}),S({onAndroid:function(n){return n.logEvent&&n.logEvent(e,JSON.stringify(t)),Promise.resolve()},onIos:function(n){return n.postMessage({command:"logEvent",name:e,parameters:t}),Promise.resolve()},onWeb:function(){return Promise.resolve()}})},e.logEvent=function(e,t){var n,o,r,i,a,u,s=b(b({},I),t).sanitize,c=e.name,l=T(e,["name"]);if(c)Object.keys(l).length>25&&console.warn("Trying to log FirebaseEvent with name ".concat(c," exceeding the limit of ").concat(25," params")),s&&(l=P(l),c=_(c));else{if(!e.category||!e.action)return console.warn('LegacyAnalyticsEvent should have "category" and "action"',{category:e.category,action:e.action}),Promise.resolve();o=(n=e).category,r=n.action,i=n.label,a=n.value,u=T(n,["category","action","label","value"]),i||(i="null_label"),a||(a=0),l=b({eventCategory:o,eventAction:r,eventLabel:A(i),eventValue:a},u),c=e.category}return l=b(b({},l),{screenName:l.screenName||N}),S({onAndroid:function(e){return e.logEvent&&e.logEvent(c,JSON.stringify(l)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:c,parameters:l}),Promise.resolve()},onWeb:function(e){return new Promise(function(t){e("event",c,b(b({},l),{event_callback:h(t)}))})}})},e.logTiming=function(e){var t=e.category,n=void 0===t?"performance_timer":t,o=e.variable,r=e.value,i=e.label;if(!n||!o||!r)return console.warn('Analytics timing should have "category", "variable" and "value"',{category:n,variable:o,value:r}),Promise.resolve();var a={timingCategory:n,timingVar:o,timingValue:r=Math.round(r),timingLabel:i},u=n;return S({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:h(e)}))})}})},e.logout=function(){return p({type:"LOG_OUT"})},e.nativeAlert=function(e){var t=e.message,n=e.title,o=e.buttonText;return f()?p({type:"ALERT",payload:{title:n,message:t,buttonText:o}}):("undefined"!=typeof window&&window.alert(t),Promise.resolve())},e.nativeConfirm=function(e){var t=e.message,n=e.title,o=e.acceptText,r=e.cancelText;return f()?p({type:"CONFIRM",payload:{message:t,title:n,acceptText:o,cancelText:r}}).then(function(e){return e.result}):Promise.resolve("undefined"!=typeof window&&window.confirm(t))},e.nativeMessage=function(e){var t=e.message,n=e.duration,o=e.buttonText,r=e.type;return f()?p({type:"MESSAGE",payload:{message:t,duration:n,buttonText:o,type:r}}):("undefined"!=typeof window&&window.alert(t),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(t){return{action:e({event:t.event}).action||"default"}})},e.onSessionRenewed=function(e){return y("SESSION_RENEWED",function(t){var n=t.accessToken;return e(n)})},e.renewSession=function(e,t){return void 0===t&&(t={}),p({type:"RENEW_SESSION",payload:{accessToken:e||null}},t.timeout).then(function(e){return e.accessToken})},e.reportStatus=function(e){var t=e.feature,n=e.status,o=e.reason;return p({type:"STATUS_REPORT",payload:{feature:t,status:n,reason:o}})},e.requestContact=function(e){var t=(void 0===e?{}:e).filter;return p({type:"GET_CONTACT_DATA",payload:{filter:void 0===t?"phone":t}})},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.sanitizeAnalyticsParam=_,e.sanitizeAnalyticsParams=P,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,t){if(!e)return console.warn("Missing analytics screenName"),Promise.resolve();var n=N;return N=e,S({onAndroid:function(t){return t.setScreenName&&t.setScreenName(e),Promise.resolve()},onIos:function(t){return t.postMessage({command:"setScreenName",name:e}),Promise.resolve()},onWeb:function(o){return new Promise(function(r){o("event","page_view",b(b({screenName:e,page_title:e,previousScreenName:n},P(null!==t&&void 0!==t?t:{})),{event_callback:h(r)}))})}})},e.setTrackingProperty=function(e,t,n){return p({type:"SET_TRACKING_PROPERTY",payload:{system:e,name:t,value:n}}).catch(function(){})},e.setUserProperty=function(e,t){return e&&t?(t=String(t),S({onAndroid:function(n){return n.setUserProperty&&n.setUserProperty(e,t),Promise.resolve()},onIos:function(n){return n.postMessage({command:"setUserProperty",name:e,value:t}),Promise.resolve()},onWeb:function(n){var o;return n("set","user_properties",((o={})[e]=_(t),o)),Promise.resolve()}})):(console.warn("Trying to set analytics user property without name or value",e,t),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.showAppRating=function(){return p({type:"SHOW_APP_RATING"})},e.updateNavigationBar=m,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "@tef-novum/webview-bridge", | ||
"version": "3.13.1", | ||
"version": "3.14.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", |
@@ -864,2 +864,56 @@ <p align="center"> | ||
### bottomSheet | ||
Show native bottom sheet ui | ||
<img height="460" src="doc/webview-bridge-bottom-sheet.png"> | ||
```ts | ||
bottomSheet = (payload: SheetUI) => Promise<SheetResponse> | ||
// see SheetUI and SheetResponse types | ||
``` | ||
For the specific case of single selection, you can use the | ||
`bottomSheetSingleSelector` method: | ||
```ts | ||
bottomSheetSingleSelector = ({ | ||
title?: string; | ||
subtitle?: string; | ||
description?: string; | ||
selectedId?: string; | ||
items: Array<SheetListItem>; | ||
}) => Promise<{action: 'SUBMIT' | 'DISMISS'; selected: string}> | ||
``` | ||
#### Example: | ||
```ts | ||
import {bottomSheetSingleSelector} from '@tef-novum/webview-bridge'; | ||
const {action, selected} = await bottomSheetSingleSelector({ | ||
title: 'Some title', | ||
subtitle: 'Some subtitle', | ||
description: 'Some description', | ||
selectedId: 'item-1', | ||
items: [ | ||
{ | ||
id: 'item-0', | ||
title: 'item 0 title', | ||
description: 'item 0 description', | ||
}, | ||
{ | ||
id: 'item-1', | ||
title: 'item 1 title', | ||
description: 'item 1 description', | ||
}, | ||
{ | ||
id: 'item-2', | ||
title: 'item 2 title', | ||
description: 'item 2 description', | ||
}, | ||
], | ||
}); | ||
``` | ||
## Error handling | ||
@@ -866,0 +920,0 @@ |
Sorry, the diff of this file is not supported yet
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
266930
37
5083
930