connect-web-sdk
Advanced tools
Comparing version
# Changelog | ||
### [2.0.0](https://www.npmjs.com/package/connect-web-sdk/v/2.0.0) (Latest) | ||
### [2.1.0](https://www.npmjs.com/package/connect-web-sdk/v/2.1.0) (Latest) | ||
--- | ||
###### Features | ||
- Added a new optional onUrl event handler to the ConnectEventHandlers interface. This handler allows developers to listen for URL-related events, such as opening or closing a URL. The onUrl function accepts two parameters: | ||
- **type**: A string literal ('OPEN' or 'CLOSE') indicating the type of event. | ||
- **url**: An optional string parameter that is only present when type is 'OPEN'. | ||
###### Considerations for upgrading to 2.1.0: | ||
- This is a non-breaking change. Existing implementations will continue to work without modification. | ||
- If you want to manually handle URL events in popup scenarios, you can now provide an onUrl handler in the eventHandlers object when calling Connect.launch(). | ||
If you provide an onUrl handler, you'll need to implement your own logic for opening and closing URLs, as the SDK will no longer handle these events automatically. | ||
Note: The default behavior for URL events remains unchanged if you don't provide an onUrl handler. The onUrl handler is optional, so you can safely ignore it if your application does not require custom URL event handling. | ||
### [2.0.0](https://www.npmjs.com/package/connect-web-sdk/v/2.0.0) (09/17/2024) | ||
___ | ||
@@ -5,0 +20,0 @@ ###### Features |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e="connectIframe",t="connectStyles",o="window";let n,s,r,i,a,d,l,c;const u={onLoad:()=>{},onUser:e=>{},onRoute:e=>{}},p={destroy(){i&&i.parentNode&&i.parentNode.removeChild(i),a&&a.parentNode&&a.parentNode.removeChild(a),!i&&d&&d.close(),i=void 0,a=void 0,window.removeEventListener("message",s)},launch(o,s,c={}){if(r=o,n=Object.assign(Object.assign({},u),s),l=new URL(r).origin,c.popup){const e={toolbar:"no",location:"no",status:"no",menubar:"no",width:720,height:520,top:window.self.outerHeight/2+window.self.screenY-360,left:window.self.outerWidth/2+window.self.screenX-260},t=Object.assign(Object.assign({},e),c.popupOptions),o=window.open(r,"targetWindow",`toolbar=${e.toolbar},location=${e.location},status=${e.status},menubar=${e.menubar},width=${t.width},height=${t.height},top=${t.top},left=${t.left}`);return o?(d=o,o.focus(),this.initPostMessage(c),n.onLoad&&n.onLoad()):n.onError({reason:"error",code:1403}),o}if(i&&i.parentNode)throw new Error('You must destroy the iframe before you can open a new one. Call "destroy()"');if(!document.getElementById(t)){const o=document.createElement("style");o.id=t,o.type="text/css",o.innerHTML=`#${e} {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 10;\n background: rgba(0,0,0,0.8);\n }`,document.getElementsByTagName("head")[0].appendChild(o)}if(0===document.querySelectorAll('meta[name="viewport"]').length&&(a=document.createElement("meta"),a.setAttribute("name","viewport"),a.setAttribute("content","initial-scale=1"),document.head.appendChild(a)),i=document.createElement("iframe"),i.src=r,i.setAttribute("id",e),i.setAttribute("frameborder","0"),i.setAttribute("scrolling","no"),i.setAttribute("aria-label","Launching Modal"),i.setAttribute("title","Launching Modal"),c.overlay&&i.setAttribute("style",`background: ${c.overlay};`),c.node)c.node.appendChild(i);else{const e=c.selector?document.querySelector(c.selector):document.body;e?e.appendChild(i):(console.warn(`Couldn't find any elements matching "${c.selector}", appending "iframe" to "body" instead.`),document.body.appendChild(i))}return i.onload=()=>{d=i.contentWindow,this.initPostMessage(c),n.onLoad&&n.onLoad()},null},initPostMessage(e){const t=setInterval((()=>{const t={type:"ping",selector:e.selector,sdkVersion:"2.0.0",platform:""+(e.popup?"web":"iframe")};e.redirectUrl&&(t.redirectUrl=e.redirectUrl),this.postMessage(t)}),1e3);s=o=>{const s=o.data.data,r=o.data.type;o.origin===l&&("ack"!==r||e.popup?"url"===r?this.openPopupWindow(o.data.url):"done"===r?(n.onDone(s),this.destroy()):"cancel"===r?(n.onCancel(s),this.destroy()):"error"===r?(n.onError(s),this.destroy()):"route"===r?n.onRoute&&n.onRoute(s):"user"===r?n.onUser&&n.onUser(s):"closePopup"===r&&(null==c||c.close()):clearInterval(t))},window.addEventListener("message",s)},openPopupWindow(e){const t=window.self.outerHeight/2+window.self.screenY-300,n=window.self.outerWidth/2+window.self.screenX-300;if(c=window.open(e,"targetWindow",`toolbar=no,location=no,status=no,menubar=no,width=600,height=600,top=${t},left=${n}`),c){c.focus();const e=setInterval((()=>{(null==c?void 0:c.closed)&&(clearInterval(e),this.postMessage({type:o,closed:!0,blocked:!1}))}),1e3)}else this.postMessage({type:o,closed:!0,blocked:!0})},postMessage(e){null==d||d.postMessage(e,r)}};exports.Connect=p; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e="connectIframe",t="connectStyles",o="window";let n,s,r,i,a,d,l,c;const u="OPEN",p="CLOSE",h={onLoad:()=>{},onUser:e=>{},onRoute:e=>{}},w={destroy(){i&&i.parentNode&&i.parentNode.removeChild(i),a&&a.parentNode&&a.parentNode.removeChild(a),!i&&d&&d.close(),i=void 0,a=void 0,window.removeEventListener("message",s)},launch(o,s,c={}){if(r=o,n=Object.assign(Object.assign({},h),s),l=new URL(r).origin,c.popup){const e={toolbar:"no",location:"no",status:"no",menubar:"no",width:720,height:520,top:window.self.outerHeight/2+window.self.screenY-360,left:window.self.outerWidth/2+window.self.screenX-260},t=Object.assign(Object.assign({},e),c.popupOptions),o=window.open(r,"targetWindow",`toolbar=${e.toolbar},location=${e.location},status=${e.status},menubar=${e.menubar},width=${t.width},height=${t.height},top=${t.top},left=${t.left}`);return o?(d=o,o.focus(),this.initPostMessage(c),n.onLoad&&n.onLoad()):n.onError({reason:"error",code:1403}),o}if(i&&i.parentNode)throw new Error('You must destroy the iframe before you can open a new one. Call "destroy()"');if(!document.getElementById(t)){const o=document.createElement("style");o.id=t,o.type="text/css",o.innerHTML=`#${e} {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 10;\n background: rgba(0,0,0,0.8);\n }`,document.getElementsByTagName("head")[0].appendChild(o)}if(0===document.querySelectorAll('meta[name="viewport"]').length&&(a=document.createElement("meta"),a.setAttribute("name","viewport"),a.setAttribute("content","initial-scale=1"),document.head.appendChild(a)),i=document.createElement("iframe"),i.src=r,i.setAttribute("id",e),i.setAttribute("frameborder","0"),i.setAttribute("scrolling","no"),i.setAttribute("aria-label","Launching Modal"),i.setAttribute("title","Launching Modal"),c.overlay&&i.setAttribute("style",`background: ${c.overlay};`),c.node)c.node.appendChild(i);else{const e=c.selector?document.querySelector(c.selector):document.body;e?e.appendChild(i):(console.warn(`Couldn't find any elements matching "${c.selector}", appending "iframe" to "body" instead.`),document.body.appendChild(i))}return i.onload=()=>{d=i.contentWindow,this.initPostMessage(c),n.onLoad&&n.onLoad()},null},initPostMessage(e){const t=setInterval((()=>{const t={type:"ping",selector:e.selector,sdkVersion:"2.1.0",platform:""+(e.popup?"web":"iframe")};e.redirectUrl&&(t.redirectUrl=e.redirectUrl),this.postMessage(t)}),1e3);s=o=>{const s=o.data.data,r=o.data.type;if(o.origin===l){const i=!!n.onUrl;"ack"!==r||e.popup?"url"===r?i?n.onUrl(u,o.data.url):this.openPopupWindow(o.data.url):"done"===r?(n.onDone(s),this.destroy()):"cancel"===r?(n.onCancel(s),this.destroy()):"error"===r?(n.onError(s),this.destroy()):"route"===r?n.onRoute&&n.onRoute(s):"user"===r?n.onUser&&n.onUser(s):"closePopup"===r&&(i?n.onUrl(p):null==c||c.close()):clearInterval(t)}},window.addEventListener("message",s)},openPopupWindow(e){const t=window.self.outerHeight/2+window.self.screenY-300,n=window.self.outerWidth/2+window.self.screenX-300;if(c=window.open(e,"targetWindow",`toolbar=no,location=no,status=no,menubar=no,width=600,height=600,top=${t},left=${n}`),c){c.focus();const e=setInterval((()=>{(null==c?void 0:c.closed)&&(clearInterval(e),this.postMessage({type:o,closed:!0,blocked:!1}))}),1e3)}else this.postMessage({type:o,closed:!0,blocked:!0})},postMessage(e){null==d||d.postMessage(e,r)}};exports.Connect=w; | ||
//# sourceMappingURL=mastercard-connect-cjs.min.js.map |
@@ -1,2 +0,2 @@ | ||
const e="connectIframe",t="connectStyles",o="window";let n,s,r,i,a,d,l,c;const u={onLoad:()=>{},onUser:e=>{},onRoute:e=>{}},p={destroy(){i&&i.parentNode&&i.parentNode.removeChild(i),a&&a.parentNode&&a.parentNode.removeChild(a),!i&&d&&d.close(),i=void 0,a=void 0,window.removeEventListener("message",s)},launch(o,s,c={}){if(r=o,n=Object.assign(Object.assign({},u),s),l=new URL(r).origin,c.popup){const e={toolbar:"no",location:"no",status:"no",menubar:"no",width:720,height:520,top:window.self.outerHeight/2+window.self.screenY-360,left:window.self.outerWidth/2+window.self.screenX-260},t=Object.assign(Object.assign({},e),c.popupOptions),o=window.open(r,"targetWindow",`toolbar=${e.toolbar},location=${e.location},status=${e.status},menubar=${e.menubar},width=${t.width},height=${t.height},top=${t.top},left=${t.left}`);return o?(d=o,o.focus(),this.initPostMessage(c),n.onLoad&&n.onLoad()):n.onError({reason:"error",code:1403}),o}if(i&&i.parentNode)throw new Error('You must destroy the iframe before you can open a new one. Call "destroy()"');if(!document.getElementById(t)){const o=document.createElement("style");o.id=t,o.type="text/css",o.innerHTML=`#${e} {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 10;\n background: rgba(0,0,0,0.8);\n }`,document.getElementsByTagName("head")[0].appendChild(o)}if(0===document.querySelectorAll('meta[name="viewport"]').length&&(a=document.createElement("meta"),a.setAttribute("name","viewport"),a.setAttribute("content","initial-scale=1"),document.head.appendChild(a)),i=document.createElement("iframe"),i.src=r,i.setAttribute("id",e),i.setAttribute("frameborder","0"),i.setAttribute("scrolling","no"),i.setAttribute("aria-label","Launching Modal"),i.setAttribute("title","Launching Modal"),c.overlay&&i.setAttribute("style",`background: ${c.overlay};`),c.node)c.node.appendChild(i);else{const e=c.selector?document.querySelector(c.selector):document.body;e?e.appendChild(i):(console.warn(`Couldn't find any elements matching "${c.selector}", appending "iframe" to "body" instead.`),document.body.appendChild(i))}return i.onload=()=>{d=i.contentWindow,this.initPostMessage(c),n.onLoad&&n.onLoad()},null},initPostMessage(e){const t=setInterval((()=>{const t={type:"ping",selector:e.selector,sdkVersion:"2.0.0",platform:""+(e.popup?"web":"iframe")};e.redirectUrl&&(t.redirectUrl=e.redirectUrl),this.postMessage(t)}),1e3);s=o=>{const s=o.data.data,r=o.data.type;o.origin===l&&("ack"!==r||e.popup?"url"===r?this.openPopupWindow(o.data.url):"done"===r?(n.onDone(s),this.destroy()):"cancel"===r?(n.onCancel(s),this.destroy()):"error"===r?(n.onError(s),this.destroy()):"route"===r?n.onRoute&&n.onRoute(s):"user"===r?n.onUser&&n.onUser(s):"closePopup"===r&&(null==c||c.close()):clearInterval(t))},window.addEventListener("message",s)},openPopupWindow(e){const t=window.self.outerHeight/2+window.self.screenY-300,n=window.self.outerWidth/2+window.self.screenX-300;if(c=window.open(e,"targetWindow",`toolbar=no,location=no,status=no,menubar=no,width=600,height=600,top=${t},left=${n}`),c){c.focus();const e=setInterval((()=>{(null==c?void 0:c.closed)&&(clearInterval(e),this.postMessage({type:o,closed:!0,blocked:!1}))}),1e3)}else this.postMessage({type:o,closed:!0,blocked:!0})},postMessage(e){null==d||d.postMessage(e,r)}};export{p as Connect}; | ||
const e="connectIframe",t="connectStyles",o="window";let n,s,r,i,a,d,l,c;const u="OPEN",p="CLOSE",h={onLoad:()=>{},onUser:e=>{},onRoute:e=>{}},w={destroy(){i&&i.parentNode&&i.parentNode.removeChild(i),a&&a.parentNode&&a.parentNode.removeChild(a),!i&&d&&d.close(),i=void 0,a=void 0,window.removeEventListener("message",s)},launch(o,s,c={}){if(r=o,n=Object.assign(Object.assign({},h),s),l=new URL(r).origin,c.popup){const e={toolbar:"no",location:"no",status:"no",menubar:"no",width:720,height:520,top:window.self.outerHeight/2+window.self.screenY-360,left:window.self.outerWidth/2+window.self.screenX-260},t=Object.assign(Object.assign({},e),c.popupOptions),o=window.open(r,"targetWindow",`toolbar=${e.toolbar},location=${e.location},status=${e.status},menubar=${e.menubar},width=${t.width},height=${t.height},top=${t.top},left=${t.left}`);return o?(d=o,o.focus(),this.initPostMessage(c),n.onLoad&&n.onLoad()):n.onError({reason:"error",code:1403}),o}if(i&&i.parentNode)throw new Error('You must destroy the iframe before you can open a new one. Call "destroy()"');if(!document.getElementById(t)){const o=document.createElement("style");o.id=t,o.type="text/css",o.innerHTML=`#${e} {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 10;\n background: rgba(0,0,0,0.8);\n }`,document.getElementsByTagName("head")[0].appendChild(o)}if(0===document.querySelectorAll('meta[name="viewport"]').length&&(a=document.createElement("meta"),a.setAttribute("name","viewport"),a.setAttribute("content","initial-scale=1"),document.head.appendChild(a)),i=document.createElement("iframe"),i.src=r,i.setAttribute("id",e),i.setAttribute("frameborder","0"),i.setAttribute("scrolling","no"),i.setAttribute("aria-label","Launching Modal"),i.setAttribute("title","Launching Modal"),c.overlay&&i.setAttribute("style",`background: ${c.overlay};`),c.node)c.node.appendChild(i);else{const e=c.selector?document.querySelector(c.selector):document.body;e?e.appendChild(i):(console.warn(`Couldn't find any elements matching "${c.selector}", appending "iframe" to "body" instead.`),document.body.appendChild(i))}return i.onload=()=>{d=i.contentWindow,this.initPostMessage(c),n.onLoad&&n.onLoad()},null},initPostMessage(e){const t=setInterval((()=>{const t={type:"ping",selector:e.selector,sdkVersion:"2.1.0",platform:""+(e.popup?"web":"iframe")};e.redirectUrl&&(t.redirectUrl=e.redirectUrl),this.postMessage(t)}),1e3);s=o=>{const s=o.data.data,r=o.data.type;if(o.origin===l){const i=!!n.onUrl;"ack"!==r||e.popup?"url"===r?i?n.onUrl(u,o.data.url):this.openPopupWindow(o.data.url):"done"===r?(n.onDone(s),this.destroy()):"cancel"===r?(n.onCancel(s),this.destroy()):"error"===r?(n.onError(s),this.destroy()):"route"===r?n.onRoute&&n.onRoute(s):"user"===r?n.onUser&&n.onUser(s):"closePopup"===r&&(i?n.onUrl(p):null==c||c.close()):clearInterval(t)}},window.addEventListener("message",s)},openPopupWindow(e){const t=window.self.outerHeight/2+window.self.screenY-300,n=window.self.outerWidth/2+window.self.screenX-300;if(c=window.open(e,"targetWindow",`toolbar=no,location=no,status=no,menubar=no,width=600,height=600,top=${t},left=${n}`),c){c.focus();const e=setInterval((()=>{(null==c?void 0:c.closed)&&(clearInterval(e),this.postMessage({type:o,closed:!0,blocked:!1}))}),1e3)}else this.postMessage({type:o,closed:!0,blocked:!0})},postMessage(e){null==d||d.postMessage(e,r)}};export{w as Connect}; | ||
//# sourceMappingURL=mastercard-connect-esm.min.js.map |
@@ -1,2 +0,2 @@ | ||
var Connect=function(){"use strict";const e="connectIframe",t="connectStyles",o="window";let n,s,r,i,a,d,l,c;const u={onLoad:()=>{},onUser:e=>{},onRoute:e=>{}},p={destroy(){i&&i.parentNode&&i.parentNode.removeChild(i),a&&a.parentNode&&a.parentNode.removeChild(a),!i&&d&&d.close(),i=void 0,a=void 0,window.removeEventListener("message",s)},launch(o,s,c={}){if(r=o,n=Object.assign(Object.assign({},u),s),l=new URL(r).origin,c.popup){const e={toolbar:"no",location:"no",status:"no",menubar:"no",width:720,height:520,top:window.self.outerHeight/2+window.self.screenY-360,left:window.self.outerWidth/2+window.self.screenX-260},t=Object.assign(Object.assign({},e),c.popupOptions),o=window.open(r,"targetWindow",`toolbar=${e.toolbar},location=${e.location},status=${e.status},menubar=${e.menubar},width=${t.width},height=${t.height},top=${t.top},left=${t.left}`);return o?(d=o,o.focus(),this.initPostMessage(c),n.onLoad&&n.onLoad()):n.onError({reason:"error",code:1403}),o}if(i&&i.parentNode)throw new Error('You must destroy the iframe before you can open a new one. Call "destroy()"');if(!document.getElementById(t)){const o=document.createElement("style");o.id=t,o.type="text/css",o.innerHTML=`#${e} {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 10;\n background: rgba(0,0,0,0.8);\n }`,document.getElementsByTagName("head")[0].appendChild(o)}if(0===document.querySelectorAll('meta[name="viewport"]').length&&(a=document.createElement("meta"),a.setAttribute("name","viewport"),a.setAttribute("content","initial-scale=1"),document.head.appendChild(a)),i=document.createElement("iframe"),i.src=r,i.setAttribute("id",e),i.setAttribute("frameborder","0"),i.setAttribute("scrolling","no"),i.setAttribute("aria-label","Launching Modal"),i.setAttribute("title","Launching Modal"),c.overlay&&i.setAttribute("style",`background: ${c.overlay};`),c.node)c.node.appendChild(i);else{const e=c.selector?document.querySelector(c.selector):document.body;e?e.appendChild(i):(console.warn(`Couldn't find any elements matching "${c.selector}", appending "iframe" to "body" instead.`),document.body.appendChild(i))}return i.onload=()=>{d=i.contentWindow,this.initPostMessage(c),n.onLoad&&n.onLoad()},null},initPostMessage(e){const t=setInterval((()=>{const t={type:"ping",selector:e.selector,sdkVersion:"2.0.0",platform:""+(e.popup?"web":"iframe")};e.redirectUrl&&(t.redirectUrl=e.redirectUrl),this.postMessage(t)}),1e3);s=o=>{const s=o.data.data,r=o.data.type;o.origin===l&&("ack"!==r||e.popup?"url"===r?this.openPopupWindow(o.data.url):"done"===r?(n.onDone(s),this.destroy()):"cancel"===r?(n.onCancel(s),this.destroy()):"error"===r?(n.onError(s),this.destroy()):"route"===r?n.onRoute&&n.onRoute(s):"user"===r?n.onUser&&n.onUser(s):"closePopup"===r&&(null==c||c.close()):clearInterval(t))},window.addEventListener("message",s)},openPopupWindow(e){const t=window.self.outerHeight/2+window.self.screenY-300,n=window.self.outerWidth/2+window.self.screenX-300;if(c=window.open(e,"targetWindow",`toolbar=no,location=no,status=no,menubar=no,width=600,height=600,top=${t},left=${n}`),c){c.focus();const e=setInterval((()=>{(null==c?void 0:c.closed)&&(clearInterval(e),this.postMessage({type:o,closed:!0,blocked:!1}))}),1e3)}else this.postMessage({type:o,closed:!0,blocked:!0})},postMessage(e){null==d||d.postMessage(e,r)}};return p}(); | ||
var Connect=function(){"use strict";const e="connectIframe",t="connectStyles",o="window";let n,s,r,i,a,d,l,c;const u="OPEN",p="CLOSE",h={onLoad:()=>{},onUser:e=>{},onRoute:e=>{}},w={destroy(){i&&i.parentNode&&i.parentNode.removeChild(i),a&&a.parentNode&&a.parentNode.removeChild(a),!i&&d&&d.close(),i=void 0,a=void 0,window.removeEventListener("message",s)},launch(o,s,c={}){if(r=o,n=Object.assign(Object.assign({},h),s),l=new URL(r).origin,c.popup){const e={toolbar:"no",location:"no",status:"no",menubar:"no",width:720,height:520,top:window.self.outerHeight/2+window.self.screenY-360,left:window.self.outerWidth/2+window.self.screenX-260},t=Object.assign(Object.assign({},e),c.popupOptions),o=window.open(r,"targetWindow",`toolbar=${e.toolbar},location=${e.location},status=${e.status},menubar=${e.menubar},width=${t.width},height=${t.height},top=${t.top},left=${t.left}`);return o?(d=o,o.focus(),this.initPostMessage(c),n.onLoad&&n.onLoad()):n.onError({reason:"error",code:1403}),o}if(i&&i.parentNode)throw new Error('You must destroy the iframe before you can open a new one. Call "destroy()"');if(!document.getElementById(t)){const o=document.createElement("style");o.id=t,o.type="text/css",o.innerHTML=`#${e} {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 10;\n background: rgba(0,0,0,0.8);\n }`,document.getElementsByTagName("head")[0].appendChild(o)}if(0===document.querySelectorAll('meta[name="viewport"]').length&&(a=document.createElement("meta"),a.setAttribute("name","viewport"),a.setAttribute("content","initial-scale=1"),document.head.appendChild(a)),i=document.createElement("iframe"),i.src=r,i.setAttribute("id",e),i.setAttribute("frameborder","0"),i.setAttribute("scrolling","no"),i.setAttribute("aria-label","Launching Modal"),i.setAttribute("title","Launching Modal"),c.overlay&&i.setAttribute("style",`background: ${c.overlay};`),c.node)c.node.appendChild(i);else{const e=c.selector?document.querySelector(c.selector):document.body;e?e.appendChild(i):(console.warn(`Couldn't find any elements matching "${c.selector}", appending "iframe" to "body" instead.`),document.body.appendChild(i))}return i.onload=()=>{d=i.contentWindow,this.initPostMessage(c),n.onLoad&&n.onLoad()},null},initPostMessage(e){const t=setInterval((()=>{const t={type:"ping",selector:e.selector,sdkVersion:"2.1.0",platform:""+(e.popup?"web":"iframe")};e.redirectUrl&&(t.redirectUrl=e.redirectUrl),this.postMessage(t)}),1e3);s=o=>{const s=o.data.data,r=o.data.type;if(o.origin===l){const i=!!n.onUrl;"ack"!==r||e.popup?"url"===r?i?n.onUrl(u,o.data.url):this.openPopupWindow(o.data.url):"done"===r?(n.onDone(s),this.destroy()):"cancel"===r?(n.onCancel(s),this.destroy()):"error"===r?(n.onError(s),this.destroy()):"route"===r?n.onRoute&&n.onRoute(s):"user"===r?n.onUser&&n.onUser(s):"closePopup"===r&&(i?n.onUrl(p):null==c||c.close()):clearInterval(t)}},window.addEventListener("message",s)},openPopupWindow(e){const t=window.self.outerHeight/2+window.self.screenY-300,n=window.self.outerWidth/2+window.self.screenX-300;if(c=window.open(e,"targetWindow",`toolbar=no,location=no,status=no,menubar=no,width=600,height=600,top=${t},left=${n}`),c){c.focus();const e=setInterval((()=>{(null==c?void 0:c.closed)&&(clearInterval(e),this.postMessage({type:o,closed:!0,blocked:!1}))}),1e3)}else this.postMessage({type:o,closed:!0,blocked:!0})},postMessage(e){null==d||d.postMessage(e,r)}};return w}(); | ||
//# sourceMappingURL=mastercard-connect-iife.min.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Connect=t()}(this,(function(){"use strict";const e="connectIframe",t="connectStyles",o="window";let n,s,r,i,d,a,l,c;const u={onLoad:()=>{},onUser:e=>{},onRoute:e=>{}},p={destroy(){i&&i.parentNode&&i.parentNode.removeChild(i),d&&d.parentNode&&d.parentNode.removeChild(d),!i&&a&&a.close(),i=void 0,d=void 0,window.removeEventListener("message",s)},launch(o,s,c={}){if(r=o,n=Object.assign(Object.assign({},u),s),l=new URL(r).origin,c.popup){const e={toolbar:"no",location:"no",status:"no",menubar:"no",width:720,height:520,top:window.self.outerHeight/2+window.self.screenY-360,left:window.self.outerWidth/2+window.self.screenX-260},t=Object.assign(Object.assign({},e),c.popupOptions),o=window.open(r,"targetWindow",`toolbar=${e.toolbar},location=${e.location},status=${e.status},menubar=${e.menubar},width=${t.width},height=${t.height},top=${t.top},left=${t.left}`);return o?(a=o,o.focus(),this.initPostMessage(c),n.onLoad&&n.onLoad()):n.onError({reason:"error",code:1403}),o}if(i&&i.parentNode)throw new Error('You must destroy the iframe before you can open a new one. Call "destroy()"');if(!document.getElementById(t)){const o=document.createElement("style");o.id=t,o.type="text/css",o.innerHTML=`#${e} {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 10;\n background: rgba(0,0,0,0.8);\n }`,document.getElementsByTagName("head")[0].appendChild(o)}if(0===document.querySelectorAll('meta[name="viewport"]').length&&(d=document.createElement("meta"),d.setAttribute("name","viewport"),d.setAttribute("content","initial-scale=1"),document.head.appendChild(d)),i=document.createElement("iframe"),i.src=r,i.setAttribute("id",e),i.setAttribute("frameborder","0"),i.setAttribute("scrolling","no"),i.setAttribute("aria-label","Launching Modal"),i.setAttribute("title","Launching Modal"),c.overlay&&i.setAttribute("style",`background: ${c.overlay};`),c.node)c.node.appendChild(i);else{const e=c.selector?document.querySelector(c.selector):document.body;e?e.appendChild(i):(console.warn(`Couldn't find any elements matching "${c.selector}", appending "iframe" to "body" instead.`),document.body.appendChild(i))}return i.onload=()=>{a=i.contentWindow,this.initPostMessage(c),n.onLoad&&n.onLoad()},null},initPostMessage(e){const t=setInterval((()=>{const t={type:"ping",selector:e.selector,sdkVersion:"2.0.0",platform:""+(e.popup?"web":"iframe")};e.redirectUrl&&(t.redirectUrl=e.redirectUrl),this.postMessage(t)}),1e3);s=o=>{const s=o.data.data,r=o.data.type;o.origin===l&&("ack"!==r||e.popup?"url"===r?this.openPopupWindow(o.data.url):"done"===r?(n.onDone(s),this.destroy()):"cancel"===r?(n.onCancel(s),this.destroy()):"error"===r?(n.onError(s),this.destroy()):"route"===r?n.onRoute&&n.onRoute(s):"user"===r?n.onUser&&n.onUser(s):"closePopup"===r&&(null==c||c.close()):clearInterval(t))},window.addEventListener("message",s)},openPopupWindow(e){const t=window.self.outerHeight/2+window.self.screenY-300,n=window.self.outerWidth/2+window.self.screenX-300;if(c=window.open(e,"targetWindow",`toolbar=no,location=no,status=no,menubar=no,width=600,height=600,top=${t},left=${n}`),c){c.focus();const e=setInterval((()=>{(null==c?void 0:c.closed)&&(clearInterval(e),this.postMessage({type:o,closed:!0,blocked:!1}))}),1e3)}else this.postMessage({type:o,closed:!0,blocked:!0})},postMessage(e){null==a||a.postMessage(e,r)}};return p})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Connect=t()}(this,(function(){"use strict";const e="connectIframe",t="connectStyles",o="window";let n,s,r,i,d,a,l,c;const u="OPEN",p="CLOSE",h={onLoad:()=>{},onUser:e=>{},onRoute:e=>{}},w={destroy(){i&&i.parentNode&&i.parentNode.removeChild(i),d&&d.parentNode&&d.parentNode.removeChild(d),!i&&a&&a.close(),i=void 0,d=void 0,window.removeEventListener("message",s)},launch(o,s,c={}){if(r=o,n=Object.assign(Object.assign({},h),s),l=new URL(r).origin,c.popup){const e={toolbar:"no",location:"no",status:"no",menubar:"no",width:720,height:520,top:window.self.outerHeight/2+window.self.screenY-360,left:window.self.outerWidth/2+window.self.screenX-260},t=Object.assign(Object.assign({},e),c.popupOptions),o=window.open(r,"targetWindow",`toolbar=${e.toolbar},location=${e.location},status=${e.status},menubar=${e.menubar},width=${t.width},height=${t.height},top=${t.top},left=${t.left}`);return o?(a=o,o.focus(),this.initPostMessage(c),n.onLoad&&n.onLoad()):n.onError({reason:"error",code:1403}),o}if(i&&i.parentNode)throw new Error('You must destroy the iframe before you can open a new one. Call "destroy()"');if(!document.getElementById(t)){const o=document.createElement("style");o.id=t,o.type="text/css",o.innerHTML=`#${e} {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 10;\n background: rgba(0,0,0,0.8);\n }`,document.getElementsByTagName("head")[0].appendChild(o)}if(0===document.querySelectorAll('meta[name="viewport"]').length&&(d=document.createElement("meta"),d.setAttribute("name","viewport"),d.setAttribute("content","initial-scale=1"),document.head.appendChild(d)),i=document.createElement("iframe"),i.src=r,i.setAttribute("id",e),i.setAttribute("frameborder","0"),i.setAttribute("scrolling","no"),i.setAttribute("aria-label","Launching Modal"),i.setAttribute("title","Launching Modal"),c.overlay&&i.setAttribute("style",`background: ${c.overlay};`),c.node)c.node.appendChild(i);else{const e=c.selector?document.querySelector(c.selector):document.body;e?e.appendChild(i):(console.warn(`Couldn't find any elements matching "${c.selector}", appending "iframe" to "body" instead.`),document.body.appendChild(i))}return i.onload=()=>{a=i.contentWindow,this.initPostMessage(c),n.onLoad&&n.onLoad()},null},initPostMessage(e){const t=setInterval((()=>{const t={type:"ping",selector:e.selector,sdkVersion:"2.1.0",platform:""+(e.popup?"web":"iframe")};e.redirectUrl&&(t.redirectUrl=e.redirectUrl),this.postMessage(t)}),1e3);s=o=>{const s=o.data.data,r=o.data.type;if(o.origin===l){const i=!!n.onUrl;"ack"!==r||e.popup?"url"===r?i?n.onUrl(u,o.data.url):this.openPopupWindow(o.data.url):"done"===r?(n.onDone(s),this.destroy()):"cancel"===r?(n.onCancel(s),this.destroy()):"error"===r?(n.onError(s),this.destroy()):"route"===r?n.onRoute&&n.onRoute(s):"user"===r?n.onUser&&n.onUser(s):"closePopup"===r&&(i?n.onUrl(p):null==c||c.close()):clearInterval(t)}},window.addEventListener("message",s)},openPopupWindow(e){const t=window.self.outerHeight/2+window.self.screenY-300,n=window.self.outerWidth/2+window.self.screenX-300;if(c=window.open(e,"targetWindow",`toolbar=no,location=no,status=no,menubar=no,width=600,height=600,top=${t},left=${n}`),c){c.focus();const e=setInterval((()=>{(null==c?void 0:c.closed)&&(clearInterval(e),this.postMessage({type:o,closed:!0,blocked:!1}))}),1e3)}else this.postMessage({type:o,closed:!0,blocked:!0})},postMessage(e){null==a||a.postMessage(e,r)}};return w})); | ||
//# sourceMappingURL=mastercard-connect-umd.min.js.map |
@@ -5,3 +5,3 @@ export declare const IFRAME_ID = "connectIframe"; | ||
export declare const PLATFORM_POPUP = "web"; | ||
export declare const CONNECT_SDK_VERSION = "2.0.0"; | ||
export declare const CONNECT_SDK_VERSION = "2.1.0"; | ||
export declare const POPUP_WIDTH = 600; | ||
@@ -8,0 +8,0 @@ export declare const POPUP_HEIGHT = 600; |
@@ -0,1 +1,6 @@ | ||
declare const PopupActionType: { | ||
readonly OPEN: "OPEN"; | ||
readonly CLOSE: "CLOSE"; | ||
}; | ||
export type PopupActionType = (typeof PopupActionType)[keyof typeof PopupActionType]; | ||
export interface ConnectEventHandlers { | ||
@@ -8,2 +13,3 @@ onDone: (event: ConnectDoneEvent) => void; | ||
onLoad?: () => void; | ||
onUrl?: (type: PopupActionType, url?: string) => void; | ||
} | ||
@@ -10,0 +16,0 @@ export interface ConnectProps { |
{ | ||
"name": "connect-web-sdk", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Mastercard Open Banking Connect Web SDK", | ||
"main": "dist/mastercard-connect-cjs.min.js", | ||
"module": "dist/mastercard-connect-esm.min.js", | ||
"browser": "dist/mastercard-connect-umd.min.js", | ||
"types": "dist/types/index.d.ts", | ||
@@ -41,3 +40,7 @@ "scripts": { | ||
"watch": "^1.0.2" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Mastercard/connect-web-sdk.git" | ||
} | ||
} |
@@ -87,4 +87,4 @@ # Mastercard Open Banking Connect Web SDK | ||
| onUser | Called when a user performs an action. User events provide visibility into what action a user could take within the Connect application | | ||
| onUrl | Called when a URL event is triggered from the Connect application. If provided, the SDK will not handle URL events automatically, and clients must manage the logic themselves. If not provided, the SDK will handle URL events by default. The default SDK behavior remains unchanged if the onUrl handler isn't supplied. | | ||
## Connect Options | ||
@@ -91,0 +91,0 @@ |
@@ -526,2 +526,78 @@ import { Connect } from './index'; | ||
}); | ||
test('should call onUrl handler when present and URL_EVENT is received', () => { | ||
let eventHandler; | ||
spyOn(Connect, 'openPopupWindow').and.callThrough(); | ||
spyOn(window, 'addEventListener').and.callFake( | ||
(eventType, eh) => (eventHandler = eh) | ||
); | ||
const eventHandlers = { | ||
onDone: jest.fn(), | ||
onError: jest.fn(), | ||
onCancel: jest.fn(), | ||
onUrl: jest.fn(), | ||
}; | ||
Connect.launch(url, eventHandlers); | ||
Connect.initPostMessage({}); | ||
const testUrl = 'https://example.com'; | ||
eventHandler({ | ||
origin: url, | ||
data: { type: URL_EVENT, url: testUrl }, | ||
}); | ||
expect(eventHandlers.onUrl).toHaveBeenCalledWith('OPEN', testUrl); | ||
expect(Connect.openPopupWindow).not.toHaveBeenCalled(); | ||
}); | ||
test('should call openPopupWindow when onUrl handler is not present and URL_EVENT is received', () => { | ||
let eventHandler; | ||
spyOn(window, 'addEventListener').and.callFake( | ||
(eventType, eh) => (eventHandler = eh) | ||
); | ||
const eventHandlers = { | ||
onDone: jest.fn(), | ||
onError: jest.fn(), | ||
onCancel: jest.fn(), | ||
}; | ||
Connect.launch(url, eventHandlers); | ||
Connect.initPostMessage({}); | ||
spyOn(Connect, 'openPopupWindow'); | ||
const testUrl = 'https://example.com'; | ||
eventHandler({ | ||
origin: url, | ||
data: { type: URL_EVENT, url: testUrl }, | ||
}); | ||
expect(Connect.openPopupWindow).toHaveBeenCalledWith(testUrl); | ||
}); | ||
test('should not close popup when handlePopupsManually is true and CLOSE_POPUP_EVENT is received & onURL with Close should be called', () => { | ||
let eventHandler; | ||
spyOn(window, 'open').and.callFake(() => mockWindow); | ||
spyOn(window, 'addEventListener').and.callFake( | ||
(eventType, eh) => (eventHandler = eh) | ||
); | ||
const eventHandlers = { | ||
onDone: jest.fn(), | ||
onError: jest.fn(), | ||
onCancel: jest.fn(), | ||
onUrl: jest.fn(), | ||
}; | ||
Connect.launch(url, eventHandlers, { popup: true }); | ||
Connect.initPostMessage({ popup: true }); | ||
const mockPopupWindow = { close: jest.fn() }; | ||
(Connect as any).popupWindow = mockPopupWindow; | ||
eventHandler({ | ||
origin: url, | ||
data: { type: CLOSE_POPUP_EVENT }, | ||
}); | ||
expect(mockPopupWindow.close).not.toHaveBeenCalled(); | ||
expect(eventHandlers.onUrl).toHaveBeenCalledWith('CLOSE'); | ||
}); | ||
}); | ||
@@ -528,0 +604,0 @@ |
@@ -32,2 +32,10 @@ import { | ||
const PopupActionType = { | ||
OPEN: 'OPEN', | ||
CLOSE: 'CLOSE', | ||
} as const; | ||
export type PopupActionType = | ||
(typeof PopupActionType)[keyof typeof PopupActionType]; | ||
export interface ConnectEventHandlers { | ||
@@ -40,2 +48,3 @@ onDone: (event: ConnectDoneEvent) => void; | ||
onLoad?: () => void; | ||
onUrl?: (type: PopupActionType, url?: string) => void; | ||
} | ||
@@ -264,2 +273,6 @@ | ||
if (event.origin === connectOrigin) { | ||
// NOTE: If onUrl is present in eventHandlers, then SDK won't handle (open/close) the popups. | ||
// The default behavior for popups remains unchanged if an onUrl handler is not supplied. | ||
const handlePopups = !!evHandlers.onUrl; | ||
// NOTE: actively pinging connect while it's displayed in a popup allows us to recover the | ||
@@ -270,3 +283,5 @@ // session if the user refreshes the popup window | ||
} else if (eventType === URL_EVENT) { | ||
this.openPopupWindow(event.data.url); | ||
if (handlePopups) | ||
evHandlers.onUrl(PopupActionType.OPEN, event.data.url); | ||
else this.openPopupWindow(event.data.url); | ||
} else if (eventType === DONE_EVENT) { | ||
@@ -286,3 +301,4 @@ evHandlers.onDone(payload); | ||
} else if (eventType === CLOSE_POPUP_EVENT) { | ||
popupWindow?.close(); | ||
if (!handlePopups) popupWindow?.close(); | ||
else evHandlers.onUrl(PopupActionType.CLOSE); | ||
} | ||
@@ -289,0 +305,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 not supported yet
Sorry, the diff of this file is not supported yet
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
142881
6.38%1397
6.64%0
-100%