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.3 to 1.0.4

doc/webview-bridge-alert-android.png

19

dist/webview-bridge-amd.js

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

if (!postMessage) {
return Promise.reject();
}
var message = JSON.stringify({ type: type, id: id, payload: payload });
if (!postMessage) {
return Promise.reject({

@@ -64,3 +60,4 @@ code: 500,

}
// ensure postMessage call is async (so tests behave like a real webview)
var message = JSON.stringify({ type: type, id: id, payload: payload });
// ensure postMessage call is async
setTimeout(function () {

@@ -115,3 +112,3 @@ postMessage(message);

var nativeConfirm = function (_a) {
var message = _a.message, _b = _a.title, title = _b === void 0 ? '' : _b, acceptText = _a.acceptText, cancelText = _a.cancelText;
var message = _a.message, title = _a.title, acceptText = _a.acceptText, cancelText = _a.cancelText;
if (isWebViewBridgeAvailable()) {

@@ -127,7 +124,7 @@ return postMessageToNativeApp({

else {
return Promise.resolve(confirm(message));
return Promise.resolve(window.confirm(message));
}
};
var nativeAlert = function (_a) {
var message = _a.message, _b = _a.title, title = _b === void 0 ? '' : _b, buttonText = _a.buttonText;
var message = _a.message, title = _a.title, buttonText = _a.buttonText;
if (isWebViewBridgeAvailable()) {

@@ -140,3 +137,3 @@ return postMessageToNativeApp({

else {
alert(message);
window.alert(message);
return Promise.resolve();

@@ -154,3 +151,3 @@ }

else {
alert(message);
window.alert(message);
return Promise.resolve();

@@ -187,3 +184,3 @@ }

var attachToEmail = function (_a) {
var url = _a.url, _b = _a.subject, subject = _b === void 0 ? '' : _b, fileName = _a.fileName, recipient = _a.recipient, body = _a.body;
var url = _a.url, subject = _a.subject, fileName = _a.fileName, recipient = _a.recipient, body = _a.body;
return postMessageToNativeApp({

@@ -190,0 +187,0 @@ type: 'ATTACH_TO_EMAIL',

@@ -56,6 +56,2 @@ 'use strict';

if (!postMessage) {
return Promise.reject();
}
var message = JSON.stringify({ type: type, id: id, payload: payload });
if (!postMessage) {
return Promise.reject({

@@ -66,3 +62,4 @@ code: 500,

}
// ensure postMessage call is async (so tests behave like a real webview)
var message = JSON.stringify({ type: type, id: id, payload: payload });
// ensure postMessage call is async
setTimeout(function () {

@@ -117,3 +114,3 @@ postMessage(message);

var nativeConfirm = function (_a) {
var message = _a.message, _b = _a.title, title = _b === void 0 ? '' : _b, acceptText = _a.acceptText, cancelText = _a.cancelText;
var message = _a.message, title = _a.title, acceptText = _a.acceptText, cancelText = _a.cancelText;
if (isWebViewBridgeAvailable()) {

@@ -129,7 +126,7 @@ return postMessageToNativeApp({

else {
return Promise.resolve(confirm(message));
return Promise.resolve(window.confirm(message));
}
};
var nativeAlert = function (_a) {
var message = _a.message, _b = _a.title, title = _b === void 0 ? '' : _b, buttonText = _a.buttonText;
var message = _a.message, title = _a.title, buttonText = _a.buttonText;
if (isWebViewBridgeAvailable()) {

@@ -142,3 +139,3 @@ return postMessageToNativeApp({

else {
alert(message);
window.alert(message);
return Promise.resolve();

@@ -156,3 +153,3 @@ }

else {
alert(message);
window.alert(message);
return Promise.resolve();

@@ -189,3 +186,3 @@ }

var attachToEmail = function (_a) {
var url = _a.url, _b = _a.subject, subject = _b === void 0 ? '' : _b, fileName = _a.fileName, recipient = _a.recipient, body = _a.body;
var url = _a.url, subject = _a.subject, fileName = _a.fileName, recipient = _a.recipient, body = _a.body;
return postMessageToNativeApp({

@@ -192,0 +189,0 @@ type: 'ATTACH_TO_EMAIL',

@@ -58,6 +58,2 @@ (function (global, factory) {

if (!postMessage) {
return Promise.reject();
}
var message = JSON.stringify({ type: type, id: id, payload: payload });
if (!postMessage) {
return Promise.reject({

@@ -68,3 +64,4 @@ code: 500,

}
// ensure postMessage call is async (so tests behave like a real webview)
var message = JSON.stringify({ type: type, id: id, payload: payload });
// ensure postMessage call is async
setTimeout(function () {

@@ -119,3 +116,3 @@ postMessage(message);

var nativeConfirm = function (_a) {
var message = _a.message, _b = _a.title, title = _b === void 0 ? '' : _b, acceptText = _a.acceptText, cancelText = _a.cancelText;
var message = _a.message, title = _a.title, acceptText = _a.acceptText, cancelText = _a.cancelText;
if (isWebViewBridgeAvailable()) {

@@ -131,7 +128,7 @@ return postMessageToNativeApp({

else {
return Promise.resolve(confirm(message));
return Promise.resolve(window.confirm(message));
}
};
var nativeAlert = function (_a) {
var message = _a.message, _b = _a.title, title = _b === void 0 ? '' : _b, buttonText = _a.buttonText;
var message = _a.message, title = _a.title, buttonText = _a.buttonText;
if (isWebViewBridgeAvailable()) {

@@ -144,3 +141,3 @@ return postMessageToNativeApp({

else {
alert(message);
window.alert(message);
return Promise.resolve();

@@ -158,3 +155,3 @@ }

else {
alert(message);
window.alert(message);
return Promise.resolve();

@@ -191,3 +188,3 @@ }

var attachToEmail = function (_a) {
var url = _a.url, _b = _a.subject, subject = _b === void 0 ? '' : _b, fileName = _a.fileName, recipient = _a.recipient, body = _a.body;
var url = _a.url, subject = _a.subject, fileName = _a.fileName, recipient = _a.recipient, body = _a.body;
return postMessageToNativeApp({

@@ -194,0 +191,0 @@ type: 'ATTACH_TO_EMAIL',

@@ -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++},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();var d=JSON.stringify({type:r,id:c,payload:l});return f?(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)})):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)}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()};e.isWebViewBridgeAvailable=u,e.nativeConfirm=function(e){var t=e.message,n=e.title,r=void 0===n?"":n,i=e.acceptText,o=e.cancelText;return u()?c({type:"CONFIRM",payload:{message:t,title:r,acceptText:i,cancelText:o}}).then(function(e){return e.result}):Promise.resolve(confirm(t))},e.nativeAlert=function(e){var t=e.message,n=e.title,r=void 0===n?"":n,i=e.buttonText;return u()?c({type:"ALERT",payload:{title:r,message:t,buttonText:i}}):(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}}):(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=void 0===n?"":n,i=e.fileName,o=e.recipient,a=e.body;return c({type:"ATTACH_TO_EMAIL",payload:{url:t,subject:r,fileName:i,recipient:o,body:a}})},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())},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.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})});
{
"name": "@tef-novum/webview-bridge",
"version": "1.0.3",
"version": "1.0.4",
"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",

@@ -1,3 +0,7 @@

# webview-bridge
<p align="center">
<img width="75%" src="./doc/webview-bridge-logo.png"/>
</p>
[![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)
##
JavaScript library to access to native functionality. Requires a webview with a

@@ -8,3 +12,4 @@ postMessage bridge.

AMD, UMD, ES builds available (see
[AMD](https://github.com/amdjs/amdjs-api/wiki/AMD),
[UMD](https://github.com/umdjs/umd), ES builds available (see
[package dist folder](https://unpkg.com/@tef-novum/webview-bridge/dist/)). Open

@@ -17,9 +22,10 @@ an issue if you need a different build.

We recommend to manage your dependencies using `npm` or `yarn` and use module
bundler like [webpack](https://webpack.js.org/) or
[parcel](https://parceljs.org/). Once configured, you can use ES imports.
We recommend to manage your dependencies using `npm` or `yarn` and use a bundler
like [webpack](https://webpack.js.org/) or [parcel](https://parceljs.org/). Once
configured, you can use
[ES imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import).
Install using `npm`:
```
```bash
npm i @tef-novum/webview-bridge

@@ -30,3 +36,3 @@ ```

```
```bash
yarn add @tef-novum/webview-bridge

@@ -93,5 +99,6 @@ ```

Picker UI elements can be filtered by available phones (default) or emails
- Android only: picker UI elements can be filtered by available phones
(default) or emails. `filter` property is ignored by iOS devices
<img width="350" src="doc/webview-bridge-contact.png">
<img height="550" src="doc/webview-bridge-contact-ios.png"><img height="550" src="doc/webview-bridge-contact-android.png">

@@ -130,3 +137,3 @@ ```typescript

<img width="350" src="doc/webview-bridge-calendar.png">
<img height="550" src="doc/webview-bridge-calendar-ios.png"><img height="550" src="doc/webview-bridge-calendar-android.png">

@@ -165,3 +172,3 @@ ```typescript

```typescript
export declare const setWebViewTitle: (title: string) => Promise<void>;
setWebViewTitle: (title: string) => Promise<void>;
```

@@ -184,6 +191,6 @@

<img width="350" src="doc/webview-bridge-confirm.png">
<img height="550" src="doc/webview-bridge-confirm-ios.png"><img height="550" src="doc/webview-bridge-confirm-android.png">
```typescript
export declare const nativeConfirm: (
nativeConfirm: (
{

@@ -227,6 +234,6 @@ message,

<img width="350" src="doc/webview-bridge-alert.png">
<img height="550" src="doc/webview-bridge-alert-ios.png"><img height="550" src="doc/webview-bridge-alert-android.png">
```typescript
export declare const nativeAlert: (
nativeAlert: (
{

@@ -266,6 +273,6 @@ message,

<img width="350" src="doc/webview-bridge-message.png">
<img height="550" src="doc/webview-bridge-message-ios.png"><img height="550" src="doc/webview-bridge-message-android.png">
```typescript
export declare const nativeMessage: (
nativeMessage: (
{

@@ -355,2 +362,2 @@ message,

MIT
This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE) file.

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