@picahq/authkit
Advanced tools
@@ -1,1 +0,1 @@ | ||
| function e(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class t{constructor(t){e(this,"linkTokenEndpoint",void 0),e(this,"linkHeaders",void 0),e(this,"baseUrl",void 0),e(this,"onClose",void 0),e(this,"title",void 0),e(this,"imageUrl",void 0),e(this,"companyName",void 0),e(this,"selectedConnection",void 0),e(this,"showNameInput",void 0),e(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}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://authkit.picaos.com"}openLink(){const e=document.createElement("iframe"),t=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(t),n=new URLSearchParams({data:i}).toString(),s=`${this._getBaseUrl()}?${n}`;document.body.appendChild(e),e.style.height="100%",e.style.width="100%",e.style.position="fixed",e.style.display="hidden",e.style.visibility="hidden",e.style.zIndex="9999",e.style.backgroundColor="transparent",e.style.inset="0px",e.style.borderWidth="0px",e.id="event-link",e.src=s,e.style.overflow="hidden auto",e.onload=()=>{var t;setTimeout(()=>{e.style.display="block",e.style.visibility="visible"},100),null===(t=e.contentWindow)||void 0===t||t.postMessage({linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme},s)}}closeLink(){const e=document.getElementById("event-link");e&&e.remove()}}const i=new Set,n=e=>{const n=(e=>new t(e))({...e});let s=null,o=!1;const l=t=>{var n,s,o;if("undefined"==typeof window)return;const l=document.getElementById("event-link");if(!l||"block"!==l.style.display)return;const r=t.data;if(null==r||!r.messageType)return;const d=`${r.messageType}-${JSON.stringify(r.message)}`;if(!i.has(d))switch(i.add(d),setTimeout(()=>i.delete(d),5e3),r.messageType){case"EXIT_EVENT_LINK":null===(n=e.onClose)||void 0===n||n.call(e),setTimeout(()=>{a()},200);break;case"LINK_SUCCESS":null===(s=e.onSuccess)||void 0===s||s.call(e,r.message);break;case"LINK_ERROR":null===(o=e.onError)||void 0===o||o.call(e,r.message)}},a=()=>{"undefined"!=typeof window&&s&&o&&(window.removeEventListener("message",s),o=!1,s=null),n.closeLink()};return{open:()=>{s&&o&&window.removeEventListener("message",s),s=l,"undefined"!=typeof window&&(window.addEventListener("message",s),o=!0),n.openLink()},close:a}};export{n as useAuthKit}; | ||
| function e(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class t{constructor(t){e(this,"linkTokenEndpoint",void 0),e(this,"linkHeaders",void 0),e(this,"baseUrl",void 0),e(this,"onClose",void 0),e(this,"title",void 0),e(this,"imageUrl",void 0),e(this,"companyName",void 0),e(this,"selectedConnection",void 0),e(this,"showNameInput",void 0),e(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}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://authkit.picaos.com"}openLink(){const e=document.createElement("iframe"),t=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(t),n=new URLSearchParams({data:i}).toString(),s=`${this._getBaseUrl()}?${n}`;document.body.appendChild(e),e.style.height="100%",e.style.width="100%",e.style.position="fixed",e.style.display="hidden",e.style.visibility="hidden",e.style.zIndex="9999",e.style.backgroundColor="transparent",e.style.inset="0px",e.style.borderWidth="0px",e.id="event-link",e.src=s,e.style.overflow="hidden auto",e.onload=()=>{var t;setTimeout(()=>{e.style.display="block",e.style.visibility="visible"},100),null===(t=e.contentWindow)||void 0===t||t.postMessage({linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme},s)}}closeLink(){const e=document.getElementById("event-link");e&&e.remove()}}let i=null;const n=e=>{const n=(e=>new t(e))({...e}),s=()=>{"undefined"!=typeof window&&i&&(window.removeEventListener("message",i),i=null),n.closeLink()};return{open:()=>{"undefined"!=typeof window&&i&&(window.removeEventListener("message",i),i=null);const t=t=>{var i,n,o;if("undefined"==typeof window)return;const l=document.getElementById("event-link");if(!l||"block"!==l.style.display)return;const a=t.data;if(null!=a&&a.messageType)switch(a.messageType){case"EXIT_EVENT_LINK":null===(i=e.onClose)||void 0===i||i.call(e),setTimeout(()=>{s()},200);break;case"LINK_SUCCESS":null===(n=e.onSuccess)||void 0===n||n.call(e,a.message);break;case"LINK_ERROR":null===(o=e.onError)||void 0===o||o.call(e,a.message)}};i=t,"undefined"!=typeof window&&window.addEventListener("message",t),n.openLink()},close:s}};export{n as useAuthKit}; |
@@ -1,1 +0,1 @@ | ||
| "use strict";function e(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class t{constructor(t){e(this,"linkTokenEndpoint",void 0),e(this,"linkHeaders",void 0),e(this,"baseUrl",void 0),e(this,"onClose",void 0),e(this,"title",void 0),e(this,"imageUrl",void 0),e(this,"companyName",void 0),e(this,"selectedConnection",void 0),e(this,"showNameInput",void 0),e(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}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://authkit.picaos.com"}openLink(){const e=document.createElement("iframe"),t=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(t),n=new URLSearchParams({data:i}).toString(),s=`${this._getBaseUrl()}?${n}`;document.body.appendChild(e),e.style.height="100%",e.style.width="100%",e.style.position="fixed",e.style.display="hidden",e.style.visibility="hidden",e.style.zIndex="9999",e.style.backgroundColor="transparent",e.style.inset="0px",e.style.borderWidth="0px",e.id="event-link",e.src=s,e.style.overflow="hidden auto",e.onload=()=>{var t;setTimeout(()=>{e.style.display="block",e.style.visibility="visible"},100),null===(t=e.contentWindow)||void 0===t||t.postMessage({linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme},s)}}closeLink(){const e=document.getElementById("event-link");e&&e.remove()}}const i=new Set;exports.useAuthKit=e=>{const n=(e=>new t(e))({...e});let s=null,o=!1;const l=t=>{var n,s,o;if("undefined"==typeof window)return;const l=document.getElementById("event-link");if(!l||"block"!==l.style.display)return;const r=t.data;if(null==r||!r.messageType)return;const d=`${r.messageType}-${JSON.stringify(r.message)}`;if(!i.has(d))switch(i.add(d),setTimeout(()=>i.delete(d),5e3),r.messageType){case"EXIT_EVENT_LINK":null===(n=e.onClose)||void 0===n||n.call(e),setTimeout(()=>{a()},200);break;case"LINK_SUCCESS":null===(s=e.onSuccess)||void 0===s||s.call(e,r.message);break;case"LINK_ERROR":null===(o=e.onError)||void 0===o||o.call(e,r.message)}},a=()=>{"undefined"!=typeof window&&s&&o&&(window.removeEventListener("message",s),o=!1,s=null),n.closeLink()};return{open:()=>{s&&o&&window.removeEventListener("message",s),s=l,"undefined"!=typeof window&&(window.addEventListener("message",s),o=!0),n.openLink()},close:a}}; | ||
| "use strict";function e(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class t{constructor(t){e(this,"linkTokenEndpoint",void 0),e(this,"linkHeaders",void 0),e(this,"baseUrl",void 0),e(this,"onClose",void 0),e(this,"title",void 0),e(this,"imageUrl",void 0),e(this,"companyName",void 0),e(this,"selectedConnection",void 0),e(this,"showNameInput",void 0),e(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}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://authkit.picaos.com"}openLink(){const e=document.createElement("iframe"),t=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(t),n=new URLSearchParams({data:i}).toString(),s=`${this._getBaseUrl()}?${n}`;document.body.appendChild(e),e.style.height="100%",e.style.width="100%",e.style.position="fixed",e.style.display="hidden",e.style.visibility="hidden",e.style.zIndex="9999",e.style.backgroundColor="transparent",e.style.inset="0px",e.style.borderWidth="0px",e.id="event-link",e.src=s,e.style.overflow="hidden auto",e.onload=()=>{var t;setTimeout(()=>{e.style.display="block",e.style.visibility="visible"},100),null===(t=e.contentWindow)||void 0===t||t.postMessage({linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme},s)}}closeLink(){const e=document.getElementById("event-link");e&&e.remove()}}let i=null;exports.useAuthKit=e=>{const n=(e=>new t(e))({...e}),s=()=>{"undefined"!=typeof window&&i&&(window.removeEventListener("message",i),i=null),n.closeLink()};return{open:()=>{"undefined"!=typeof window&&i&&(window.removeEventListener("message",i),i=null);const t=t=>{var i,n,o;if("undefined"==typeof window)return;const l=document.getElementById("event-link");if(!l||"block"!==l.style.display)return;const a=t.data;if(null!=a&&a.messageType)switch(a.messageType){case"EXIT_EVENT_LINK":null===(i=e.onClose)||void 0===i||i.call(e),setTimeout(()=>{s()},200);break;case"LINK_SUCCESS":null===(n=e.onSuccess)||void 0===n||n.call(e,a.message);break;case"LINK_ERROR":null===(o=e.onError)||void 0===o||o.call(e,a.message)}};i=t,"undefined"!=typeof window&&window.addEventListener("message",t),n.openLink()},close:s}}; |
+1
-1
| { | ||
| "name": "@picahq/authkit", | ||
| "version": "1.0.9", | ||
| "version": "1.0.10", | ||
| "description": "Frontend bindings for Pica AuthKit", | ||
@@ -5,0 +5,0 @@ "files": [ |
+42
-52
| 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; | ||
| // Module-level listener reference — ensures only one listener exists at a time, | ||
| // regardless of how many times useEventLink is called (e.g., across framework | ||
| // reactivity cycles or re-renders) | ||
| let activeListener: ((event: MessageEvent) => void) | null = null; | ||
@@ -11,49 +12,49 @@ export const useEventLink = (props: EventLinkProps) => { | ||
| 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; | ||
| const close = () => { | ||
| if (typeof window !== "undefined" && activeListener) { | ||
| window.removeEventListener("message", activeListener); | ||
| activeListener = null; | ||
| } | ||
| 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; | ||
| } | ||
| linkWindow.closeLink(); | ||
| }; | ||
| const open = () => { | ||
| // Remove existing listener first (defensive) | ||
| if (messageHandler && isListenerActive) { | ||
| window.removeEventListener("message", messageHandler); | ||
| // Always clean up any existing listener before adding a new one. | ||
| // Because activeListener is module-level, this works across closures/re-renders — | ||
| // unlike the old closure-local messageHandler which was null in each new closure. | ||
| if (typeof window !== "undefined" && activeListener) { | ||
| window.removeEventListener("message", activeListener); | ||
| activeListener = null; | ||
| } | ||
| messageHandler = handleMessage; | ||
| 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; | ||
| 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; | ||
| } | ||
| }; | ||
| activeListener = handleMessage; | ||
| if (typeof window !== "undefined") { | ||
| window.addEventListener("message", messageHandler); | ||
| isListenerActive = true; | ||
| window.addEventListener("message", handleMessage); | ||
| } | ||
@@ -64,14 +65,3 @@ | ||
| const close = () => { | ||
| // Clean up listener when closing | ||
| if (typeof window !== "undefined" && messageHandler && isListenerActive) { | ||
| window.removeEventListener("message", messageHandler); | ||
| isListenerActive = false; | ||
| messageHandler = null; | ||
| } | ||
| linkWindow.closeLink(); | ||
| }; | ||
| return { open, close }; | ||
| }; |
54914
-0.73%329
-2.95%