@krishp/one-auth 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- function e(e,t,n){return(t=function(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);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+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const t={oauthRedirect:!0},n="event-link";class i{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),e(this,"checkState",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,this.checkState=t.checkState}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://auth.withone.ai"}_buildPayload(){return{linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme,capabilities:t,checkState:this.checkState}}openLink(){const e=document.getElementById(n);e&&e.remove();const t=document.createElement("iframe"),i=this._buildPayload(),o=JSON.stringify(i),s=btoa(o),a=new URLSearchParams({data:s}).toString(),r=`${this._getBaseUrl()}?${a}`;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=n,t.style.overflow="hidden auto",t.src=r,t.onload=()=>{var e;setTimeout(()=>{t.style.display="block",t.style.visibility="visible"},100),null===(e=t.contentWindow)||void 0===e||e.postMessage(i,r)}}closeLink(){const e=document.getElementById(n);e&&e.remove()}}const o=new Set;let s=!1;const a="one_auth_state",r="one_auth_error";function l(e,t,n){const i=`${t}~${o=n,btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}`;var o;try{const t=new URL(e);return t.searchParams.set("state",i),t.toString()}catch{return e.replace(`state=${encodeURIComponent(t)}`,`state=${encodeURIComponent(i)}`).replace(`state=${t}`,`state=${encodeURIComponent(i)}`)}}function c(){if("undefined"!=typeof window)try{const e=new URL(window.location.href);let t=!1;e.searchParams.has(a)&&(e.searchParams.delete(a),t=!0),e.searchParams.has(r)&&(e.searchParams.delete(r),t=!0),t&&window.history.replaceState({},document.title,e.toString())}catch{}}function d(e,t){const o=new i({...e,checkState:t});let a=!1,r=!1;const l=t=>{if("undefined"==typeof window)return;const i=document.getElementById(n);if(!i||t.source!==i.contentWindow)return;const d=t.data;if(null!=d&&d.messageType)if("LINK_SUCCESS"===d.messageType){if(!r){r=!0;try{var u;null===(u=e.onSuccess)||void 0===u||u.call(e,d.message)}catch{}c()}}else if("LINK_ERROR"===d.messageType){if(!r){r=!0;try{var h;null===(h=e.onError)||void 0===h||h.call(e,d.message)}catch{}c()}}else if("EXIT_EVENT_LINK"===d.messageType){if(!r)try{var m;null===(m=e.onClose)||void 0===m||m.call(e)}catch{}!function(){if(a)return;a=!0,"undefined"!=typeof window&&window.removeEventListener("message",l);o.closeLink(),c(),s=!1}()}};"undefined"!=typeof window&&window.addEventListener("message",l),o.openLink()}function u(e){if("undefined"==typeof window)return;if(s)return;let t;try{t=new URLSearchParams(window.location.search)}catch{return}const n=t.get(r),i=t.get(a);(n||i)&&(s=!0,n?function(e,t){setTimeout(()=>{try{var n;null===(n=e.onError)||void 0===n||n.call(e,t)}finally{c()}},0)}(e,n):i&&d(e,i))}const h=e=>{u(e);const t=(e=>new i(e))({...e});let s=null,a=!1;const r=i=>{var r,d,u,h,m;if("undefined"==typeof window)return;const p=document.getElementById(n);if(!p||"block"!==p.style.display)return;if(i.source!==p.contentWindow)return;const f=i.data;if(null==f||!f.messageType)return;const y=`${f.messageType}-${JSON.stringify(null!==(r=null!==(d=f.message)&&void 0!==d?d:f.url)&&void 0!==r?r:"")}`;if(!o.has(y))switch(o.add(y),setTimeout(()=>o.delete(y),5e3),f.messageType){case"EXIT_EVENT_LINK":null===(u=e.onClose)||void 0===u||u.call(e),setTimeout(()=>{c()},200);break;case"LINK_SUCCESS":null===(h=e.onSuccess)||void 0===h||h.call(e,f.message);break;case"LINK_ERROR":null===(m=e.onError)||void 0===m||m.call(e,f.message);break;case"OAUTH_REDIRECT":{const n=f.url,i=f.state;if(!n||!i){var w;null===(w=e.onError)||void 0===w||w.call(e,"Invalid OAuth redirect message");break}const o=l(n,i,window.location.href);s&&a&&(window.removeEventListener("message",s),a=!1,s=null),t.closeLink(),window.location.href=o;break}}},c=()=>{"undefined"!=typeof window&&s&&a&&(window.removeEventListener("message",s),a=!1,s=null);for(const e of o)e.startsWith("EXIT_EVENT_LINK")&&o.delete(e);t.closeLink()};return{open:()=>{s&&a&&window.removeEventListener("message",s),s=r,"undefined"!=typeof window&&(window.addEventListener("message",s),a=!0),t.openLink()},close:c}};export{h as useOneAuth};
1
+ function e(e,t,n){return(t=function(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);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+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const t={oauthRedirect:!0},n="event-link";class i{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),e(this,"checkState",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,this.checkState=t.checkState}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://auth.withone.ai"}_buildPayload(){return{linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme,capabilities:t,checkState:this.checkState}}openLink(){const e=document.getElementById(n);e&&e.remove();const t=document.createElement("iframe"),i=this._buildPayload(),o=JSON.stringify(i),s=btoa(o),a=new URLSearchParams({data:s}).toString(),r=`${this._getBaseUrl()}?${a}`;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=n,t.style.overflow="hidden auto",t.src=r,t.onload=()=>{var e;setTimeout(()=>{t.style.display="block",t.style.visibility="visible"},100),null===(e=t.contentWindow)||void 0===e||e.postMessage(i,r)}}closeLink(){const e=document.getElementById(n);e&&e.remove()}}const o=new Set;let s=!1;const a="one_auth_state",r="one_auth_error";function l(e,t,n){const i=`${t}~${o=n,btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}`;var o;try{const t=new URL(e);return t.searchParams.set("state",i),t.toString()}catch{return e.replace(`state=${encodeURIComponent(t)}`,`state=${encodeURIComponent(i)}`).replace(`state=${t}`,`state=${encodeURIComponent(i)}`)}}function c(){if("undefined"!=typeof window)try{const e=new URL(window.location.href);let t=!1;e.searchParams.has(a)&&(e.searchParams.delete(a),t=!0),e.searchParams.has(r)&&(e.searchParams.delete(r),t=!0),t&&window.history.replaceState({},document.title,e.toString())}catch{}}function d(e,t){const o=new i({...e,checkState:t});let a=!1,r=!1;const l=t=>{if("undefined"==typeof window)return;const i=document.getElementById(n);if(!i||t.source!==i.contentWindow)return;const d=t.data;if(null!=d&&d.messageType)if("LINK_SUCCESS"===d.messageType){if(!r){r=!0;try{var u;null===(u=e.onSuccess)||void 0===u||u.call(e,d.message)}catch{}c()}}else if("LINK_ERROR"===d.messageType){if(!r){r=!0;try{var h;null===(h=e.onError)||void 0===h||h.call(e,d.message)}catch{}c()}}else if("EXIT_EVENT_LINK"===d.messageType){if(!r)try{var m;null===(m=e.onClose)||void 0===m||m.call(e)}catch{}!function(){if(a)return;a=!0,"undefined"!=typeof window&&window.removeEventListener("message",l);o.closeLink(),c(),s=!1}()}};"undefined"!=typeof window&&window.addEventListener("message",l),o.openLink()}function u(e){if("undefined"==typeof window)return;if(s)return;let t;try{t=new URLSearchParams(window.location.search)}catch{return}const n=t.get(r),i=t.get(a);(n||i)&&(s=!0,n?function(e,t){setTimeout(()=>{try{var n;null===(n=e.onError)||void 0===n||n.call(e,t)}finally{c()}},0)}(e,n):i&&d(e,i))}const h=e=>{u(e);const t=(e=>new i(e))({...e});let s=null,a=!1;const r=t=>{var i,r,d,u,h;if("undefined"==typeof window)return;const m=document.getElementById(n);if(!m||"block"!==m.style.display)return;if(t.source!==m.contentWindow)return;const p=t.data;if(null==p||!p.messageType)return;const f=`${p.messageType}-${JSON.stringify(null!==(i=null!==(r=p.message)&&void 0!==r?r:p.url)&&void 0!==i?i:"")}`;if(!o.has(f))switch(o.add(f),setTimeout(()=>o.delete(f),5e3),p.messageType){case"EXIT_EVENT_LINK":null===(d=e.onClose)||void 0===d||d.call(e),setTimeout(()=>{c()},200);break;case"LINK_SUCCESS":null===(u=e.onSuccess)||void 0===u||u.call(e,p.message);break;case"LINK_ERROR":null===(h=e.onError)||void 0===h||h.call(e,p.message);break;case"OAUTH_REDIRECT":{const t=p.url,n=p.state;if(!t||!n){var y;null===(y=e.onError)||void 0===y||y.call(e,"Invalid OAuth redirect message");break}const i=l(t,n,window.location.href);s&&a&&(window.removeEventListener("message",s),a=!1,s=null),window.location.href=i;break}}},c=()=>{"undefined"!=typeof window&&s&&a&&(window.removeEventListener("message",s),a=!1,s=null);for(const e of o)e.startsWith("EXIT_EVENT_LINK")&&o.delete(e);t.closeLink()};return{open:()=>{s&&a&&window.removeEventListener("message",s),s=r,"undefined"!=typeof window&&(window.addEventListener("message",s),a=!0),t.openLink()},close:c}};export{h as useOneAuth};
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- "use strict";function e(e,t,n){return(t=function(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);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+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const t={oauthRedirect:!0},n="event-link";class i{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),e(this,"checkState",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,this.checkState=t.checkState}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://auth.withone.ai"}_buildPayload(){return{linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme,capabilities:t,checkState:this.checkState}}openLink(){const e=document.getElementById(n);e&&e.remove();const t=document.createElement("iframe"),i=this._buildPayload(),o=JSON.stringify(i),s=btoa(o),a=new URLSearchParams({data:s}).toString(),r=`${this._getBaseUrl()}?${a}`;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=n,t.style.overflow="hidden auto",t.src=r,t.onload=()=>{var e;setTimeout(()=>{t.style.display="block",t.style.visibility="visible"},100),null===(e=t.contentWindow)||void 0===e||e.postMessage(i,r)}}closeLink(){const e=document.getElementById(n);e&&e.remove()}}const o=new Set;let s=!1;const a="one_auth_state",r="one_auth_error";function l(e,t,n){const i=`${t}~${o=n,btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}`;var o;try{const t=new URL(e);return t.searchParams.set("state",i),t.toString()}catch{return e.replace(`state=${encodeURIComponent(t)}`,`state=${encodeURIComponent(i)}`).replace(`state=${t}`,`state=${encodeURIComponent(i)}`)}}function c(){if("undefined"!=typeof window)try{const e=new URL(window.location.href);let t=!1;e.searchParams.has(a)&&(e.searchParams.delete(a),t=!0),e.searchParams.has(r)&&(e.searchParams.delete(r),t=!0),t&&window.history.replaceState({},document.title,e.toString())}catch{}}function d(e,t){const o=new i({...e,checkState:t});let a=!1,r=!1;const l=t=>{if("undefined"==typeof window)return;const i=document.getElementById(n);if(!i||t.source!==i.contentWindow)return;const d=t.data;if(null!=d&&d.messageType)if("LINK_SUCCESS"===d.messageType){if(!r){r=!0;try{var u;null===(u=e.onSuccess)||void 0===u||u.call(e,d.message)}catch{}c()}}else if("LINK_ERROR"===d.messageType){if(!r){r=!0;try{var h;null===(h=e.onError)||void 0===h||h.call(e,d.message)}catch{}c()}}else if("EXIT_EVENT_LINK"===d.messageType){if(!r)try{var m;null===(m=e.onClose)||void 0===m||m.call(e)}catch{}!function(){if(a)return;a=!0,"undefined"!=typeof window&&window.removeEventListener("message",l);o.closeLink(),c(),s=!1}()}};"undefined"!=typeof window&&window.addEventListener("message",l),o.openLink()}function u(e){if("undefined"==typeof window)return;if(s)return;let t;try{t=new URLSearchParams(window.location.search)}catch{return}const n=t.get(r),i=t.get(a);(n||i)&&(s=!0,n?function(e,t){setTimeout(()=>{try{var n;null===(n=e.onError)||void 0===n||n.call(e,t)}finally{c()}},0)}(e,n):i&&d(e,i))}exports.useOneAuth=e=>{u(e);const t=(e=>new i(e))({...e});let s=null,a=!1;const r=i=>{var r,d,u,h,m;if("undefined"==typeof window)return;const p=document.getElementById(n);if(!p||"block"!==p.style.display)return;if(i.source!==p.contentWindow)return;const f=i.data;if(null==f||!f.messageType)return;const y=`${f.messageType}-${JSON.stringify(null!==(r=null!==(d=f.message)&&void 0!==d?d:f.url)&&void 0!==r?r:"")}`;if(!o.has(y))switch(o.add(y),setTimeout(()=>o.delete(y),5e3),f.messageType){case"EXIT_EVENT_LINK":null===(u=e.onClose)||void 0===u||u.call(e),setTimeout(()=>{c()},200);break;case"LINK_SUCCESS":null===(h=e.onSuccess)||void 0===h||h.call(e,f.message);break;case"LINK_ERROR":null===(m=e.onError)||void 0===m||m.call(e,f.message);break;case"OAUTH_REDIRECT":{const n=f.url,i=f.state;if(!n||!i){var w;null===(w=e.onError)||void 0===w||w.call(e,"Invalid OAuth redirect message");break}const o=l(n,i,window.location.href);s&&a&&(window.removeEventListener("message",s),a=!1,s=null),t.closeLink(),window.location.href=o;break}}},c=()=>{"undefined"!=typeof window&&s&&a&&(window.removeEventListener("message",s),a=!1,s=null);for(const e of o)e.startsWith("EXIT_EVENT_LINK")&&o.delete(e);t.closeLink()};return{open:()=>{s&&a&&window.removeEventListener("message",s),s=r,"undefined"!=typeof window&&(window.addEventListener("message",s),a=!0),t.openLink()},close:c}};
1
+ "use strict";function e(e,t,n){return(t=function(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);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+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const t={oauthRedirect:!0},n="event-link";class i{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),e(this,"checkState",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,this.checkState=t.checkState}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://auth.withone.ai"}_buildPayload(){return{linkTokenEndpoint:this.linkTokenEndpoint,linkHeaders:this.linkHeaders,title:this.title,imageUrl:this.imageUrl,companyName:this.companyName,selectedConnection:this.selectedConnection,showNameInput:this.showNameInput,appTheme:this.appTheme,capabilities:t,checkState:this.checkState}}openLink(){const e=document.getElementById(n);e&&e.remove();const t=document.createElement("iframe"),i=this._buildPayload(),o=JSON.stringify(i),s=btoa(o),a=new URLSearchParams({data:s}).toString(),r=`${this._getBaseUrl()}?${a}`;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=n,t.style.overflow="hidden auto",t.src=r,t.onload=()=>{var e;setTimeout(()=>{t.style.display="block",t.style.visibility="visible"},100),null===(e=t.contentWindow)||void 0===e||e.postMessage(i,r)}}closeLink(){const e=document.getElementById(n);e&&e.remove()}}const o=new Set;let s=!1;const a="one_auth_state",r="one_auth_error";function l(e,t,n){const i=`${t}~${o=n,btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}`;var o;try{const t=new URL(e);return t.searchParams.set("state",i),t.toString()}catch{return e.replace(`state=${encodeURIComponent(t)}`,`state=${encodeURIComponent(i)}`).replace(`state=${t}`,`state=${encodeURIComponent(i)}`)}}function c(){if("undefined"!=typeof window)try{const e=new URL(window.location.href);let t=!1;e.searchParams.has(a)&&(e.searchParams.delete(a),t=!0),e.searchParams.has(r)&&(e.searchParams.delete(r),t=!0),t&&window.history.replaceState({},document.title,e.toString())}catch{}}function d(e,t){const o=new i({...e,checkState:t});let a=!1,r=!1;const l=t=>{if("undefined"==typeof window)return;const i=document.getElementById(n);if(!i||t.source!==i.contentWindow)return;const d=t.data;if(null!=d&&d.messageType)if("LINK_SUCCESS"===d.messageType){if(!r){r=!0;try{var u;null===(u=e.onSuccess)||void 0===u||u.call(e,d.message)}catch{}c()}}else if("LINK_ERROR"===d.messageType){if(!r){r=!0;try{var h;null===(h=e.onError)||void 0===h||h.call(e,d.message)}catch{}c()}}else if("EXIT_EVENT_LINK"===d.messageType){if(!r)try{var m;null===(m=e.onClose)||void 0===m||m.call(e)}catch{}!function(){if(a)return;a=!0,"undefined"!=typeof window&&window.removeEventListener("message",l);o.closeLink(),c(),s=!1}()}};"undefined"!=typeof window&&window.addEventListener("message",l),o.openLink()}function u(e){if("undefined"==typeof window)return;if(s)return;let t;try{t=new URLSearchParams(window.location.search)}catch{return}const n=t.get(r),i=t.get(a);(n||i)&&(s=!0,n?function(e,t){setTimeout(()=>{try{var n;null===(n=e.onError)||void 0===n||n.call(e,t)}finally{c()}},0)}(e,n):i&&d(e,i))}exports.useOneAuth=e=>{u(e);const t=(e=>new i(e))({...e});let s=null,a=!1;const r=t=>{var i,r,d,u,h;if("undefined"==typeof window)return;const m=document.getElementById(n);if(!m||"block"!==m.style.display)return;if(t.source!==m.contentWindow)return;const p=t.data;if(null==p||!p.messageType)return;const f=`${p.messageType}-${JSON.stringify(null!==(i=null!==(r=p.message)&&void 0!==r?r:p.url)&&void 0!==i?i:"")}`;if(!o.has(f))switch(o.add(f),setTimeout(()=>o.delete(f),5e3),p.messageType){case"EXIT_EVENT_LINK":null===(d=e.onClose)||void 0===d||d.call(e),setTimeout(()=>{c()},200);break;case"LINK_SUCCESS":null===(u=e.onSuccess)||void 0===u||u.call(e,p.message);break;case"LINK_ERROR":null===(h=e.onError)||void 0===h||h.call(e,p.message);break;case"OAUTH_REDIRECT":{const t=p.url,n=p.state;if(!t||!n){var y;null===(y=e.onError)||void 0===y||y.call(e,"Invalid OAuth redirect message");break}const i=l(t,n,window.location.href);s&&a&&(window.removeEventListener("message",s),a=!1,s=null),window.location.href=i;break}}},c=()=>{"undefined"!=typeof window&&s&&a&&(window.removeEventListener("message",s),a=!1,s=null);for(const e of o)e.startsWith("EXIT_EVENT_LINK")&&o.delete(e);t.closeLink()};return{open:()=>{s&&a&&window.removeEventListener("message",s),s=r,"undefined"!=typeof window&&(window.addEventListener("message",s),a=!0),t.openLink()},close:c}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krishp/one-auth",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Frontend bindings for One Auth, a drop-in authentication widget that lets your users connect their third-party apps to your application. Supports OAuth and non-OAuth integrations across 250+ platforms with project-level multi-tenant configuration.",
5
5
  "files": [
6
6
  "dist",
@@ -285,15 +285,18 @@ export const useEventLink = (props: EventLinkProps) => {
285
285
  returnUrl
286
286
  );
287
287
 
288
- // Detach our message listener and close the iframe before
289
- // navigation. We close explicitly (instead of relying on the
290
- // navigation to destroy it) so we leave a clean DOM state.
288
+ // Detach our message listener but keep the iframe visible.
289
+ // The page navigation will destroy it naturally when the
290
+ // browser starts loading the OAuth provider's page. This
291
+ // avoids the visual flicker that happens when the iframe is
292
+ // removed before the navigation starts — the user sees the
293
+ // iframe's loading state continuously until the new page
294
+ // begins to render.
291
295
  if (messageHandler && isListenerActive) {
292
296
  window.removeEventListener("message", messageHandler);
293
297
  isListenerActive = false;
294
298
  messageHandler = null;
295
299
  }
296
- linkWindow.closeLink();
297
300
 
298
301
  window.location.href = navigateUrl;
299
302
  break;