New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

encrypted-postmate

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encrypted-postmate - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

4

build/postmate.min.js

@@ -6,5 +6,5 @@ /*!

* See https://opensource.org/licenses/MIT
* @version 1.0.0
* @version 1.0.3
*/
!(function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Postmate",[],t):"object"==typeof exports?exports.Postmate=t():e.Postmate=t()})(this,(function(){return (function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)})([(function(e,t,n){function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(){return++p}function o(){var e;v.debug&&(e=console).log.apply(e,arguments)}function s(e){var t=document.createElement("a");return t.href=e,t.origin||t.protocol+"//"+t.hostname}function a(e,t,n){return e.origin===t&&("object"===l(e.data)&&("postmate"in e.data&&(e.data.type===n&&("{"===e.data.postmate.substring(0,1)||!!{"handshake-reply":1,call:1,emit:1,reply:1,request:1}[e.data.postmate]))))}function u(e,t){var n="function"==typeof e[t]?e[t]():e[t];return f.resolve(n)}var c=(function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}})(),l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f="undefined"==typeof Promise?n(1).Promise:Promise,h="application/x-postmate-v1+json",d=Object.prototype.hasOwnProperty,p=0,m=(function(){function e(t){var n=this;r(this,e),this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.messageType=t.messageType,this.getIncomingMessage=t.getIncomingMessage.bind(t),this.getOutcomingMessage=t.getOutcomingMessage.bind(t),this.events={},o("Parent: Registering API"),o("Parent: Awaiting messages..."),this.listener=function(e){var t=n.getIncomingMessage(e.data),r=t.value||{},i=r.data,s=r.name;"emit"===t.postmate&&(o("Parent: Received event emission: "+s),s in n.events&&n.events[s].call(n,i))},this.parent.addEventListener("message",this.listener,!1),o("Parent: Awaiting event emissions from Child")}return c(e,[{key:"get",value:function(e){var t=this;return new f(function(n){var r=i(),o=function e(i){var o=t.getIncomingMessage(i.data);o.uid===r&&"reply"===o.postmate&&(t.parent.removeEventListener("message",e,!1),n(o.value))};t.parent.addEventListener("message",o,!1),t.child.postMessage(t.getOutcomingMessage({postmate:"request",property:e,uid:r}),t.childOrigin)})}},{key:"call",value:function(e,t){this.child.postMessage(this.getOutcomingMessage({postmate:"call",property:e,data:t}),this.childOrigin)}},{key:"on",value:function(e,t){this.events[e]=t}},{key:"destroy",value:function(){o("Parent: Destroying Postmate instance"),window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)}}]),e})(),g=(function(){function e(t){var n=this;r(this,e),this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.messageType=t.messageType,this.getIncomingMessage=t.getIncomingMessage.bind(t),this.getOutcomingMessage=t.getOutcomingMessage.bind(t),o("Child: Registering API"),o("Child: Awaiting messages..."),this.child.addEventListener("message",(function(e){if(a(e,n.parentOrigin,n.messageType)){var t=n.getIncomingMessage(e.data);o("Child: Received request",t);var r=t.property,i=t.uid,s=t.data;if("call"===t.postmate)return void(r in n.model&&"function"==typeof n.model[r]&&n.model[r].call(n,s));u(n.model,r).then((function(t){return e.source.postMessage(n.getOutcomingMessage({property:r,postmate:"reply",uid:i,value:t}),e.origin)}))}}))}return c(e,[{key:"emit",value:function(e,t){o('Child: Emitting Event "'+e+'"',t),this.parent.postMessage(this.getOutcomingMessage({postmate:"emit",value:{name:e,data:t}}),this.parentOrigin)}}]),e})(),v=(function(){function e(t){var n=t.container,i=t.url,o=t.model,s=t.messageType;return r(this,e),this.parent=window,this.frame=document.createElement("iframe"),(n||document.body).appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=o||{},this.messageType=s||h,this.sendHandshake(i)}return c(e,[{key:"getIncomingMessage",value:function(e){return e}},{key:"getOutcomingMessage",value:function(e){return e.type=this.messageType,e}},{key:"sendHandshake",value:function(e){var t=this,n=s(e),r=this.messageType,i=0,u=void 0;return new f(function(s,c){var l=function e(i){return!!a(i,n,r)&&("handshake-reply"===t.getIncomingMessage(i.data).postmate?(clearInterval(u),o("Parent: Received handshake reply from Child"),t.parent.removeEventListener("message",e,!1),t.childOrigin=i.origin,o("Parent: Saving Child origin",t.childOrigin),t.handleHandshakeData(i.data),s(new m(t))):(o("Parent: Invalid handshake reply"),c("Failed handshake")))};t.parent.addEventListener("message",l,!1);var f=function(){i++,o("Parent: Sending handshake attempt "+i,{childOrigin:n}),t.child.postMessage(t.getHandshakeRequest(),n),5===i&&clearInterval(u)},h=function(){f(),u=setInterval(f,500)};t.frame.attachEvent?t.frame.attachEvent("onload",h):t.frame.onload=h,o("Parent: Loading frame",{url:e}),t.frame.src=e})}},{key:"getHandshakeRequest",value:function(){return this.getOutcomingMessage({postmate:"handshake",model:this.model})}},{key:"handleHandshakeData",value:function(e){}}]),e})();v.debug=!1,v.Model=(function(){function e(t,n){return r(this,e),this.child=window,this.model=t,this.parent=this.child.parent,this.messageType=n||h,this.sendHandshakeReply()}return c(e,[{key:"sendHandshakeReply",value:function(){var e=this;return new f(function(t,n){var r=function r(i){i.data.postmate&&("handshake"===i.data.postmate?(o("Child: Received handshake from Parent"),e.child.removeEventListener("message",r,!1),o("Child: Inherited and extended model from Parent"),e.handleHandshakeData(i.data),o("Child: Saving Parent origin",e.parentOrigin),e.parentOrigin=i.origin,o("Child: Sending handshake reply to Parent"),i.source.postMessage(e.getOutcomingMessage(e.getHandshakeResponse()),e.parentOrigin),t(new g(e))):n("Handshake Reply Failed"))};e.child.addEventListener("message",r,!1)})}},{key:"handleHandshakeData",value:function(e){var t=e.model;if(t)for(var n=Object.keys(t),r=0;r<n.length;r++)d.call(t,n[r])&&(this.model[n[r]]=t[n[r]])}},{key:"getHandshakeResponse",value:function(){return{postmate:"handshake-reply"}}},{key:"getIncomingMessage",value:function(e){return e}},{key:"getOutcomingMessage",value:function(e){return e.type=this.messageType,e}}]),e})(),e.exports=v}),(function(e,t,n){(function(t,r){/*!
!(function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Postmate",[],t):"object"==typeof exports?exports.Postmate=t():e.Postmate=t()})(this,(function(){return (function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)})([(function(e,t,n){function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(){return++p}function o(){var e;v.debug&&(e=console).log.apply(e,arguments)}function s(e){var t=document.createElement("a");return t.href=e,t.origin||t.protocol+"//"+t.host}function a(e,t,n){return e.origin===t&&("object"===l(e.data)&&("postmate"in e.data&&(e.data.type===n&&("{"===e.data.postmate.substring(0,1)||!!{"handshake-reply":1,call:1,emit:1,reply:1,request:1}[e.data.postmate]))))}function u(e,t){var n="function"==typeof e[t]?e[t]():e[t];return f.resolve(n)}var c=(function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}})(),l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f="undefined"==typeof Promise?n(1).Promise:Promise,h="application/x-postmate-v1+json",d=Object.prototype.hasOwnProperty,p=0,m=(function(){function e(t){var n=this;r(this,e),this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.messageType=t.messageType,this.getIncomingMessage=t.getIncomingMessage.bind(t),this.getOutcomingMessage=t.getOutcomingMessage.bind(t),this.events={},o("Parent: Registering API"),o("Parent: Awaiting messages..."),this.listener=function(e){var t=n.getIncomingMessage(e.data),r=t.value||{},i=r.data,s=r.name;"emit"===t.postmate&&(o("Parent: Received event emission: "+s),s in n.events&&n.events[s].call(n,i))},this.parent.addEventListener("message",this.listener,!1),o("Parent: Awaiting event emissions from Child")}return c(e,[{key:"get",value:function(e){var t=this;return new f(function(n){var r=i(),o=function e(i){var o=t.getIncomingMessage(i.data);o.uid===r&&"reply"===o.postmate&&(t.parent.removeEventListener("message",e,!1),n(o.value))};t.parent.addEventListener("message",o,!1),t.child.postMessage(t.getOutcomingMessage({postmate:"request",property:e,uid:r}),t.childOrigin)})}},{key:"call",value:function(e,t){this.child.postMessage(this.getOutcomingMessage({postmate:"call",property:e,data:t}),this.childOrigin)}},{key:"on",value:function(e,t){this.events[e]=t}},{key:"destroy",value:function(){o("Parent: Destroying Postmate instance"),window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)}}]),e})(),g=(function(){function e(t){var n=this;r(this,e),this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.messageType=t.messageType,this.getIncomingMessage=t.getIncomingMessage.bind(t),this.getOutcomingMessage=t.getOutcomingMessage.bind(t),o("Child: Registering API"),o("Child: Awaiting messages..."),this.child.addEventListener("message",(function(e){if(a(e,n.parentOrigin,n.messageType)){var t=n.getIncomingMessage(e.data);o("Child: Received request",t);var r=t.property,i=t.uid,s=t.data;if("call"===t.postmate)return void(r in n.model&&"function"==typeof n.model[r]&&n.model[r].call(n,s));u(n.model,r).then((function(t){return e.source.postMessage(n.getOutcomingMessage({property:r,postmate:"reply",uid:i,value:t}),e.origin)}))}}))}return c(e,[{key:"emit",value:function(e,t){o('Child: Emitting Event "'+e+'"',t),this.parent.postMessage(this.getOutcomingMessage({postmate:"emit",value:{name:e,data:t}}),this.parentOrigin)}}]),e})(),v=(function(){function e(t){var n=t.container,i=t.url,o=t.model,s=t.messageType;return r(this,e),this.parent=window,this.frame=document.createElement("iframe"),(n||document.body).appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=o||{},this.messageType=s||h,this.sendHandshake(i)}return c(e,[{key:"getIncomingMessage",value:function(e){return e}},{key:"getOutcomingMessage",value:function(e){return e.type=this.messageType,e}},{key:"sendHandshake",value:function(e){var t=this,n=s(e),r=this.messageType,i=0,u=void 0;return new f(function(s,c){var l=function e(i){return!!a(i,n,r)&&("handshake-reply"===t.getIncomingMessage(i.data).postmate?(clearInterval(u),o("Parent: Received handshake reply from Child"),t.parent.removeEventListener("message",e,!1),t.childOrigin=i.origin,o("Parent: Saving Child origin",t.childOrigin),t.handleHandshakeData(i.data),s(new m(t))):(o("Parent: Invalid handshake reply"),c("Failed handshake")))};t.parent.addEventListener("message",l,!1);var f=t.getHandshakeRequest(),h=function(){i++,o("Parent: Sending handshake attempt "+i+", "+n),t.child.postMessage(f,n),5===i&&clearInterval(u)},d=function(){h(),u=setInterval(h,500)};t.frame.attachEvent?t.frame.attachEvent("onload",d):t.frame.onload=d,o("Parent: Loading frame",{url:e}),t.frame.src=e})}},{key:"getHandshakeRequest",value:function(){return this.getOutcomingMessage({postmate:"handshake",model:this.model})}},{key:"handleHandshakeData",value:function(e){}}]),e})();v.debug=!1,v.Model=(function(){function e(t,n){return r(this,e),this.child=window,this.model=t,this.parent=this.child.parent,this.messageType=n||h,this.sendHandshakeReply()}return c(e,[{key:"sendHandshakeReply",value:function(){var e=this;return new f(function(t,n){var r=function r(i){i.data.postmate&&("handshake"===i.data.postmate?(o("Child: Received handshake from Parent"),e.child.removeEventListener("message",r,!1),o("Child: Inherited and extended model from Parent"),e.handleHandshakeData(i.data),o("Child: Saving Parent origin",i.origin),e.parentOrigin=i.origin,o("Child: Sending handshake reply to Parent"),i.source.postMessage(e.getOutcomingMessage(e.getHandshakeResponse()),e.parentOrigin),t(new g(e))):n("Handshake Reply Failed"))};o("Child: Waiting for handshake from Parent"),e.child.addEventListener("message",r,!1)})}},{key:"handleHandshakeData",value:function(e){var t=e.model;if(t)for(var n=Object.keys(t),r=0;r<n.length;r++)d.call(t,n[r])&&(this.model[n[r]]=t[n[r]])}},{key:"getHandshakeResponse",value:function(){return{postmate:"handshake-reply"}}},{key:"getIncomingMessage",value:function(e){return e}},{key:"getOutcomingMessage",value:function(e){return e.type=this.messageType,e}}]),e})(),e.exports=v}),(function(e,t,n){(function(t,r){/*!
* @overview es6-promise - a tiny implementation of Promises/A+.

@@ -11,0 +11,0 @@ * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)

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

const env = require('yargs').argv.env; // use --env with webpack 2
const webpackConfig = require('./webpack.config')[0];

@@ -5,7 +6,57 @@

const customLaunchers = {
slChrome: {
base: 'SauceLabs',
browserName: 'chrome',
platform: 'Windows 7',
version: '35'
},
slFirefox: {
base: 'SauceLabs',
browserName: 'firefox',
version: '30'
},
slMobileSafari: {
base: 'SauceLabs',
browserName: 'Safari',
version: '9.3',
platform: 'iOS',
appiumVersion: '1.6.4',
deviceName: 'iPhone 6s Simulator',
deviceOrientation: 'portrait'
},
slAndroid: {
base: 'SauceLabs',
browserName: 'Browser',
version: '4.4',
platform: 'Android',
appiumVersion: '1.6.4',
deviceName: 'Samsung Galaxy S3 Emulator',
deviceOrientation: 'portrait'
},
slEdge: {
base: 'SauceLabs',
browserName: 'MicrosoftEdge',
platform: 'Windows 10',
version: '13.10586'
}
};
module.exports = function (config) {
config.set({
sauceLabs: {
testName: 'Encrypted Postmate',
startConnect: false,
tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER,
build: process.env.TRAVIS_BUILD_NUMBER
},
frameworks: ['mocha'],
browsers: ['Electron'],
customLaunchers: customLaunchers,
browsers: env === 'build' ? Object.keys(customLaunchers) : ['Electron'],
reporters: ['progress', 'saucelabs'],
concurrency: 5,
browserNoActivityTimeout: 30000,
captureTimeout: 180000,
files: [

@@ -12,0 +63,0 @@ {

{
"name": "encrypted-postmate",
"version": "1.0.2",
"version": "1.0.3",
"description": "A powerful, simple, promise-based, encrypted postMessage library",

@@ -11,3 +11,4 @@ "main": "build/encrypted-postmate.min.js",

"test": "karma start karma.config.js --single-run --env build",
"test:watch": "karma start karma.config.js"
"test:watch": "karma start karma.config.js",
"prepublish": "npm run build"
},

@@ -31,2 +32,3 @@ "devDependencies": {

"karma-mocha": "^1.3.0",
"karma-sauce-launcher": "^1.1.0",
"karma-webpack": "^2.0.3",

@@ -33,0 +35,0 @@ "mocha": "^3.4.2",

@@ -7,16 +7,14 @@ <a href="https://github.com/regily/encrypted-postmate">

[![npm][npm-image]][npm-url]
[![bower][bower-image]][bower-url]
[![Build Status](https://travis-ci.org/regily/encrypted-postmate.svg?branch=master)](https://travis-ci.org/regily/encrypted-postmate)
[![Share](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/home?status=Postmate%3A%20A%20powerful,%20simple,%20promise-based%20postMessage%20library%20https%3A//github.com/regily/encrypted-postmate%20via%20%40DSCEngineering%20%40javascript)
[![NPM](https://img.shields.io/npm/v/encrypted-postmate.svg?style=flat-square)](https://www.npmjs.com/package/encrypted-postmate)
[![NPM](https://img.shields.io/npm/dt/encrypted-postmate.svg?style=flat-square)](https://www.npmjs.com/package/encrypted-postmate)
[![Build Status](https://travis-ci.org/Regily/encrypted-postmate.svg?branch=master)](https://travis-ci.org/Regily/encrypted-postmate)
[![License](https://img.shields.io/npm/l/encrypted-postmate.svg?style=flat-square)](https://github.com/klarna/encrypted-postmate/blob/master/LICENSE)
[npm-image]: https://badge.fury.io/js/postmate.svg
[npm-url]: https://www.npmjs.com/package/postmate
[bower-image]: https://badge.fury.io/bo/postmate.svg
[bower-url]: https://github.com/regily/encrypted-postmate
![Build Status](https://saucelabs.com/browser-matrix/maratoss.svg)
[npm-image]: https://badge.fury.io/js/encrypted-postmate.svg
[npm-url]: https://www.npmjs.com/package/encrypted-postmate
_EncryptedPostmate_ is a promise-based API built on `postMessage`. It allows a parent page to speak with a child `iFrame` across origins with minimal effort.
You can download the compiled javascript directly [here](/build/postmate.min.js)
* [Features](#features)

@@ -38,7 +36,5 @@ * [Installing](#installing)

* Parent can `call` functions within a `child`
* *Zero* dependencies. Provide your own polyfill or abstraction for the `Promise` API if needed.
* Lightweight, weighing in at ~ <span class="size">`5.3kb`</span>.
## Installing
EncryptedPostmate can be installed via NPM or Bower.
EncryptedPostmate can be installed via NPM.

@@ -54,2 +50,4 @@ **NPM**

Also you can download the compiled javascript directly [here](/build/encrypted-postmate.min.js)
## Glossary

@@ -56,0 +54,0 @@ * **`Parent`**: The **top level** page that will embed an `iFrame`, creating a `Child`.

@@ -54,3 +54,3 @@

a.href = url;
return a.origin || `${a.protocol}//${a.hostname}`;
return a.origin || `${a.protocol}//${a.host}`;
}

@@ -301,6 +301,8 @@

const request = this.getHandshakeRequest();
const doSend = () => {
attempt++;
log(`Parent: Sending handshake attempt ${attempt}`, { childOrigin });
this.child.postMessage(this.getHandshakeRequest(), childOrigin);
log(`Parent: Sending handshake attempt ${attempt}, ${childOrigin}`);
this.child.postMessage(request, childOrigin);

@@ -378,3 +380,3 @@ if (attempt === maxHandshakeRequests) {

log('Child: Saving Parent origin', this.parentOrigin);
log('Child: Saving Parent origin', e.origin);
this.parentOrigin = e.origin;

@@ -391,2 +393,3 @@

log('Child: Waiting for handshake from Parent');
this.child.addEventListener('message', shake, false);

@@ -393,0 +396,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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