window-post-message-proxy
Advanced tools
Comparing version 0.2.8 to 0.2.9
@@ -1,2 +0,2 @@ | ||
/*! window-post-message-proxy v0.2.8 | (c) 2016 Microsoft Corporation MIT */ | ||
/*! window-post-message-proxy v0.2.9 | (c) 2016 Microsoft Corporation MIT */ | ||
declare global { | ||
@@ -3,0 +3,0 @@ interface Window { |
@@ -1,2 +0,2 @@ | ||
/*! window-post-message-proxy v0.2.8 | (c) 2016 Microsoft Corporation MIT */ | ||
/*! window-post-message-proxy v0.2.9 | (c) 2016 Microsoft Corporation MIT */ | ||
declare global { | ||
@@ -3,0 +3,0 @@ interface Window { |
@@ -1,1 +0,1 @@ | ||
/*! window-post-message-proxy v0.2.8 | (c) 2016 Microsoft Corporation MIT */ | ||
/*! window-post-message-proxy v0.2.9 | (c) 2016 Microsoft Corporation MIT */ |
/*! For license information please see windowPostMessageProxy.js.LICENSE.txt */ | ||
!function(e,s){"object"==typeof exports&&"object"==typeof module?module.exports=s():"function"==typeof define&&define.amd?define([],s):"object"==typeof exports?exports["window-post-message-proxy"]=s():e["window-post-message-proxy"]=s()}(self,()=>(()=>{"use strict";var e,s,r={};return e=r,Object.defineProperty(e,"__esModule",{value:!0}),e.WindowPostMessageProxy=void 0,n.defaultAddTrackingProperties=function(e,s){return e[n.messagePropertyName]=s,e},n.defaultGetTrackingProperties=function(e){return e[n.messagePropertyName]},n.defaultIsErrorMessage=function(e){return!!e.error},n.createDeferred=function(){var r={resolve:null,reject:null,promise:null},e=new Promise(function(e,s){r.resolve=e,r.reject=s});return r.promise=e,r},n.createRandomString=function(){var e=window.crypto||window.msCrypto,s=new Uint32Array(1);return e.getRandomValues(s),s[0].toString(36).substring(1)},n.prototype.addHandler=function(e){this.handlers.push(e)},n.prototype.removeHandler=function(e){e=this.handlers.indexOf(e);if(-1===e)throw new Error("You attempted to remove a handler but no matching handler was found.");this.handlers.splice(e,1)},n.prototype.start=function(){this.receiveWindow.addEventListener("message",this.windowMessageHandler)},n.prototype.stop=function(){this.receiveWindow.removeEventListener("message",this.windowMessageHandler)},n.prototype.postMessage=function(e,s){var r={id:n.createRandomString()},e=(this.addTrackingProperties(s,r),this.logMessages&&(console.log("".concat(this.name," Posting message:")),console.log(JSON.stringify(s,null," "))),e.postMessage(s,"*"),n.createDeferred());return(this.pendingRequestPromises[r.id]=e).promise},n.prototype.sendResponse=function(e,s,r){this.addTrackingProperties(s,r),this.logMessages&&(console.log("".concat(this.name," Sending response:")),console.log(JSON.stringify(s,null," "))),e.postMessage(s,"*")},n.prototype.onMessageReceived=function(e){var r=this,n=(this.logMessages&&(console.log("".concat(this.name," Received message:")),console.log("type: ".concat(e.type)),console.log(JSON.stringify(e.data,null," "))),this.eventSourceOverrideWindow||e.source);if(n){var o,s,t=e.data;if("object"==typeof t){try{o=this.getTrackingProperties(t)}catch(e){this.suppressWarnings||console.warn("Proxy(".concat(this.name,"): Error occurred when attempting to get tracking properties from incoming message:"),JSON.stringify(t,null," "),"Error: ",e)}if(s=o?this.pendingRequestPromises[o.id]:s){var i=!0;try{i=this.isErrorMessage(t)}catch(e){console.warn("Proxy(".concat(this.name,") Error occurred when trying to determine if message is consider an error response. Message: "),JSON.stringify(t,null,""),"Error: ",e)}i?s.reject(t):s.resolve(t),delete this.pendingRequestPromises[o.id]}else this.handlers.some(function(e){var s=!1;try{s=e.test(t)}catch(e){r.suppressWarnings||console.warn("Proxy(".concat(r.name,"): Error occurred when handler was testing incoming message:"),JSON.stringify(t,null," "),"Error: ",e)}if(s){s=void 0;try{s=Promise.resolve(e.handle(t))}catch(e){r.suppressWarnings||console.warn("Proxy(".concat(r.name,"): Error occurred when handler was processing incoming message:"),JSON.stringify(t,null," "),"Error: ",e),s=Promise.resolve()}return s.then(function(e){var s;e||(s="Handler for message: ".concat(JSON.stringify(t,null," ")," did not return a response message. The default response message will be returned instead."),r.suppressWarnings||console.warn("Proxy(".concat(r.name,"): ").concat(s)),e={warning:s}),r.sendResponse(n,e,o)}),!0}})||this.suppressWarnings||console.warn("Proxy(".concat(this.name,") did not handle message. Handlers: ").concat(this.handlers.length," Message: ").concat(JSON.stringify(t,null,""),"."))}else this.suppressWarnings||console.warn("Proxy(".concat(this.name,"): Received message that was not an object. Discarding message"))}},n.messagePropertyName="windowPostMessageProxy",s=n,e.WindowPostMessageProxy=s,r;function n(e){void 0===e&&(e={processTrackingProperties:{addTrackingProperties:n.defaultAddTrackingProperties,getTrackingProperties:n.defaultGetTrackingProperties},isErrorMessage:n.defaultIsErrorMessage,receiveWindow:window,name:n.createRandomString()});var s=this;this.pendingRequestPromises={},this.addTrackingProperties=e.processTrackingProperties&&e.processTrackingProperties.addTrackingProperties||n.defaultAddTrackingProperties,this.getTrackingProperties=e.processTrackingProperties&&e.processTrackingProperties.getTrackingProperties||n.defaultGetTrackingProperties,this.isErrorMessage=e.isErrorMessage||n.defaultIsErrorMessage,this.receiveWindow=e.receiveWindow||window,this.name=e.name||n.createRandomString(),this.logMessages=e.logMessages||!1,this.eventSourceOverrideWindow=e.eventSourceOverrideWindow,this.suppressWarnings=e.suppressWarnings||!1,this.logMessages&&console.log("new WindowPostMessageProxy created with name: ".concat(this.name," receiving on window: ").concat(this.receiveWindow.document.title)),this.handlers=[],this.windowMessageHandler=function(e){return s.onMessageReceived(e)},this.start()}})()); | ||
!function(e,s){"object"==typeof exports&&"object"==typeof module?module.exports=s():"function"==typeof define&&define.amd?define([],s):"object"==typeof exports?exports["window-post-message-proxy"]=s():e["window-post-message-proxy"]=s()}(self,()=>{return e=r={},Object.defineProperty(e,"__esModule",{value:!0}),e.WindowPostMessageProxy=void 0,n.defaultAddTrackingProperties=function(e,s){return e[n.messagePropertyName]=s,e},n.defaultGetTrackingProperties=function(e){return e[n.messagePropertyName]},n.defaultIsErrorMessage=function(e){return!!e.error},n.createDeferred=function(){var r={resolve:null,reject:null,promise:null},e=new Promise(function(e,s){r.resolve=e,r.reject=s});return r.promise=e,r},n.createRandomString=function(){var e=window.crypto||window.msCrypto,s=new Uint32Array(1);return e.getRandomValues(s),s[0].toString(36).substring(1)},n.prototype.addHandler=function(e){this.handlers.push(e)},n.prototype.removeHandler=function(e){e=this.handlers.indexOf(e);if(-1===e)throw new Error("You attempted to remove a handler but no matching handler was found.");this.handlers.splice(e,1)},n.prototype.start=function(){this.receiveWindow.addEventListener("message",this.windowMessageHandler)},n.prototype.stop=function(){this.receiveWindow.removeEventListener("message",this.windowMessageHandler)},n.prototype.postMessage=function(e,s){var r={id:n.createRandomString()},e=(this.addTrackingProperties(s,r),this.logMessages&&(console.log("".concat(this.name," Posting message:")),console.log(JSON.stringify(s,null," "))),e.postMessage(s,"*"),n.createDeferred());return(this.pendingRequestPromises[r.id]=e).promise},n.prototype.sendResponse=function(e,s,r){this.addTrackingProperties(s,r),this.logMessages&&(console.log("".concat(this.name," Sending response:")),console.log(JSON.stringify(s,null," "))),e.postMessage(s,"*")},n.prototype.onMessageReceived=function(e){var r=this,n=(this.logMessages&&(console.log("".concat(this.name," Received message:")),console.log("type: ".concat(e.type)),console.log(JSON.stringify(e.data,null," "))),this.eventSourceOverrideWindow||e.source);if(n){var o,s,t=e.data;if("object"==typeof t){try{o=this.getTrackingProperties(t)}catch(e){this.suppressWarnings||console.warn("Proxy(".concat(this.name,"): Error occurred when attempting to get tracking properties from incoming message:"),JSON.stringify(t,null," "),"Error: ",e)}if(s=o?this.pendingRequestPromises[o.id]:s){var i=!0;try{i=this.isErrorMessage(t)}catch(e){console.warn("Proxy(".concat(this.name,") Error occurred when trying to determine if message is consider an error response. Message: "),JSON.stringify(t,null,""),"Error: ",e)}i?s.reject(t):s.resolve(t),delete this.pendingRequestPromises[o.id]}else this.handlers.some(function(e){var s=!1;try{s=e.test(t)}catch(e){r.suppressWarnings||console.warn("Proxy(".concat(r.name,"): Error occurred when handler was testing incoming message:"),JSON.stringify(t,null," "),"Error: ",e)}if(s){s=void 0;try{s=Promise.resolve(e.handle(t))}catch(e){r.suppressWarnings||console.warn("Proxy(".concat(r.name,"): Error occurred when handler was processing incoming message:"),JSON.stringify(t,null," "),"Error: ",e),s=Promise.resolve()}return s.then(function(e){var s;e||(s="Handler for message: ".concat(JSON.stringify(t,null," ")," did not return a response message. The default response message will be returned instead."),r.suppressWarnings||console.warn("Proxy(".concat(r.name,"): ").concat(s)),e={warning:s}),r.sendResponse(n,e,o)}),!0}})||this.suppressWarnings||console.warn("Proxy(".concat(this.name,") did not handle message. Handlers: ").concat(this.handlers.length," Message: ").concat(JSON.stringify(t,null,""),"."))}else this.suppressWarnings||console.warn("Proxy(".concat(this.name,"): Received message that was not an object. Discarding message"))}},n.messagePropertyName="windowPostMessageProxy",s=n,e.WindowPostMessageProxy=s,r;function n(e){void 0===e&&(e={processTrackingProperties:{addTrackingProperties:n.defaultAddTrackingProperties,getTrackingProperties:n.defaultGetTrackingProperties},isErrorMessage:n.defaultIsErrorMessage,receiveWindow:window,name:n.createRandomString()});var s=this;this.pendingRequestPromises={},this.addTrackingProperties=e.processTrackingProperties&&e.processTrackingProperties.addTrackingProperties||n.defaultAddTrackingProperties,this.getTrackingProperties=e.processTrackingProperties&&e.processTrackingProperties.getTrackingProperties||n.defaultGetTrackingProperties,this.isErrorMessage=e.isErrorMessage||n.defaultIsErrorMessage,this.receiveWindow=e.receiveWindow||window,this.name=e.name||n.createRandomString(),this.logMessages=e.logMessages||!1,this.eventSourceOverrideWindow=e.eventSourceOverrideWindow,this.suppressWarnings=e.suppressWarnings||!1,this.logMessages&&console.log("new WindowPostMessageProxy created with name: ".concat(this.name," receiving on window: ").concat(this.receiveWindow.document.title)),this.handlers=[],this.windowMessageHandler=function(e){return s.onMessageReceived(e)},this.start()}var e,s,r}); |
{ | ||
"name": "window-post-message-proxy", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"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", | ||
@@ -48,8 +48,6 @@ "main": "dist/windowPostMessageProxy.js", | ||
"gulp-eslint": "^6.0.0", | ||
"gulp-gh-pages": "^0.5.4", | ||
"gulp-header": "^1.8.7", | ||
"gulp-help-four": "^0.2.3", | ||
"gulp-prepend": "^0.3.0", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-replace": "^0.5.4", | ||
"gulp-typedoc": "^2.0.0", | ||
"gulp-uglify": "^3.0.2", | ||
@@ -65,3 +63,2 @@ "gulp4-run-sequence": "^1.0.1", | ||
"karma-spec-reporter": "0.0.26", | ||
"moment": "^2.14.1", | ||
"ts-loader": "^9.2.8", | ||
@@ -77,4 +74,4 @@ "typedoc": "^0.22.15", | ||
"glob-parent": "^6.0.2", | ||
"lodash.template": "^4.5.0", | ||
"micromatch": "^4.0.5" | ||
"micromatch": "^4.0.5", | ||
"braces": "^3.0.3" | ||
}, | ||
@@ -81,0 +78,0 @@ "publishConfig": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
36
0
43157