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

window-post-message-proxy

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

window-post-message-proxy - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

2

dist/windowPostMessageProxy-noexports.d.ts

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

/*! window-post-message-proxy v0.2.0 | (c) 2016 Microsoft Corporation MIT */
/*! window-post-message-proxy v0.2.1 | (c) 2016 Microsoft Corporation MIT */
interface ITrackingProperties {

@@ -3,0 +3,0 @@ id: string;

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

/*! window-post-message-proxy v0.2.0 | (c) 2016 Microsoft Corporation MIT */
/*! window-post-message-proxy v0.2.1 | (c) 2016 Microsoft Corporation MIT */
export interface ITrackingProperties {

@@ -3,0 +3,0 @@ id: string;

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

/*! window-post-message-proxy v0.2.0 | (c) 2016 Microsoft Corporation MIT */
/*! window-post-message-proxy v0.2.1 | (c) 2016 Microsoft Corporation MIT */
(function webpackUniversalModuleDefinition(root, factory) {

@@ -221,4 +221,3 @@ if(typeof exports === 'object' && typeof module === 'object')

responseMessage = {
warning: warningMessage,
originalMessage: message
warning: warningMessage
};

@@ -225,0 +224,0 @@ }

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

/*! window-post-message-proxy v0.2.0 | (c) 2016 Microsoft Corporation MIT */
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports["window-post-message-proxy"]=r():e["window-post-message-proxy"]=r()}(this,function(){return function(e){function r(n){if(s[n])return s[n].exports;var t=s[n]={exports:{},id:n,loaded:!1};return e[n].call(t.exports,t,t.exports,r),t.loaded=!0,t.exports}var s={};return r.m=e,r.c=s,r.p="",r(0)}([function(e,r){"use strict";var s=function(){function e(r){var s=this;void 0===r&&(r={processTrackingProperties:{addTrackingProperties:e.defaultAddTrackingProperties,getTrackingProperties:e.defaultGetTrackingProperties},isErrorMessage:e.defaultIsErrorMessage,receiveWindow:window,name:e.createRandomString()}),this.pendingRequestPromises={},this.addTrackingProperties=r.processTrackingProperties&&r.processTrackingProperties.addTrackingProperties||e.defaultAddTrackingProperties,this.getTrackingProperties=r.processTrackingProperties&&r.processTrackingProperties.getTrackingProperties||e.defaultGetTrackingProperties,this.isErrorMessage=r.isErrorMessage||e.defaultIsErrorMessage,this.receiveWindow=r.receiveWindow||window,this.name=r.name||e.createRandomString(),this.logMessages=r.logMessages||!1,this.eventSourceOverrideWindow=r.eventSourceOverrideWindow,this.suppressWarnings=r.suppressWarnings||!1,this.logMessages&&console.log("new WindowPostMessageProxy created with name: "+this.name+" receiving on window: "+this.receiveWindow.document.title),this.handlers=[],this.windowMessageHandler=function(e){return s.onMessageReceived(e)},this.start()}return e.defaultAddTrackingProperties=function(r,s){return r[e.messagePropertyName]=s,r},e.defaultGetTrackingProperties=function(r){return r[e.messagePropertyName]},e.defaultIsErrorMessage=function(e){return!!e.error},e.prototype.addHandler=function(e){this.handlers.push(e)},e.prototype.removeHandler=function(e){var r=this.handlers.indexOf(e);if(-1==r)throw new Error("You attempted to remove a handler but no matching handler was found.");this.handlers.splice(r,1)},e.prototype.start=function(){this.receiveWindow.addEventListener("message",this.windowMessageHandler)},e.prototype.stop=function(){this.receiveWindow.removeEventListener("message",this.windowMessageHandler)},e.prototype.postMessage=function(r,s){var n={id:e.createRandomString()};this.addTrackingProperties(s,n),this.logMessages&&(console.log(this.name+" Posting message:"),console.log(JSON.stringify(s,null," "))),r.postMessage(s,"*");var t=e.createDeferred();return this.pendingRequestPromises[n.id]=t,t.promise},e.prototype.sendResponse=function(e,r,s){this.addTrackingProperties(r,s),this.logMessages&&(console.log(this.name+" Sending response:"),console.log(JSON.stringify(r,null," "))),e.postMessage(r,"*")},e.prototype.onMessageReceived=function(e){var r=this;this.logMessages&&(console.log(this.name+" Received message:"),console.log("type: "+e.type),console.log(JSON.stringify(e.data,null," ")));var s=this.eventSourceOverrideWindow||e.source,n=e.data;if("object"!=typeof n)return void(this.suppressWarnings||console.warn("Proxy("+this.name+"): Received message that was not an object. Discarding message"));var t;try{t=this.getTrackingProperties(n)}catch(o){this.suppressWarnings||console.warn("Proxy("+this.name+"): Error occurred when attempting to get tracking properties from incoming message:",JSON.stringify(n,null," "),"Error: ",o)}var i;if(t&&(i=this.pendingRequestPromises[t.id]),i){var a=!0;try{a=this.isErrorMessage(n)}catch(o){console.warn("Proxy("+this.name+") Error occurred when trying to determine if message is consider an error response. Message: ",JSON.stringify(n,null,""),"Error: ",o)}a?i.reject(n):i.resolve(n),delete this.pendingRequestPromises[t.id]}else{var d=this.handlers.some(function(e){var o=!1;try{o=e.test(n)}catch(i){r.suppressWarnings||console.warn("Proxy("+r.name+"): Error occurred when handler was testing incoming message:",JSON.stringify(n,null," "),"Error: ",i)}if(o){var a=void 0;try{a=Promise.resolve(e.handle(n))}catch(i){r.suppressWarnings||console.warn("Proxy("+r.name+"): Error occurred when handler was processing incoming message:",JSON.stringify(n,null," "),"Error: ",i),a=Promise.resolve()}return a.then(function(e){if(!e){var o="Handler for message: "+JSON.stringify(n,null," ")+" did not return a response message. The default response message will be returned instead.";r.suppressWarnings||console.warn("Proxy("+r.name+"): "+o),e={warning:o,originalMessage:n}}r.sendResponse(s,e,t)}),!0}});d||this.suppressWarnings||console.warn("Proxy("+this.name+") did not handle message. Handlers: "+this.handlers.length+" Message: "+JSON.stringify(n,null,"")+".")}},e.createDeferred=function(){var e={resolve:null,reject:null,promise:null},r=new Promise(function(r,s){e.resolve=r,e.reject=s});return e.promise=r,e},e.createRandomString=function(){return(Math.random()+1).toString(36).substring(7)},e.messagePropertyName="windowPostMessageProxy",e}();r.WindowPostMessageProxy=s}])});
/*! window-post-message-proxy v0.2.1 | (c) 2016 Microsoft Corporation MIT */
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports["window-post-message-proxy"]=r():e["window-post-message-proxy"]=r()}(this,function(){return function(e){function r(n){if(s[n])return s[n].exports;var t=s[n]={exports:{},id:n,loaded:!1};return e[n].call(t.exports,t,t.exports,r),t.loaded=!0,t.exports}var s={};return r.m=e,r.c=s,r.p="",r(0)}([function(e,r){"use strict";var s=function(){function e(r){var s=this;void 0===r&&(r={processTrackingProperties:{addTrackingProperties:e.defaultAddTrackingProperties,getTrackingProperties:e.defaultGetTrackingProperties},isErrorMessage:e.defaultIsErrorMessage,receiveWindow:window,name:e.createRandomString()}),this.pendingRequestPromises={},this.addTrackingProperties=r.processTrackingProperties&&r.processTrackingProperties.addTrackingProperties||e.defaultAddTrackingProperties,this.getTrackingProperties=r.processTrackingProperties&&r.processTrackingProperties.getTrackingProperties||e.defaultGetTrackingProperties,this.isErrorMessage=r.isErrorMessage||e.defaultIsErrorMessage,this.receiveWindow=r.receiveWindow||window,this.name=r.name||e.createRandomString(),this.logMessages=r.logMessages||!1,this.eventSourceOverrideWindow=r.eventSourceOverrideWindow,this.suppressWarnings=r.suppressWarnings||!1,this.logMessages&&console.log("new WindowPostMessageProxy created with name: "+this.name+" receiving on window: "+this.receiveWindow.document.title),this.handlers=[],this.windowMessageHandler=function(e){return s.onMessageReceived(e)},this.start()}return e.defaultAddTrackingProperties=function(r,s){return r[e.messagePropertyName]=s,r},e.defaultGetTrackingProperties=function(r){return r[e.messagePropertyName]},e.defaultIsErrorMessage=function(e){return!!e.error},e.prototype.addHandler=function(e){this.handlers.push(e)},e.prototype.removeHandler=function(e){var r=this.handlers.indexOf(e);if(-1==r)throw new Error("You attempted to remove a handler but no matching handler was found.");this.handlers.splice(r,1)},e.prototype.start=function(){this.receiveWindow.addEventListener("message",this.windowMessageHandler)},e.prototype.stop=function(){this.receiveWindow.removeEventListener("message",this.windowMessageHandler)},e.prototype.postMessage=function(r,s){var n={id:e.createRandomString()};this.addTrackingProperties(s,n),this.logMessages&&(console.log(this.name+" Posting message:"),console.log(JSON.stringify(s,null," "))),r.postMessage(s,"*");var t=e.createDeferred();return this.pendingRequestPromises[n.id]=t,t.promise},e.prototype.sendResponse=function(e,r,s){this.addTrackingProperties(r,s),this.logMessages&&(console.log(this.name+" Sending response:"),console.log(JSON.stringify(r,null," "))),e.postMessage(r,"*")},e.prototype.onMessageReceived=function(e){var r=this;this.logMessages&&(console.log(this.name+" Received message:"),console.log("type: "+e.type),console.log(JSON.stringify(e.data,null," ")));var s=this.eventSourceOverrideWindow||e.source,n=e.data;if("object"!=typeof n)return void(this.suppressWarnings||console.warn("Proxy("+this.name+"): Received message that was not an object. Discarding message"));var t;try{t=this.getTrackingProperties(n)}catch(o){this.suppressWarnings||console.warn("Proxy("+this.name+"): Error occurred when attempting to get tracking properties from incoming message:",JSON.stringify(n,null," "),"Error: ",o)}var i;if(t&&(i=this.pendingRequestPromises[t.id]),i){var a=!0;try{a=this.isErrorMessage(n)}catch(o){console.warn("Proxy("+this.name+") Error occurred when trying to determine if message is consider an error response. Message: ",JSON.stringify(n,null,""),"Error: ",o)}a?i.reject(n):i.resolve(n),delete this.pendingRequestPromises[t.id]}else{var d=this.handlers.some(function(e){var o=!1;try{o=e.test(n)}catch(i){r.suppressWarnings||console.warn("Proxy("+r.name+"): Error occurred when handler was testing incoming message:",JSON.stringify(n,null," "),"Error: ",i)}if(o){var a=void 0;try{a=Promise.resolve(e.handle(n))}catch(i){r.suppressWarnings||console.warn("Proxy("+r.name+"): Error occurred when handler was processing incoming message:",JSON.stringify(n,null," "),"Error: ",i),a=Promise.resolve()}return a.then(function(e){if(!e){var o="Handler for message: "+JSON.stringify(n,null," ")+" did not return a response message. The default response message will be returned instead.";r.suppressWarnings||console.warn("Proxy("+r.name+"): "+o),e={warning:o}}r.sendResponse(s,e,t)}),!0}});d||this.suppressWarnings||console.warn("Proxy("+this.name+") did not handle message. Handlers: "+this.handlers.length+" Message: "+JSON.stringify(n,null,"")+".")}},e.createDeferred=function(){var e={resolve:null,reject:null,promise:null},r=new Promise(function(r,s){e.resolve=r,e.reject=s});return e.promise=r,e},e.createRandomString=function(){return(Math.random()+1).toString(36).substring(7)},e.messagePropertyName="windowPostMessageProxy",e}();r.WindowPostMessageProxy=s}])});
{
"name": "window-post-message-proxy",
"version": "0.2.0",
"version": "0.2.1",
"description": "A library used in place of the native window.postMessage which when used on both the sending and receiving windows allow for a nicer asynchronouse promise messaging between the windows",

@@ -34,2 +34,3 @@ "main": "dist/windowPostMessageProxy.js",

"gulp": "^3.9.1",
"gulp-gh-pages": "^0.5.4",
"gulp-header": "^1.8.7",

@@ -39,2 +40,3 @@ "gulp-help": "^1.6.1",

"gulp-replace": "^0.5.4",
"gulp-typedoc": "^2.0.0",
"gulp-uglify": "^1.5.3",

@@ -50,5 +52,7 @@ "jasmine-core": "^2.4.1",

"karma-spec-reporter": "0.0.26",
"moment": "^2.14.1",
"phantomjs-prebuilt": "^2.1.7",
"run-sequence": "^1.1.5",
"ts-loader": "^0.8.2",
"typedoc": "^0.4.4",
"webpack-stream": "^3.2.0",

@@ -55,0 +59,0 @@ "yargs": "^4.6.0"

# window-post-message-proxy
[![Build Status](https://travis-ci.com/Microsoft/window-post-message-proxy.svg?token=nXyWFYxRu6tVxUMJAuJr&branch=master)](https://travis-ci.com/Microsoft/window-post-message-proxy)

@@ -10,3 +11,4 @@ A library used in place of the native window.postMessage which when used on both the sending and receiving windows allow for a nicer asynchronouse promise messaging between the windows.

## Installation
```
```bash
npm install --save window-post-message-proxy

@@ -16,3 +18,4 @@ ```

## Basic Usage
```
```typescript
// Setup

@@ -40,3 +43,4 @@ const iframe = document.getElementById("myFrame");

This means if you call:
```
```typescript
const message = {

@@ -49,3 +53,4 @@ key: "Value"

The message is actually modified before it's sent to become:
```
```typescript
{

@@ -59,4 +64,5 @@ windowPostMessageProxy: {

If you want to customize how the tracking properties are added to and retreived from the message you can provide it at construction time as an object with two funtions. See the interface below:
```
If you want to customize how the tracking properties are added to and retreived from the message you can provide it at construction time as an object with two funtions. See the interface below:
```typescript
export interface IProcessTrackingProperties {

@@ -72,3 +78,4 @@ addTrackingProperties<T>(message: T, trackingProperties: ITrackingProperties): T;

Example:
```
```typescript
const customProcessTrackingProperties = {

@@ -96,3 +103,4 @@ addTrackingProperties(message, trackingProperties) {

You can override this behavior by passing an `isErrorMessage` function at construction time. See interface:
```
```typescript
export interface IIsErrorMessage {

@@ -104,3 +112,4 @@ (message: any): boolean;

Example:
```
```typescript
function isErrorMessage(message: any) {

@@ -116,3 +125,4 @@ return !(200 <= message.status && message.status < 300);

By default messagse are not logged, but you can override this behavior by passing `logMessages: true` in the options object.
```
```typescript
const windowPostMessageProxy = new WindowPostMessageProxy({ logMessages: true });

@@ -128,3 +138,3 @@ ```

```
```typescript
const windowPostMessageProxy = new WindowPostMessageProxy({ name: 'Iframe' });

@@ -137,4 +147,4 @@ ```

```typescript
const windowPostMessageProxy = new WindowPostMessageProxy({ suppressMessageNotHandledWarning: true });
```
const windowPostMessageProxy = new WindowPostMessageProxy({ suppressMessageNotHandledWarning: true });
```

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