@tef-novum/webview-bridge
Advanced tools
Comparing version 2.3.4 to 2.4.0
# CHANGELOG | ||
## v.2.4.0 - 2019-11-04 | ||
- New function: `checkPermissionStatus` | ||
- New function: `internalNavigation` | ||
## v.2.3.4 - 2019-10-07 | ||
- Add 500ms timeout to remote config | ||
## v.2.3.3 - 2019-10-02 | ||
@@ -4,0 +13,0 @@ |
export { isWebViewBridgeAvailable, onNativeEvent, NativeEventHandler, } from './src/post-message'; | ||
export { nativeConfirm, nativeAlert, nativeMessage } from './src/dialogs'; | ||
export { requestSimIcc, requestSimImsi, requestDeviceImei } from './src/device'; | ||
export { attachToEmail, share, setWebViewTitle, updateNavigationBar, notifyPageLoaded, isABTestingAvailable, reportStatus, fetch, } from './src/utils'; | ||
export { requestSimIcc, requestSimImsi, requestDeviceImei, internalNavigation, } from './src/device'; | ||
export { attachToEmail, share, setWebViewTitle, updateNavigationBar, notifyPageLoaded, isABTestingAvailable, reportStatus, fetch, checkPermissionStatus, } from './src/utils'; | ||
export { createCalendarEvent } from './src/calendar'; | ||
export { requestContact } from './src/contacts'; | ||
export { logEvent, logTiming, setScreenName, setUserProperty, CD_WEBAPP_INSTALLED, CD_NOVUM_UID, CD_EVENT_VALUE, } from './src/analytics'; |
export declare const requestSimIcc: () => Promise<string | null>; | ||
export declare const requestSimImsi: () => Promise<string | null>; | ||
export declare const requestDeviceImei: () => Promise<string | null>; | ||
export declare const internalNavigation: (feature: "notification-settings") => Promise<void>; |
@@ -131,2 +131,14 @@ /** | ||
}; | ||
OS_PERMISSION_STATUS: { | ||
id: string; | ||
type: 'OS_PERMISSION_STATUS'; | ||
payload: { | ||
granted: boolean; | ||
}; | ||
}; | ||
INTERNAL_NAVIGATION: { | ||
type: 'INTERNAL_NAVIGATION'; | ||
id: string; | ||
payload: void; | ||
}; | ||
}; | ||
@@ -140,3 +152,3 @@ /** | ||
*/ | ||
export declare const postMessageToNativeApp: <T extends "SIM_ICC" | "IMEI" | "IMSI" | "ATTACH_TO_EMAIL" | "SET_TITLE" | "PAGE_LOADED" | "ALERT" | "MESSAGE" | "CONFIRM" | "CREATE_CALENDAR_EVENT" | "GET_CONTACT_DATA" | "NAVIGATION_BAR" | "SHARE" | "ERROR" | "GET_REMOTE_CONFIG" | "STATUS_REPORT" | "FETCH" | "EVENT">({ type, id, payload }: { | ||
export declare const postMessageToNativeApp: <T extends "SIM_ICC" | "IMEI" | "IMSI" | "ATTACH_TO_EMAIL" | "SET_TITLE" | "PAGE_LOADED" | "ALERT" | "MESSAGE" | "CONFIRM" | "CREATE_CALENDAR_EVENT" | "GET_CONTACT_DATA" | "NAVIGATION_BAR" | "SHARE" | "ERROR" | "GET_REMOTE_CONFIG" | "STATUS_REPORT" | "FETCH" | "OS_PERMISSION_STATUS" | "INTERNAL_NAVIGATION" | "EVENT">({ type, id, payload }: { | ||
type: T; | ||
@@ -143,0 +155,0 @@ id?: string | undefined; |
@@ -47,2 +47,5 @@ export declare const attachToEmail: ({ url, subject, fileName, recipient, body, }: { | ||
}>; | ||
export declare const checkPermissionStatus: (feature: "notifications", params?: { | ||
[key: string]: string; | ||
} | undefined) => Promise<boolean>; | ||
export {}; |
@@ -199,2 +199,10 @@ define(['exports'], function (exports) { 'use strict'; | ||
}; | ||
var internalNavigation = function (feature) { | ||
return postMessageToNativeApp({ | ||
type: 'INTERNAL_NAVIGATION', | ||
payload: { | ||
feature: feature, | ||
}, | ||
}); | ||
}; | ||
@@ -298,2 +306,14 @@ var attachToEmail = function (_a) { | ||
}; | ||
var checkPermissionStatus = function (feature, params) { | ||
return postMessageToNativeApp({ | ||
type: 'OS_PERMISSION_STATUS', | ||
payload: { | ||
feature: feature, | ||
params: params, | ||
}, | ||
}).then(function (_a) { | ||
var granted = _a.granted; | ||
return granted; | ||
}); | ||
}; | ||
@@ -349,4 +369,6 @@ var msToS = function (ms) { return Math.floor(ms / 1000); }; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
@@ -432,3 +454,3 @@ } | ||
return new Promise(function (resolve) { | ||
ga('NovumTracker.send', 'event', __assign({}, params, { hitCallback: resolve })); | ||
ga('NovumTracker.send', 'event', __assign(__assign({}, params), { hitCallback: resolve })); | ||
}); | ||
@@ -507,3 +529,3 @@ }, | ||
tracker.set('page', pageName); | ||
tracker.send('pageView', __assign({}, fieldsObject, { hitCallback: resolve })); | ||
tracker.send('pageView', __assign(__assign({}, fieldsObject), { hitCallback: resolve })); | ||
}); | ||
@@ -574,4 +596,6 @@ }); | ||
exports.attachToEmail = attachToEmail; | ||
exports.checkPermissionStatus = checkPermissionStatus; | ||
exports.createCalendarEvent = createCalendarEvent; | ||
exports.fetch = fetch; | ||
exports.internalNavigation = internalNavigation; | ||
exports.isABTestingAvailable = isABTestingAvailable; | ||
@@ -578,0 +602,0 @@ exports.isWebViewBridgeAvailable = isWebViewBridgeAvailable; |
@@ -201,2 +201,10 @@ 'use strict'; | ||
}; | ||
var internalNavigation = function (feature) { | ||
return postMessageToNativeApp({ | ||
type: 'INTERNAL_NAVIGATION', | ||
payload: { | ||
feature: feature, | ||
}, | ||
}); | ||
}; | ||
@@ -300,2 +308,14 @@ var attachToEmail = function (_a) { | ||
}; | ||
var checkPermissionStatus = function (feature, params) { | ||
return postMessageToNativeApp({ | ||
type: 'OS_PERMISSION_STATUS', | ||
payload: { | ||
feature: feature, | ||
params: params, | ||
}, | ||
}).then(function (_a) { | ||
var granted = _a.granted; | ||
return granted; | ||
}); | ||
}; | ||
@@ -351,4 +371,6 @@ var msToS = function (ms) { return Math.floor(ms / 1000); }; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
@@ -434,3 +456,3 @@ } | ||
return new Promise(function (resolve) { | ||
ga('NovumTracker.send', 'event', __assign({}, params, { hitCallback: resolve })); | ||
ga('NovumTracker.send', 'event', __assign(__assign({}, params), { hitCallback: resolve })); | ||
}); | ||
@@ -509,3 +531,3 @@ }, | ||
tracker.set('page', pageName); | ||
tracker.send('pageView', __assign({}, fieldsObject, { hitCallback: resolve })); | ||
tracker.send('pageView', __assign(__assign({}, fieldsObject), { hitCallback: resolve })); | ||
}); | ||
@@ -576,4 +598,6 @@ }); | ||
exports.attachToEmail = attachToEmail; | ||
exports.checkPermissionStatus = checkPermissionStatus; | ||
exports.createCalendarEvent = createCalendarEvent; | ||
exports.fetch = fetch; | ||
exports.internalNavigation = internalNavigation; | ||
exports.isABTestingAvailable = isABTestingAvailable; | ||
@@ -580,0 +604,0 @@ exports.isWebViewBridgeAvailable = isWebViewBridgeAvailable; |
@@ -200,2 +200,10 @@ var webviewBridge = (function (exports) { | ||
}; | ||
var internalNavigation = function (feature) { | ||
return postMessageToNativeApp({ | ||
type: 'INTERNAL_NAVIGATION', | ||
payload: { | ||
feature: feature, | ||
}, | ||
}); | ||
}; | ||
@@ -299,2 +307,14 @@ var attachToEmail = function (_a) { | ||
}; | ||
var checkPermissionStatus = function (feature, params) { | ||
return postMessageToNativeApp({ | ||
type: 'OS_PERMISSION_STATUS', | ||
payload: { | ||
feature: feature, | ||
params: params, | ||
}, | ||
}).then(function (_a) { | ||
var granted = _a.granted; | ||
return granted; | ||
}); | ||
}; | ||
@@ -350,4 +370,6 @@ var msToS = function (ms) { return Math.floor(ms / 1000); }; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
@@ -433,3 +455,3 @@ } | ||
return new Promise(function (resolve) { | ||
ga('NovumTracker.send', 'event', __assign({}, params, { hitCallback: resolve })); | ||
ga('NovumTracker.send', 'event', __assign(__assign({}, params), { hitCallback: resolve })); | ||
}); | ||
@@ -508,3 +530,3 @@ }, | ||
tracker.set('page', pageName); | ||
tracker.send('pageView', __assign({}, fieldsObject, { hitCallback: resolve })); | ||
tracker.send('pageView', __assign(__assign({}, fieldsObject), { hitCallback: resolve })); | ||
}); | ||
@@ -575,4 +597,6 @@ }); | ||
exports.attachToEmail = attachToEmail; | ||
exports.checkPermissionStatus = checkPermissionStatus; | ||
exports.createCalendarEvent = createCalendarEvent; | ||
exports.fetch = fetch; | ||
exports.internalNavigation = internalNavigation; | ||
exports.isABTestingAvailable = isABTestingAvailable; | ||
@@ -579,0 +603,0 @@ exports.isWebViewBridgeAvailable = isWebViewBridgeAvailable; |
@@ -1,1 +0,1 @@ | ||
var webviewBridge=function(e){"use strict";var n=1,t=function(){return""+n++},r="__tuenti_webview_bridge",o=function(){return!(!window.tuentiWebView||!window.tuentiWebView.postMessage)},i=function(){return!!(window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.tuentiWebView&&window.webkit.messageHandlers.tuentiWebView.postMessage)},a=function(){return o()?function(e){window.tuentiWebView.postMessage(e)}:i()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null},s=[],u=function(e){s.push(e)},c=function(e){s=s.filter(function(n){return n!==e})},l=function(){return o()||i()},d=function(e,n){var r=e.type,o=e.id,i=void 0===o?t():o,s=e.payload,l=a(),d=JSON.stringify({type:r,id:i,payload:s});return l?(setTimeout(function(){l(d)}),new Promise(function(e,t){var o=!1,a=function(n){n.id!==i||o||(n.type===r?e(n.payload):"ERROR"===n.type?t(n.payload):t({code:500,reason:"bad type: "+n.type+". Expecting "+r}),c(a))};u(a),n&&setTimeout(function(){o=!0,c(a),t({code:408,reason:"request timeout"})},n)})):Promise.reject({code:500,reason:"WebView postMessage not available"})};window[r]=window[r]||{postMessage:function(e){var n;try{n=JSON.parse(e)}catch(n){throw Error("Problem parsing webview message: "+e)}s.forEach(function(e){return e(n)})}};var f=function(e){var n=e.title,t=e.showBackButton,r=e.showReloadButton,o=e.backgroundColor;return l()?d({type:"NAVIGATION_BAR",payload:{title:n,showBackButton:t,showReloadButton:r,backgroundColor:o}}):(void 0!==n&&(document.title=n),Promise.resolve())},m=null,v=function(e){return"true"===m.result[e]},p=function(e){return Math.floor(e/1e3)},w=function(){return(w=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)};var y,g=["NovumTracker","OBARGTracker"],b=function(e){return g.indexOf(e.get("name"))>=0},T=function(e){var n=e.onAndroid,t=e.onIos,r=e.onWeb;return window.AnalyticsWebInterface?n(window.AnalyticsWebInterface):window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.firebase?t(window.webkit.messageHandlers.firebase):window.ga&&window.ga.loaded?r(window.ga):Promise.resolve()},h={obIds:1,paymentModels:2,serviceWorkerStatus:3,isAdmin:5,hasIpComms:6,af_source:9,af_campaign:10,novum_uid_session:11,user_logged:12,currentSubscriptionId:13,currentSubscriptionType:14,currentPaymentModel:15,webviewBrowserVersion:16};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,r=e.fileName,o=e.recipient,i=e.body;return d({type:"ATTACH_TO_EMAIL",payload:{url:n,subject:t,fileName:r,recipient:o,body:i}})},e.createCalendarEvent=function(e){var n=e.beginTime,t=e.endTime,r=e.title;return d({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:p(n),endTime:p(t),title:r}})},e.fetch=function(e){var n=e.url,t=e.method,r=e.headers,o=e.body;return l()?d({type:"FETCH",payload:{url:n,method:t,headers:r,body:o}}).catch(function(){return{status:500,headers:{},body:"Bridge call failed"}}):Promise.resolve({status:500,headers:{},body:"Bridge not available"})},e.isABTestingAvailable=function(e){if(m)return Promise.resolve(v(e));var n=new Promise(function(e){setTimeout(function(){e(!1)},500)}),t=d({type:"GET_REMOTE_CONFIG"}).then(function(n){return m=n,v(e)});return Promise.race([n,t])},e.isWebViewBridgeAvailable=l,e.logEvent=function(e){var n=e.category,t=e.action,r=e.label,o=e.value,i=function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&(t[r[o]]=e[r[o]])}return t}(e,["category","action","label","value"]);if(!n||!t)return console.warn('Analytics event should have "category" and "action"',{category:n,action:t}),Promise.resolve();var a=n;r||(r="null_label"),o||(o=0);var s=w({eventCategory:n,eventAction:t,eventLabel:r,eventValue:o},i);return T({onAndroid:function(e){return e.logEvent&&e.logEvent(a,JSON.stringify(s)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:a,parameters:s}),Promise.resolve()},onWeb:function(e){return new Promise(function(n){e("NovumTracker.send","event",w({},s,{hitCallback:n}))})}})},e.logTiming=function(e){var n=e.category,t=void 0===n?"performance_timer":n,r=e.variable,o=e.value,i=e.label;if(!t||!r||!o)return console.warn('Analytics timing should have "category", "variable" and "value"',{category:t,variable:r,value:o}),Promise.resolve();var a={timingCategory:t,timingVar:r,timingValue:o,timingLabel:i},s=t;return T({onAndroid:function(e){return e.logEvent&&e.logEvent(s,JSON.stringify(a)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:s,parameters:a}),Promise.resolve()},onWeb:function(e){return new Promise(function(n){var t;e("NovumTracker.send",w(((t={hitType:"timing",hitCallback:n}).dimension8=String(o),t),a))})}})},e.nativeAlert=function(e){var n=e.message,t=e.title,r=e.buttonText;return l()?d({type:"ALERT",payload:{title:t,message:n,buttonText:r}}):(window.alert(n),Promise.resolve())},e.nativeConfirm=function(e){var n=e.message,t=e.title,r=e.acceptText,o=e.cancelText;return l()?d({type:"CONFIRM",payload:{message:n,title:t,acceptText:r,cancelText:o}}).then(function(e){return e.result}):Promise.resolve(window.confirm(n))},e.nativeMessage=function(e){var n=e.message,t=e.duration,r=e.buttonText,o=e.type;return l()?d({type:"MESSAGE",payload:{message:n,duration:t,buttonText:r,type:o}}):(window.alert(n),Promise.resolve())},e.notifyPageLoaded=function(){return d({type:"PAGE_LOADED"})},e.onNativeEvent=function(e){var n=function(n){if("NATIVE_EVENT"===n.type){var t=e({event:n.payload.event}),r=a();r&&r(JSON.stringify({type:"NATIVE_EVENT",id:n.id,payload:{action:t.action||"default"}}))}};return u(n),function(){c(n)}},e.reportStatus=function(e){var n=e.feature,t=e.status,r=e.reason;return d({type:"STATUS_REPORT",payload:{feature:n,status:t,reason:r}})},e.requestContact=function(e){var n=(void 0===e?{}:e).filter;return d({type:"GET_CONTACT_DATA",payload:{filter:void 0===n?"phone":n}})},e.requestDeviceImei=function(){return d({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.requestSimIcc=function(){return d({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return d({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},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(r){var o=e.startsWith("/")?e:"/"+e;o!==y?(y=o,t(function(){t.getAll().filter(b).forEach(function(e){e.set("page",o),e.send("pageView",w({},n,{hitCallback:r}))})})):r()})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},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 r,o=h[e];return o?(t("NovumTracker.set",((r={})["dimension"+o]=String(n),r)),Promise.resolve()):(console.warn("No custom dimension defined for user property",e),Promise.resolve())}})):(console.warn("Trying to set analytics user property without name or value",e,n),Promise.resolve())},e.setWebViewTitle=function(e){return l()?f({title:e}):(document.title=e,Promise.resolve())},e.share=function(e){return d({type:"SHARE",payload:e})},e.updateNavigationBar=f,e}({}); | ||
var webviewBridge=function(e){"use strict";var t=1,n=function(){return""+t++},r="__tuenti_webview_bridge",o=function(){return!(!window.tuentiWebView||!window.tuentiWebView.postMessage)},i=function(){return!!(window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.tuentiWebView&&window.webkit.messageHandlers.tuentiWebView.postMessage)},a=function(){return o()?function(e){window.tuentiWebView.postMessage(e)}:i()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null},s=[],u=function(e){s.push(e)},c=function(e){s=s.filter(function(t){return t!==e})},l=function(){return o()||i()},d=function(e,t){var r=e.type,o=e.id,i=void 0===o?n():o,s=e.payload,l=a(),d=JSON.stringify({type:r,id:i,payload:s});return l?(setTimeout(function(){l(d)}),new Promise(function(e,n){var o=!1,a=function(t){t.id!==i||o||(t.type===r?e(t.payload):"ERROR"===t.type?n(t.payload):n({code:500,reason:"bad type: "+t.type+". Expecting "+r}),c(a))};u(a),t&&setTimeout(function(){o=!0,c(a),n({code:408,reason:"request timeout"})},t)})):Promise.reject({code:500,reason:"WebView postMessage not available"})};window[r]=window[r]||{postMessage:function(e){var t;try{t=JSON.parse(e)}catch(t){throw Error("Problem parsing webview message: "+e)}s.forEach(function(e){return e(t)})}};var f=function(e){var t=e.title,n=e.showBackButton,r=e.showReloadButton,o=e.backgroundColor;return l()?d({type:"NAVIGATION_BAR",payload:{title:t,showBackButton:n,showReloadButton:r,backgroundColor:o}}):(void 0!==t&&(document.title=t),Promise.resolve())},m=null,v=function(e){return"true"===m.result[e]},p=function(e){return Math.floor(e/1e3)},y=function(){return(y=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var w,g=["NovumTracker","OBARGTracker"],b=function(e){return g.indexOf(e.get("name"))>=0},T=function(e){var t=e.onAndroid,n=e.onIos,r=e.onWeb;return window.AnalyticsWebInterface?t(window.AnalyticsWebInterface):window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.firebase?n(window.webkit.messageHandlers.firebase):window.ga&&window.ga.loaded?r(window.ga):Promise.resolve()},E={obIds:1,paymentModels:2,serviceWorkerStatus:3,isAdmin:5,hasIpComms:6,af_source:9,af_campaign:10,novum_uid_session:11,user_logged:12,currentSubscriptionId:13,currentSubscriptionType:14,currentPaymentModel:15,webviewBrowserVersion:16};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,r=e.fileName,o=e.recipient,i=e.body;return d({type:"ATTACH_TO_EMAIL",payload:{url:t,subject:n,fileName:r,recipient:o,body:i}})},e.checkPermissionStatus=function(e,t){return d({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,r=e.title;return d({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:p(t),endTime:p(n),title:r}})},e.fetch=function(e){var t=e.url,n=e.method,r=e.headers,o=e.body;return l()?d({type:"FETCH",payload:{url:t,method:n,headers:r,body:o}}).catch(function(){return{status:500,headers:{},body:"Bridge call failed"}}):Promise.resolve({status:500,headers:{},body:"Bridge not available"})},e.internalNavigation=function(e){return d({type:"INTERNAL_NAVIGATION",payload:{feature:e}})},e.isABTestingAvailable=function(e){if(m)return Promise.resolve(v(e));var t=new Promise(function(e){setTimeout(function(){e(!1)},500)}),n=d({type:"GET_REMOTE_CONFIG"}).then(function(t){return m=t,v(e)});return Promise.race([t,n])},e.isWebViewBridgeAvailable=l,e.logEvent=function(e){var t=e.category,n=e.action,r=e.label,o=e.value,i=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(e,["category","action","label","value"]);if(!t||!n)return console.warn('Analytics event should have "category" and "action"',{category:t,action:n}),Promise.resolve();var a=t;r||(r="null_label"),o||(o=0);var s=y({eventCategory:t,eventAction:n,eventLabel:r,eventValue:o},i);return T({onAndroid:function(e){return e.logEvent&&e.logEvent(a,JSON.stringify(s)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:a,parameters:s}),Promise.resolve()},onWeb:function(e){return new Promise(function(t){e("NovumTracker.send","event",y(y({},s),{hitCallback:t}))})}})},e.logTiming=function(e){var t=e.category,n=void 0===t?"performance_timer":t,r=e.variable,o=e.value,i=e.label;if(!n||!r||!o)return console.warn('Analytics timing should have "category", "variable" and "value"',{category:n,variable:r,value:o}),Promise.resolve();var a={timingCategory:n,timingVar:r,timingValue:o,timingLabel:i},s=n;return T({onAndroid:function(e){return e.logEvent&&e.logEvent(s,JSON.stringify(a)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:s,parameters:a}),Promise.resolve()},onWeb:function(e){return new Promise(function(t){var n;e("NovumTracker.send",y(((n={hitType:"timing",hitCallback:t}).dimension8=String(o),n),a))})}})},e.nativeAlert=function(e){var t=e.message,n=e.title,r=e.buttonText;return l()?d({type:"ALERT",payload:{title:n,message:t,buttonText:r}}):(window.alert(t),Promise.resolve())},e.nativeConfirm=function(e){var t=e.message,n=e.title,r=e.acceptText,o=e.cancelText;return l()?d({type:"CONFIRM",payload:{message:t,title:n,acceptText:r,cancelText:o}}).then(function(e){return e.result}):Promise.resolve(window.confirm(t))},e.nativeMessage=function(e){var t=e.message,n=e.duration,r=e.buttonText,o=e.type;return l()?d({type:"MESSAGE",payload:{message:t,duration:n,buttonText:r,type:o}}):(window.alert(t),Promise.resolve())},e.notifyPageLoaded=function(){return d({type:"PAGE_LOADED"})},e.onNativeEvent=function(e){var t=function(t){if("NATIVE_EVENT"===t.type){var n=e({event:t.payload.event}),r=a();r&&r(JSON.stringify({type:"NATIVE_EVENT",id:t.id,payload:{action:n.action||"default"}}))}};return u(t),function(){c(t)}},e.reportStatus=function(e){var t=e.feature,n=e.status,r=e.reason;return d({type:"STATUS_REPORT",payload:{feature:t,status:n,reason:r}})},e.requestContact=function(e){var t=(void 0===e?{}:e).filter;return d({type:"GET_CONTACT_DATA",payload:{filter:void 0===t?"phone":t}})},e.requestDeviceImei=function(){return d({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.requestSimIcc=function(){return d({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return d({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},e.setScreenName=function(e,t){return e?T({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(n){return new Promise(function(r){var o=e.startsWith("/")?e:"/"+e;o!==w?(w=o,n(function(){n.getAll().filter(b).forEach(function(e){e.set("page",o),e.send("pageView",y(y({},t),{hitCallback:r}))})})):r()})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setUserProperty=function(e,t){return e&&t?(t=String(t),T({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 r,o=E[e];return o?(n("NovumTracker.set",((r={})["dimension"+o]=String(t),r)),Promise.resolve()):(console.warn("No custom dimension defined for user property",e),Promise.resolve())}})):(console.warn("Trying to set analytics user property without name or value",e,t),Promise.resolve())},e.setWebViewTitle=function(e){return l()?f({title:e}):(document.title=e,Promise.resolve())},e.share=function(e){return d({type:"SHARE",payload:e})},e.updateNavigationBar=f,e}({}); |
@@ -203,2 +203,10 @@ (function (global, factory) { | ||
}; | ||
var internalNavigation = function (feature) { | ||
return postMessageToNativeApp({ | ||
type: 'INTERNAL_NAVIGATION', | ||
payload: { | ||
feature: feature, | ||
}, | ||
}); | ||
}; | ||
@@ -302,2 +310,14 @@ var attachToEmail = function (_a) { | ||
}; | ||
var checkPermissionStatus = function (feature, params) { | ||
return postMessageToNativeApp({ | ||
type: 'OS_PERMISSION_STATUS', | ||
payload: { | ||
feature: feature, | ||
params: params, | ||
}, | ||
}).then(function (_a) { | ||
var granted = _a.granted; | ||
return granted; | ||
}); | ||
}; | ||
@@ -353,4 +373,6 @@ var msToS = function (ms) { return Math.floor(ms / 1000); }; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
@@ -436,3 +458,3 @@ } | ||
return new Promise(function (resolve) { | ||
ga('NovumTracker.send', 'event', __assign({}, params, { hitCallback: resolve })); | ||
ga('NovumTracker.send', 'event', __assign(__assign({}, params), { hitCallback: resolve })); | ||
}); | ||
@@ -511,3 +533,3 @@ }, | ||
tracker.set('page', pageName); | ||
tracker.send('pageView', __assign({}, fieldsObject, { hitCallback: resolve })); | ||
tracker.send('pageView', __assign(__assign({}, fieldsObject), { hitCallback: resolve })); | ||
}); | ||
@@ -578,4 +600,6 @@ }); | ||
exports.attachToEmail = attachToEmail; | ||
exports.checkPermissionStatus = checkPermissionStatus; | ||
exports.createCalendarEvent = createCalendarEvent; | ||
exports.fetch = fetch; | ||
exports.internalNavigation = internalNavigation; | ||
exports.isABTestingAvailable = isABTestingAvailable; | ||
@@ -582,0 +606,0 @@ exports.isWebViewBridgeAvailable = isWebViewBridgeAvailable; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).webviewBridge={})}(this,function(e){"use strict";var t=1,n=function(){return""+t++},r="__tuenti_webview_bridge",o=function(){return!(!window.tuentiWebView||!window.tuentiWebView.postMessage)},i=function(){return!!(window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.tuentiWebView&&window.webkit.messageHandlers.tuentiWebView.postMessage)},a=function(){return o()?function(e){window.tuentiWebView.postMessage(e)}:i()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null},s=[],u=function(e){s.push(e)},c=function(e){s=s.filter(function(t){return t!==e})},l=function(){return o()||i()},d=function(e,t){var r=e.type,o=e.id,i=void 0===o?n():o,s=e.payload,l=a(),d=JSON.stringify({type:r,id:i,payload:s});return l?(setTimeout(function(){l(d)}),new Promise(function(e,n){var o=!1,a=function(t){t.id!==i||o||(t.type===r?e(t.payload):"ERROR"===t.type?n(t.payload):n({code:500,reason:"bad type: "+t.type+". Expecting "+r}),c(a))};u(a),t&&setTimeout(function(){o=!0,c(a),n({code:408,reason:"request timeout"})},t)})):Promise.reject({code:500,reason:"WebView postMessage not available"})};window[r]=window[r]||{postMessage:function(e){var t;try{t=JSON.parse(e)}catch(t){throw Error("Problem parsing webview message: "+e)}s.forEach(function(e){return e(t)})}};var f=function(e){var t=e.title,n=e.showBackButton,r=e.showReloadButton,o=e.backgroundColor;return l()?d({type:"NAVIGATION_BAR",payload:{title:t,showBackButton:n,showReloadButton:r,backgroundColor:o}}):(void 0!==t&&(document.title=t),Promise.resolve())},m=null,v=function(e){return"true"===m.result[e]},p=function(e){return Math.floor(e/1e3)},y=function(){return(y=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var w,g=["NovumTracker","OBARGTracker"],b=function(e){return g.indexOf(e.get("name"))>=0},T=function(e){var t=e.onAndroid,n=e.onIos,r=e.onWeb;return window.AnalyticsWebInterface?t(window.AnalyticsWebInterface):window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.firebase?n(window.webkit.messageHandlers.firebase):window.ga&&window.ga.loaded?r(window.ga):Promise.resolve()},h={obIds:1,paymentModels:2,serviceWorkerStatus:3,isAdmin:5,hasIpComms:6,af_source:9,af_campaign:10,novum_uid_session:11,user_logged:12,currentSubscriptionId:13,currentSubscriptionType:14,currentPaymentModel:15,webviewBrowserVersion:16};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,r=e.fileName,o=e.recipient,i=e.body;return d({type:"ATTACH_TO_EMAIL",payload:{url:t,subject:n,fileName:r,recipient:o,body:i}})},e.createCalendarEvent=function(e){var t=e.beginTime,n=e.endTime,r=e.title;return d({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:p(t),endTime:p(n),title:r}})},e.fetch=function(e){var t=e.url,n=e.method,r=e.headers,o=e.body;return l()?d({type:"FETCH",payload:{url:t,method:n,headers:r,body:o}}).catch(function(){return{status:500,headers:{},body:"Bridge call failed"}}):Promise.resolve({status:500,headers:{},body:"Bridge not available"})},e.isABTestingAvailable=function(e){if(m)return Promise.resolve(v(e));var t=new Promise(function(e){setTimeout(function(){e(!1)},500)}),n=d({type:"GET_REMOTE_CONFIG"}).then(function(t){return m=t,v(e)});return Promise.race([t,n])},e.isWebViewBridgeAvailable=l,e.logEvent=function(e){var t=e.category,n=e.action,r=e.label,o=e.value,i=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&(n[r[o]]=e[r[o]])}return n}(e,["category","action","label","value"]);if(!t||!n)return console.warn('Analytics event should have "category" and "action"',{category:t,action:n}),Promise.resolve();var a=t;r||(r="null_label"),o||(o=0);var s=y({eventCategory:t,eventAction:n,eventLabel:r,eventValue:o},i);return T({onAndroid:function(e){return e.logEvent&&e.logEvent(a,JSON.stringify(s)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:a,parameters:s}),Promise.resolve()},onWeb:function(e){return new Promise(function(t){e("NovumTracker.send","event",y({},s,{hitCallback:t}))})}})},e.logTiming=function(e){var t=e.category,n=void 0===t?"performance_timer":t,r=e.variable,o=e.value,i=e.label;if(!n||!r||!o)return console.warn('Analytics timing should have "category", "variable" and "value"',{category:n,variable:r,value:o}),Promise.resolve();var a={timingCategory:n,timingVar:r,timingValue:o,timingLabel:i},s=n;return T({onAndroid:function(e){return e.logEvent&&e.logEvent(s,JSON.stringify(a)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:s,parameters:a}),Promise.resolve()},onWeb:function(e){return new Promise(function(t){var n;e("NovumTracker.send",y(((n={hitType:"timing",hitCallback:t}).dimension8=String(o),n),a))})}})},e.nativeAlert=function(e){var t=e.message,n=e.title,r=e.buttonText;return l()?d({type:"ALERT",payload:{title:n,message:t,buttonText:r}}):(window.alert(t),Promise.resolve())},e.nativeConfirm=function(e){var t=e.message,n=e.title,r=e.acceptText,o=e.cancelText;return l()?d({type:"CONFIRM",payload:{message:t,title:n,acceptText:r,cancelText:o}}).then(function(e){return e.result}):Promise.resolve(window.confirm(t))},e.nativeMessage=function(e){var t=e.message,n=e.duration,r=e.buttonText,o=e.type;return l()?d({type:"MESSAGE",payload:{message:t,duration:n,buttonText:r,type:o}}):(window.alert(t),Promise.resolve())},e.notifyPageLoaded=function(){return d({type:"PAGE_LOADED"})},e.onNativeEvent=function(e){var t=function(t){if("NATIVE_EVENT"===t.type){var n=e({event:t.payload.event}),r=a();r&&r(JSON.stringify({type:"NATIVE_EVENT",id:t.id,payload:{action:n.action||"default"}}))}};return u(t),function(){c(t)}},e.reportStatus=function(e){var t=e.feature,n=e.status,r=e.reason;return d({type:"STATUS_REPORT",payload:{feature:t,status:n,reason:r}})},e.requestContact=function(e){var t=(void 0===e?{}:e).filter;return d({type:"GET_CONTACT_DATA",payload:{filter:void 0===t?"phone":t}})},e.requestDeviceImei=function(){return d({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.requestSimIcc=function(){return d({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return d({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},e.setScreenName=function(e,t){return e?T({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(n){return new Promise(function(r){var o=e.startsWith("/")?e:"/"+e;o!==w?(w=o,n(function(){n.getAll().filter(b).forEach(function(e){e.set("page",o),e.send("pageView",y({},t,{hitCallback:r}))})})):r()})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setUserProperty=function(e,t){return e&&t?(t=String(t),T({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 r,o=h[e];return o?(n("NovumTracker.set",((r={})["dimension"+o]=String(t),r)),Promise.resolve()):(console.warn("No custom dimension defined for user property",e),Promise.resolve())}})):(console.warn("Trying to set analytics user property without name or value",e,t),Promise.resolve())},e.setWebViewTitle=function(e){return l()?f({title:e}):(document.title=e,Promise.resolve())},e.share=function(e){return d({type:"SHARE",payload:e})},e.updateNavigationBar=f,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=e||self).webviewBridge={})}(this,function(e){"use strict";var t=1,n=function(){return""+t++},r="__tuenti_webview_bridge",o=function(){return!(!window.tuentiWebView||!window.tuentiWebView.postMessage)},i=function(){return!!(window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.tuentiWebView&&window.webkit.messageHandlers.tuentiWebView.postMessage)},a=function(){return o()?function(e){window.tuentiWebView.postMessage(e)}:i()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null},s=[],u=function(e){s.push(e)},c=function(e){s=s.filter(function(t){return t!==e})},l=function(){return o()||i()},d=function(e,t){var r=e.type,o=e.id,i=void 0===o?n():o,s=e.payload,l=a(),d=JSON.stringify({type:r,id:i,payload:s});return l?(setTimeout(function(){l(d)}),new Promise(function(e,n){var o=!1,a=function(t){t.id!==i||o||(t.type===r?e(t.payload):"ERROR"===t.type?n(t.payload):n({code:500,reason:"bad type: "+t.type+". Expecting "+r}),c(a))};u(a),t&&setTimeout(function(){o=!0,c(a),n({code:408,reason:"request timeout"})},t)})):Promise.reject({code:500,reason:"WebView postMessage not available"})};window[r]=window[r]||{postMessage:function(e){var t;try{t=JSON.parse(e)}catch(t){throw Error("Problem parsing webview message: "+e)}s.forEach(function(e){return e(t)})}};var f=function(e){var t=e.title,n=e.showBackButton,r=e.showReloadButton,o=e.backgroundColor;return l()?d({type:"NAVIGATION_BAR",payload:{title:t,showBackButton:n,showReloadButton:r,backgroundColor:o}}):(void 0!==t&&(document.title=t),Promise.resolve())},m=null,v=function(e){return"true"===m.result[e]},p=function(e){return Math.floor(e/1e3)},y=function(){return(y=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var w,g=["NovumTracker","OBARGTracker"],b=function(e){return g.indexOf(e.get("name"))>=0},T=function(e){var t=e.onAndroid,n=e.onIos,r=e.onWeb;return window.AnalyticsWebInterface?t(window.AnalyticsWebInterface):window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.firebase?n(window.webkit.messageHandlers.firebase):window.ga&&window.ga.loaded?r(window.ga):Promise.resolve()},h={obIds:1,paymentModels:2,serviceWorkerStatus:3,isAdmin:5,hasIpComms:6,af_source:9,af_campaign:10,novum_uid_session:11,user_logged:12,currentSubscriptionId:13,currentSubscriptionType:14,currentPaymentModel:15,webviewBrowserVersion:16};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,r=e.fileName,o=e.recipient,i=e.body;return d({type:"ATTACH_TO_EMAIL",payload:{url:t,subject:n,fileName:r,recipient:o,body:i}})},e.checkPermissionStatus=function(e,t){return d({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,r=e.title;return d({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:p(t),endTime:p(n),title:r}})},e.fetch=function(e){var t=e.url,n=e.method,r=e.headers,o=e.body;return l()?d({type:"FETCH",payload:{url:t,method:n,headers:r,body:o}}).catch(function(){return{status:500,headers:{},body:"Bridge call failed"}}):Promise.resolve({status:500,headers:{},body:"Bridge not available"})},e.internalNavigation=function(e){return d({type:"INTERNAL_NAVIGATION",payload:{feature:e}})},e.isABTestingAvailable=function(e){if(m)return Promise.resolve(v(e));var t=new Promise(function(e){setTimeout(function(){e(!1)},500)}),n=d({type:"GET_REMOTE_CONFIG"}).then(function(t){return m=t,v(e)});return Promise.race([t,n])},e.isWebViewBridgeAvailable=l,e.logEvent=function(e){var t=e.category,n=e.action,r=e.label,o=e.value,i=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(e,["category","action","label","value"]);if(!t||!n)return console.warn('Analytics event should have "category" and "action"',{category:t,action:n}),Promise.resolve();var a=t;r||(r="null_label"),o||(o=0);var s=y({eventCategory:t,eventAction:n,eventLabel:r,eventValue:o},i);return T({onAndroid:function(e){return e.logEvent&&e.logEvent(a,JSON.stringify(s)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:a,parameters:s}),Promise.resolve()},onWeb:function(e){return new Promise(function(t){e("NovumTracker.send","event",y(y({},s),{hitCallback:t}))})}})},e.logTiming=function(e){var t=e.category,n=void 0===t?"performance_timer":t,r=e.variable,o=e.value,i=e.label;if(!n||!r||!o)return console.warn('Analytics timing should have "category", "variable" and "value"',{category:n,variable:r,value:o}),Promise.resolve();var a={timingCategory:n,timingVar:r,timingValue:o,timingLabel:i},s=n;return T({onAndroid:function(e){return e.logEvent&&e.logEvent(s,JSON.stringify(a)),Promise.resolve()},onIos:function(e){return e.postMessage({command:"logEvent",name:s,parameters:a}),Promise.resolve()},onWeb:function(e){return new Promise(function(t){var n;e("NovumTracker.send",y(((n={hitType:"timing",hitCallback:t}).dimension8=String(o),n),a))})}})},e.nativeAlert=function(e){var t=e.message,n=e.title,r=e.buttonText;return l()?d({type:"ALERT",payload:{title:n,message:t,buttonText:r}}):(window.alert(t),Promise.resolve())},e.nativeConfirm=function(e){var t=e.message,n=e.title,r=e.acceptText,o=e.cancelText;return l()?d({type:"CONFIRM",payload:{message:t,title:n,acceptText:r,cancelText:o}}).then(function(e){return e.result}):Promise.resolve(window.confirm(t))},e.nativeMessage=function(e){var t=e.message,n=e.duration,r=e.buttonText,o=e.type;return l()?d({type:"MESSAGE",payload:{message:t,duration:n,buttonText:r,type:o}}):(window.alert(t),Promise.resolve())},e.notifyPageLoaded=function(){return d({type:"PAGE_LOADED"})},e.onNativeEvent=function(e){var t=function(t){if("NATIVE_EVENT"===t.type){var n=e({event:t.payload.event}),r=a();r&&r(JSON.stringify({type:"NATIVE_EVENT",id:t.id,payload:{action:n.action||"default"}}))}};return u(t),function(){c(t)}},e.reportStatus=function(e){var t=e.feature,n=e.status,r=e.reason;return d({type:"STATUS_REPORT",payload:{feature:t,status:n,reason:r}})},e.requestContact=function(e){var t=(void 0===e?{}:e).filter;return d({type:"GET_CONTACT_DATA",payload:{filter:void 0===t?"phone":t}})},e.requestDeviceImei=function(){return d({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.requestSimIcc=function(){return d({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return d({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},e.setScreenName=function(e,t){return e?T({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(n){return new Promise(function(r){var o=e.startsWith("/")?e:"/"+e;o!==w?(w=o,n(function(){n.getAll().filter(b).forEach(function(e){e.set("page",o),e.send("pageView",y(y({},t),{hitCallback:r}))})})):r()})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setUserProperty=function(e,t){return e&&t?(t=String(t),T({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 r,o=h[e];return o?(n("NovumTracker.set",((r={})["dimension"+o]=String(t),r)),Promise.resolve()):(console.warn("No custom dimension defined for user property",e),Promise.resolve())}})):(console.warn("Trying to set analytics user property without name or value",e,t),Promise.resolve())},e.setWebViewTitle=function(e){return l()?f({title:e}):(document.title=e,Promise.resolve())},e.share=function(e){return d({type:"SHARE",payload:e})},e.updateNavigationBar=f,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "@tef-novum/webview-bridge", | ||
"version": "2.3.4", | ||
"version": "2.4.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", |
@@ -69,3 +69,3 @@ <p align="center"> | ||
- [share](#share) | ||
- [setWebViewTitle](#setwebviewtitle) | ||
- [updateNavigationBar](#updateNavigationBar) | ||
- [nativeConfirm](#nativeconfirm) | ||
@@ -226,17 +226,41 @@ - [nativeAlert](#nativealert) | ||
### setWebViewTitle | ||
### updateNavigationBar | ||
Update webview title. If the bridge is not present, automatically fallbacks to a | ||
`document.title` update. | ||
Customize WebView NavigationBar properties | ||
- You can set one or more properties in a single call | ||
- Available for app versions 10.7 and higher | ||
- Returning promise will be rejected if not supported (app versions lower than | ||
10.7) | ||
```typescript | ||
setWebViewTitle: (title: string) => Promise<void>; | ||
updateNavigationBar = ({ | ||
title?: string; | ||
showBackButton?: boolean; | ||
showReloadButton?: boolean; | ||
backgroundColor?: string; | ||
}) => Promise<void> | ||
``` | ||
#### Example | ||
- `title`: updates NavigationBar title | ||
- `showBackButton`: shows or hides NavigationBar Back button | ||
- `showReloadButton`: shows or hides NavigationBar Reload button | ||
- `backgroundColor`: change NavigationBar background color, use a hex color | ||
string (for example: `'#FF128A'`) | ||
#### Examples | ||
```javascript | ||
import {setWebViewTitle} from '@tef-novum/webview-bridge'; | ||
import {updateNavigationBar} from '@tef-novum/webview-bridge'; | ||
setWebViewTitle('My new title'); | ||
// updates WebView NavigationBar title | ||
updateNavigationBar({title: 'Hello, World!'}); | ||
// full featured example | ||
updateNavigationBar({ | ||
title: 'Hello', | ||
showBackButton: true, | ||
showReloadButton: false, | ||
backgroundColor: '#FF0000', // red | ||
}); | ||
``` | ||
@@ -459,2 +483,51 @@ | ||
### checkPermissionStatus | ||
Returns true if the app has the specific notifications permissions. You have to | ||
pass feature and required params for this request. | ||
- Available for app versions 11.4 and higher | ||
Avalaible features: | ||
- `notifications` | ||
```typescript | ||
checkPermissionStatus: (feature: string, params?: {[key: string]: string},) => Promise<boolean>; | ||
``` | ||
#### Example | ||
```javascript | ||
import {checkPermissionStatus} from '@tef-novum/webview-bridge'; | ||
checkPermissionStatus('notifications', {channelId: 'default'}).then( | ||
hasPermissions => { | ||
console.log(hasPermissions); | ||
}, | ||
); | ||
``` | ||
### internalNavigation | ||
Init an internal and native navigation to a device specific feature | ||
- Available for app versions 11.4 and higher | ||
Avalaible features: | ||
- `notification-settings` | ||
```typescript | ||
internalNavigation: (feature: string) => Promise<void>; | ||
``` | ||
#### Example | ||
```javascript | ||
import {internalNavigation} from '@tef-novum/webview-bridge'; | ||
internalNavigation('notification-settings'); | ||
``` | ||
## Error handling | ||
@@ -461,0 +534,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
542
2124823
36
3285