@picahq/authkit
Advanced tools
@@ -1,1 +0,1 @@ | ||
| function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function t(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function n(e,n){for(var i=0;i<n.length;i++){var o=n[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,t(o.key),o)}}function i(e,n,i){return(n=t(n))in e?Object.defineProperty(e,n,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[n]=i,e}var o=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i(this,"linkTokenEndpoint",void 0),i(this,"linkHeaders",void 0),i(this,"baseUrl",void 0),i(this,"onClose",void 0),i(this,"title",void 0),i(this,"imageUrl",void 0),i(this,"companyName",void 0),i(this,"selectedConnection",void 0),i(this,"showNameInput",void 0),i(this,"appTheme",void 0),this.linkTokenEndpoint=t.token.url,this.linkHeaders=t.token.headers,this.baseUrl=t.baseUrl,this.onClose=t.onClose,this.title=t.title,this.imageUrl=t.imageUrl,this.companyName=t.companyName,this.selectedConnection=t.selectedConnection,this.showNameInput=t.showNameInput,this.appTheme=t.appTheme},(t=[{key:"_getBaseUrl",value:function(){return this.baseUrl?this.baseUrl:"https://authkit.picaos.com"}},{key:"openLink",value:function(){var e=this,t=document.createElement("iframe"),n=JSON.stringify({linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme}),i=btoa(n),o=new URLSearchParams({data:i}).toString(),r="".concat(this._getBaseUrl(),"?").concat(o);document.body.appendChild(t),t.style.height="100%",t.style.width="100%",t.style.position="fixed",t.style.display="hidden",t.style.visibility="hidden",t.style.zIndex="9999",t.style.backgroundColor="transparent",t.style.inset="0px",t.style.borderWidth="0px",t.id="event-link",t.src=r,t.style.overflow="hidden auto",t.onload=function(){var n;setTimeout((function(){t.style.display="block",t.style.visibility="visible"}),100),null===(n=t.contentWindow)||void 0===n||n.postMessage({linkTokenEndpoint:e.linkTokenEndpoint,linkHeaders:e.linkHeaders,title:e.title,imageUrl:e.imageUrl,companyName:e.companyName,selectedConnection:e.selectedConnection,showNameInput:e.showNameInput,appTheme:e.appTheme},r)}}},{key:"closeLink",value:function(){var e=document.getElementById("event-link");e&&e.remove()}}])&&n(e.prototype,t),o&&n(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,o}(),r=function(t){var n=function(e){return new o(e)}(function(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?e(Object(o),!0).forEach((function(e){i(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}({},t));"undefined"!=typeof window&&window.addEventListener("message",(function(e){var i,o,r,s,a;if("undefined"!=typeof window){var l,c,d=document.getElementById("event-link");if("block"===(null==d||null===(l=d.style)||void 0===l?void 0:l.display))switch(null===(c=e.data)||void 0===c?void 0:c.messageType){case"EXIT_EVENT_LINK":null===(i=t.onClose)||void 0===i||i.call(t),setTimeout((function(){n.closeLink()}),200);break;case"LINK_SUCCESS":null===(o=t.onSuccess)||void 0===o||o.call(t,null===(r=e.data)||void 0===r?void 0:r.message);break;case"LINK_ERROR":null===(s=t.onError)||void 0===s||s.call(t,null===(a=e.data)||void 0===a?void 0:a.message)}}}));return{open:function(){n.openLink()},close:function(){n.closeLink()}}};export{r as useAuthKit}; | ||
| function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,i(o.key),o)}}function t(e,t,n){return(t=i(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,i)}return n}function i(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}var o=function(){return n=function e(n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),t(this,"linkTokenEndpoint",void 0),t(this,"linkHeaders",void 0),t(this,"baseUrl",void 0),t(this,"onClose",void 0),t(this,"title",void 0),t(this,"imageUrl",void 0),t(this,"companyName",void 0),t(this,"selectedConnection",void 0),t(this,"showNameInput",void 0),t(this,"appTheme",void 0),this.linkTokenEndpoint=n.token.url,this.linkHeaders=n.token.headers,this.baseUrl=n.baseUrl,this.onClose=n.onClose,this.title=n.title,this.imageUrl=n.imageUrl,this.companyName=n.companyName,this.selectedConnection=n.selectedConnection,this.showNameInput=n.showNameInput,this.appTheme=n.appTheme},(i=[{key:"_getBaseUrl",value:function(){return this.baseUrl?this.baseUrl:"https://authkit.picaos.com"}},{key:"openLink",value:function(){var e=this,t=document.createElement("iframe"),n=JSON.stringify({linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme}),i=btoa(n),o=new URLSearchParams({data:i}).toString(),r="".concat(this._getBaseUrl(),"?").concat(o);document.body.appendChild(t),t.style.height="100%",t.style.width="100%",t.style.position="fixed",t.style.display="hidden",t.style.visibility="hidden",t.style.zIndex="9999",t.style.backgroundColor="transparent",t.style.inset="0px",t.style.borderWidth="0px",t.id="event-link",t.src=r,t.style.overflow="hidden auto",t.onload=function(){var n;setTimeout(function(){t.style.display="block",t.style.visibility="visible"},100),null===(n=t.contentWindow)||void 0===n||n.postMessage({linkTokenEndpoint:e.linkTokenEndpoint,linkHeaders:e.linkHeaders,title:e.title,imageUrl:e.imageUrl,companyName:e.companyName,selectedConnection:e.selectedConnection,showNameInput:e.showNameInput,appTheme:e.appTheme},r)}}},{key:"closeLink",value:function(){var e=document.getElementById("event-link");e&&e.remove()}}])&&e(n.prototype,i),o&&e(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,i,o}(),r=new Set,s=function(e){var i=function(e){return new o(e)}(function(e){for(var i=1;i<arguments.length;i++){var o=null!=arguments[i]?arguments[i]:{};i%2?n(Object(o),!0).forEach(function(n){t(e,n,o[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})}return e}({},e)),s=null,a=!1,l=function(t){var n,i,o;if("undefined"!=typeof window){var s=document.getElementById("event-link");if(s&&"block"===s.style.display){var a=t.data;if(null!=a&&a.messageType){var l="".concat(a.messageType,"-").concat(JSON.stringify(a.message));if(!r.has(l))switch(r.add(l),setTimeout(function(){return r.delete(l)},5e3),a.messageType){case"EXIT_EVENT_LINK":null===(n=e.onClose)||void 0===n||n.call(e),setTimeout(function(){c()},200);break;case"LINK_SUCCESS":null===(i=e.onSuccess)||void 0===i||i.call(e,a.message);break;case"LINK_ERROR":null===(o=e.onError)||void 0===o||o.call(e,a.message)}}}}},c=function(){"undefined"!=typeof window&&s&&a&&(window.removeEventListener("message",s),a=!1,s=null),i.closeLink()};return{open:function(){s&&a&&window.removeEventListener("message",s),s=l,"undefined"!=typeof window&&(window.addEventListener("message",s),a=!0),i.openLink()},close:c}};export{s as useAuthKit}; |
@@ -1,1 +0,1 @@ | ||
| "use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function t(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function n(e,n){for(var i=0;i<n.length;i++){var o=n[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,t(o.key),o)}}function i(e,n,i){return(n=t(n))in e?Object.defineProperty(e,n,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[n]=i,e}Object.defineProperty(exports,"__esModule",{value:!0});var o=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i(this,"linkTokenEndpoint",void 0),i(this,"linkHeaders",void 0),i(this,"baseUrl",void 0),i(this,"onClose",void 0),i(this,"title",void 0),i(this,"imageUrl",void 0),i(this,"companyName",void 0),i(this,"selectedConnection",void 0),i(this,"showNameInput",void 0),i(this,"appTheme",void 0),this.linkTokenEndpoint=t.token.url,this.linkHeaders=t.token.headers,this.baseUrl=t.baseUrl,this.onClose=t.onClose,this.title=t.title,this.imageUrl=t.imageUrl,this.companyName=t.companyName,this.selectedConnection=t.selectedConnection,this.showNameInput=t.showNameInput,this.appTheme=t.appTheme},(t=[{key:"_getBaseUrl",value:function(){return this.baseUrl?this.baseUrl:"https://authkit.picaos.com"}},{key:"openLink",value:function(){var e=this,t=document.createElement("iframe"),n=JSON.stringify({linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme}),i=btoa(n),o=new URLSearchParams({data:i}).toString(),r="".concat(this._getBaseUrl(),"?").concat(o);document.body.appendChild(t),t.style.height="100%",t.style.width="100%",t.style.position="fixed",t.style.display="hidden",t.style.visibility="hidden",t.style.zIndex="9999",t.style.backgroundColor="transparent",t.style.inset="0px",t.style.borderWidth="0px",t.id="event-link",t.src=r,t.style.overflow="hidden auto",t.onload=function(){var n;setTimeout((function(){t.style.display="block",t.style.visibility="visible"}),100),null===(n=t.contentWindow)||void 0===n||n.postMessage({linkTokenEndpoint:e.linkTokenEndpoint,linkHeaders:e.linkHeaders,title:e.title,imageUrl:e.imageUrl,companyName:e.companyName,selectedConnection:e.selectedConnection,showNameInput:e.showNameInput,appTheme:e.appTheme},r)}}},{key:"closeLink",value:function(){var e=document.getElementById("event-link");e&&e.remove()}}])&&n(e.prototype,t),o&&n(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,o}();exports.useAuthKit=function(t){var n=function(e){return new o(e)}(function(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?e(Object(o),!0).forEach((function(e){i(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}({},t));"undefined"!=typeof window&&window.addEventListener("message",(function(e){var i,o,r,s,l;if("undefined"!=typeof window){var a,c,d=document.getElementById("event-link");if("block"===(null==d||null===(a=d.style)||void 0===a?void 0:a.display))switch(null===(c=e.data)||void 0===c?void 0:c.messageType){case"EXIT_EVENT_LINK":null===(i=t.onClose)||void 0===i||i.call(t),setTimeout((function(){n.closeLink()}),200);break;case"LINK_SUCCESS":null===(o=t.onSuccess)||void 0===o||o.call(t,null===(r=e.data)||void 0===r?void 0:r.message);break;case"LINK_ERROR":null===(s=t.onError)||void 0===s||s.call(t,null===(l=e.data)||void 0===l?void 0:l.message)}}}));return{open:function(){n.openLink()},close:function(){n.closeLink()}}}; | ||
| "use strict";function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,i(o.key),o)}}function t(e,t,n){return(t=i(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,i)}return n}function i(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}Object.defineProperty(exports,"__esModule",{value:!0});var o=function(){return n=function e(n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),t(this,"linkTokenEndpoint",void 0),t(this,"linkHeaders",void 0),t(this,"baseUrl",void 0),t(this,"onClose",void 0),t(this,"title",void 0),t(this,"imageUrl",void 0),t(this,"companyName",void 0),t(this,"selectedConnection",void 0),t(this,"showNameInput",void 0),t(this,"appTheme",void 0),this.linkTokenEndpoint=n.token.url,this.linkHeaders=n.token.headers,this.baseUrl=n.baseUrl,this.onClose=n.onClose,this.title=n.title,this.imageUrl=n.imageUrl,this.companyName=n.companyName,this.selectedConnection=n.selectedConnection,this.showNameInput=n.showNameInput,this.appTheme=n.appTheme},(i=[{key:"_getBaseUrl",value:function(){return this.baseUrl?this.baseUrl:"https://authkit.picaos.com"}},{key:"openLink",value:function(){var e=this,t=document.createElement("iframe"),n=JSON.stringify({linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme}),i=btoa(n),o=new URLSearchParams({data:i}).toString(),r="".concat(this._getBaseUrl(),"?").concat(o);document.body.appendChild(t),t.style.height="100%",t.style.width="100%",t.style.position="fixed",t.style.display="hidden",t.style.visibility="hidden",t.style.zIndex="9999",t.style.backgroundColor="transparent",t.style.inset="0px",t.style.borderWidth="0px",t.id="event-link",t.src=r,t.style.overflow="hidden auto",t.onload=function(){var n;setTimeout(function(){t.style.display="block",t.style.visibility="visible"},100),null===(n=t.contentWindow)||void 0===n||n.postMessage({linkTokenEndpoint:e.linkTokenEndpoint,linkHeaders:e.linkHeaders,title:e.title,imageUrl:e.imageUrl,companyName:e.companyName,selectedConnection:e.selectedConnection,showNameInput:e.showNameInput,appTheme:e.appTheme},r)}}},{key:"closeLink",value:function(){var e=document.getElementById("event-link");e&&e.remove()}}])&&e(n.prototype,i),o&&e(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,i,o}(),r=new Set;exports.useAuthKit=function(e){var i=function(e){return new o(e)}(function(e){for(var i=1;i<arguments.length;i++){var o=null!=arguments[i]?arguments[i]:{};i%2?n(Object(o),!0).forEach(function(n){t(e,n,o[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})}return e}({},e)),s=null,a=!1,l=function(t){var n,i,o;if("undefined"!=typeof window){var s=document.getElementById("event-link");if(s&&"block"===s.style.display){var a=t.data;if(null!=a&&a.messageType){var l="".concat(a.messageType,"-").concat(JSON.stringify(a.message));if(!r.has(l))switch(r.add(l),setTimeout(function(){return r.delete(l)},5e3),a.messageType){case"EXIT_EVENT_LINK":null===(n=e.onClose)||void 0===n||n.call(e),setTimeout(function(){c()},200);break;case"LINK_SUCCESS":null===(i=e.onSuccess)||void 0===i||i.call(e,a.message);break;case"LINK_ERROR":null===(o=e.onError)||void 0===o||o.call(e,a.message)}}}}},c=function(){"undefined"!=typeof window&&s&&a&&(window.removeEventListener("message",s),a=!1,s=null),i.closeLink()};return{open:function(){s&&a&&window.removeEventListener("message",s),s=l,"undefined"!=typeof window&&(window.addEventListener("message",s),a=!0),i.openLink()},close:c}}; |
+2
-2
| { | ||
| "name": "@picahq/authkit", | ||
| "version": "1.0.5", | ||
| "version": "1.0.7", | ||
| "description": "Frontend bindings for Pica AuthKit", | ||
@@ -66,2 +66,2 @@ "files": [ | ||
| "homepage": "https://picaos.com" | ||
| } | ||
| } |
+56
-25
| import { ConnectionRecord, EventLinkProps, EventProps } from "./types"; | ||
| import { createWindow } from "./window"; | ||
| // Track processed messages to prevent duplicates (defense-in-depth) | ||
| const processedMessages = new Set<string>(); | ||
| const MESSAGE_EXPIRY_MS = 5000; | ||
| export const useEventLink = (props: EventLinkProps) => { | ||
| const linkWindow = createWindow({ ...props }); | ||
| const handleMessage = (event: EventProps) => { | ||
| if (typeof window !== "undefined") { | ||
| const iFrameWindow = document.getElementById( | ||
| `event-link` | ||
| ) as HTMLIFrameElement; | ||
| if (iFrameWindow?.style?.display === "block") { | ||
| switch (event.data?.messageType) { | ||
| case "EXIT_EVENT_LINK": | ||
| props.onClose?.(); | ||
| setTimeout(() => { | ||
| linkWindow.closeLink(); | ||
| }, 200); | ||
| break; | ||
| case "LINK_SUCCESS": | ||
| props.onSuccess?.(event.data?.message as ConnectionRecord); | ||
| break; | ||
| case "LINK_ERROR": | ||
| props.onError?.(event.data?.message as string); | ||
| break; | ||
| } | ||
| } | ||
| let messageHandler: ((event: MessageEvent) => void) | null = null; | ||
| let isListenerActive = false; | ||
| const handleMessage = (event: MessageEvent) => { | ||
| if (typeof window === "undefined") return; | ||
| const iFrameWindow = document.getElementById("event-link") as HTMLIFrameElement; | ||
| if (!iFrameWindow || iFrameWindow.style.display !== "block") return; | ||
| const eventData = (event as unknown as EventProps).data; | ||
| if (!eventData?.messageType) return; | ||
| // Deduplication: prevent processing same message type within expiry window | ||
| const dedupeKey = `${eventData.messageType}-${JSON.stringify(eventData.message)}`; | ||
| if (processedMessages.has(dedupeKey)) { | ||
| return; | ||
| } | ||
| processedMessages.add(dedupeKey); | ||
| setTimeout(() => processedMessages.delete(dedupeKey), MESSAGE_EXPIRY_MS); | ||
| switch (eventData.messageType) { | ||
| case "EXIT_EVENT_LINK": | ||
| props.onClose?.(); | ||
| setTimeout(() => { | ||
| close(); | ||
| }, 200); | ||
| break; | ||
| case "LINK_SUCCESS": | ||
| props.onSuccess?.(eventData.message as ConnectionRecord); | ||
| break; | ||
| case "LINK_ERROR": | ||
| props.onError?.(eventData.message as string); | ||
| break; | ||
| } | ||
| }; | ||
| if (typeof window !== "undefined") { | ||
| window.addEventListener("message", handleMessage); | ||
| } | ||
| const open = () => { | ||
| // Remove existing listener first (defensive) | ||
| if (messageHandler && isListenerActive) { | ||
| window.removeEventListener("message", messageHandler); | ||
| } | ||
| const open = () => { | ||
| messageHandler = handleMessage; | ||
| if (typeof window !== "undefined") { | ||
| window.addEventListener("message", messageHandler); | ||
| isListenerActive = true; | ||
| } | ||
| linkWindow.openLink(); | ||
@@ -40,2 +64,9 @@ }; | ||
| const close = () => { | ||
| // Clean up listener when closing | ||
| if (typeof window !== "undefined" && messageHandler && isListenerActive) { | ||
| window.removeEventListener("message", messageHandler); | ||
| isListenerActive = false; | ||
| messageHandler = null; | ||
| } | ||
| linkWindow.closeLink(); | ||
@@ -42,0 +73,0 @@ }; |
57819
2.58%347
7.1%