UNPKG

onairos

Version:

The Onairos Library is a collection of functions that enable Applications to connect and communicate data with Onairos Identities via User Authorization. Integration for developers is seamless, simple and effective for all applications. LLM SDK capabiliti

2 lines 39.9 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define("Onairos",["React"],t):"object"==typeof exports?exports.Onairos=t(require("react")):e.Onairos=t(e.React)}(this,(e=>(()=>{"use strict";var t={639:t=>{t.exports=e}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var o=r[e]={exports:{}};return t[e](o,o.exports,n),o.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{n.r(a),n.d(a,{Onairos:()=>A,OnairosButton:()=>_,default:()=>T,initializeApiKey:()=>L});var e=n(639),t=n.n(e);const r=e=>{const t=(e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,((e,t,r)=>r?r.toUpperCase():t.toLowerCase())))(e);return t.charAt(0).toUpperCase()+t.slice(1)},o=(...e)=>e.filter(((e,t,r)=>Boolean(e)&&""!==e.trim()&&r.indexOf(e)===t)).join(" ").trim(),l=e=>{for(const t in e)if(t.startsWith("aria-")||"role"===t||"title"===t)return!0};var s={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const c=(0,e.forwardRef)((({color:t="currentColor",size:r=24,strokeWidth:n=2,absoluteStrokeWidth:a,className:c="",children:i,iconNode:m,...u},d)=>(0,e.createElement)("svg",{ref:d,...s,width:r,height:r,stroke:t,strokeWidth:a?24*Number(n)/Number(r):n,className:o("lucide",c),...!i&&!l(u)&&{"aria-hidden":"true"},...u},[...m.map((([t,r])=>(0,e.createElement)(t,r))),...Array.isArray(i)?i:[i]]))),i=(t,n)=>{const a=(0,e.forwardRef)((({className:a,...l},s)=>{return(0,e.createElement)(c,{ref:s,iconNode:n,className:o(`lucide-${i=r(t),i.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}`,`lucide-${t}`,a),...l});var i}));return a.displayName=r(t),a},m=i("mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]]),u=i("arrow-right",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]),d=i("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);function p(r){let{onSuccess:n,testMode:a=!0}=r;const[o,l]=(0,e.useState)(""),[s,c]=(0,e.useState)(""),[i,p]=(0,e.useState)("email"),[g,b]=(0,e.useState)(!1),[f,y]=(0,e.useState)(""),h=async e=>{if(e.preventDefault(),y(""),(e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))(o)){b(!0);try{if(a)setTimeout((()=>{p("code"),b(!1)}),1e3);else{if(!(await fetch("https://api2.onairos.uk/email/verify",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:o})})).ok)throw new Error("Failed to send verification code");p("code"),b(!1)}}catch(e){y(e.message),b(!1)}}else y("Please enter a valid email address")},x=async e=>{if(e.preventDefault(),y(""),a&&"123456"===s)return p("success"),void setTimeout((()=>{n({email:o,verified:!0})}),1e3);if(a)y("Invalid code. Use 123456 for testing.");else{b(!0);try{const e=await fetch("https://api2.onairos.uk/email/verify/confirm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:o,code:s})});if(!e.ok)throw new Error("Invalid verification code");const t=await e.json();p("success"),setTimeout((()=>{n({email:o,verified:!0,token:t.token})}),1e3)}catch(e){y(e.message),b(!1)}}};return t().createElement("div",{className:"flex flex-col items-center space-y-6 p-6 w-full"},"email"===i&&t().createElement("div",{className:"flex flex-col items-center space-y-6 w-full"},t().createElement("div",{className:"flex items-center justify-center w-16 h-16 bg-blue-100 rounded-full"},t().createElement(m,{className:"w-8 h-8 text-blue-600"})),t().createElement("div",{className:"text-center"},t().createElement("h2",{className:"text-xl font-semibold text-gray-900 mb-2"},"Sign in to Onairos"),t().createElement("p",{className:"text-gray-600"},"Enter your email address to continue"),a&&t().createElement("p",{className:"text-sm text-blue-600 mt-2"},"Test mode: Any valid email will work")),t().createElement("form",{onSubmit:h,className:"w-full max-w-md space-y-4"},t().createElement("div",null,t().createElement("label",{htmlFor:"email",className:"block text-sm font-medium text-gray-700 mb-1"},"Email address"),t().createElement("input",{type:"email",id:"email",value:o,onChange:e=>l(e.target.value),placeholder:"Enter your email",className:"w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none",required:!0})),f&&t().createElement("p",{className:"text-sm text-red-600"},f),t().createElement("button",{type:"submit",disabled:g,className:"w-full py-3 px-4 bg-blue-600 text-white rounded-lg font-semibold hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center"},g?t().createElement("div",{className:"animate-spin h-5 w-5 border-2 border-white rounded-full border-t-transparent"}):t().createElement(t().Fragment,null,"Continue",t().createElement(u,{className:"ml-2 w-4 h-4"}))))),"code"===i&&t().createElement("div",{className:"flex flex-col items-center space-y-6 w-full"},t().createElement("div",{className:"flex items-center justify-center w-16 h-16 bg-green-100 rounded-full"},t().createElement(m,{className:"w-8 h-8 text-green-600"})),t().createElement("div",{className:"text-center"},t().createElement("h2",{className:"text-xl font-semibold text-gray-900 mb-2"},"Check your email"),t().createElement("p",{className:"text-gray-600"},"We sent a verification code to"),t().createElement("p",{className:"text-gray-900 font-medium"},o),a&&t().createElement("p",{className:"text-sm text-blue-600 mt-2"},"Test mode: Use code 123456")),t().createElement("form",{onSubmit:x,className:"w-full max-w-md space-y-4"},t().createElement("div",null,t().createElement("label",{htmlFor:"code",className:"block text-sm font-medium text-gray-700 mb-1"},"Verification code"),t().createElement("input",{type:"text",id:"code",value:s,onChange:e=>c(e.target.value),placeholder:"Enter 6-digit code",className:"w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none text-center text-lg tracking-widest",maxLength:"6",required:!0})),f&&t().createElement("p",{className:"text-sm text-red-600"},f),t().createElement("button",{type:"submit",disabled:g,className:"w-full py-3 px-4 bg-blue-600 text-white rounded-lg font-semibold hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center"},g?t().createElement("div",{className:"animate-spin h-5 w-5 border-2 border-white rounded-full border-t-transparent"}):"Verify Code"),t().createElement("button",{type:"button",onClick:()=>p("email"),className:"w-full py-2 px-4 text-gray-600 hover:text-gray-800"},"Use a different email"))),"success"===i&&t().createElement("div",{className:"flex flex-col items-center space-y-6 w-full"},t().createElement("div",{className:"flex items-center justify-center w-16 h-16 bg-green-100 rounded-full"},t().createElement(d,{className:"w-8 h-8 text-green-600"})),t().createElement("div",{className:"text-center"},t().createElement("h2",{className:"text-xl font-semibold text-gray-900 mb-2"},"Email verified!"),t().createElement("p",{className:"text-gray-600"},"Setting up your account...")),t().createElement("div",{className:"w-8 h-8"},t().createElement("div",{className:"animate-spin h-8 w-8 border-2 border-blue-600 rounded-full border-t-transparent"}))))}function g(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?g(Object(r),!0).forEach((function(t){f(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):g(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function f(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");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:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const y=[{name:"YouTube",icon:"📺",color:"bg-red-500",connector:"youtube"},{name:"LinkedIn",icon:"💼",color:"bg-blue-700",connector:"linkedin"},{name:"Reddit",icon:"🔥",color:"bg-orange-500",connector:"reddit"},{name:"Pinterest",icon:"📌",color:"bg-red-600",connector:"pinterest"},{name:"Instagram",icon:"📷",color:"bg-pink-500",connector:"instagram"},{name:"GitHub",icon:"⚡",color:"bg-gray-800",connector:"github"},{name:"Facebook",icon:"👥",color:"bg-blue-600",connector:"facebook"},{name:"Gmail",icon:"✉️",color:"bg-red-400",connector:"gmail"}],h={apiKey:process.env.REACT_APP_ONAIROS_API_KEY||"onairos_web_sdk_live_key_2024",baseUrl:process.env.REACT_APP_ONAIROS_BASE_URL||"https://api2.onairos.uk",sdkType:"web",enableHealthMonitoring:!0,enableAutoRefresh:!0,enableConnectionValidation:!0};function x(r){let{onComplete:n,appIcon:a,appName:o="App"}=r;const[l,s]=(0,e.useState)({}),[c,i]=(0,e.useState)(!1),[m,u]=(0,e.useState)(null),[d,p]=(0,e.useState)({}),[g,f]=(0,e.useState)({}),[x,v]=(0,e.useState)(0);(0,e.useEffect)((()=>{(()=>{const e=localStorage.getItem("onairos_oauth_platform");e&&(console.log("📱 OAuth return detected for: ".concat(e)),localStorage.removeItem("onairos_oauth_platform"),localStorage.removeItem("onairos_oauth_return"),s((t=>b(b({},t),{},{[e]:!0}))),p((t=>b(b({},t),{},{[e]:null}))),console.log("✅ ".concat(e," marked as connected from OAuth return")))})()}),[]);const w=async e=>{console.log("🚀 connectToPlatform called for: ".concat(e));const t=y.find((t=>t.name===e));if(null==t||!t.connector)return console.error("❌ No connector found for platform: ".concat(e)),!1;try{var r;i(!0),u(e),p((t=>b(b({},t),{},{[e]:null}))),console.log("🔗 Starting OAuth connection for ".concat(e,"..."));const n=localStorage.getItem("username")||(null===(r=localStorage.getItem("onairosUser"))||void 0===r?void 0:r.email)||"user@example.com",a="".concat(h.baseUrl,"/").concat(t.connector,"/authorize"),o=await fetch(a,{method:"POST",headers:{"x-api-key":h.apiKey,"Content-Type":"application/json"},body:JSON.stringify({session:{username:n}})});if(!o.ok)throw new Error("HTTP ".concat(o.status,": ").concat(o.statusText));const l=await o.json();console.log("📋 ".concat(e," OAuth response:"),l);const c={youtube:["youtubeURL","youtubeUrl","youtube_url"],linkedin:["linkedinURL","linkedinUrl","linkedin_url"],reddit:["redditURL","redditUrl","reddit_url"],pinterest:["pinterestURL","pinterestUrl","pinterest_url"],instagram:["instagramURL","instagramUrl","instagram_url"],github:["githubURL","githubUrl","github_url"],facebook:["facebookURL","facebookUrl","facebook_url"],gmail:["gmailURL","gmailUrl","gmail_url"]}[t.connector]||["".concat(t.connector,"URL"),"".concat(t.connector,"Url"),"".concat(t.connector,"_url"),"platformURL","authUrl","url"];let m=null,d=null;for(const e of c)if(l[e]){m=l[e],d=e;break}if(!m)throw console.error("❌ No OAuth URL found for ".concat(e,":")),console.error("Expected one of:",c),console.error("Response keys:",Object.keys(l)),console.error("Full response:",l),new Error("No OAuth URL found. Backend should return one of: ".concat(c.join(", ")));if(console.log("✅ Found OAuth URL for ".concat(e," using key: ").concat(d)),/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||window.innerWidth<=768)return localStorage.setItem("onairos_oauth_platform",e),localStorage.setItem("onairos_oauth_return",window.location.href),window.location.href=m,!0;{const r=window.open(m,"".concat(t.connector,"_oauth"),"width=500,height=600,scrollbars=yes,resizable=yes,status=no,location=no,toolbar=no,menubar=no");if(!r)throw new Error("Popup blocked. Please allow popups and try again.");let n=!1;const a=setInterval((()=>{try{if(r.location&&"onairos.uk"===r.location.hostname)return n=!0,console.log("🔄 ".concat(e," popup navigated to onairos.uk - treating as success")),void r.close()}catch(t){n||(n=!0,console.log("🔄 ".concat(e," popup navigated (cross-origin) - likely to onairos.uk")))}try{if(r.closed){clearInterval(a);const t=localStorage.getItem("onairos_".concat(e,"_success")),r=localStorage.getItem("onairos_".concat(e,"_error")),o=localStorage.getItem("onairos_".concat(e,"_timestamp")),l=o&&Date.now()-parseInt(o)<3e4;t&&l?(console.log("✅ ".concat(e," OAuth completed successfully (callback page)")),localStorage.removeItem("onairos_".concat(e,"_success")),localStorage.removeItem("onairos_".concat(e,"_timestamp")),s((t=>b(b({},t),{},{[e]:!0}))),p((t=>b(b({},t),{},{[e]:null})))):r&&l?(console.log("❌ ".concat(e," OAuth failed:"),r),localStorage.removeItem("onairos_".concat(e,"_error")),localStorage.removeItem("onairos_".concat(e,"_timestamp")),p((t=>b(b({},t),{},{[e]:r})))):n?(console.log("✅ ".concat(e," OAuth likely successful (navigated to onairos.uk)")),s((t=>b(b({},t),{},{[e]:!0}))),p((t=>b(b({},t),{},{[e]:null})))):(console.log("⚠️ ".concat(e," OAuth cancelled or no response")),p((t=>b(b({},t),{},{[e]:"Connection was cancelled"})))),i(!1),u(null)}}catch(e){}}),1e3);return setTimeout((()=>{try{!r.closed&&r.location&&"onairos.uk"===r.location.hostname&&(console.log("🚪 Auto-closing ".concat(e," popup showing onairos.uk (not found)")),r.close())}catch(t){!r.closed&&n&&(console.log("🚪 Auto-closing ".concat(e," popup (cross-origin, likely onairos.uk)")),r.close())}}),1e4),setTimeout((()=>{r.closed||(r.close(),clearInterval(a),p((t=>b(b({},t),{},{[e]:"Connection timeout"}))),i(!1),u(null))}),3e5),!0}}catch(t){return console.error("❌ Error connecting to ".concat(e,":"),t),p((r=>b(b({},r),{},{[e]:t.message}))),i(!1),u(null),!1}},E=Object.values(l).filter(Boolean).length;return t().createElement("div",{className:"max-w-sm mx-auto bg-white p-4 rounded-lg shadow-lg"},t().createElement("div",{className:"flex items-center justify-center mb-4"},t().createElement("div",{className:"flex items-center space-x-2"},t().createElement("img",{src:a||"https://onairos.sirv.com/Images/OnairosBlack.png",alt:o,className:"w-8 h-8 rounded-lg"}),t().createElement("div",{className:"flex items-center text-gray-400"},t().createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},t().createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17 8l4 4m0 0l-4 4m4-4H3"}))),t().createElement("img",{src:"https://onairos.sirv.com/Images/OnairosBlack.png",alt:"Onairos",className:"w-8 h-8 rounded-lg"}))),t().createElement("div",{className:"text-center mb-4"},t().createElement("h2",{className:"text-lg font-bold text-gray-900 mb-1"},"Connect Data"),t().createElement("p",{className:"text-gray-600 text-sm"},"Connect data here to enhance your ",o," experience")),t().createElement("div",{className:"grid grid-cols-2 gap-3 mb-4"},y.map((e=>{const r=l[e.name]||!1,n=m===e.name,a=d[e.name],o=c&&!n;return t().createElement("div",{key:e.name,className:"relative p-3 border-2 rounded-lg transition-all duration-200 cursor-pointer ".concat(o?"opacity-50 cursor-not-allowed":"hover:shadow-md"," ").concat(r?"border-green-400 bg-green-50":a?"border-red-400 bg-red-50":n?"border-blue-400 bg-blue-50":"border-gray-200 bg-white hover:border-gray-300"),onClick:()=>!o&&(async e=>{if(console.log("🔥 TOGGLE CLICKED: ".concat(e)),c&&m!==e)return void console.log("⚠️ Already connecting to ".concat(m,", ignoring click on ").concat(e));l[e]?(console.log("🔌 Disconnecting from ".concat(e,"...")),s((t=>b(b({},t),{},{[e]:!1}))),p((t=>b(b({},t),{},{[e]:null})))):await w(e)})(e.name)},t().createElement("div",{className:"w-8 h-8 rounded-lg ".concat(e.color," flex items-center justify-center text-white text-lg mb-2 mx-auto relative")},n?t().createElement("div",{className:"animate-spin h-4 w-4 border-2 border-white rounded-full border-t-transparent"}):e.icon,r&&!n&&t().createElement("div",{className:"absolute -top-1 -right-1 w-4 h-4 bg-green-500 rounded-full flex items-center justify-center"},t().createElement("svg",{className:"w-2.5 h-2.5 text-white",fill:"currentColor",viewBox:"0 0 20 20"},t().createElement("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"}))),a&&!n&&t().createElement("div",{className:"absolute -top-1 -right-1 w-4 h-4 bg-red-500 rounded-full flex items-center justify-center"},t().createElement("svg",{className:"w-2.5 h-2.5 text-white",fill:"currentColor",viewBox:"0 0 20 20"},t().createElement("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})))),t().createElement("div",{className:"text-center"},t().createElement("h3",{className:"font-medium text-gray-900 text-xs"},e.name),t().createElement("p",{className:"text-xs mt-1 ".concat(n?"text-blue-600":r?"text-green-600":a?"text-red-600":"text-gray-500")},n?"Connecting...":r?"Connected":a?"Failed":"Tap to connect"),a&&t().createElement("p",{className:"text-xs text-red-600 mt-1 break-words"},a)))}))),E>0&&t().createElement("div",{className:"mb-4 p-2 bg-green-50 border border-green-200 rounded-lg"},t().createElement("p",{className:"text-green-800 text-sm text-center"},"✅ ",E," connection",E>1?"s":""," active")),t().createElement("button",{onClick:()=>{const e=Object.entries(l).filter((e=>{let[t,r]=e;return r})).map((e=>{let[t]=e;return t}));n({connectedAccounts:e,totalConnections:e.length,healthScore:x,connectionHealth:g,sdkVersion:"2.1.7",enhancedFeatures:{healthMonitoring:h.enableHealthMonitoring,autoRefresh:h.enableAutoRefresh,connectionValidation:h.enableConnectionValidation}})},disabled:0===E,className:"w-full py-3 px-4 rounded-lg font-semibold transition-colors ".concat(E>0?"bg-blue-600 text-white hover:bg-blue-700":"bg-gray-300 text-gray-500 cursor-not-allowed")},E>0?"Continue with ".concat(E," connection").concat(E>1?"s":""):"Connect at least one platform"),t().createElement("button",{onClick:()=>n({connectedAccounts:[],totalConnections:0}),className:"w-full mt-2 py-2 text-gray-500 hover:text-gray-700 text-sm"},"Skip for now"))}function v(r){let{onComplete:n,userEmail:a}=r;const[o,l]=(0,e.useState)(""),[s,c]=(0,e.useState)({length:!1,number:!1,special:!1});(0,e.useEffect)((()=>{c({length:o.length>=8,number:/[0-9]/.test(o),special:/[!@#$%^&*(),.?":{}|<>]/.test(o)})}),[o]);const i=Object.values(s).every((e=>e))&&o.length>0;return t().createElement("div",{className:"max-w-md mx-auto bg-white p-6"},t().createElement("div",{className:"text-center mb-6"},t().createElement("div",{className:"w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mx-auto mb-4"},t().createElement("svg",{className:"w-8 h-8 text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},t().createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-1a2 2 0 00-2-2H6a2 2 0 00-2 2v1a2 2 0 002 2zM12 7V3m0 4l3-3m-3 3L9 4"}))),t().createElement("h2",{className:"text-2xl font-bold text-gray-900 mb-2"},"Create Your Secure PIN"),t().createElement("p",{className:"text-gray-600"},"Your PIN will be used to securely access your data")),t().createElement("form",{onSubmit:e=>{e.preventDefault(),i&&n({pin:o,pinCreated:!0,timestamp:(new Date).toISOString()})},className:"space-y-4"},t().createElement("div",null,t().createElement("label",{htmlFor:"pin",className:"block text-sm font-medium text-gray-700 mb-2"},"Create PIN"),t().createElement("input",{type:"password",id:"pin",value:o,onChange:e=>l(e.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"Enter your secure PIN"})),t().createElement("div",{className:"bg-gray-50 p-4 rounded-lg"},t().createElement("h4",{className:"text-sm font-medium text-gray-700 mb-3"},"PIN Requirements:"),t().createElement("div",{className:"space-y-2"},Object.entries({length:"At least 8 characters",number:"One number (0-9)",special:"One special character (!@#$%^&*)"}).map((e=>{let[r,n]=e;return t().createElement("div",{key:r,className:"flex items-center"},t().createElement("div",{className:"w-4 h-4 rounded-full mr-2 flex items-center justify-center ".concat(s[r]?"bg-green-500":"bg-gray-300")},s[r]&&t().createElement("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},t().createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"}))),t().createElement("span",{className:"text-sm ".concat(s[r]?"text-green-600":"text-gray-600")},n))})))),t().createElement("button",{type:"submit",disabled:!i,className:"w-full py-3 px-4 rounded-lg font-semibold transition-colors ".concat(i?"bg-blue-600 text-white hover:bg-blue-700":"bg-gray-300 text-gray-500 cursor-not-allowed")},"Create PIN")),a&&t().createElement("p",{className:"text-center text-sm text-gray-500 mt-4"},"Securing account for: ",t().createElement("span",{className:"font-medium"},a)))}function w(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function E(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?w(Object(r),!0).forEach((function(t){N(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):w(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function N(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");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:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const k=[{id:"basic",name:"Basic Info",description:"Essential profile information, account details, and basic demographics",icon:"👤",required:!0,tooltip:"Includes name, email, basic profile information. This data is essential for personalization and is always included.",privacyLink:"https://onairos.uk/privacy#basic-info"},{id:"personality",name:"Personality",description:"Personality traits, behavioral patterns and psychological insights",icon:"🧠",required:!1,tooltip:"AI-analyzed personality traits based on your social media activity and interactions. Used to improve content recommendations.",privacyLink:"https://onairos.uk/privacy#personality-data"},{id:"preferences",name:"Preferences",description:"User preferences, interests, settings and personal choices",icon:"⚙️",required:!1,tooltip:"Your stated preferences and interests from connected platforms. Helps customize your experience.",privacyLink:"https://onairos.uk/privacy#preferences-data"}],O=r=>{let{children:n,content:a,privacyLink:o}=r;const[l,s]=(0,e.useState)(!1);return t().createElement("div",{className:"relative inline-block"},t().createElement("span",{onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),className:"border-b border-dotted border-gray-400 cursor-help"},n),l&&t().createElement("div",{className:"absolute z-50 w-64 p-3 mt-2 text-sm bg-white border border-gray-200 rounded-lg shadow-lg left-0"},t().createElement("p",{className:"mb-2 text-gray-700"},a),t().createElement("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 text-xs font-medium"},"Learn more about privacy →")))};function S(r){let{onComplete:n,userEmail:a,appName:o="App",autoFetch:l=!1,testMode:s=!1,connectedAccounts:c={}}=r;const[i,m]=(0,e.useState)({basic:!0,personality:!1,preferences:!1}),[u,d]=(0,e.useState)(!1),[p,g]=(0,e.useState)(!1),[b,f]=(0,e.useState)(null),[y,h]=(0,e.useState)(null),x=e=>{const t=k.find((t=>t.id===e));null!=t&&t.required||m((t=>E(E({},t),{},{[e]:!t[e]})))},v=async()=>{g(!0),h(null);try{const e=(e=>{let t=0;const r=e+Date.now().toString();for(let e=0;e<r.length;e++)t=(t<<5)-t+r.charCodeAt(e),t&=t;return"user_".concat(Math.abs(t).toString(36))})(a),t=Object.entries(i).filter((e=>{let[t,r]=e;return r})).map((e=>{let[t]=e;return t})),r=e=>{const t=[],r=(new Date).toISOString(),n={basic:"Medium",personality:"Large",preferences:"Traits"};return e.forEach((e=>{n[e]&&t.push({data:n[e],date:r})})),t},c=s?"https://api2.onairos.uk/inferenceTest":"https://api2.onairos.uk/getAPIurlMobile",m={userHash:e,appName:o,approvedData:t,apiUrl:c,testMode:s,timestamp:(new Date).toISOString()};if(!l)return n(m),m;try{const e=r(t),l=s?{approvedData:t,userEmail:a,appName:o,testMode:s,timestamp:(new Date).toISOString()}:{Info:{storage:"local",appId:o,confirmations:e,EncryptedUserPin:"pending_pin_integration",account:a,proofMode:!1,Domain:window.location.hostname,web3Type:"standard",OthentSub:null}},i=await fetch(c,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":"onairos_web_sdk_live_key_2024"},body:JSON.stringify(l)});if(!i.ok)throw new Error("API request failed: ".concat(i.status));const u=await i.json();f(u);const d=E(E({},m),{},{apiResponse:u,success:!0});return setTimeout((()=>{n(d)}),1500),d}catch(e){console.error("API request failed:",e),h("API request failed: ".concat(e.message));const t=E(E({},m),{},{error:e.message,success:!1});return setTimeout((()=>{n(t)}),2e3),t}}catch(e){throw console.error("Data processing failed:",e),h("Processing failed: ".concat(e.message)),e}finally{g(!1)}},w=Object.values(i).filter(Boolean).length;return t().createElement("div",{className:"w-full max-w-md mx-auto bg-white rounded-lg shadow-xl overflow-hidden",style:{maxHeight:"90vh",height:"auto"}},t().createElement("div",{className:"p-4 sm:p-6 overflow-y-auto",style:{maxHeight:"calc(90vh - 4rem)"}},t().createElement("div",{className:"text-center mb-4 sm:mb-6"},t().createElement("h2",{className:"text-lg sm:text-xl font-bold text-gray-900 mb-2"},"Data Request"),t().createElement("p",{className:"text-gray-600 text-xs sm:text-sm"},"Select the data types and connections to share with ",t().createElement("span",{className:"font-medium"},o))),t().createElement("div",{className:"mb-4 sm:mb-6 p-2 sm:p-3 bg-blue-50 border border-blue-200 rounded-lg"},t().createElement("p",{className:"text-blue-800 text-xs sm:text-sm"},"🔒 Your selected data will be securely processed and used only for the intended purpose.")),t().createElement("div",{className:"mb-6"},t().createElement("h3",{className:"text-md font-semibold text-gray-900 mb-3"},"Data Types"),t().createElement("div",{className:"space-y-2 sm:space-y-3"},k.map((e=>{const r=i[e.id]||!1,n=e.required;return t().createElement("div",{key:e.id,className:"flex items-center justify-between p-3 sm:p-4 border rounded-lg transition-colors ".concat(n?"bg-gray-100 border-gray-300 cursor-not-allowed":"hover:bg-gray-50 cursor-pointer border-gray-200"),onClick:()=>(e=>{const t=k.find((t=>t.id===e));null!=t&&t.required||x(e)})(e.id)},t().createElement("div",{className:"flex items-center space-x-3"},t().createElement("div",{className:"text-xl sm:text-2xl"},e.icon),t().createElement("div",null,t().createElement("h4",{className:"font-medium text-gray-900 text-sm sm:text-base"},t().createElement(O,{content:e.tooltip,privacyLink:e.privacyLink},e.name),n&&t().createElement("span",{className:"text-gray-500 ml-1 text-xs"},"(Required)")),t().createElement("p",{className:"text-xs sm:text-sm text-gray-500"},e.description))),n?t().createElement("div",{className:"px-2 py-1 bg-gray-400 text-white text-xs rounded-full"},"Required"):t().createElement("button",{onClick:t=>{t.stopPropagation(),x(e.id)},className:"relative inline-flex h-5 sm:h-6 w-9 sm:w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 ".concat(r?"bg-blue-600":"bg-gray-200")},t().createElement("span",{className:"inline-block h-3 sm:h-4 w-3 sm:w-4 transform rounded-full bg-white transition-transform ".concat(r?"translate-x-5 sm:translate-x-6":"translate-x-1")})))})))),t().createElement("div",{className:"mb-3 sm:mb-4 p-2 sm:p-3 bg-green-50 border border-green-200 rounded-lg"},t().createElement("p",{className:"text-green-800 text-xs sm:text-sm"},"✅ ",w," data type",w>1?"s":""," selected")),p&&t().createElement("div",{className:"mb-3 sm:mb-4 p-2 sm:p-3 bg-blue-50 border border-blue-200 rounded-lg"},t().createElement("p",{className:"text-blue-800 text-xs sm:text-sm"},"🔄 Processing your data request...")),y&&t().createElement("div",{className:"mb-3 sm:mb-4 p-2 sm:p-3 bg-red-50 border border-red-200 rounded-lg"},t().createElement("p",{className:"text-red-800 text-xs sm:text-sm"},"❌ ",y)),t().createElement("form",{onSubmit:async e=>{e.preventDefault(),d(!0);try{const e=await v();e&&n(e)}catch(e){h("Submission failed: ".concat(e.message))}finally{d(!1)}},className:"space-y-3"},t().createElement("button",{type:"submit",disabled:u||0===w,className:"w-full py-2 sm:py-3 px-4 rounded-lg font-semibold transition-colors text-sm sm:text-base ".concat(w>0&&!u?"bg-blue-600 text-white hover:bg-blue-700":"bg-gray-300 text-gray-500 cursor-not-allowed")},u?"Processing...":"Share Selected Data"),t().createElement("button",{type:"button",onClick:()=>n({selectedData:{},selectedConnectors:[],cancelled:!0}),className:"w-full py-2 text-gray-500 hover:text-gray-700 text-xs sm:text-sm"},"Cancel"))))}function j(r){var n,a,o,l,s;let{onComplete:c,userEmail:i,appName:m="App"}=r;const[u,d]=(0,e.useState)(0),[p,g]=(0,e.useState)(0),[b,f]=(0,e.useState)(!1),y=[{title:"Setting up your personal AI",description:"Initializing your secure data model",icon:"🤖",duration:2e3},{title:"Processing your connections",description:"Analyzing your social media patterns",icon:"🔗",duration:2500},{title:"Training your model",description:"Building your personalized insights",icon:"🧠",duration:3e3},{title:"Finalizing setup",description:"Preparing your Onairos experience",icon:"✨",duration:2e3}];return(0,e.useEffect)((()=>{let e,t;if(u<y.length){const r=y[u].duration,n=100/y.length;e=setInterval((()=>{g((e=>{const t=e+n/(r/100);return Math.min(t,(u+1)*n)}))}),100),t=setTimeout((()=>{u<y.length-1?d((e=>e+1)):(f(!0),setTimeout((()=>{c({trainingComplete:!0,timestamp:(new Date).toISOString(),userEmail:i,appName:m})}),1e3))}),r)}return()=>{e&&clearInterval(e),t&&clearTimeout(t)}}),[u,c,i,m]),t().createElement("div",{className:"max-w-md mx-auto bg-white p-6 min-h-[400px] flex flex-col justify-center"},t().createElement("div",{className:"text-center mb-8"},t().createElement("div",{className:"w-20 h-20 bg-gradient-to-br from-blue-500 to-purple-600 rounded-full flex items-center justify-center mx-auto mb-4"},t().createElement("div",{className:"text-3xl"},b?"🎉":null===(n=y[u])||void 0===n?void 0:n.icon)),t().createElement("h2",{className:"text-2xl font-bold text-gray-900 mb-2"},b?"All set!":null===(a=y[u])||void 0===a?void 0:a.title),t().createElement("p",{className:"text-gray-600"},b?"Your personal AI is ready to use":null===(o=y[u])||void 0===o?void 0:o.description)),t().createElement("div",{className:"mb-6"},t().createElement("div",{className:"flex justify-between text-sm text-gray-500 mb-2"},t().createElement("span",null,"Progress"),t().createElement("span",null,Math.round(p),"%")),t().createElement("div",{className:"w-full bg-gray-200 rounded-full h-2"},t().createElement("div",{className:"bg-gradient-to-r from-blue-500 to-purple-600 h-2 rounded-full transition-all duration-300 ease-out",style:{width:"".concat(p,"%")}}))),t().createElement("div",{className:"flex justify-center space-x-2 mb-6"},y.map(((e,r)=>t().createElement("div",{key:r,className:"w-3 h-3 rounded-full transition-all duration-300 ".concat(r<=u?"bg-blue-500":"bg-gray-300")})))),t().createElement("div",{className:"bg-gray-50 p-4 rounded-lg"},t().createElement("div",{className:"flex items-center space-x-3"},t().createElement("div",{className:"w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center"},t().createElement("div",{className:"text-sm"},b?"✅":null===(l=y[u])||void 0===l?void 0:l.icon)),t().createElement("div",null,t().createElement("h3",{className:"font-medium text-gray-900"},b?"Training Complete":"Step ".concat(u+1," of ").concat(y.length)),t().createElement("p",{className:"text-sm text-gray-600"},b?"Your Onairos experience is ready":null===(s=y[u])||void 0===s?void 0:s.description)))),t().createElement("div",{className:"mt-6 text-center"},t().createElement("p",{className:"text-sm text-gray-500"},"Setting up for ",t().createElement("span",{className:"font-medium"},m)),i&&t().createElement("p",{className:"text-xs text-gray-400 mt-1"},i)))}function C(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function P(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?C(Object(r),!0).forEach((function(t){I(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):C(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function I(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");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:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const _=function(r){let{requestData:n,webpageName:a,inferenceData:o=null,onComplete:l=null,autoFetch:s=!1,testMode:c=!1,proofMode:i=!1,textLayout:m="below",textColor:u="white",login:d=!1,buttonType:g="pill",loginReturn:b=null,loginType:f="signIn",visualType:y="full",appIcon:h=null,enableTraining:w=!0}=r;const[E,N]=(0,e.useState)(!1),[k,O]=(0,e.useState)("email"),[C,I]=(0,e.useState)(null),[_,A]=(0,e.useState)(null);(0,e.useEffect)((()=>{(()=>{const e=localStorage.getItem("onairosUser");if(e)try{const t=JSON.parse(e);I(t),t.onboardingComplete&&t.pinCreated?O("dataRequest"):t.verified&&!t.onboardingComplete?O("onboarding"):t.onboardingComplete&&!t.pinCreated&&O("pin")}catch(e){console.error("Error parsing saved user data:",e),localStorage.removeItem("onairosUser")}})()}),[]);const T=()=>{N(!1),A(null)},L=e=>{console.log("🔥 Email auth successful:",e),console.log("🔧 User State:",{isNewUser:e.isNewUser,userState:e.userState,flowType:e.flowType,existingUser:e.existingUser});const t=!0===e.isNewUser||"onboarding"===e.flowType||"new"===e.userState,r=P(P({},e),{},{verified:!0,onboardingComplete:!t,pinCreated:!t});I(r),localStorage.setItem("onairosUser",JSON.stringify(r)),t?(console.log("🚀 New user detected → Starting onboarding flow (includes training)"),O("onboarding")):(console.log("👋 Existing user detected → Going directly to data request"),O("dataRequest"))},U=e=>{console.log("Onboarding completed:",e);const t=P(P({},C),{},{onboardingComplete:!0,connectedAccounts:e.connectedAccounts||[]});I(t),localStorage.setItem("onairosUser",JSON.stringify(t)),O("pin")},R=e=>{console.log("PIN setup completed:",e);const t=P(P(P({},C),e),{},{pinCreated:!0});I(t),localStorage.setItem("onairosUser",JSON.stringify(t)),O("dataRequest")},D=e=>{console.log("🎓 Training completed:",e);const t=P(P({},C),{},{trainingCompleted:!0},e);I(t),localStorage.setItem("onairosUser",JSON.stringify(t)),O("dataRequest")},M=e=>{console.log("🔥 OnairosButton: Data request completed:",e);const t=P(P({},C),{},{lastDataRequest:e});if(I(t),localStorage.setItem("onairosUser",JSON.stringify(t)),N(!1),console.log("🔥 Calling onComplete callback with:",e),l)try{l(e),console.log("🔥 onComplete callback executed successfully")}catch(e){console.error("🔥 Error in onComplete callback:",e)}else console.log("🔥 No onComplete callback provided")},q="flex items-center justify-center font-bold rounded cursor-pointer ".concat("pill"===g?"px-4 py-2":"w-12 h-12"," bg-transparent OnairosConnect"),B={flexDirection:"below"===m?"column":"row",backgroundColor:"transparent",color:u,border:"1px solid transparent"},z={width:"20px",height:"20px",marginRight:"full"===y?"12px":"0"};return t().createElement(t().Fragment,null,t().createElement("button",{className:q,onClick:async()=>{try{console.log("🔥 openTerminal called"),N(!0)}catch(e){console.error("Error in openTerminal:",e)}},style:B},("full"===y||"icon"===y)&&t().createElement("img",{src:d?"https://onairos.sirv.com/Images/OnairosWhite.png":"https://onairos.sirv.com/Images/OnairosBlack.png",alt:"Onairos Logo",style:z}),"icon"!==y&&t().createElement("span",{className:"".concat("black"===u?"text-black":"text-white"," ").concat("icon"===y?"sr-only":""," ").concat("right"===m?"ml-2":"left"===m?"mr-2":"")},(()=>{switch(f){case"signUp":return"Sign Up with Onairos";case"signOut":return"Sign Out of Onairos";default:return"Sign In with Onairos"}})())),E&&t().createElement("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",onClick:e=>{e.target===e.currentTarget&&T()}},t().createElement("div",{className:"bg-white rounded-lg shadow-xl max-w-md w-full mx-4 max-h-[90vh] overflow-hidden relative",onClick:e=>e.stopPropagation()},t().createElement("button",{onClick:T,className:"absolute top-4 right-4 text-gray-400 hover:text-gray-600 z-10"},t().createElement("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},t().createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"}))),t().createElement("div",{className:"overflow-y-auto max-h-[90vh]"},(()=>{switch(k){case"email":return t().createElement(p,{onSuccess:L,testMode:c});case"onboarding":return t().createElement(x,{onComplete:U,appIcon:h||"https://onairos.sirv.com/Images/OnairosBlack.png",appName:a,username:(null==C?void 0:C.email)||(null==C?void 0:C.username)});case"pin":return t().createElement(v,{onComplete:R,userEmail:null==C?void 0:C.email});case"training":return t().createElement(j,{onComplete:D,userEmail:null==C?void 0:C.email,appName:a,connectedAccounts:(null==C?void 0:C.connectedAccounts)||[]});case"dataRequest":return t().createElement(S,{onComplete:M,userEmail:null==C?void 0:C.email,requestData:n,appName:a,autoFetch:s,testMode:c,appIcon:h,connectedAccounts:(null==C?void 0:C.connectedAccounts)||{}});default:return t().createElement("div",{className:"flex flex-col items-center space-y-4 p-6"},t().createElement("div",{className:"animate-spin h-8 w-8 border-2 border-blue-600 rounded-full border-t-transparent"}),t().createElement("p",{className:"text-gray-600"},"Loading..."))}})()))))};function A(e){return t().createElement(t().Fragment,null,t().createElement(_,e))}const T=A,L=async e=>(console.log("🔧 SDK initialized with config:",e),Promise.resolve())})(),a})())); //# sourceMappingURL=onairos.bundle.js.map