Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tef-novum/webview-bridge

Package Overview
Dependencies
Maintainers
3
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tef-novum/webview-bridge - npm Package Compare versions

Comparing version 2.2.0-beta.0 to 2.2.0-beta.1

3

.vscode/settings.json
{
"javascript.validate.enable": false,
"eslint.validate": ["typescript"],
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"editor.formatOnSave": true
}
# CHANGELOG
## v.2.2.0 - 2019-09.04
- New function: `onNativeEvent`
## v.2.1.0 - 2019-07-31

@@ -4,0 +8,0 @@

@@ -1,2 +0,2 @@

export { isWebViewBridgeAvailable, onEvent } from './src/post-message';
export { isWebViewBridgeAvailable, onNativeEvent, NativeEventHandler, } from './src/post-message';
export { nativeConfirm, nativeAlert, nativeMessage } from './src/dialogs';

@@ -3,0 +3,0 @@ export { requestSimIcc, requestSimImsi, requestDeviceImei } from './src/device';

@@ -9,3 +9,3 @@ /**

EVENT: {
type: 'EVENT';
type: 'NATIVE_EVENT';
id: string;

@@ -129,3 +129,3 @@ payload: {

*/
export declare const postMessageToNativeApp: <T extends "EVENT" | "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">({ 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" | "EVENT">({ type, id, payload }: {
type: T;

@@ -135,3 +135,3 @@ id?: string | undefined;

}, timeout?: number | undefined) => Promise<IncomingMessageMap[T]["payload"]>;
export declare type EventHandler = ({ event }: {
export declare type NativeEventHandler = ({ event, }: {
event: string;

@@ -141,3 +141,3 @@ }) => {

};
export declare const onEvent: (handler: EventHandler) => () => void;
export declare const onNativeEvent: (handler: NativeEventHandler) => () => void;
export {};

@@ -108,19 +108,12 @@ define(['exports'], function (exports) { 'use strict';

};
var onEvent = function (handler) {
var onNativeEvent = function (handler) {
var listener = function (message) {
if (message.type === 'EVENT') {
if (message.type === 'NATIVE_EVENT') {
var response = handler({
event: message.payload.event,
});
console.log({
type: 'EVENT',
id: message.id,
payload: {
action: response.action || 'default',
},
});
var postMessage_1 = getWebViewPostMessage();
if (postMessage_1) {
postMessage_1(JSON.stringify({
type: 'EVENT',
type: 'NATIVE_EVENT',
id: message.id,

@@ -559,3 +552,3 @@ payload: {

exports.notifyPageLoaded = notifyPageLoaded;
exports.onEvent = onEvent;
exports.onNativeEvent = onNativeEvent;
exports.reportStatus = reportStatus;

@@ -562,0 +555,0 @@ exports.requestContact = requestContact;

@@ -110,19 +110,12 @@ 'use strict';

};
var onEvent = function (handler) {
var onNativeEvent = function (handler) {
var listener = function (message) {
if (message.type === 'EVENT') {
if (message.type === 'NATIVE_EVENT') {
var response = handler({
event: message.payload.event,
});
console.log({
type: 'EVENT',
id: message.id,
payload: {
action: response.action || 'default',
},
});
var postMessage_1 = getWebViewPostMessage();
if (postMessage_1) {
postMessage_1(JSON.stringify({
type: 'EVENT',
type: 'NATIVE_EVENT',
id: message.id,

@@ -561,3 +554,3 @@ payload: {

exports.notifyPageLoaded = notifyPageLoaded;
exports.onEvent = onEvent;
exports.onNativeEvent = onNativeEvent;
exports.reportStatus = reportStatus;

@@ -564,0 +557,0 @@ exports.requestContact = requestContact;

@@ -109,19 +109,12 @@ var webviewBridge = (function (exports) {

};
var onEvent = function (handler) {
var onNativeEvent = function (handler) {
var listener = function (message) {
if (message.type === 'EVENT') {
if (message.type === 'NATIVE_EVENT') {
var response = handler({
event: message.payload.event,
});
console.log({
type: 'EVENT',
id: message.id,
payload: {
action: response.action || 'default',
},
});
var postMessage_1 = getWebViewPostMessage();
if (postMessage_1) {
postMessage_1(JSON.stringify({
type: 'EVENT',
type: 'NATIVE_EVENT',
id: message.id,

@@ -560,3 +553,3 @@ payload: {

exports.notifyPageLoaded = notifyPageLoaded;
exports.onEvent = onEvent;
exports.onNativeEvent = onNativeEvent;
exports.reportStatus = reportStatus;

@@ -563,0 +556,0 @@ exports.requestContact = requestContact;

@@ -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();if(!l)return Promise.reject({code:500,reason:"WebView postMessage not available"});var d=JSON.stringify({type:r,id:i,payload:s});return 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)})};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=null,m=function(e){return"true"===f.result[e]},v=function(e){return Math.floor(e/1e3)},p=function(){return(p=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 w,y=["NovumTracker","OBARGTracker"],g=function(e){return y.indexOf(e.get("name"))>=0},b=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()},T={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:v(n),endTime:v(t),title:r}})},e.isABTestingAvailable=function(e){return f?Promise.resolve(m(e)):d({type:"GET_REMOTE_CONFIG"}).then(function(n){return f=n,m(e)})},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=p({eventCategory:n,eventAction:t,eventLabel:r,eventValue:o},i);return b({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",p({},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 b({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",p(((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.onEvent=function(e){var n=function(n){if("EVENT"===n.type){var t=e({event:n.payload.event});console.log({type:"EVENT",id:n.id,payload:{action:t.action||"default"}});var r=a();r&&r(JSON.stringify({type:"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?b({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!==w?(w=o,t(function(){t.getAll().filter(g).forEach(function(e){e.set("page",o),e.send("pageView",p({},n,{hitCallback:r}))})})):r()})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setUserProperty=function(e,n){return e&&n?(n=String(n),b({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=T[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()?d({type:"SET_TITLE",payload:{title:e}}):(document.title=e,Promise.resolve())},e.share=function(e){return d({type:"SHARE",payload:e})},e.updateNavigationBar=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())},e}({});
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();if(!l)return Promise.reject({code:500,reason:"WebView postMessage not available"});var d=JSON.stringify({type:r,id:i,payload:s});return 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)})};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=null,m=function(e){return"true"===f.result[e]},v=function(e){return Math.floor(e/1e3)},p=function(){return(p=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 w,g=["NovumTracker","OBARGTracker"],y=function(e){return g.indexOf(e.get("name"))>=0},b=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()},T={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:v(n),endTime:v(t),title:r}})},e.isABTestingAvailable=function(e){return f?Promise.resolve(m(e)):d({type:"GET_REMOTE_CONFIG"}).then(function(n){return f=n,m(e)})},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=p({eventCategory:n,eventAction:t,eventLabel:r,eventValue:o},i);return b({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",p({},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 b({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",p(((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?b({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!==w?(w=o,t(function(){t.getAll().filter(y).forEach(function(e){e.set("page",o),e.send("pageView",p({},n,{hitCallback:r}))})})):r()})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setUserProperty=function(e,n){return e&&n?(n=String(n),b({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=T[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()?d({type:"SET_TITLE",payload:{title:e}}):(document.title=e,Promise.resolve())},e.share=function(e){return d({type:"SHARE",payload:e})},e.updateNavigationBar=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())},e}({});

@@ -112,19 +112,12 @@ (function (global, factory) {

};
var onEvent = function (handler) {
var onNativeEvent = function (handler) {
var listener = function (message) {
if (message.type === 'EVENT') {
if (message.type === 'NATIVE_EVENT') {
var response = handler({
event: message.payload.event,
});
console.log({
type: 'EVENT',
id: message.id,
payload: {
action: response.action || 'default',
},
});
var postMessage_1 = getWebViewPostMessage();
if (postMessage_1) {
postMessage_1(JSON.stringify({
type: 'EVENT',
type: 'NATIVE_EVENT',
id: message.id,

@@ -563,3 +556,3 @@ payload: {

exports.notifyPageLoaded = notifyPageLoaded;
exports.onEvent = onEvent;
exports.onNativeEvent = onNativeEvent;
exports.reportStatus = reportStatus;

@@ -566,0 +559,0 @@ exports.requestContact = requestContact;

@@ -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=e||self).webviewBridge={})}(this,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();if(!l)return Promise.reject({code:500,reason:"WebView postMessage not available"});var d=JSON.stringify({type:r,id:i,payload:s});return 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)})};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=null,m=function(e){return"true"===f.result[e]},v=function(e){return Math.floor(e/1e3)},p=function(){return(p=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 w,y=["NovumTracker","OBARGTracker"],g=function(e){return y.indexOf(e.get("name"))>=0},b=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()},T={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 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:v(n),endTime:v(t),title:r}})},e.isABTestingAvailable=function(e){return f?Promise.resolve(m(e)):d({type:"GET_REMOTE_CONFIG"}).then(function(n){return f=n,m(e)})},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=p({eventCategory:n,eventAction:t,eventLabel:r,eventValue:o},i);return b({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",p({},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 b({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",p(((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.onEvent=function(e){var n=function(n){if("EVENT"===n.type){var t=e({event:n.payload.event});console.log({type:"EVENT",id:n.id,payload:{action:t.action||"default"}});var r=a();r&&r(JSON.stringify({type:"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?b({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!==w?(w=o,t(function(){t.getAll().filter(g).forEach(function(e){e.set("page",o),e.send("pageView",p({},n,{hitCallback:r}))})})):r()})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setUserProperty=function(e,n){return e&&n?(n=String(n),b({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=T[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()?d({type:"SET_TITLE",payload:{title:e}}):(document.title=e,Promise.resolve())},e.share=function(e){return d({type:"SHARE",payload:e})},e.updateNavigationBar=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())},Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).webviewBridge={})}(this,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();if(!l)return Promise.reject({code:500,reason:"WebView postMessage not available"});var d=JSON.stringify({type:r,id:i,payload:s});return 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)})};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=null,m=function(e){return"true"===f.result[e]},v=function(e){return Math.floor(e/1e3)},p=function(){return(p=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 w,y=["NovumTracker","OBARGTracker"],g=function(e){return y.indexOf(e.get("name"))>=0},b=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()},T={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 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:v(n),endTime:v(t),title:r}})},e.isABTestingAvailable=function(e){return f?Promise.resolve(m(e)):d({type:"GET_REMOTE_CONFIG"}).then(function(n){return f=n,m(e)})},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=p({eventCategory:n,eventAction:t,eventLabel:r,eventValue:o},i);return b({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",p({},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 b({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",p(((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?b({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!==w?(w=o,t(function(){t.getAll().filter(g).forEach(function(e){e.set("page",o),e.send("pageView",p({},n,{hitCallback:r}))})})):r()})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setUserProperty=function(e,n){return e&&n?(n=String(n),b({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=T[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()?d({type:"SET_TITLE",payload:{title:e}}):(document.title=e,Promise.resolve())},e.share=function(e){return d({type:"SHARE",payload:e})},e.updateNavigationBar=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())},Object.defineProperty(e,"__esModule",{value:!0})});
{
"name": "@tef-novum/webview-bridge",
"version": "2.2.0-beta.0",
"version": "2.2.0-beta.1",
"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",

@@ -411,2 +411,30 @@ <p align="center">

### onNativeEvent
Listens to native app events
- Available for app versions 11.3 and higher
```typescript
type NativeEventHandler = ({ event }: {event: string}) => {action: 'default'};
onNativeEvent: (handler: NativeEventHandler) => () => void;
```
#### Example
```typescript
onNativeEvent(({event}) => {
if (event === 'tappedNavigationBarBackButton') {
// do something
}
return {action: 'default'};
});
```
#### Available events
- `tappedNavigationBarBackButton`: fired when the user taps on the back button
of the native Navigation Bar. Allowed response actions: `default`
## Error handling

@@ -413,0 +441,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc