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
2
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 1.0.6 to 1.1.0

dist/webview-bridge-cjs.js.flow

2

dist/index.d.ts

@@ -7,2 +7,2 @@ export { isWebViewBridgeAvailable } from './src/post-message';

export { requestContact } from './src/contacts';
export { logEvent, setScreenName } from './src/analytics';
export { logEvent, logTiming, setScreenName, setUserProperty, CD_WEBAPP_INSTALLED, CD_NOVUM_UID, CD_EVENT_VALUE, } from './src/analytics';

@@ -252,2 +252,10 @@ define(['exports'], function (exports) { 'use strict';

// Google Analytics custom dimension indices.
var CD_OB_IDS = 1; // from sessionInfo
var CD_PAYMENT_MODELS = 2; // from sessionInfo
var CD_SERVICE_WORKER_STATUS = 3;
var CD_WEBAPP_INSTALLED = 4;
var CD_SUBSCRIPTION_ADMIN = 5; // from sessionInfo
var CD_SUBSCRIPTION_WITH_IPCOMMS = 6; // from sessionInfo
var CD_NOVUM_UID = 7;
var CD_EVENT_VALUE = 8;
var withAnalytics = function (_a) {

@@ -307,2 +315,38 @@ var onAndroid = _a.onAndroid, onIos = _a.onIos, onWeb = _a.onWeb;

};
var logTiming = function (_a) {
var _b = _a.category, category = _b === void 0 ? 'performance_timer' : _b, variable = _a.variable, value = _a.value, label = _a.label;
if (!category || !variable || !value) {
console.warn('Analytics timing should have "category", "variable" and "value"', { category: category, variable: variable, value: value });
return Promise.resolve();
}
var params = {
timingCategory: category,
timingVar: variable,
timingValue: value,
timingLabel: label,
};
var name = category;
return withAnalytics({
onAndroid: function (androidFirebase) {
if (androidFirebase.logEvent) {
androidFirebase.logEvent(name, JSON.stringify(params));
}
return Promise.resolve();
},
onIos: function (iosFirebase) {
iosFirebase.postMessage({
command: 'logEvent',
name: name,
parameters: params,
});
return Promise.resolve();
},
onWeb: function (ga) {
return new Promise(function (resolve) {
var _a;
ga('send', __assign((_a = { hitType: 'timing', hitCallback: resolve }, _a["dimension" + CD_EVENT_VALUE] = String(value), _a), params));
});
},
});
};
var currentPageName;

@@ -324,3 +368,3 @@ var setScreenName = function (screenName, fieldsObject) {

command: 'setScreenName',
screenName: screenName,
name: screenName,
});

@@ -353,2 +397,42 @@ return Promise.resolve();

};
var USER_PROPERTY_TO_CUSTOM_DIMENSION = {
obIds: CD_OB_IDS,
paymentModels: CD_PAYMENT_MODELS,
serviceWorkerStatus: CD_SERVICE_WORKER_STATUS,
isAdmin: CD_SUBSCRIPTION_ADMIN,
hasIpComms: CD_SUBSCRIPTION_WITH_IPCOMMS,
};
var setUserProperty = function (name, value) {
if (!name || !value) {
console.warn('Trying to set analytics user property without name or value', name, value);
return Promise.resolve();
}
value = String(value);
return withAnalytics({
onAndroid: function (androidFirebase) {
if (androidFirebase.setUserProperty) {
androidFirebase.setUserProperty(name, value);
}
return Promise.resolve();
},
onIos: function (iosFirebase) {
iosFirebase.postMessage({
command: 'setUserProperty',
name: name,
value: value,
});
return Promise.resolve();
},
onWeb: function (ga) {
var _a;
var dimensionIdx = USER_PROPERTY_TO_CUSTOM_DIMENSION[name];
if (!dimensionIdx) {
console.warn('No custom dimension defined for user property', name);
return Promise.resolve();
}
ga('set', (_a = {}, _a["dimension" + dimensionIdx] = String(value), _a));
return Promise.resolve();
},
});
};

@@ -368,3 +452,8 @@ exports.isWebViewBridgeAvailable = isWebViewBridgeAvailable;

exports.logEvent = logEvent;
exports.logTiming = logTiming;
exports.setScreenName = setScreenName;
exports.setUserProperty = setUserProperty;
exports.CD_WEBAPP_INSTALLED = CD_WEBAPP_INSTALLED;
exports.CD_NOVUM_UID = CD_NOVUM_UID;
exports.CD_EVENT_VALUE = CD_EVENT_VALUE;

@@ -371,0 +460,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

@@ -254,2 +254,10 @@ 'use strict';

// Google Analytics custom dimension indices.
var CD_OB_IDS = 1; // from sessionInfo
var CD_PAYMENT_MODELS = 2; // from sessionInfo
var CD_SERVICE_WORKER_STATUS = 3;
var CD_WEBAPP_INSTALLED = 4;
var CD_SUBSCRIPTION_ADMIN = 5; // from sessionInfo
var CD_SUBSCRIPTION_WITH_IPCOMMS = 6; // from sessionInfo
var CD_NOVUM_UID = 7;
var CD_EVENT_VALUE = 8;
var withAnalytics = function (_a) {

@@ -309,2 +317,38 @@ var onAndroid = _a.onAndroid, onIos = _a.onIos, onWeb = _a.onWeb;

};
var logTiming = function (_a) {
var _b = _a.category, category = _b === void 0 ? 'performance_timer' : _b, variable = _a.variable, value = _a.value, label = _a.label;
if (!category || !variable || !value) {
console.warn('Analytics timing should have "category", "variable" and "value"', { category: category, variable: variable, value: value });
return Promise.resolve();
}
var params = {
timingCategory: category,
timingVar: variable,
timingValue: value,
timingLabel: label,
};
var name = category;
return withAnalytics({
onAndroid: function (androidFirebase) {
if (androidFirebase.logEvent) {
androidFirebase.logEvent(name, JSON.stringify(params));
}
return Promise.resolve();
},
onIos: function (iosFirebase) {
iosFirebase.postMessage({
command: 'logEvent',
name: name,
parameters: params,
});
return Promise.resolve();
},
onWeb: function (ga) {
return new Promise(function (resolve) {
var _a;
ga('send', __assign((_a = { hitType: 'timing', hitCallback: resolve }, _a["dimension" + CD_EVENT_VALUE] = String(value), _a), params));
});
},
});
};
var currentPageName;

@@ -326,3 +370,3 @@ var setScreenName = function (screenName, fieldsObject) {

command: 'setScreenName',
screenName: screenName,
name: screenName,
});

@@ -355,2 +399,42 @@ return Promise.resolve();

};
var USER_PROPERTY_TO_CUSTOM_DIMENSION = {
obIds: CD_OB_IDS,
paymentModels: CD_PAYMENT_MODELS,
serviceWorkerStatus: CD_SERVICE_WORKER_STATUS,
isAdmin: CD_SUBSCRIPTION_ADMIN,
hasIpComms: CD_SUBSCRIPTION_WITH_IPCOMMS,
};
var setUserProperty = function (name, value) {
if (!name || !value) {
console.warn('Trying to set analytics user property without name or value', name, value);
return Promise.resolve();
}
value = String(value);
return withAnalytics({
onAndroid: function (androidFirebase) {
if (androidFirebase.setUserProperty) {
androidFirebase.setUserProperty(name, value);
}
return Promise.resolve();
},
onIos: function (iosFirebase) {
iosFirebase.postMessage({
command: 'setUserProperty',
name: name,
value: value,
});
return Promise.resolve();
},
onWeb: function (ga) {
var _a;
var dimensionIdx = USER_PROPERTY_TO_CUSTOM_DIMENSION[name];
if (!dimensionIdx) {
console.warn('No custom dimension defined for user property', name);
return Promise.resolve();
}
ga('set', (_a = {}, _a["dimension" + dimensionIdx] = String(value), _a));
return Promise.resolve();
},
});
};

@@ -370,2 +454,7 @@ exports.isWebViewBridgeAvailable = isWebViewBridgeAvailable;

exports.logEvent = logEvent;
exports.logTiming = logTiming;
exports.setScreenName = setScreenName;
exports.setUserProperty = setUserProperty;
exports.CD_WEBAPP_INSTALLED = CD_WEBAPP_INSTALLED;
exports.CD_NOVUM_UID = CD_NOVUM_UID;
exports.CD_EVENT_VALUE = CD_EVENT_VALUE;

@@ -253,2 +253,10 @@ var webviewBridge = (function (exports) {

// Google Analytics custom dimension indices.
var CD_OB_IDS = 1; // from sessionInfo
var CD_PAYMENT_MODELS = 2; // from sessionInfo
var CD_SERVICE_WORKER_STATUS = 3;
var CD_WEBAPP_INSTALLED = 4;
var CD_SUBSCRIPTION_ADMIN = 5; // from sessionInfo
var CD_SUBSCRIPTION_WITH_IPCOMMS = 6; // from sessionInfo
var CD_NOVUM_UID = 7;
var CD_EVENT_VALUE = 8;
var withAnalytics = function (_a) {

@@ -308,2 +316,38 @@ var onAndroid = _a.onAndroid, onIos = _a.onIos, onWeb = _a.onWeb;

};
var logTiming = function (_a) {
var _b = _a.category, category = _b === void 0 ? 'performance_timer' : _b, variable = _a.variable, value = _a.value, label = _a.label;
if (!category || !variable || !value) {
console.warn('Analytics timing should have "category", "variable" and "value"', { category: category, variable: variable, value: value });
return Promise.resolve();
}
var params = {
timingCategory: category,
timingVar: variable,
timingValue: value,
timingLabel: label,
};
var name = category;
return withAnalytics({
onAndroid: function (androidFirebase) {
if (androidFirebase.logEvent) {
androidFirebase.logEvent(name, JSON.stringify(params));
}
return Promise.resolve();
},
onIos: function (iosFirebase) {
iosFirebase.postMessage({
command: 'logEvent',
name: name,
parameters: params,
});
return Promise.resolve();
},
onWeb: function (ga) {
return new Promise(function (resolve) {
var _a;
ga('send', __assign((_a = { hitType: 'timing', hitCallback: resolve }, _a["dimension" + CD_EVENT_VALUE] = String(value), _a), params));
});
},
});
};
var currentPageName;

@@ -325,3 +369,3 @@ var setScreenName = function (screenName, fieldsObject) {

command: 'setScreenName',
screenName: screenName,
name: screenName,
});

@@ -354,2 +398,42 @@ return Promise.resolve();

};
var USER_PROPERTY_TO_CUSTOM_DIMENSION = {
obIds: CD_OB_IDS,
paymentModels: CD_PAYMENT_MODELS,
serviceWorkerStatus: CD_SERVICE_WORKER_STATUS,
isAdmin: CD_SUBSCRIPTION_ADMIN,
hasIpComms: CD_SUBSCRIPTION_WITH_IPCOMMS,
};
var setUserProperty = function (name, value) {
if (!name || !value) {
console.warn('Trying to set analytics user property without name or value', name, value);
return Promise.resolve();
}
value = String(value);
return withAnalytics({
onAndroid: function (androidFirebase) {
if (androidFirebase.setUserProperty) {
androidFirebase.setUserProperty(name, value);
}
return Promise.resolve();
},
onIos: function (iosFirebase) {
iosFirebase.postMessage({
command: 'setUserProperty',
name: name,
value: value,
});
return Promise.resolve();
},
onWeb: function (ga) {
var _a;
var dimensionIdx = USER_PROPERTY_TO_CUSTOM_DIMENSION[name];
if (!dimensionIdx) {
console.warn('No custom dimension defined for user property', name);
return Promise.resolve();
}
ga('set', (_a = {}, _a["dimension" + dimensionIdx] = String(value), _a));
return Promise.resolve();
},
});
};

@@ -369,3 +453,8 @@ exports.isWebViewBridgeAvailable = isWebViewBridgeAvailable;

exports.logEvent = logEvent;
exports.logTiming = logTiming;
exports.setScreenName = setScreenName;
exports.setUserProperty = setUserProperty;
exports.CD_WEBAPP_INSTALLED = CD_WEBAPP_INSTALLED;
exports.CD_NOVUM_UID = CD_NOVUM_UID;
exports.CD_EVENT_VALUE = CD_EVENT_VALUE;

@@ -372,0 +461,0 @@ return exports;

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

var webviewBridge=function(e){"use strict";var t=1,n=function(){return""+t++},r="__tuenti_webview_bridge",i=function(){return!(!window.tuentiWebView||!window.tuentiWebView.postMessage)},o=function(){return!!(window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.tuentiWebView&&window.webkit.messageHandlers.tuentiWebView.postMessage)},a=[],s=function(e){a=a.filter(function(t){return t!==e})},u=function(){return i()||o()},c=function(e,t){var r=e.type,u=e.id,c=void 0===u?n():u,l=e.payload,f=i()?function(e){window.tuentiWebView.postMessage(e)}:o()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null;if(!f)return Promise.reject({code:500,reason:"WebView postMessage not available"});var d=JSON.stringify({type:r,id:c,payload:l});return setTimeout(function(){f(d)}),new Promise(function(e,n){var i=!1,o=function(t){t.id!==c||i||(t.type===r?e(t.payload):"ERROR"===t.type?n(t.payload):n({code:500,reason:"bad type: "+t.type+". Expecting "+r}),s(o))};!function(e){a.push(e)}(o),t&&setTimeout(function(){i=!0,s(o),n({code:408,reason:"request timeout"})},t)})};window[r]=window[r]||{postMessage:function(e){var t;try{t=JSON.parse(e)}catch(t){throw Error("Problem parsing webview message: "+e)}a.forEach(function(e){return e(t)})}};var l=function(e){return Math.floor(e/1e3)},f=function(){return(f=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};var d,w=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()};return e.isWebViewBridgeAvailable=u,e.nativeConfirm=function(e){var t=e.message,n=e.title,r=e.acceptText,i=e.cancelText;return u()?c({type:"CONFIRM",payload:{message:t,title:n,acceptText:r,cancelText:i}}).then(function(e){return e.result}):Promise.resolve(window.confirm(t))},e.nativeAlert=function(e){var t=e.message,n=e.title,r=e.buttonText;return u()?c({type:"ALERT",payload:{title:n,message:t,buttonText:r}}):(window.alert(t),Promise.resolve())},e.nativeMessage=function(e){var t=e.message,n=e.duration,r=e.buttonText,i=e.type;return u()?c({type:"MESSAGE",payload:{message:t,duration:n,buttonText:r,type:i}}):(window.alert(t),Promise.resolve())},e.requestSimIcc=function(){return c({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return c({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},e.requestDeviceImei=function(){return c({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.attachToEmail=function(e){var t=e.url,n=e.subject,r=e.fileName,i=e.recipient,o=e.body;return c({type:"ATTACH_TO_EMAIL",payload:{url:t,subject:n,fileName:r,recipient:i,body:o}})},e.setWebViewTitle=function(e){return u()?c({type:"SET_TITLE",payload:{title:e}}):(document.title=e,Promise.resolve())},e.notifyPageLoaded=function(){return c({type:"PAGE_LOADED"})},e.createCalendarEvent=function(e){var t=e.beginTime,n=e.endTime,r=e.title;return c({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:l(t),endTime:l(n),title:r}})},e.requestContact=function(e){var t=(void 0===e?{}:e).filter;return c({type:"GET_CONTACT_DATA",payload:{filter:void 0===t?"phone":t}})},e.logEvent=function(e){var t=e.category,n=e.action,r=e.label,i=e.value,o=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 i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&(n[r[i]]=e[r[i]])}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,s=f({eventCategory:t,eventAction:n,eventLabel:r,eventValue:i},o);return w({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("send","event",f({},s,{hitCallback:t}))})}})},e.setScreenName=function(e,t){return e?w({onAndroid:function(t){return t.setScreenName&&t.setScreenName(e),Promise.resolve()},onIos:function(t){return t.postMessage({command:"setScreenName",screenName:e}),Promise.resolve()},onWeb:function(n){return new Promise(function(r){var i=e.startsWith("/")?e:"/"+e;i!==d?(d=i,n(function(){n.getAll().forEach(function(e){e.set("page",i),e.send("pageView",f({},t,{hitCallback:r}))})})):r()})}}):(console.warn("Missing analytics screenName"),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=[],s=function(e){a=a.filter(function(n){return n!==e})},u=function(){return o()||i()},c=function(e,n){var r=e.type,u=e.id,c=void 0===u?t():u,l=e.payload,d=o()?function(e){window.tuentiWebView.postMessage(e)}:i()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null;if(!d)return Promise.reject({code:500,reason:"WebView postMessage not available"});var m=JSON.stringify({type:r,id:c,payload:l});return setTimeout(function(){d(m)}),new Promise(function(e,t){var o=!1,i=function(n){n.id!==c||o||(n.type===r?e(n.payload):"ERROR"===n.type?t(n.payload):t({code:500,reason:"bad type: "+n.type+". Expecting "+r}),s(i))};!function(e){a.push(e)}(i),n&&setTimeout(function(){o=!0,s(i),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)}a.forEach(function(e){return e(n)})}};var l=function(e){return Math.floor(e/1e3)},d=function(){return(d=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 m,f=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()},v={obIds:1,paymentModels:2,serviceWorkerStatus:3,isAdmin:5,hasIpComms:6};return e.isWebViewBridgeAvailable=u,e.nativeConfirm=function(e){var n=e.message,t=e.title,r=e.acceptText,o=e.cancelText;return u()?c({type:"CONFIRM",payload:{message:n,title:t,acceptText:r,cancelText:o}}).then(function(e){return e.result}):Promise.resolve(window.confirm(n))},e.nativeAlert=function(e){var n=e.message,t=e.title,r=e.buttonText;return u()?c({type:"ALERT",payload:{title:t,message:n,buttonText:r}}):(window.alert(n),Promise.resolve())},e.nativeMessage=function(e){var n=e.message,t=e.duration,r=e.buttonText,o=e.type;return u()?c({type:"MESSAGE",payload:{message:n,duration:t,buttonText:r,type:o}}):(window.alert(n),Promise.resolve())},e.requestSimIcc=function(){return c({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return c({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},e.requestDeviceImei=function(){return c({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.attachToEmail=function(e){var n=e.url,t=e.subject,r=e.fileName,o=e.recipient,i=e.body;return c({type:"ATTACH_TO_EMAIL",payload:{url:n,subject:t,fileName:r,recipient:o,body:i}})},e.setWebViewTitle=function(e){return u()?c({type:"SET_TITLE",payload:{title:e}}):(document.title=e,Promise.resolve())},e.notifyPageLoaded=function(){return c({type:"PAGE_LOADED"})},e.createCalendarEvent=function(e){var n=e.beginTime,t=e.endTime,r=e.title;return c({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:l(n),endTime:l(t),title:r}})},e.requestContact=function(e){var n=(void 0===e?{}:e).filter;return c({type:"GET_CONTACT_DATA",payload:{filter:void 0===n?"phone":n}})},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,s=d({eventCategory:n,eventAction:t,eventLabel:r,eventValue:o},i);return f({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("send","event",d({},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 f({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("send",d(((t={hitType:"timing",hitCallback:n}).dimension8=String(o),t),a))})}})},e.setScreenName=function(e,n){return e?f({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!==m?(m=o,t(function(){t.getAll().forEach(function(e){e.set("page",o),e.send("pageView",d({},n,{hitCallback:r}))})})):r()})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setUserProperty=function(e,n){return e&&n?(n=String(n),f({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=v[e];return o?(t("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.CD_WEBAPP_INSTALLED=4,e.CD_NOVUM_UID=7,e.CD_EVENT_VALUE=8,e}({});

@@ -256,2 +256,10 @@ (function (global, factory) {

// Google Analytics custom dimension indices.
var CD_OB_IDS = 1; // from sessionInfo
var CD_PAYMENT_MODELS = 2; // from sessionInfo
var CD_SERVICE_WORKER_STATUS = 3;
var CD_WEBAPP_INSTALLED = 4;
var CD_SUBSCRIPTION_ADMIN = 5; // from sessionInfo
var CD_SUBSCRIPTION_WITH_IPCOMMS = 6; // from sessionInfo
var CD_NOVUM_UID = 7;
var CD_EVENT_VALUE = 8;
var withAnalytics = function (_a) {

@@ -311,2 +319,38 @@ var onAndroid = _a.onAndroid, onIos = _a.onIos, onWeb = _a.onWeb;

};
var logTiming = function (_a) {
var _b = _a.category, category = _b === void 0 ? 'performance_timer' : _b, variable = _a.variable, value = _a.value, label = _a.label;
if (!category || !variable || !value) {
console.warn('Analytics timing should have "category", "variable" and "value"', { category: category, variable: variable, value: value });
return Promise.resolve();
}
var params = {
timingCategory: category,
timingVar: variable,
timingValue: value,
timingLabel: label,
};
var name = category;
return withAnalytics({
onAndroid: function (androidFirebase) {
if (androidFirebase.logEvent) {
androidFirebase.logEvent(name, JSON.stringify(params));
}
return Promise.resolve();
},
onIos: function (iosFirebase) {
iosFirebase.postMessage({
command: 'logEvent',
name: name,
parameters: params,
});
return Promise.resolve();
},
onWeb: function (ga) {
return new Promise(function (resolve) {
var _a;
ga('send', __assign((_a = { hitType: 'timing', hitCallback: resolve }, _a["dimension" + CD_EVENT_VALUE] = String(value), _a), params));
});
},
});
};
var currentPageName;

@@ -328,3 +372,3 @@ var setScreenName = function (screenName, fieldsObject) {

command: 'setScreenName',
screenName: screenName,
name: screenName,
});

@@ -357,2 +401,42 @@ return Promise.resolve();

};
var USER_PROPERTY_TO_CUSTOM_DIMENSION = {
obIds: CD_OB_IDS,
paymentModels: CD_PAYMENT_MODELS,
serviceWorkerStatus: CD_SERVICE_WORKER_STATUS,
isAdmin: CD_SUBSCRIPTION_ADMIN,
hasIpComms: CD_SUBSCRIPTION_WITH_IPCOMMS,
};
var setUserProperty = function (name, value) {
if (!name || !value) {
console.warn('Trying to set analytics user property without name or value', name, value);
return Promise.resolve();
}
value = String(value);
return withAnalytics({
onAndroid: function (androidFirebase) {
if (androidFirebase.setUserProperty) {
androidFirebase.setUserProperty(name, value);
}
return Promise.resolve();
},
onIos: function (iosFirebase) {
iosFirebase.postMessage({
command: 'setUserProperty',
name: name,
value: value,
});
return Promise.resolve();
},
onWeb: function (ga) {
var _a;
var dimensionIdx = USER_PROPERTY_TO_CUSTOM_DIMENSION[name];
if (!dimensionIdx) {
console.warn('No custom dimension defined for user property', name);
return Promise.resolve();
}
ga('set', (_a = {}, _a["dimension" + dimensionIdx] = String(value), _a));
return Promise.resolve();
},
});
};

@@ -372,3 +456,8 @@ exports.isWebViewBridgeAvailable = isWebViewBridgeAvailable;

exports.logEvent = logEvent;
exports.logTiming = logTiming;
exports.setScreenName = setScreenName;
exports.setUserProperty = setUserProperty;
exports.CD_WEBAPP_INSTALLED = CD_WEBAPP_INSTALLED;
exports.CD_NOVUM_UID = CD_NOVUM_UID;
exports.CD_EVENT_VALUE = CD_EVENT_VALUE;

@@ -375,0 +464,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

@@ -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.webviewBridge={})}(this,function(e){"use strict";var t=1,n=function(){return""+t++},i="__tuenti_webview_bridge",o=function(){return!(!window.tuentiWebView||!window.tuentiWebView.postMessage)},r=function(){return!!(window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.tuentiWebView&&window.webkit.messageHandlers.tuentiWebView.postMessage)},a=[],s=function(e){a=a.filter(function(t){return t!==e})},u=function(){return o()||r()},c=function(e,t){var i=e.type,u=e.id,c=void 0===u?n():u,l=e.payload,f=o()?function(e){window.tuentiWebView.postMessage(e)}:r()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null;if(!f)return Promise.reject({code:500,reason:"WebView postMessage not available"});var d=JSON.stringify({type:i,id:c,payload:l});return setTimeout(function(){f(d)}),new Promise(function(e,n){var o=!1,r=function(t){t.id!==c||o||(t.type===i?e(t.payload):"ERROR"===t.type?n(t.payload):n({code:500,reason:"bad type: "+t.type+". Expecting "+i}),s(r))};!function(e){a.push(e)}(r),t&&setTimeout(function(){o=!0,s(r),n({code:408,reason:"request timeout"})},t)})};window[i]=window[i]||{postMessage:function(e){var t;try{t=JSON.parse(e)}catch(t){throw Error("Problem parsing webview message: "+e)}a.forEach(function(e){return e(t)})}};var l=function(e){return Math.floor(e/1e3)},f=function(){return(f=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var d,w=function(e){var t=e.onAndroid,n=e.onIos,i=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?i(window.ga):Promise.resolve()};e.isWebViewBridgeAvailable=u,e.nativeConfirm=function(e){var t=e.message,n=e.title,i=e.acceptText,o=e.cancelText;return u()?c({type:"CONFIRM",payload:{message:t,title:n,acceptText:i,cancelText:o}}).then(function(e){return e.result}):Promise.resolve(window.confirm(t))},e.nativeAlert=function(e){var t=e.message,n=e.title,i=e.buttonText;return u()?c({type:"ALERT",payload:{title:n,message:t,buttonText:i}}):(window.alert(t),Promise.resolve())},e.nativeMessage=function(e){var t=e.message,n=e.duration,i=e.buttonText,o=e.type;return u()?c({type:"MESSAGE",payload:{message:t,duration:n,buttonText:i,type:o}}):(window.alert(t),Promise.resolve())},e.requestSimIcc=function(){return c({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return c({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},e.requestDeviceImei=function(){return c({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.attachToEmail=function(e){var t=e.url,n=e.subject,i=e.fileName,o=e.recipient,r=e.body;return c({type:"ATTACH_TO_EMAIL",payload:{url:t,subject:n,fileName:i,recipient:o,body:r}})},e.setWebViewTitle=function(e){return u()?c({type:"SET_TITLE",payload:{title:e}}):(document.title=e,Promise.resolve())},e.notifyPageLoaded=function(){return c({type:"PAGE_LOADED"})},e.createCalendarEvent=function(e){var t=e.beginTime,n=e.endTime,i=e.title;return c({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:l(t),endTime:l(n),title:i}})},e.requestContact=function(e){var t=(void 0===e?{}:e).filter;return c({type:"GET_CONTACT_DATA",payload:{filter:void 0===t?"phone":t}})},e.logEvent=function(e){var t=e.category,n=e.action,i=e.label,o=e.value,r=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&(n[i[o]]=e[i[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,s=f({eventCategory:t,eventAction:n,eventLabel:i,eventValue:o},r);return w({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("send","event",f({},s,{hitCallback:t}))})}})},e.setScreenName=function(e,t){return e?w({onAndroid:function(t){return t.setScreenName&&t.setScreenName(e),Promise.resolve()},onIos:function(t){return t.postMessage({command:"setScreenName",screenName:e}),Promise.resolve()},onWeb:function(n){return new Promise(function(i){var o=e.startsWith("/")?e:"/"+e;o!==d?(d=o,n(function(){n.getAll().forEach(function(e){e.set("page",o),e.send("pageView",f({},t,{hitCallback:i}))})})):i()})}}):(console.warn("Missing analytics screenName"),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.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=[],s=function(e){a=a.filter(function(n){return n!==e})},u=function(){return o()||i()},c=function(e,n){var r=e.type,u=e.id,c=void 0===u?t():u,l=e.payload,d=o()?function(e){window.tuentiWebView.postMessage(e)}:i()?function(e){window.webkit.messageHandlers.tuentiWebView.postMessage(e)}:null;if(!d)return Promise.reject({code:500,reason:"WebView postMessage not available"});var f=JSON.stringify({type:r,id:c,payload:l});return setTimeout(function(){d(f)}),new Promise(function(e,t){var o=!1,i=function(n){n.id!==c||o||(n.type===r?e(n.payload):"ERROR"===n.type?t(n.payload):t({code:500,reason:"bad type: "+n.type+". Expecting "+r}),s(i))};!function(e){a.push(e)}(i),n&&setTimeout(function(){o=!0,s(i),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)}a.forEach(function(e){return e(n)})}};var l=function(e){return Math.floor(e/1e3)},d=function(){return(d=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 f,m=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()},v={obIds:1,paymentModels:2,serviceWorkerStatus:3,isAdmin:5,hasIpComms:6};e.isWebViewBridgeAvailable=u,e.nativeConfirm=function(e){var n=e.message,t=e.title,r=e.acceptText,o=e.cancelText;return u()?c({type:"CONFIRM",payload:{message:n,title:t,acceptText:r,cancelText:o}}).then(function(e){return e.result}):Promise.resolve(window.confirm(n))},e.nativeAlert=function(e){var n=e.message,t=e.title,r=e.buttonText;return u()?c({type:"ALERT",payload:{title:t,message:n,buttonText:r}}):(window.alert(n),Promise.resolve())},e.nativeMessage=function(e){var n=e.message,t=e.duration,r=e.buttonText,o=e.type;return u()?c({type:"MESSAGE",payload:{message:n,duration:t,buttonText:r,type:o}}):(window.alert(n),Promise.resolve())},e.requestSimIcc=function(){return c({type:"SIM_ICC"},200).then(function(e){return e.icc}).catch(function(){return null})},e.requestSimImsi=function(){return c({type:"IMSI"},200).then(function(e){return e.imsi}).catch(function(){return null})},e.requestDeviceImei=function(){return c({type:"IMEI"},200).then(function(e){return e.imei}).catch(function(){return null})},e.attachToEmail=function(e){var n=e.url,t=e.subject,r=e.fileName,o=e.recipient,i=e.body;return c({type:"ATTACH_TO_EMAIL",payload:{url:n,subject:t,fileName:r,recipient:o,body:i}})},e.setWebViewTitle=function(e){return u()?c({type:"SET_TITLE",payload:{title:e}}):(document.title=e,Promise.resolve())},e.notifyPageLoaded=function(){return c({type:"PAGE_LOADED"})},e.createCalendarEvent=function(e){var n=e.beginTime,t=e.endTime,r=e.title;return c({type:"CREATE_CALENDAR_EVENT",payload:{beginTime:l(n),endTime:l(t),title:r}})},e.requestContact=function(e){var n=(void 0===e?{}:e).filter;return c({type:"GET_CONTACT_DATA",payload:{filter:void 0===n?"phone":n}})},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,s=d({eventCategory:n,eventAction:t,eventLabel:r,eventValue:o},i);return m({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("send","event",d({},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 m({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("send",d(((t={hitType:"timing",hitCallback:n}).dimension8=String(o),t),a))})}})},e.setScreenName=function(e,n){return e?m({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!==f?(f=o,t(function(){t.getAll().forEach(function(e){e.set("page",o),e.send("pageView",d({},n,{hitCallback:r}))})})):r()})}}):(console.warn("Missing analytics screenName"),Promise.resolve())},e.setUserProperty=function(e,n){return e&&n?(n=String(n),m({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=v[e];return o?(t("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.CD_WEBAPP_INSTALLED=4,e.CD_NOVUM_UID=7,e.CD_EVENT_VALUE=8,Object.defineProperty(e,"__esModule",{value:!0})});
{
"name": "@tef-novum/webview-bridge",
"version": "1.0.6",
"version": "1.1.0",
"description": "JavaScript library to access to native functionality. Requires a webview with a postMessage bridge.",

@@ -9,3 +9,3 @@ "main": "./dist/webview-bridge-cjs.js",

"scripts": {
"build": "del dist && rollup -c && uglifyjs --compress --mangle -o dist/webview-bridge-umd.min.js dist/webview-bridge-umd.js && uglifyjs --compress --mangle -o dist/webview-bridge-iife.min.js dist/webview-bridge-iife.js && cpx ./src/webview-bridge-cjs.flow ./dist",
"build": "del dist && rollup -c && uglifyjs --compress --mangle -o dist/webview-bridge-umd.min.js dist/webview-bridge-umd.js && uglifyjs --compress --mangle -o dist/webview-bridge-iife.min.js dist/webview-bridge-iife.js && cpx ./src/webview-bridge-cjs.js.flow ./dist",
"test": "jest",

@@ -17,3 +17,3 @@ "lint": "tslint *.ts",

"type": "git",
"url": "git+https://github.com/tef-novum/webview-bridge.git"
"url": "git+https://github.com/tef-dig/webview-bridge.git"
},

@@ -23,5 +23,5 @@ "author": "appscore@tuenti.com",

"bugs": {
"url": "https://github.com/tef-novum/webview-bridge/issues"
"url": "https://github.com/tef-dig/webview-bridge/issues"
},
"homepage": "https://github.com/tef-novum/webview-bridge#readme",
"homepage": "https://github.com/tef-dig/webview-bridge#readme",
"dependencies": {},

@@ -28,0 +28,0 @@ "devDependencies": {

@@ -5,3 +5,3 @@ <p align="center">

[![GitHub tag](https://img.shields.io/github/tag/tef-novum/webview-bridge.svg)](https://github.com/tef-novum/webview-bridge) [![npm version](https://badge.fury.io/js/%40tef-novum%2Fwebview-bridge.svg)](https://badge.fury.io/js/%40tef-novum%2Fwebview-bridge) [![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/tef-novum/webview-bridge/blob/master/LICENSE)
[![GitHub tag](https://img.shields.io/github/tag/tef-dig/webview-bridge.svg)](https://github.com/tef-dig/webview-bridge) [![npm version](https://badge.fury.io/js/%40tef-novum%2Fwebview-bridge.svg)](https://badge.fury.io/js/%40tef-novum%2Fwebview-bridge) [![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/tef-dig/webview-bridge/blob/master/LICENSE)
##

@@ -14,3 +14,5 @@ JavaScript library to access to native functionality. Requires a webview with a

[AMD](https://github.com/amdjs/amdjs-api/wiki/AMD),
[UMD](https://github.com/umdjs/umd), ES builds available (see
[UMD](https://github.com/umdjs/umd),
[IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE),
[ES Module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) builds available (see
[package dist folder](https://unpkg.com/@tef-novum/webview-bridge/dist/)). Open

@@ -53,3 +55,3 @@ an issue if you need a different build.

```html
<script src="https://unpkg.com/@tef-novum/webview-bridge/dist/webview-bridge-umd.min.js"></script>
<script src="https://unpkg.com/@tef-novum/webview-bridge/dist/webview-bridge-iife.min.js"></script>

@@ -56,0 +58,0 @@ <script>

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