@withone/auth
Advanced tools
@@ -1,1 +0,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="event-link";class n{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,"authWindow",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.authWindow=t.authWindow,this.checkState=t.checkState}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://auth.withone.ai"}_buildPayload(){const e="popup"!==this.authWindow;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:{oauthRedirect:e},checkState:this.checkState}}openLink(){const e=document.getElementById(t);e&&e.remove();const n=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(n),n.style.height="100%",n.style.width="100%",n.style.position="fixed",n.style.display="hidden",n.style.visibility="hidden",n.style.zIndex="9999",n.style.backgroundColor="transparent",n.style.inset="0px",n.style.borderWidth="0px",n.id=t,n.style.overflow="hidden auto",n.src=r,n.onload=()=>{var e;setTimeout(()=>{n.style.display="block",n.style.visibility="visible"},100),null===(e=n.contentWindow)||void 0===e||e.postMessage(i,r)}}closeLink(){const e=document.getElementById(t);e&&e.remove()}}const i=new Set;let o=!1;const s="__withone_auth_pending";function a(e,t,n){const i=`${t}~${o=n,btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}~v3`;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 r(e,i){const s=new n({...e,checkState:i});let a=!1,r=!1;const l=n=>{if("undefined"==typeof window)return;const i=document.getElementById(t);if(!i||n.source!==i.contentWindow)return;const c=n.data;if(null!=c&&c.messageType)if("LINK_SUCCESS"===c.messageType){if(!r){r=!0;try{var d;null===(d=e.onSuccess)||void 0===d||d.call(e,c.message)}catch{}}}else if("LINK_ERROR"===c.messageType){if(!r){r=!0;try{var u;null===(u=e.onError)||void 0===u||u.call(e,c.message)}catch{}}}else if("EXIT_EVENT_LINK"===c.messageType){try{var h;null===(h=e.onClose)||void 0===h||h.call(e)}catch{}!function(){if(a)return;a=!0,"undefined"!=typeof window&&window.removeEventListener("message",l);s.closeLink(),o=!1}()}};"undefined"!=typeof window&&window.addEventListener("message",l),s.openLink()}function l(e){if("undefined"==typeof window)return;if(o)return;let t=null;try{const e=window.sessionStorage.getItem(s);e&&(t=JSON.parse(e))}catch{t=null}if(!t)return;try{window.sessionStorage.removeItem(s)}catch{}"number"==typeof t.at&&Date.now()-t.at<6e5&&(t.state?(o=!0,r(e,t.state)):t.error&&(o=!0,function(e,t){setTimeout(()=>{var n;null===(n=e.onError)||void 0===n||n.call(e,t)},0)}(e,t.error)))}const c=e=>{l(e);const o=(e=>new n(e))({...e});let r=null,c=!1;const d=n=>{var o,l,d,h,m;if("undefined"==typeof window)return;const p=document.getElementById(t);if(!p||"block"!==p.style.display)return;if(n.source!==p.contentWindow)return;const w=n.data;if(null==w||!w.messageType)return;const y=`${w.messageType}-${JSON.stringify(null!==(o=null!==(l=w.message)&&void 0!==l?l:w.url)&&void 0!==o?o:"")}`;if(!i.has(y))switch(i.add(y),setTimeout(()=>i.delete(y),5e3),w.messageType){case"EXIT_EVENT_LINK":null===(d=e.onClose)||void 0===d||d.call(e),setTimeout(()=>{u()},200);break;case"LINK_SUCCESS":null===(h=e.onSuccess)||void 0===h||h.call(e,w.message);break;case"LINK_ERROR":null===(m=e.onError)||void 0===m||m.call(e,w.message);break;case"OAUTH_REDIRECT":{const t=w.url,n=w.state;if(!t||!n){var v;null===(v=e.onError)||void 0===v||v.call(e,"Invalid OAuth redirect message");break}const i=a(t,n,window.location.href);try{window.sessionStorage.setItem(s,JSON.stringify({state:n,at:Date.now()}))}catch{}r&&c&&(window.removeEventListener("message",r),c=!1,r=null),window.location.href=i;break}}},u=()=>{"undefined"!=typeof window&&r&&c&&(window.removeEventListener("message",r),c=!1,r=null);for(const e of i)e.startsWith("EXIT_EVENT_LINK")&&i.delete(e);o.closeLink()};return{open:()=>{r&&c&&window.removeEventListener("message",r),r=d,"undefined"!=typeof window&&(window.addEventListener("message",r),c=!0),o.openLink()},close:u}};export{c as useOneAuth}; | ||
| 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 o=n.call(e,t);if("object"!=typeof o)return o;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="event-link";class n{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,"authWindow",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.authWindow=t.authWindow,this.checkState=t.checkState}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://auth.withone.ai"}_buildPayload(){const e="popup"!==this.authWindow;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:{oauthRedirect:e},checkState:this.checkState}}openLink(){const e=document.getElementById(t);e&&e.remove();const n=document.createElement("iframe"),o=this._buildPayload(),i=JSON.stringify(o),s=btoa(i),r=new URLSearchParams({data:s}).toString(),a=`${this._getBaseUrl()}?${r}`;document.body.appendChild(n),n.style.height="100%",n.style.width="100%",n.style.position="fixed",n.style.display="hidden",n.style.visibility="hidden",n.style.zIndex="9999",n.style.backgroundColor="transparent",n.style.inset="0px",n.style.borderWidth="0px",n.id=t,n.style.overflow="hidden auto",n.src=a,n.onload=()=>{var e;setTimeout(()=>{n.style.display="block",n.style.visibility="visible"},100),null===(e=n.contentWindow)||void 0===e||e.postMessage(o,a)}}closeLink(){const e=document.getElementById(t);e&&e.remove()}}const o=new Set;let i=!1,s=null;const r="__withone_auth_pending";function a(e,t,n){const o=`${t}~${i=n,btoa(i).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}~v3`;var i;try{const t=new URL(e);return t.searchParams.set("state",o),t.toString()}catch{return e.replace(`state=${encodeURIComponent(t)}`,`state=${encodeURIComponent(o)}`).replace(`state=${t}`,`state=${encodeURIComponent(o)}`)}}function l(e,o){const s=new n({...e,checkState:o});let r=!1,a=!1;const l=n=>{if("undefined"==typeof window)return;const o=document.getElementById(t);if(!o||n.source!==o.contentWindow)return;const d=n.data;if(null!=d&&d.messageType)if("LINK_SUCCESS"===d.messageType){if(!a){a=!0;try{var c;null===(c=e.onSuccess)||void 0===c||c.call(e,d.message)}catch{}}}else if("LINK_ERROR"===d.messageType){if(!a){a=!0;try{var u;null===(u=e.onError)||void 0===u||u.call(e,d.message)}catch{}}}else if("EXIT_EVENT_LINK"===d.messageType){try{var h;null===(h=e.onClose)||void 0===h||h.call(e)}catch{}!function(){if(r)return;r=!0,"undefined"!=typeof window&&window.removeEventListener("message",l);s.closeLink(),i=!1}()}};"undefined"!=typeof window&&window.addEventListener("message",l),s.openLink()}function d(e){if("undefined"==typeof window)return;if(i)return;let n,o=null;try{const e=window.sessionStorage.getItem(r);e&&(o=JSON.parse(e))}catch{o=null}if(!o)return;try{window.sessionStorage.removeItem(r)}catch{}try{var s;n=null===(s=performance.getEntriesByType("navigation")[0])||void 0===s?void 0:s.type}catch{}if("back_forward"===n){const n=document.getElementById(t);return n&&n.remove(),void setTimeout(()=>{try{var t;null===(t=e.onClose)||void 0===t||t.call(e)}catch{}},0)}"number"==typeof o.at&&Date.now()-o.at<6e5&&(o.state?(i=!0,l(e,o.state)):o.error&&(i=!0,function(e,t){setTimeout(()=>{var n;null===(n=e.onError)||void 0===n||n.call(e,t)},0)}(e,o.error)))}const c=e=>{d(e);const i=(e=>new n(e))({...e});let l=null,c=!1;const u=n=>{var i,s,d,u,m;if("undefined"==typeof window)return;const p=document.getElementById(t);if(!p||"block"!==p.style.display)return;if(n.source!==p.contentWindow)return;const w=n.data;if(null==w||!w.messageType)return;const v=`${w.messageType}-${JSON.stringify(null!==(i=null!==(s=w.message)&&void 0!==s?s:w.url)&&void 0!==i?i:"")}`;if(!o.has(v))switch(o.add(v),setTimeout(()=>o.delete(v),5e3),w.messageType){case"EXIT_EVENT_LINK":null===(d=e.onClose)||void 0===d||d.call(e),setTimeout(()=>{h()},200);break;case"LINK_SUCCESS":null===(u=e.onSuccess)||void 0===u||u.call(e,w.message);break;case"LINK_ERROR":null===(m=e.onError)||void 0===m||m.call(e,w.message);break;case"OAUTH_REDIRECT":{const t=w.url,n=w.state;if(!t||!n){var y;null===(y=e.onError)||void 0===y||y.call(e,"Invalid OAuth redirect message");break}const o=a(t,n,window.location.href);try{window.sessionStorage.setItem(r,JSON.stringify({state:n,at:Date.now()}))}catch{}l&&c&&(window.removeEventListener("message",l),c=!1,l=null),window.location.href=o;break}}},h=()=>{"undefined"!=typeof window&&l&&c&&(window.removeEventListener("message",l),c=!1,l=null),"undefined"!=typeof window&&s&&(window.removeEventListener("pageshow",s),s=null);for(const e of o)e.startsWith("EXIT_EVENT_LINK")&&o.delete(e);i.closeLink()};return{open:()=>{l&&c&&window.removeEventListener("message",l),l=u,"undefined"!=typeof window&&(window.addEventListener("message",l),c=!0,s&&window.removeEventListener("pageshow",s),s=n=>{if(n.persisted){let n=null;try{n=window.sessionStorage.getItem(r)}catch{}if(!n)return;try{window.sessionStorage.removeItem(r)}catch{}const i=document.getElementById(t);i&&i.remove();try{var o;null===(o=e.onClose)||void 0===o||o.call(e)}catch{}return}d(e)},window.addEventListener("pageshow",s)),i.openLink()},close:h}};export{c as useOneAuth}; |
@@ -1,1 +0,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="event-link";class n{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,"authWindow",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.authWindow=t.authWindow,this.checkState=t.checkState}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://auth.withone.ai"}_buildPayload(){const e="popup"!==this.authWindow;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:{oauthRedirect:e},checkState:this.checkState}}openLink(){const e=document.getElementById(t);e&&e.remove();const n=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(n),n.style.height="100%",n.style.width="100%",n.style.position="fixed",n.style.display="hidden",n.style.visibility="hidden",n.style.zIndex="9999",n.style.backgroundColor="transparent",n.style.inset="0px",n.style.borderWidth="0px",n.id=t,n.style.overflow="hidden auto",n.src=r,n.onload=()=>{var e;setTimeout(()=>{n.style.display="block",n.style.visibility="visible"},100),null===(e=n.contentWindow)||void 0===e||e.postMessage(i,r)}}closeLink(){const e=document.getElementById(t);e&&e.remove()}}const i=new Set;let o=!1;const s="__withone_auth_pending";function a(e,t,n){const i=`${t}~${o=n,btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}~v3`;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 r(e,i){const s=new n({...e,checkState:i});let a=!1,r=!1;const l=n=>{if("undefined"==typeof window)return;const i=document.getElementById(t);if(!i||n.source!==i.contentWindow)return;const c=n.data;if(null!=c&&c.messageType)if("LINK_SUCCESS"===c.messageType){if(!r){r=!0;try{var d;null===(d=e.onSuccess)||void 0===d||d.call(e,c.message)}catch{}}}else if("LINK_ERROR"===c.messageType){if(!r){r=!0;try{var u;null===(u=e.onError)||void 0===u||u.call(e,c.message)}catch{}}}else if("EXIT_EVENT_LINK"===c.messageType){try{var h;null===(h=e.onClose)||void 0===h||h.call(e)}catch{}!function(){if(a)return;a=!0,"undefined"!=typeof window&&window.removeEventListener("message",l);s.closeLink(),o=!1}()}};"undefined"!=typeof window&&window.addEventListener("message",l),s.openLink()}function l(e){if("undefined"==typeof window)return;if(o)return;let t=null;try{const e=window.sessionStorage.getItem(s);e&&(t=JSON.parse(e))}catch{t=null}if(!t)return;try{window.sessionStorage.removeItem(s)}catch{}"number"==typeof t.at&&Date.now()-t.at<6e5&&(t.state?(o=!0,r(e,t.state)):t.error&&(o=!0,function(e,t){setTimeout(()=>{var n;null===(n=e.onError)||void 0===n||n.call(e,t)},0)}(e,t.error)))}exports.useOneAuth=e=>{l(e);const o=(e=>new n(e))({...e});let r=null,c=!1;const d=n=>{var o,l,d,h,m;if("undefined"==typeof window)return;const p=document.getElementById(t);if(!p||"block"!==p.style.display)return;if(n.source!==p.contentWindow)return;const w=n.data;if(null==w||!w.messageType)return;const y=`${w.messageType}-${JSON.stringify(null!==(o=null!==(l=w.message)&&void 0!==l?l:w.url)&&void 0!==o?o:"")}`;if(!i.has(y))switch(i.add(y),setTimeout(()=>i.delete(y),5e3),w.messageType){case"EXIT_EVENT_LINK":null===(d=e.onClose)||void 0===d||d.call(e),setTimeout(()=>{u()},200);break;case"LINK_SUCCESS":null===(h=e.onSuccess)||void 0===h||h.call(e,w.message);break;case"LINK_ERROR":null===(m=e.onError)||void 0===m||m.call(e,w.message);break;case"OAUTH_REDIRECT":{const t=w.url,n=w.state;if(!t||!n){var v;null===(v=e.onError)||void 0===v||v.call(e,"Invalid OAuth redirect message");break}const i=a(t,n,window.location.href);try{window.sessionStorage.setItem(s,JSON.stringify({state:n,at:Date.now()}))}catch{}r&&c&&(window.removeEventListener("message",r),c=!1,r=null),window.location.href=i;break}}},u=()=>{"undefined"!=typeof window&&r&&c&&(window.removeEventListener("message",r),c=!1,r=null);for(const e of i)e.startsWith("EXIT_EVENT_LINK")&&i.delete(e);o.closeLink()};return{open:()=>{r&&c&&window.removeEventListener("message",r),r=d,"undefined"!=typeof window&&(window.addEventListener("message",r),c=!0),o.openLink()},close:u}}; | ||
| "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 o=n.call(e,t);if("object"!=typeof o)return o;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="event-link";class n{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,"authWindow",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.authWindow=t.authWindow,this.checkState=t.checkState}_getBaseUrl(){return this.baseUrl?this.baseUrl:"https://auth.withone.ai"}_buildPayload(){const e="popup"!==this.authWindow;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:{oauthRedirect:e},checkState:this.checkState}}openLink(){const e=document.getElementById(t);e&&e.remove();const n=document.createElement("iframe"),o=this._buildPayload(),i=JSON.stringify(o),s=btoa(i),r=new URLSearchParams({data:s}).toString(),a=`${this._getBaseUrl()}?${r}`;document.body.appendChild(n),n.style.height="100%",n.style.width="100%",n.style.position="fixed",n.style.display="hidden",n.style.visibility="hidden",n.style.zIndex="9999",n.style.backgroundColor="transparent",n.style.inset="0px",n.style.borderWidth="0px",n.id=t,n.style.overflow="hidden auto",n.src=a,n.onload=()=>{var e;setTimeout(()=>{n.style.display="block",n.style.visibility="visible"},100),null===(e=n.contentWindow)||void 0===e||e.postMessage(o,a)}}closeLink(){const e=document.getElementById(t);e&&e.remove()}}const o=new Set;let i=!1,s=null;const r="__withone_auth_pending";function a(e,t,n){const o=`${t}~${i=n,btoa(i).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}~v3`;var i;try{const t=new URL(e);return t.searchParams.set("state",o),t.toString()}catch{return e.replace(`state=${encodeURIComponent(t)}`,`state=${encodeURIComponent(o)}`).replace(`state=${t}`,`state=${encodeURIComponent(o)}`)}}function l(e,o){const s=new n({...e,checkState:o});let r=!1,a=!1;const l=n=>{if("undefined"==typeof window)return;const o=document.getElementById(t);if(!o||n.source!==o.contentWindow)return;const d=n.data;if(null!=d&&d.messageType)if("LINK_SUCCESS"===d.messageType){if(!a){a=!0;try{var c;null===(c=e.onSuccess)||void 0===c||c.call(e,d.message)}catch{}}}else if("LINK_ERROR"===d.messageType){if(!a){a=!0;try{var u;null===(u=e.onError)||void 0===u||u.call(e,d.message)}catch{}}}else if("EXIT_EVENT_LINK"===d.messageType){try{var h;null===(h=e.onClose)||void 0===h||h.call(e)}catch{}!function(){if(r)return;r=!0,"undefined"!=typeof window&&window.removeEventListener("message",l);s.closeLink(),i=!1}()}};"undefined"!=typeof window&&window.addEventListener("message",l),s.openLink()}function d(e){if("undefined"==typeof window)return;if(i)return;let n,o=null;try{const e=window.sessionStorage.getItem(r);e&&(o=JSON.parse(e))}catch{o=null}if(!o)return;try{window.sessionStorage.removeItem(r)}catch{}try{var s;n=null===(s=performance.getEntriesByType("navigation")[0])||void 0===s?void 0:s.type}catch{}if("back_forward"===n){const n=document.getElementById(t);return n&&n.remove(),void setTimeout(()=>{try{var t;null===(t=e.onClose)||void 0===t||t.call(e)}catch{}},0)}"number"==typeof o.at&&Date.now()-o.at<6e5&&(o.state?(i=!0,l(e,o.state)):o.error&&(i=!0,function(e,t){setTimeout(()=>{var n;null===(n=e.onError)||void 0===n||n.call(e,t)},0)}(e,o.error)))}exports.useOneAuth=e=>{d(e);const i=(e=>new n(e))({...e});let l=null,c=!1;const u=n=>{var i,s,d,u,m;if("undefined"==typeof window)return;const p=document.getElementById(t);if(!p||"block"!==p.style.display)return;if(n.source!==p.contentWindow)return;const w=n.data;if(null==w||!w.messageType)return;const v=`${w.messageType}-${JSON.stringify(null!==(i=null!==(s=w.message)&&void 0!==s?s:w.url)&&void 0!==i?i:"")}`;if(!o.has(v))switch(o.add(v),setTimeout(()=>o.delete(v),5e3),w.messageType){case"EXIT_EVENT_LINK":null===(d=e.onClose)||void 0===d||d.call(e),setTimeout(()=>{h()},200);break;case"LINK_SUCCESS":null===(u=e.onSuccess)||void 0===u||u.call(e,w.message);break;case"LINK_ERROR":null===(m=e.onError)||void 0===m||m.call(e,w.message);break;case"OAUTH_REDIRECT":{const t=w.url,n=w.state;if(!t||!n){var y;null===(y=e.onError)||void 0===y||y.call(e,"Invalid OAuth redirect message");break}const o=a(t,n,window.location.href);try{window.sessionStorage.setItem(r,JSON.stringify({state:n,at:Date.now()}))}catch{}l&&c&&(window.removeEventListener("message",l),c=!1,l=null),window.location.href=o;break}}},h=()=>{"undefined"!=typeof window&&l&&c&&(window.removeEventListener("message",l),c=!1,l=null),"undefined"!=typeof window&&s&&(window.removeEventListener("pageshow",s),s=null);for(const e of o)e.startsWith("EXIT_EVENT_LINK")&&o.delete(e);i.closeLink()};return{open:()=>{l&&c&&window.removeEventListener("message",l),l=u,"undefined"!=typeof window&&(window.addEventListener("message",l),c=!0,s&&window.removeEventListener("pageshow",s),s=n=>{if(n.persisted){let n=null;try{n=window.sessionStorage.getItem(r)}catch{}if(!n)return;try{window.sessionStorage.removeItem(r)}catch{}const i=document.getElementById(t);i&&i.remove();try{var o;null===(o=e.onClose)||void 0===o||o.call(e)}catch{}return}d(e)},window.addEventListener("pageshow",s)),i.openLink()},close:h}}; |
+2
-2
| { | ||
| "name": "@withone/auth", | ||
| "version": "1.3.0", | ||
| "version": "1.4.0", | ||
| "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.", | ||
@@ -58,2 +58,2 @@ "files": [ | ||
| "homepage": "https://withone.ai" | ||
| } | ||
| } |
+99
-0
@@ -14,2 +14,8 @@ import { ConnectionRecord, EventLinkProps, EventProps } from "./types"; | ||
| // Module-level reference to the most recently registered pageshow | ||
| // handler. Survives across useEventLink calls so we can de-duplicate | ||
| // listeners. open() replaces it; close() tears it down. | ||
| let pageshowHandler: ((e: PageTransitionEvent) => void) | null = null; | ||
| // Separator used between the original OAuth state and the base64url | ||
@@ -222,2 +228,41 @@ // encoded return URL. Tilde is in the URL "unreserved" set so it | ||
| // Cancel detection. performance.navigation.type === "back_forward" | ||
| // is set when the user arrived at this page via the browser back/ | ||
| // forward button. The OAuth success path arrives via the One-hosted | ||
| // callback's redirect, which is type "navigate" — so the two paths | ||
| // are cleanly distinguishable. | ||
| // | ||
| // Works in BOTH cases: | ||
| // - bfcache enabled (prod): pageshow listener calls this function | ||
| // after the page is restored; navigationType is "back_forward" | ||
| // - bfcache disabled (Next.js dev, etc.): page reloads fresh, | ||
| // detectOAuthReturn runs from the initial render; | ||
| // navigationType is also "back_forward" | ||
| // | ||
| // On cancel: tear down the iframe (no-op if already destroyed by | ||
| // the reload) and fire onClose. The user can retry by re-opening | ||
| // the modal — that gets them a fresh OAuth request, avoiding the | ||
| // "not in pending state" backend error from re-authorizing the | ||
| // same requestId. | ||
| let navigationType: string | undefined; | ||
| try { | ||
| const entries = performance.getEntriesByType("navigation"); | ||
| navigationType = (entries[0] as PerformanceNavigationTiming | undefined) | ||
| ?.type; | ||
| } catch { | ||
| /* performance API unavailable — fall through to normal handling */ | ||
| } | ||
| if (navigationType === "back_forward") { | ||
| const iframe = document.getElementById(VISIBLE_IFRAME_ID); | ||
| if (iframe) iframe.remove(); | ||
| setTimeout(() => { | ||
| try { | ||
| props.onClose?.(); | ||
| } catch { | ||
| /* consumer callback errors are not our problem */ | ||
| } | ||
| }, 0); | ||
| return; | ||
| } | ||
| const fresh = | ||
@@ -355,2 +400,50 @@ typeof pending.at === "number" && Date.now() - pending.at < PENDING_TTL_MS; | ||
| isListenerActive = true; | ||
| // bfcache scenario: when the browser restores a cached page on | ||
| // back navigation, React doesn't re-render so detectOAuthReturn | ||
| // doesn't auto-fire. This pageshow listener wakes it up. | ||
| // | ||
| // We use TWO signals because they each cover a different case: | ||
| // • event.persisted=true (set by spec on bfcache restore) is | ||
| // the definitive bfcache signal. Always reliable. | ||
| // • Otherwise, fall through to detectOAuthReturn, which uses | ||
| // navigation.type === "back_forward" — the right signal for | ||
| // full-reload back navigation (no bfcache). | ||
| // | ||
| // Both paths converge on the same cancel logic. sessionStorage | ||
| // is consumed atomically, so even if both fire, only one acts. | ||
| if (pageshowHandler) { | ||
| window.removeEventListener("pageshow", pageshowHandler); | ||
| } | ||
| pageshowHandler = (e: PageTransitionEvent) => { | ||
| if (e.persisted) { | ||
| // bfcache restore — pageshow guarantees this is back/forward | ||
| // navigation. Don't rely on performance.navigation.type here | ||
| // because browser behavior on bfcache restore varies. | ||
| let raw: string | null = null; | ||
| try { | ||
| raw = window.sessionStorage.getItem(PENDING_STORAGE_KEY); | ||
| } catch { | ||
| /* ignore */ | ||
| } | ||
| if (!raw) return; | ||
| try { | ||
| window.sessionStorage.removeItem(PENDING_STORAGE_KEY); | ||
| } catch { | ||
| /* ignore */ | ||
| } | ||
| const iframe = document.getElementById(VISIBLE_IFRAME_ID); | ||
| if (iframe) iframe.remove(); | ||
| try { | ||
| props.onClose?.(); | ||
| } catch { | ||
| /* consumer callback errors are not our problem */ | ||
| } | ||
| return; | ||
| } | ||
| // Fresh load (no bfcache). detectOAuthReturn's navigationType | ||
| // check handles the back-button case here. | ||
| detectOAuthReturn(props); | ||
| }; | ||
| window.addEventListener("pageshow", pageshowHandler); | ||
| } | ||
@@ -368,2 +461,8 @@ | ||
| } | ||
| // Tear down the pageshow handler too — nothing to cancel once | ||
| // the modal is closed. | ||
| if (typeof window !== "undefined" && pageshowHandler) { | ||
| window.removeEventListener("pageshow", pageshowHandler); | ||
| pageshowHandler = null; | ||
| } | ||
| // Only clear the EXIT dedup key so re-opening works immediately. | ||
@@ -370,0 +469,0 @@ // LINK_SUCCESS / LINK_ERROR dedup keys stay to prevent duplicate callbacks. |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
86384
6.81%781
14.85%2
-33.33%