lucia-sdk 0.10.0 → 0.10.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.es.js CHANGED
@@ -1,2 +1,2 @@
1
- function e(e,t,n,i){return new(n||(n=Promise))(function(r,o){function s(e){try{l(i.next(e))}catch(e){o(e)}}function a(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class t{constructor(e){this.store=e}log(e,...t){var n;(null===(n=this.store.config)||void 0===n?void 0:n.debug)&&console[e](t)}}const n="0.10.0";class i{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new t(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"http://52.22.177.60/fk":"https://api.clickinsights.xyz"}get(t){return e(this,void 0,void 0,function*(){if(!this.store.config)return this.logger.log("error","Config is not set"),null;try{const e=yield fetch(`${this.baseURL}${t}`,{method:"GET",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":n}});return yield e.json()}catch(e){this.logger.log("error",e)}return null})}post(t,n){return e(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;const i="/api/sdk/init"===e;if(!i&&!this.initComplete)return new Promise((r,o)=>{this.requestQueue.push({url:e,data:t,fireAndForget:n,resolve:r,reject:o,isInit:i}),this.processQueue()});if(i){const i=yield this.executePost(e,t,n);return this.initComplete=!0,yield this.processQueue(),i}return this.executePost(e,t,n)})}processQueue(){return e(this,void 0,void 0,function*(){if(!this.isProcessingQueue&&this.initComplete&&0!==this.requestQueue.length){this.isProcessingQueue=!0;try{const t=()=>e(this,void 0,void 0,function*(){if(0===this.requestQueue.length)return;const e=this.requestQueue.shift();try{const t=yield this.executePost(e.url,e.data,e.fireAndForget);e.resolve(t)}catch(t){e.reject(t)}yield t()});yield t()}finally{this.isProcessingQueue=!1}}})}executePost(t,i){return e(this,arguments,void 0,function*(e,t,i=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;if(i&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon){try{const n=`${this.baseURL}${e}`,i=t&&"object"==typeof t&&!Array.isArray(t)?t:{payload:t},r=JSON.stringify(Object.assign(Object.assign({},i),{_apiKey:this.store.config.apiKey})),o=new Blob([r],{type:"application/json"});navigator.sendBeacon(n,o)||this.logger.log("error","sendBeacon failed")}catch(e){this.logger.log("error",e)}return null}try{const i=yield fetch(`${this.baseURL}${e}`,{method:"POST",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":n},body:JSON.stringify(t)});return yield i.json()}catch(e){this.logger.log("error",e)}return null})}}class r{static dispatch(e){Object.keys(e).forEach(t=>{if(Object.keys(r.store).includes(t)){const n=e[t];r.store[t]="object"==typeof n?Array.isArray(n)?[...n]:Object.assign({},n):n}})}}r.store={isInitialized:!1,config:null,session:null};const o=[];for(let e=0;e<256;++e)o.push((e+256).toString(16).slice(1));let s;const a=new Uint8Array(16);var l={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function c(e,t,n){const i=(e=e||{}).random??e.rng?.()??function(){if(!s){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");s=crypto.getRandomValues.bind(crypto)}return s(a)}();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=15&i[6]|64,i[8]=63&i[8]|128,function(e,t=0){return(o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]).toLowerCase()}(i)}const d="luci_session",u=new t(r.store);function h(){try{const e=sessionStorage.getItem(d);return e?JSON.parse(e):null}catch(e){return u.log("error","Error retrieving session data:",e),null}}function v(){var e;const t={id:l.randomUUID&&!e?l.randomUUID():c(e),timestamp:Date.now()};return sessionStorage.setItem(d,JSON.stringify(t)),t}function g(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function f(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class m{constructor(e){this.store=r.store,this.dispatch=r.dispatch,this.dispatch({config:e}),this.httpClient=new i(this.store),this.logger=new t(this.store)}}class p{constructor(e,t,n,i){this.enabled=!1,this.sdkConfig=e,this.config=t,this.callback=n,this.logger=i}enable(){this.enabled||(this.enabled=!0,this.attachListeners(),this.logger.log("log",`${this.name}: Enabled`))}disable(){this.enabled&&(this.enabled=!1,this.logger.log("log",`${this.name}: Disabled`))}destroy(){this.disable(),this.detachListeners(),this.logger.log("log",`${this.name}: Destroyed`)}isEnabled(){return this.enabled}}const w=new class{constructor(){this.registrations=new Map,this.activeTrackers=new Map,this.logger=null}register(e){this.registrations.set(e.name,e)}initAll(e,t,n){this.logger=n;for(const[i,r]of this.registrations){const o=e[r.configKey],s=r.normalizeConfig(o);if(null===s)continue;const a=t[i];if(a)try{const t=r.factory(e,s,a,n);this.activeTrackers.set(i,t),t.enable(),n.log("log",`AutoTrackerRegistry: Initialized ${i}`)}catch(e){n.log("error",`AutoTrackerRegistry: Failed to initialize ${i}`,e)}else n.log("warn",`AutoTrackerRegistry: No callback registered for ${i}`)}}get(e){return this.activeTrackers.get(e)}enable(e){const t=this.activeTrackers.get(e);return!!t&&(t.enable(),!0)}disable(e){const t=this.activeTrackers.get(e);return!!t&&(t.disable(),!0)}destroyAll(){var e;for(const[t,n]of this.activeTrackers)try{n.destroy()}catch(n){null===(e=this.logger)||void 0===e||e.log("error",`AutoTrackerRegistry: Error destroying ${t}`,n)}this.activeTrackers.clear()}getRegisteredTrackers(){return Array.from(this.registrations.keys())}getActiveTrackers(){return Array.from(this.activeTrackers.keys())}reset(){this.destroyAll(),this.logger=null}},y=['input[type="password"]','input[type="text"][autocomplete*="cc-"]','input[type="text"][autocomplete*="card"]','input[type="text"][name*="card"]','input[type="text"][name*="cvv"]','input[type="text"][name*="cvc"]','input[name*="ssn"]','input[name*="social"]',"[data-sensitive]","[data-private]"],b=[/\b\d{3}-\d{2}-\d{4}\b/,/\b\d{4}[\s-]\d{4}[\s-]\d{4}[\s-]\d{4}\b/,/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i];const k=new class{constructor(e=[]){this.sensitiveSelectors=[...y,...e]}isSensitive(e){if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;let t=e.parentElement;for(;t;){const e=t;if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;t=t.parentElement}return!1}containsSensitiveData(e){return!!e&&b.some(t=>t.test(e))}sanitizeText(e){if(!e)return"";let t=e;return t=t.replace(/\b\d{3}-\d{2}-\d{4}\b/g,"***-**-****"),t=t.replace(/\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,"****-****-****-****"),t=t.replace(/\b([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,})\b/gi,"***@$2"),t}},C=["button","a[href]",'[role="button"]'],T=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class A extends p{constructor(e,t,n,i){var r,o,s;super(e,{enabled:null===(r=t.enabled)||void 0===r||r,selectors:null!==(o=t.selectors)&&void 0!==o?o:C,ignore:null!==(s=t.ignore)&&void 0!==s?s:T},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=k}attachListeners(){this.listenerAttached||("undefined"!=typeof document?(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,{passive:!0,capture:!1}),this.listenerAttached=!0,this.logger.log("log","ClickTracker: Delegated click listener attached")):this.logger.log("warn","ClickTracker: document not available, cannot attach listener"))}detachListeners(){this.listenerAttached&&this.boundHandleClick&&"undefined"!=typeof document&&(document.removeEventListener("click",this.boundHandleClick),this.listenerAttached=!1),this.debounceTimers.clear(),this.boundHandleClick=null}handleClick(e){if(!this.enabled)return;const t=e.target;if(!t)return;const n=this.findTrackableElement(t);if(!n)return;if(this.shouldIgnore(n))return void this.logger.log("log","ClickTracker: Element ignored",n);if(this.privacyGuard.isSensitive(n))return void this.logger.log("warn","ClickTracker: Sensitive element not tracked",n);if(this.isDebounced(n))return void this.logger.log("log","ClickTracker: Click debounced",n);const i=this.extractTrackingData(n);i&&(this.logger.log("log","ClickTracker: Tracking click",i),this.callback(i))}findTrackableElement(e){const t=this.config.selectors||C;try{const n=e.closest('[data-lucia-track]:not([data-lucia-track="false"])');if(n&&n!==document.body&&document.body.contains(n)){if(this.config.selectors&&this.config.selectors!==C){return t.some(e=>{try{return n.matches(e)}catch(e){return!1}})?n:null}return n}const i=t.join(", "),r=e.closest(i);return r&&r!==document.body&&document.body.contains(r)?r:null}catch(t){this.logger.log("warn","ClickTracker: Invalid combined selector, using fallback",t);let n=e;for(;n&&n!==document.body;){if(this.isTrackable(n))return n;n=n.parentElement}return null}}isTrackable(e){return(this.config.selectors||C).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid selector "${t}"`,e),!1}})}shouldIgnore(e){return(this.config.ignore||T).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid ignore selector "${t}"`,e),!1}})}isDebounced(e){const t=Date.now(),n=this.debounceTimers.get(e);return!!(n&&t-n<500)||(this.debounceTimers.set(e,t),this.debounceTimers.size>100&&this.cleanupDebounceTimers(),!1)}cleanupDebounceTimers(){const e=Date.now();Array.from(this.debounceTimers.entries()).forEach(([t,n])=>{e-n>1e3&&this.debounceTimers.delete(t)})}extractTrackingData(e){var t;const n=this.getElementIdentifier(e);if(!n)return this.logger.log("warn","ClickTracker: Could not generate identifier for element",e),null;const i={button:n,elementType:this.getElementType(e),timestamp:Date.now()},r=null===(t=e.textContent)||void 0===t?void 0:t.trim();r&&(this.privacyGuard.containsSensitiveData(r)||(i.text=this.sanitizeText(r))),"a"===e.tagName.toLowerCase()?i.href=e.getAttribute("href"):i.href=null;const o=this.extractMetadata(e);return o&&Object.keys(o).length>0&&(i.meta=o),i}getElementIdentifier(e){var t;const n=e.getAttribute("data-lucia-track");if(n&&"false"!==n)return n;const i=e.getAttribute("id");if(i)return i;const r=e.getAttribute("name");if(r)return r;const o=e.getAttribute("aria-label");if(o)return o;if("a"===e.tagName.toLowerCase()){const t=e.getAttribute("href");if(t)return`link:${t}`}const s=null===(t=e.textContent)||void 0===t?void 0:t.trim();if(s)return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using text content as identifier for element. Consider adding data-lucia-track attribute.",e),`text:${this.sanitizeText(s).substring(0,50)}`;const a=this.generateCSSPath(e);return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using CSS path as identifier. Consider adding data-lucia-track attribute.",e),`path:${a}`}getElementType(e){const t=e.tagName.toLowerCase();if("a"===t)return"link";if("button"===t)return"button";const n=e.getAttribute("role");return n||t}sanitizeText(e){return e.trim().replace(/\s+/g," ").substring(0,100)}generateCSSPath(e){const t=[];let n=e;for(;n&&n!==document.body&&t.length<5;){let e=n.tagName.toLowerCase();if(n.id){e+=`#${n.id}`,t.unshift(e);break}const i=n.getAttribute("class");if(i){const t=i.trim().split(/\s+/).slice(0,2);t.length>0&&(e+=`.${t.join(".")}`)}t.unshift(e),n=n.parentElement}return t.join(" > ")}extractMetadata(e){const t={},{attributes:n}=e;return Array.from(n).forEach(e=>{if(e.name.startsWith("data-lucia-meta-")){const n=e.name.replace("data-lucia-meta-","").replace(/-([a-z])/g,e=>e[1].toUpperCase());t[n]=e.value}}),Object.keys(t).length>0?t:null}}const I={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new A(e,t,n,i),normalizeConfig:function(e){return void 0===e||!1===e?null:!0===e?{enabled:!0}:!1===e.enabled?null:e}};function P(){return e(this,void 0,void 0,function*(){if(O)return O;const e={device:{cores:E(()=>navigator.hardwareConcurrency),memory:E(()=>navigator.deviceMemory),cpuClass:E(()=>navigator.cpuClass),touch:j(),devicePixelRatio:E(()=>window.devicePixelRatio)},screen:{width:E(()=>window.screen.width),height:E(()=>window.screen.height),colorDepth:E(()=>window.screen.colorDepth),availHeight:E(()=>window.screen.availHeight),availWidth:E(()=>window.screen.availWidth),orientation:{type:E(()=>window.screen.orientation.type),angle:E(()=>window.screen.orientation.angle)}},browser:{language:E(()=>navigator.language),encoding:E(()=>TextDecoder.encoding),timezone:E(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:E(()=>navigator.plugins.length),pluginNames:E(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:W(),uniqueHash:yield D(),colorGamut:R(),contrastPreference:x()},permissions:{navPer:E(()=>navigator.permissions.webglVersion),renderedPer:E(()=>navigator.permissions.RENDERER),geoPer:E(()=>navigator.permissions.geolocation)},storage:{localStorage:E(()=>!!window.localStorage),indexedDB:E(()=>!!window.indexedDB),openDB:E(()=>window.openDatabase)}};return O=e,e})}function S(){const e=new URL(window.location.href).searchParams,t={};return e.forEach((e,n)=>{(n.startsWith("utm_")||n.includes("id")||"ref"===n||"source"===n)&&(t[n]=e)}),t}function E(e,t){try{return e()}catch(e){return t}}function L(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t}let O=null;function D(){return e(this,void 0,void 0,function*(){try{const t=document.createElement("canvas"),n=t.getContext("2d",{willReadFrequently:!0});if(!n)return;const i=200,r=120;t.width=i,t.height=r,t.style.width=`${i}px`,t.style.height=`${r}px`,n.fillStyle="#ffffff",n.fillRect(0,0,i,r),n.fillStyle="#ff00ff",n.fillRect(10,10,100,100),n.fillStyle="#00ffff",n.beginPath(),n.arc(150,50,40,0,2*Math.PI,!0),n.fill();const{data:o}=n.getImageData(0,0,i,r);return function(t){return e(this,void 0,void 0,function*(){const e=(new TextEncoder).encode(t),n=yield crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("")})}([[20,20],[60,60],[100,100],[150,50],[150,60],[140,50],[5,5]].map(([e,t])=>{const n=4*(t*i+e);return`${o[n]},${o[n+1]},${o[n+2]},${o[n+3]};`}).join(""))}catch(e){return}})}function j(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function W(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function x(){try{const{matchMedia:e}=window,t=t=>e(`(prefers-contrast: ${t})`).matches;return t("no-preference")?"None":t("high")||t("more")?"More":t("low")||t("less")?"Less":t("forced")?"ForcedColors":void 0}catch(e){return}}function R(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const $=new Map;let U=null,M=!1;function K(){return new Map($)}const _=[{name:"Rabby",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRabby)}},{name:"Brave Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBraveWallet)}},{name:"Rainbow",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRainbow)}},{name:"Coinbase Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoinbaseWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCoinbase)}},{name:"Trust Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTrust)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTrustWallet)}},{name:"TokenPocket",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTokenPocket)}},{name:"Zerion",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isZerion)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isPhantom)}},{name:"OKX Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOkxWallet)}},{name:"Bitget Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBitKeep)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isBitgetWallet)}},{name:"SafePal",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isSafePal)}},{name:"Frontier",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrontier)}},{name:"XDEFI",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isXDEFI)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCtrl)}},{name:"Enkrypt",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isEnkrypt)}},{name:"MetaMask",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMetaMask)}},{name:"WalletConnect",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isWalletConnect)}},{name:"imToken",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isImToken)}},{name:"Status",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isStatus)}},{name:"Tally",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTally)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTallyWallet)}},{name:"AlphaWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isAlphaWallet)}},{name:"Opera",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOpera)}},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoin98)}},{name:"MathWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMathWallet)}},{name:"1inch Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOneInchIOSWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isOneInchAndroidWallet)}},{name:"Frame",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrame)}},{name:"Binance Chain Wallet",detect:()=>!!window.BinanceChain},{name:"MetaMask",detect:()=>{var e;return Object.prototype.hasOwnProperty.call(null!==(e=window.ethereum)&&void 0!==e?e:{},"_metamask")}}],N=[{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.phantom)||void 0===e?void 0:e.solana)}},{name:"Solflare",detect:()=>!!window.solflare},{name:"Backpack",detect:()=>!!window.backpack},{name:"Glow",detect:()=>!!window.glow},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isCoin98)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isPhantom)}}];function q(){var e,t;return window.ethereum&&null!==(t=null===(e=_.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}function z(){var e,t;return null!==(t=null===(e=N.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}w.register(I);let B=class extends m{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}authenticate(){this.httpClient.post("/api/key/auth",{})}init(){return e(this,void 0,void 0,function*(){let e=h();e||(e=v());try{M||(M=!0,U=e=>{var t;const n=e.detail;(null===(t=null==n?void 0:n.info)||void 0===t?void 0:t.rdns)&&(null==n?void 0:n.provider)&&$.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",U),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield P(),n=new URL(window.location.href).searchParams.get("lucia"),i={id:e.id};e.hash&&(i.hash=e.hash);const r=yield this.httpClient.post("/api/sdk/init",{user:{name:f()},data:t,session:i,redirectHash:n,utm:S()},!1);r&&(r.lid&&localStorage.setItem("lid",r.lid),r.session&&function(e){const t={id:e.id,hash:e.hash,timestamp:Date.now()};sessionStorage.setItem(d,JSON.stringify(t))}(r.session)),w.initAll(this.store.config,{clicks:this.handleAutoTrackedClick.bind(this)},this.logger),yield this.autoDetectWallets(),this.setupWalletListeners()})}handleAutoTrackedClick(e){const t=e,n={elementType:t.elementType,text:t.text,href:t.href,meta:t.meta};this.buttonClick(t.button,n)}autoDetectWallets(){return e(this,void 0,void 0,function*(){var t,n,i;try{const t=yield function(){return e(this,void 0,void 0,function*(){const e=Array.from($.values());if(0===e.length)return[];const t=yield Promise.allSettled(e.map(({info:e,provider:t})=>{const n=t.request({method:"eth_accounts"}).then(n=>{const i=n;return Array.isArray(i)?i.filter(e=>"string"==typeof e&&e.length>0).map(n=>({address:n,providerName:e.name,providerRdns:e.rdns,provider:t})):[]}),i=new Promise((t,n)=>setTimeout(()=>n(new Error(`EIP-6963 timeout: ${e.name}`)),3e3));return Promise.race([n,i])})),n=[];for(const e of t)"fulfilled"===e.status&&n.push(...e.value);return n})}();for(const e of t)yield this.sendWalletInfo(e.address,{provider:e.providerName,providerRdns:e.providerRdns})}catch(e){}if(0===K().size&&(null===(t=window.ethereum)||void 0===t?void 0:t.selectedAddress))try{const e=q();yield this.sendWalletInfo(window.ethereum.selectedAddress,{provider:null!=e?e:void 0})}catch(e){}if((null===(n=window.solana)||void 0===n?void 0:n.isConnected)&&(null===(i=window.solana)||void 0===i?void 0:i.publicKey))try{const e=z();yield this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0})}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){var e,t;const n=function(e){const t=t=>{var n;const i=t.detail;(null===(n=null==i?void 0:i.info)||void 0===n?void 0:n.rdns)&&(null==i?void 0:i.provider)&&($.set(i.info.rdns,i),e(i))};return window.addEventListener("eip6963:announceProvider",t),()=>window.removeEventListener("eip6963:announceProvider",t)}(e=>{this.handleLateEIP6963Provider(e)});if(this.walletListenerCleanups.push(n),(null===(e=window.ethereum)||void 0===e?void 0:e.on)&&0===K().size){const e=e=>{const t=e;if(t[0]){const e=t[0],n=q();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};window.ethereum.on("accountsChanged",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"accountsChanged",e)})}if(null===(t=window.solana)||void 0===t?void 0:t.on){const e=()=>{var e;if(null===(e=window.solana)||void 0===e?void 0:e.publicKey){const e=z();this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0}).catch(()=>{})}};window.solana.on("connect",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"connect",e)})}}setupEIP6963AccountListeners(){const e=K();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e;n.request&&n.request({method:"eth_accounts"}).then(e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})}).catch(()=>{}),this.attachEIP6963AccountsChanged(e)}attachEIP6963AccountsChanged(e){const{info:t,provider:n}=e;if(!n.on)return;const i=e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})};n.on("accountsChanged",i),this.walletListenerCleanups.push(()=>{var e;null===(e=n.removeListener)||void 0===e||e.call(n,"accountsChanged",i)})}userInfo(t,n){return e(this,void 0,void 0,function*(){const e=g(),i=h();t&&localStorage.setItem("luc_uid",t);const r=Object.assign({user:{name:t,userInfo:n},session:i},e&&{lid:e});yield this.httpClient.post("/api/sdk/user",r)})}pageView(t){return e(this,void 0,void 0,function*(){const e=g(),n=h(),i=Object.assign({page:t,user:{name:f()},session:n},e&&{lid:e});yield this.httpClient.post("/api/sdk/page",i)})}trackConversion(t,n,i){return e(this,void 0,void 0,function*(){const e=g(),r=h(),o=Object.assign({tag:t,amount:n,event:i,user:{name:f()},session:r},e&&{lid:e});yield this.httpClient.post("/api/sdk/conversion",o)})}buttonClick(t,n){return e(this,void 0,void 0,function*(){const e=g(),i=h(),r=Object.assign(Object.assign({button:t,user:{name:f()},session:i},e&&{lid:e}),n&&Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n.elementType&&{elementType:n.elementType}),n.text&&{text:n.text}),void 0!==n.href&&{href:n.href}),n.meta&&{meta:n.meta}),{timestamp:Date.now()}));yield this.httpClient.post("/api/sdk/click",r)})}sendWalletInfo(t,n,i){return e(this,void 0,void 0,function*(){var e,r,o;if(!t||"string"!=typeof t)return;const s=t.startsWith("0x")?t.toLowerCase():t;if(this.sentWallets.has(s))return;this.sentWallets.add(s);let a={};n&&"object"==typeof n?a=n:void 0!==n&&(a={chainId:"number"==typeof n?n:void 0,provider:i});const l=g(),c=h(),d=Object.assign(Object.assign(Object.assign(Object.assign({walletAddress:t,provider:null!==(e=a.provider)&&void 0!==e?e:null,providerRdns:null!==(r=a.providerRdns)&&void 0!==r?r:null,connectorType:null!==(o=a.connectorType)&&void 0!==o?o:null},null!=a.chainId&&{chainId:a.chainId}),i&&{walletName:i}),{user:{name:f()},session:c}),l&&{lid:l});try{yield this.httpClient.post("/api/sdk/wallet",d)}catch(e){throw this.sentWallets.delete(s),e}})}trackUserAcquisition(t){return e(this,arguments,void 0,function*(e,t={}){const n=yield P(),i=S(),r=h();yield this.httpClient.post("/api/sdk/acquisition",{user:{name:e},session:r,data:Object.assign({timestamp:(new Date).toISOString(),browserData:n,utmParams:i},t)})})}checkMetaMaskConnection(){var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))}destroy(){w.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),M&&(U&&(window.removeEventListener("eip6963:announceProvider",U),U=null),$.clear(),M=!1)}},Q=null;const F=()=>{const e=Q||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},H=()=>{const e=Q||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),Q=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,w.reset()},V={init:t=>{if("undefined"==typeof window)return Promise.reject(new Error("LuciaSDK requires a browser environment"));if(Q)return Q;if(window.__luciaInitPromise)return Q=window.__luciaInitPromise,Q;if(!(null==t?void 0:t.apiKey))return Promise.reject(new Error("apiKey is required in config"));const n=e(void 0,void 0,void 0,function*(){const e=new B(t);return yield e.init(),e});return Q=n,window.__luciaInitPromise=n,n},userInfo:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield F()).userInfo(t,n)}),pageView:t=>e(void 0,void 0,void 0,function*(){return(yield F()).pageView(t)}),trackConversion:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield F()).trackConversion(t,n,i)}),buttonClick:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield F()).buttonClick(t,n)}),sendWalletInfo:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield F()).sendWalletInfo(t,n,i)}),trackUserAcquisition:(t,...n)=>e(void 0,[t,...n],void 0,function*(e,t={}){return(yield F()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>{var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))},VERSION:n};if("undefined"!=typeof window){window.LuciaSDK=V;const e=()=>{const e=document.currentScript||document.querySelector("script[data-api-key]"),t=null==e?void 0:e.getAttribute("data-api-key");if(!t)return;const n=e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");V.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{debugURL:n}),"true"===i&&{autoTrackClicks:!r||{enabled:!0,selectors:r.split(",").map(e=>e.trim())}}),"false"===i&&{autoTrackClicks:!1})).catch(e=>console.error("LuciaSDK auto-init failed:",e))};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}export{H as __resetInstance,V as default,q as detectEvmProvider,z as detectSolanaProvider,L as filterObject,W as getApplePayAvailable,P as getBrowserData,D as getCanvasFingerprint,R as getColorGamut,x as getContrastPreference,S as getUtmParams,j as isTouchEnabled,E as safeAccess};
1
+ function e(e,t,n,i){return new(n||(n=Promise))(function(r,o){function s(e){try{l(i.next(e))}catch(e){o(e)}}function a(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class t{constructor(e){this.store=e}log(e,...t){var n;(null===(n=this.store.config)||void 0===n?void 0:n.debug)&&console[e](t)}}const n="0.10.2";class i{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new t(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"http://52.22.177.60/fk":"https://api.clickinsights.xyz"}get(t){return e(this,void 0,void 0,function*(){if(!this.store.config)return this.logger.log("error","Config is not set"),null;try{const e=yield fetch(`${this.baseURL}${t}`,{method:"GET",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":n}});return yield e.json()}catch(e){this.logger.log("error",e)}return null})}post(t,n){return e(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;const i="/api/sdk/init"===e;if(!i&&!this.initComplete)return new Promise((r,o)=>{this.requestQueue.push({url:e,data:t,fireAndForget:n,resolve:r,reject:o,isInit:i}),this.processQueue()});if(i){const i=yield this.executePost(e,t,n);return this.initComplete=!0,yield this.processQueue(),i}return this.executePost(e,t,n)})}processQueue(){return e(this,void 0,void 0,function*(){if(!this.isProcessingQueue&&this.initComplete&&0!==this.requestQueue.length){this.isProcessingQueue=!0;try{const t=()=>e(this,void 0,void 0,function*(){if(0===this.requestQueue.length)return;const e=this.requestQueue.shift();try{const t=yield this.executePost(e.url,e.data,e.fireAndForget);e.resolve(t)}catch(t){e.reject(t)}yield t()});yield t()}finally{this.isProcessingQueue=!1}}})}executePost(t,i){return e(this,arguments,void 0,function*(e,t,i=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;if(i&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon){try{const n=`${this.baseURL}${e}`,i=t&&"object"==typeof t&&!Array.isArray(t)?t:{payload:t},r=JSON.stringify(Object.assign(Object.assign({},i),{_apiKey:this.store.config.apiKey})),o=new Blob([r],{type:"application/json"});navigator.sendBeacon(n,o)||this.logger.log("error","sendBeacon failed")}catch(e){this.logger.log("error",e)}return null}try{const i=yield fetch(`${this.baseURL}${e}`,{method:"POST",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":n},body:JSON.stringify(t)});return yield i.json()}catch(e){this.logger.log("error",e)}return null})}}class r{static dispatch(e){Object.keys(e).forEach(t=>{if(Object.keys(r.store).includes(t)){const n=e[t];r.store[t]="object"==typeof n?Array.isArray(n)?[...n]:Object.assign({},n):n}})}}r.store={isInitialized:!1,config:null,session:null};const o=[];for(let e=0;e<256;++e)o.push((e+256).toString(16).slice(1));let s;const a=new Uint8Array(16);var l={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function c(e,t,n){const i=(e=e||{}).random??e.rng?.()??function(){if(!s){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");s=crypto.getRandomValues.bind(crypto)}return s(a)}();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=15&i[6]|64,i[8]=63&i[8]|128,function(e,t=0){return(o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]).toLowerCase()}(i)}const d="luci_session",u=new t(r.store);function h(){try{const e=sessionStorage.getItem(d);return e?JSON.parse(e):null}catch(e){return u.log("error","Error retrieving session data:",e),null}}function v(){var e;const t={id:l.randomUUID&&!e?l.randomUUID():c(e),timestamp:Date.now()};return sessionStorage.setItem(d,JSON.stringify(t)),t}function g(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function f(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class m{constructor(e){this.store=r.store,this.dispatch=r.dispatch,this.dispatch({config:e}),this.httpClient=new i(this.store),this.logger=new t(this.store)}}class p{constructor(e,t,n,i){this.enabled=!1,this.sdkConfig=e,this.config=t,this.callback=n,this.logger=i}enable(){this.enabled||(this.enabled=!0,this.attachListeners(),this.logger.log("log",`${this.name}: Enabled`))}disable(){this.enabled&&(this.enabled=!1,this.logger.log("log",`${this.name}: Disabled`))}destroy(){this.disable(),this.detachListeners(),this.logger.log("log",`${this.name}: Destroyed`)}isEnabled(){return this.enabled}}const w=new class{constructor(){this.registrations=new Map,this.activeTrackers=new Map,this.logger=null}register(e){this.registrations.set(e.name,e)}initAll(e,t,n){this.logger=n;for(const[i,r]of this.registrations){const o=e[r.configKey],s=r.normalizeConfig(o);if(null===s)continue;const a=t[i];if(a)try{const t=r.factory(e,s,a,n);this.activeTrackers.set(i,t),t.enable(),n.log("log",`AutoTrackerRegistry: Initialized ${i}`)}catch(e){n.log("error",`AutoTrackerRegistry: Failed to initialize ${i}`,e)}else n.log("warn",`AutoTrackerRegistry: No callback registered for ${i}`)}}get(e){return this.activeTrackers.get(e)}enable(e){const t=this.activeTrackers.get(e);return!!t&&(t.enable(),!0)}disable(e){const t=this.activeTrackers.get(e);return!!t&&(t.disable(),!0)}destroyAll(){var e;for(const[t,n]of this.activeTrackers)try{n.destroy()}catch(n){null===(e=this.logger)||void 0===e||e.log("error",`AutoTrackerRegistry: Error destroying ${t}`,n)}this.activeTrackers.clear()}getRegisteredTrackers(){return Array.from(this.registrations.keys())}getActiveTrackers(){return Array.from(this.activeTrackers.keys())}reset(){this.destroyAll(),this.logger=null}},y=['input[type="password"]','input[type="text"][autocomplete*="cc-"]','input[type="text"][autocomplete*="card"]','input[type="text"][name*="card"]','input[type="text"][name*="cvv"]','input[type="text"][name*="cvc"]','input[name*="ssn"]','input[name*="social"]',"[data-sensitive]","[data-private]"],b=[/\b\d{3}-\d{2}-\d{4}\b/,/\b\d{4}[\s-]\d{4}[\s-]\d{4}[\s-]\d{4}\b/,/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i];const k=new class{constructor(e=[]){this.sensitiveSelectors=[...y,...e]}isSensitive(e){if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;let t=e.parentElement;for(;t;){const e=t;if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;t=t.parentElement}return!1}containsSensitiveData(e){return!!e&&b.some(t=>t.test(e))}sanitizeText(e){if(!e)return"";let t=e;return t=t.replace(/\b\d{3}-\d{2}-\d{4}\b/g,"***-**-****"),t=t.replace(/\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,"****-****-****-****"),t=t.replace(/\b([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,})\b/gi,"***@$2"),t}},C=["button","a[href]",'[role="button"]'],T=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class A extends p{constructor(e,t,n,i){var r,o,s;super(e,{enabled:null===(r=t.enabled)||void 0===r||r,selectors:null!==(o=t.selectors)&&void 0!==o?o:C,ignore:null!==(s=t.ignore)&&void 0!==s?s:T},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=k}attachListeners(){this.listenerAttached||("undefined"!=typeof document?(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,{passive:!0,capture:!1}),this.listenerAttached=!0,this.logger.log("log","ClickTracker: Delegated click listener attached")):this.logger.log("warn","ClickTracker: document not available, cannot attach listener"))}detachListeners(){this.listenerAttached&&this.boundHandleClick&&"undefined"!=typeof document&&(document.removeEventListener("click",this.boundHandleClick),this.listenerAttached=!1),this.debounceTimers.clear(),this.boundHandleClick=null}handleClick(e){if(!this.enabled)return;const t=e.target;if(!t)return;const n=this.findTrackableElement(t);if(!n)return;if(this.shouldIgnore(n))return void this.logger.log("log","ClickTracker: Element ignored",n);if(this.privacyGuard.isSensitive(n))return void this.logger.log("warn","ClickTracker: Sensitive element not tracked",n);if(this.isDebounced(n))return void this.logger.log("log","ClickTracker: Click debounced",n);const i=this.extractTrackingData(n);i&&(this.logger.log("log","ClickTracker: Tracking click",i),this.callback(i))}findTrackableElement(e){const t=this.config.selectors||C;try{const n=e.closest('[data-lucia-track]:not([data-lucia-track="false"])');if(n&&n!==document.body&&document.body.contains(n)){if(this.config.selectors&&this.config.selectors!==C){return t.some(e=>{try{return n.matches(e)}catch(e){return!1}})?n:null}return n}const i=t.join(", "),r=e.closest(i);return r&&r!==document.body&&document.body.contains(r)?r:null}catch(t){this.logger.log("warn","ClickTracker: Invalid combined selector, using fallback",t);let n=e;for(;n&&n!==document.body;){if(this.isTrackable(n))return n;n=n.parentElement}return null}}isTrackable(e){return(this.config.selectors||C).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid selector "${t}"`,e),!1}})}shouldIgnore(e){return(this.config.ignore||T).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid ignore selector "${t}"`,e),!1}})}isDebounced(e){const t=Date.now(),n=this.debounceTimers.get(e);return!!(n&&t-n<500)||(this.debounceTimers.set(e,t),this.debounceTimers.size>100&&this.cleanupDebounceTimers(),!1)}cleanupDebounceTimers(){const e=Date.now();Array.from(this.debounceTimers.entries()).forEach(([t,n])=>{e-n>1e3&&this.debounceTimers.delete(t)})}extractTrackingData(e){var t;const n=this.getElementIdentifier(e);if(!n)return this.logger.log("warn","ClickTracker: Could not generate identifier for element",e),null;const i={button:n,elementType:this.getElementType(e),timestamp:Date.now()},r=null===(t=e.textContent)||void 0===t?void 0:t.trim();r&&(this.privacyGuard.containsSensitiveData(r)||(i.text=this.sanitizeText(r))),"a"===e.tagName.toLowerCase()?i.href=e.getAttribute("href"):i.href=null;const o=this.extractMetadata(e);return o&&Object.keys(o).length>0&&(i.meta=o),i}getElementIdentifier(e){var t;const n=e.getAttribute("data-lucia-track");if(n&&"false"!==n)return n;const i=e.getAttribute("id");if(i)return i;const r=e.getAttribute("name");if(r)return r;const o=e.getAttribute("aria-label");if(o)return o;if("a"===e.tagName.toLowerCase()){const t=e.getAttribute("href");if(t)return`link:${t}`}const s=null===(t=e.textContent)||void 0===t?void 0:t.trim();if(s)return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using text content as identifier for element. Consider adding data-lucia-track attribute.",e),`text:${this.sanitizeText(s).substring(0,50)}`;const a=this.generateCSSPath(e);return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using CSS path as identifier. Consider adding data-lucia-track attribute.",e),`path:${a}`}getElementType(e){const t=e.tagName.toLowerCase();if("a"===t)return"link";if("button"===t)return"button";const n=e.getAttribute("role");return n||t}sanitizeText(e){return e.trim().replace(/\s+/g," ").substring(0,100)}generateCSSPath(e){const t=[];let n=e;for(;n&&n!==document.body&&t.length<5;){let e=n.tagName.toLowerCase();if(n.id){e+=`#${n.id}`,t.unshift(e);break}const i=n.getAttribute("class");if(i){const t=i.trim().split(/\s+/).slice(0,2);t.length>0&&(e+=`.${t.join(".")}`)}t.unshift(e),n=n.parentElement}return t.join(" > ")}extractMetadata(e){const t={},{attributes:n}=e;return Array.from(n).forEach(e=>{if(e.name.startsWith("data-lucia-meta-")){const n=e.name.replace("data-lucia-meta-","").replace(/-([a-z])/g,e=>e[1].toUpperCase());t[n]=e.value}}),Object.keys(t).length>0?t:null}}const I={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new A(e,t,n,i),normalizeConfig:function(e){return void 0===e||!1===e?null:!0===e?{enabled:!0}:!1===e.enabled?null:e}};function P(){return e(this,void 0,void 0,function*(){if(O)return O;const e={device:{cores:E(()=>navigator.hardwareConcurrency),memory:E(()=>navigator.deviceMemory),cpuClass:E(()=>navigator.cpuClass),touch:D(),devicePixelRatio:E(()=>window.devicePixelRatio)},screen:{width:E(()=>window.screen.width),height:E(()=>window.screen.height),colorDepth:E(()=>window.screen.colorDepth),availHeight:E(()=>window.screen.availHeight),availWidth:E(()=>window.screen.availWidth),orientation:{type:E(()=>window.screen.orientation.type),angle:E(()=>window.screen.orientation.angle)}},browser:{language:E(()=>navigator.language),encoding:E(()=>TextDecoder.encoding),timezone:E(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:E(()=>navigator.plugins.length),pluginNames:E(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:W(),uniqueHash:yield j(),colorGamut:R(),contrastPreference:x()},permissions:{navPer:E(()=>navigator.permissions.webglVersion),renderedPer:E(()=>navigator.permissions.RENDERER),geoPer:E(()=>navigator.permissions.geolocation)},storage:{localStorage:E(()=>!!window.localStorage),indexedDB:E(()=>!!window.indexedDB),openDB:E(()=>window.openDatabase)}};return O=e,e})}function S(){const e=new URL(window.location.href).searchParams,t={};return e.forEach((e,n)=>{(n.startsWith("utm_")||n.includes("id")||"ref"===n||"source"===n)&&(t[n]=e)}),t}function E(e,t){try{return e()}catch(e){return t}}function L(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t}let O=null;function j(){return e(this,void 0,void 0,function*(){try{const t=document.createElement("canvas"),n=t.getContext("2d",{willReadFrequently:!0});if(!n)return;const i=200,r=120;t.width=i,t.height=r,t.style.width=`${i}px`,t.style.height=`${r}px`,n.fillStyle="#ffffff",n.fillRect(0,0,i,r),n.fillStyle="#ff00ff",n.fillRect(10,10,100,100),n.fillStyle="#00ffff",n.beginPath(),n.arc(150,50,40,0,2*Math.PI,!0),n.fill();const{data:o}=n.getImageData(0,0,i,r);return function(t){return e(this,void 0,void 0,function*(){const e=(new TextEncoder).encode(t),n=yield crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("")})}([[20,20],[60,60],[100,100],[150,50],[150,60],[140,50],[5,5]].map(([e,t])=>{const n=4*(t*i+e);return`${o[n]},${o[n+1]},${o[n+2]},${o[n+3]};`}).join(""))}catch(e){return}})}function D(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function W(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function x(){try{const{matchMedia:e}=window,t=t=>e(`(prefers-contrast: ${t})`).matches;return t("no-preference")?"None":t("high")||t("more")?"More":t("low")||t("less")?"Less":t("forced")?"ForcedColors":void 0}catch(e){return}}function R(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const $=new Map;let U=null,M=!1;function K(){return new Map($)}const _=[{name:"Rabby",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRabby)}},{name:"Brave Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBraveWallet)}},{name:"Rainbow",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRainbow)}},{name:"Coinbase Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoinbaseWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCoinbase)}},{name:"Trust Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTrust)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTrustWallet)}},{name:"TokenPocket",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTokenPocket)}},{name:"Zerion",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isZerion)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isPhantom)}},{name:"OKX Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOkxWallet)}},{name:"Bitget Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBitKeep)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isBitgetWallet)}},{name:"SafePal",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isSafePal)}},{name:"Frontier",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrontier)}},{name:"XDEFI",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isXDEFI)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCtrl)}},{name:"Enkrypt",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isEnkrypt)}},{name:"MetaMask",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMetaMask)}},{name:"WalletConnect",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isWalletConnect)}},{name:"imToken",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isImToken)}},{name:"Status",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isStatus)}},{name:"Tally",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTally)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTallyWallet)}},{name:"AlphaWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isAlphaWallet)}},{name:"Opera",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOpera)}},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoin98)}},{name:"MathWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMathWallet)}},{name:"1inch Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOneInchIOSWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isOneInchAndroidWallet)}},{name:"Frame",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrame)}},{name:"Binance Chain Wallet",detect:()=>!!window.BinanceChain},{name:"MetaMask",detect:()=>{var e;return Object.prototype.hasOwnProperty.call(null!==(e=window.ethereum)&&void 0!==e?e:{},"_metamask")}}],N=[{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.phantom)||void 0===e?void 0:e.solana)}},{name:"Solflare",detect:()=>!!window.solflare},{name:"Backpack",detect:()=>!!window.backpack},{name:"Glow",detect:()=>!!window.glow},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isCoin98)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isPhantom)}}];function q(){var e,t;return window.ethereum&&null!==(t=null===(e=_.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}function z(){var e,t;return null!==(t=null===(e=N.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}w.register(I);let B=class extends m{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}authenticate(){this.httpClient.post("/api/key/auth",{})}init(){return e(this,void 0,void 0,function*(){let e=h();e||(e=v());try{M||(M=!0,U=e=>{var t;const n=e.detail;(null===(t=null==n?void 0:n.info)||void 0===t?void 0:t.rdns)&&(null==n?void 0:n.provider)&&$.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",U),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield P(),n=new URL(window.location.href).searchParams.get("lucia"),i={id:e.id};e.hash&&(i.hash=e.hash);const r=g(),o=yield this.httpClient.post("/api/sdk/init",Object.assign({user:{name:f()},data:t,session:i,redirectHash:n,utm:S()},r&&{lid:r}),!1);o&&(o.lid&&localStorage.setItem("lid",o.lid),o.session&&function(e){const t={id:e.id,hash:e.hash,timestamp:Date.now()};sessionStorage.setItem(d,JSON.stringify(t))}(o.session)),w.initAll(this.store.config,{clicks:this.handleAutoTrackedClick.bind(this)},this.logger),yield this.autoDetectWallets(),this.setupWalletListeners()})}handleAutoTrackedClick(e){const t=e,n={elementType:t.elementType,text:t.text,href:t.href,meta:t.meta};this.buttonClick(t.button,n)}autoDetectWallets(){return e(this,void 0,void 0,function*(){var t,n,i;try{const t=yield function(){return e(this,void 0,void 0,function*(){const e=Array.from($.values());if(0===e.length)return[];const t=yield Promise.allSettled(e.map(({info:e,provider:t})=>{const n=t.request({method:"eth_accounts"}).then(n=>{const i=n;return Array.isArray(i)?i.filter(e=>"string"==typeof e&&e.length>0).map(n=>({address:n,providerName:e.name,providerRdns:e.rdns,provider:t})):[]}),i=new Promise((t,n)=>setTimeout(()=>n(new Error(`EIP-6963 timeout: ${e.name}`)),3e3));return Promise.race([n,i])})),n=[];for(const e of t)"fulfilled"===e.status&&n.push(...e.value);return n})}();for(const e of t)yield this.sendWalletInfo(e.address,{provider:e.providerName,providerRdns:e.providerRdns})}catch(e){}if(0===K().size&&(null===(t=window.ethereum)||void 0===t?void 0:t.selectedAddress))try{const e=q();yield this.sendWalletInfo(window.ethereum.selectedAddress,{provider:null!=e?e:void 0})}catch(e){}if((null===(n=window.solana)||void 0===n?void 0:n.isConnected)&&(null===(i=window.solana)||void 0===i?void 0:i.publicKey))try{const e=z();yield this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0})}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){var e,t;const n=function(e){const t=t=>{var n;const i=t.detail;(null===(n=null==i?void 0:i.info)||void 0===n?void 0:n.rdns)&&(null==i?void 0:i.provider)&&($.set(i.info.rdns,i),e(i))};return window.addEventListener("eip6963:announceProvider",t),()=>window.removeEventListener("eip6963:announceProvider",t)}(e=>{this.handleLateEIP6963Provider(e)});if(this.walletListenerCleanups.push(n),(null===(e=window.ethereum)||void 0===e?void 0:e.on)&&0===K().size){const e=e=>{const t=e;if(t[0]){const e=t[0],n=q();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};window.ethereum.on("accountsChanged",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"accountsChanged",e)})}if(null===(t=window.solana)||void 0===t?void 0:t.on){const e=()=>{var e;if(null===(e=window.solana)||void 0===e?void 0:e.publicKey){const e=z();this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0}).catch(()=>{})}};window.solana.on("connect",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"connect",e)})}}setupEIP6963AccountListeners(){const e=K();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e;n.request&&n.request({method:"eth_accounts"}).then(e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})}).catch(()=>{}),this.attachEIP6963AccountsChanged(e)}attachEIP6963AccountsChanged(e){const{info:t,provider:n}=e;if(!n.on)return;const i=e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})};n.on("accountsChanged",i),this.walletListenerCleanups.push(()=>{var e;null===(e=n.removeListener)||void 0===e||e.call(n,"accountsChanged",i)})}userInfo(t,n){return e(this,void 0,void 0,function*(){const e=g(),i=h();t&&localStorage.setItem("luc_uid",t);const r=Object.assign({user:{name:t,userInfo:n},session:i},e&&{lid:e});yield this.httpClient.post("/api/sdk/user",r)})}pageView(t){return e(this,void 0,void 0,function*(){const e=g(),n=h(),i=Object.assign({page:t,user:{name:f()},session:n},e&&{lid:e});yield this.httpClient.post("/api/sdk/page",i)})}trackConversion(t,n,i){return e(this,void 0,void 0,function*(){const e=g(),r=h(),o=Object.assign({tag:t,amount:n,event:i,user:{name:f()},session:r},e&&{lid:e});yield this.httpClient.post("/api/sdk/conversion",o)})}buttonClick(t,n){return e(this,void 0,void 0,function*(){const e=g(),i=h(),r=Object.assign(Object.assign({button:t,user:{name:f()},session:i},e&&{lid:e}),n&&Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n.elementType&&{elementType:n.elementType}),n.text&&{text:n.text}),void 0!==n.href&&{href:n.href}),n.meta&&{meta:n.meta}),{timestamp:Date.now()}));yield this.httpClient.post("/api/sdk/click",r)})}sendWalletInfo(t,n,i){return e(this,void 0,void 0,function*(){var e,r,o;if(!t||"string"!=typeof t)return;const s=t.startsWith("0x")?t.toLowerCase():t;if(this.sentWallets.has(s))return;this.sentWallets.add(s);let a={};n&&"object"==typeof n?a=n:void 0!==n&&(a={chainId:"number"==typeof n?n:void 0,provider:i});const l=g(),c=h(),d=Object.assign(Object.assign(Object.assign(Object.assign({walletAddress:t,provider:null!==(e=a.provider)&&void 0!==e?e:null,providerRdns:null!==(r=a.providerRdns)&&void 0!==r?r:null,connectorType:null!==(o=a.connectorType)&&void 0!==o?o:null},null!=a.chainId&&{chainId:a.chainId}),i&&{walletName:i}),{user:{name:f()},session:c}),l&&{lid:l});try{yield this.httpClient.post("/api/sdk/wallet",d)}catch(e){throw this.sentWallets.delete(s),e}})}trackUserAcquisition(t){return e(this,arguments,void 0,function*(e,t={}){const n=yield P(),i=S(),r=h();yield this.httpClient.post("/api/sdk/acquisition",{user:{name:e},session:r,data:Object.assign({timestamp:(new Date).toISOString(),browserData:n,utmParams:i},t)})})}checkMetaMaskConnection(){var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))}destroy(){w.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),M&&(U&&(window.removeEventListener("eip6963:announceProvider",U),U=null),$.clear(),M=!1)}},Q=null;const F=()=>{const e=Q||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},H=()=>{const e=Q||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),Q=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,w.reset()},V={init:t=>{if("undefined"==typeof window)return Promise.reject(new Error("LuciaSDK requires a browser environment"));if(Q)return Q;if(window.__luciaInitPromise)return Q=window.__luciaInitPromise,Q;if(!(null==t?void 0:t.apiKey))return Promise.reject(new Error("apiKey is required in config"));const n=e(void 0,void 0,void 0,function*(){const e=new B(t);return yield e.init(),e});return Q=n,window.__luciaInitPromise=n,n},userInfo:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield F()).userInfo(t,n)}),pageView:t=>e(void 0,void 0,void 0,function*(){return(yield F()).pageView(t)}),trackConversion:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield F()).trackConversion(t,n,i)}),buttonClick:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield F()).buttonClick(t,n)}),sendWalletInfo:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield F()).sendWalletInfo(t,n,i)}),trackUserAcquisition:(t,...n)=>e(void 0,[t,...n],void 0,function*(e,t={}){return(yield F()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>{var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))},VERSION:n};if("undefined"!=typeof window){window.LuciaSDK=V;const e=()=>{const e=document.currentScript||document.querySelector("script[data-api-key]"),t=null==e?void 0:e.getAttribute("data-api-key");if(!t)return;const n=e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");V.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{debugURL:n}),"true"===i&&{autoTrackClicks:!r||{enabled:!0,selectors:r.split(",").map(e=>e.trim())}}),"false"===i&&{autoTrackClicks:!1})).catch(e=>console.error("LuciaSDK auto-init failed:",e))};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}export{H as __resetInstance,V as default,q as detectEvmProvider,z as detectSolanaProvider,L as filterObject,W as getApplePayAvailable,P as getBrowserData,j as getCanvasFingerprint,R as getColorGamut,x as getContrastPreference,S as getUtmParams,D as isTouchEnabled,E as safeAccess};
2
2
  //# sourceMappingURL=index.es.js.map
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";function e(e,t,n,i){return new(n||(n=Promise))(function(r,o){function s(e){try{l(i.next(e))}catch(e){o(e)}}function a(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((i=i.apply(e,t||[])).next())})}Object.defineProperty(exports,"__esModule",{value:!0}),"function"==typeof SuppressedError&&SuppressedError;class t{constructor(e){this.store=e}log(e,...t){var n;(null===(n=this.store.config)||void 0===n?void 0:n.debug)&&console[e](t)}}const n="0.10.0";class i{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new t(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"http://52.22.177.60/fk":"https://api.clickinsights.xyz"}get(t){return e(this,void 0,void 0,function*(){if(!this.store.config)return this.logger.log("error","Config is not set"),null;try{const e=yield fetch(`${this.baseURL}${t}`,{method:"GET",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":n}});return yield e.json()}catch(e){this.logger.log("error",e)}return null})}post(t,n){return e(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;const i="/api/sdk/init"===e;if(!i&&!this.initComplete)return new Promise((r,o)=>{this.requestQueue.push({url:e,data:t,fireAndForget:n,resolve:r,reject:o,isInit:i}),this.processQueue()});if(i){const i=yield this.executePost(e,t,n);return this.initComplete=!0,yield this.processQueue(),i}return this.executePost(e,t,n)})}processQueue(){return e(this,void 0,void 0,function*(){if(!this.isProcessingQueue&&this.initComplete&&0!==this.requestQueue.length){this.isProcessingQueue=!0;try{const t=()=>e(this,void 0,void 0,function*(){if(0===this.requestQueue.length)return;const e=this.requestQueue.shift();try{const t=yield this.executePost(e.url,e.data,e.fireAndForget);e.resolve(t)}catch(t){e.reject(t)}yield t()});yield t()}finally{this.isProcessingQueue=!1}}})}executePost(t,i){return e(this,arguments,void 0,function*(e,t,i=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;if(i&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon){try{const n=`${this.baseURL}${e}`,i=t&&"object"==typeof t&&!Array.isArray(t)?t:{payload:t},r=JSON.stringify(Object.assign(Object.assign({},i),{_apiKey:this.store.config.apiKey})),o=new Blob([r],{type:"application/json"});navigator.sendBeacon(n,o)||this.logger.log("error","sendBeacon failed")}catch(e){this.logger.log("error",e)}return null}try{const i=yield fetch(`${this.baseURL}${e}`,{method:"POST",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":n},body:JSON.stringify(t)});return yield i.json()}catch(e){this.logger.log("error",e)}return null})}}class r{static dispatch(e){Object.keys(e).forEach(t=>{if(Object.keys(r.store).includes(t)){const n=e[t];r.store[t]="object"==typeof n?Array.isArray(n)?[...n]:Object.assign({},n):n}})}}r.store={isInitialized:!1,config:null,session:null};const o=[];for(let e=0;e<256;++e)o.push((e+256).toString(16).slice(1));let s;const a=new Uint8Array(16);var l={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function c(e,t,n){const i=(e=e||{}).random??e.rng?.()??function(){if(!s){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");s=crypto.getRandomValues.bind(crypto)}return s(a)}();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=15&i[6]|64,i[8]=63&i[8]|128,function(e,t=0){return(o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]).toLowerCase()}(i)}const d="luci_session",u=new t(r.store);function h(){try{const e=sessionStorage.getItem(d);return e?JSON.parse(e):null}catch(e){return u.log("error","Error retrieving session data:",e),null}}function v(){var e;const t={id:l.randomUUID&&!e?l.randomUUID():c(e),timestamp:Date.now()};return sessionStorage.setItem(d,JSON.stringify(t)),t}function g(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function f(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class m{constructor(e){this.store=r.store,this.dispatch=r.dispatch,this.dispatch({config:e}),this.httpClient=new i(this.store),this.logger=new t(this.store)}}class p{constructor(e,t,n,i){this.enabled=!1,this.sdkConfig=e,this.config=t,this.callback=n,this.logger=i}enable(){this.enabled||(this.enabled=!0,this.attachListeners(),this.logger.log("log",`${this.name}: Enabled`))}disable(){this.enabled&&(this.enabled=!1,this.logger.log("log",`${this.name}: Disabled`))}destroy(){this.disable(),this.detachListeners(),this.logger.log("log",`${this.name}: Destroyed`)}isEnabled(){return this.enabled}}const w=new class{constructor(){this.registrations=new Map,this.activeTrackers=new Map,this.logger=null}register(e){this.registrations.set(e.name,e)}initAll(e,t,n){this.logger=n;for(const[i,r]of this.registrations){const o=e[r.configKey],s=r.normalizeConfig(o);if(null===s)continue;const a=t[i];if(a)try{const t=r.factory(e,s,a,n);this.activeTrackers.set(i,t),t.enable(),n.log("log",`AutoTrackerRegistry: Initialized ${i}`)}catch(e){n.log("error",`AutoTrackerRegistry: Failed to initialize ${i}`,e)}else n.log("warn",`AutoTrackerRegistry: No callback registered for ${i}`)}}get(e){return this.activeTrackers.get(e)}enable(e){const t=this.activeTrackers.get(e);return!!t&&(t.enable(),!0)}disable(e){const t=this.activeTrackers.get(e);return!!t&&(t.disable(),!0)}destroyAll(){var e;for(const[t,n]of this.activeTrackers)try{n.destroy()}catch(n){null===(e=this.logger)||void 0===e||e.log("error",`AutoTrackerRegistry: Error destroying ${t}`,n)}this.activeTrackers.clear()}getRegisteredTrackers(){return Array.from(this.registrations.keys())}getActiveTrackers(){return Array.from(this.activeTrackers.keys())}reset(){this.destroyAll(),this.logger=null}},y=['input[type="password"]','input[type="text"][autocomplete*="cc-"]','input[type="text"][autocomplete*="card"]','input[type="text"][name*="card"]','input[type="text"][name*="cvv"]','input[type="text"][name*="cvc"]','input[name*="ssn"]','input[name*="social"]',"[data-sensitive]","[data-private]"],b=[/\b\d{3}-\d{2}-\d{4}\b/,/\b\d{4}[\s-]\d{4}[\s-]\d{4}[\s-]\d{4}\b/,/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i];const k=new class{constructor(e=[]){this.sensitiveSelectors=[...y,...e]}isSensitive(e){if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;let t=e.parentElement;for(;t;){const e=t;if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;t=t.parentElement}return!1}containsSensitiveData(e){return!!e&&b.some(t=>t.test(e))}sanitizeText(e){if(!e)return"";let t=e;return t=t.replace(/\b\d{3}-\d{2}-\d{4}\b/g,"***-**-****"),t=t.replace(/\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,"****-****-****-****"),t=t.replace(/\b([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,})\b/gi,"***@$2"),t}},C=["button","a[href]",'[role="button"]'],T=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class A extends p{constructor(e,t,n,i){var r,o,s;super(e,{enabled:null===(r=t.enabled)||void 0===r||r,selectors:null!==(o=t.selectors)&&void 0!==o?o:C,ignore:null!==(s=t.ignore)&&void 0!==s?s:T},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=k}attachListeners(){this.listenerAttached||("undefined"!=typeof document?(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,{passive:!0,capture:!1}),this.listenerAttached=!0,this.logger.log("log","ClickTracker: Delegated click listener attached")):this.logger.log("warn","ClickTracker: document not available, cannot attach listener"))}detachListeners(){this.listenerAttached&&this.boundHandleClick&&"undefined"!=typeof document&&(document.removeEventListener("click",this.boundHandleClick),this.listenerAttached=!1),this.debounceTimers.clear(),this.boundHandleClick=null}handleClick(e){if(!this.enabled)return;const t=e.target;if(!t)return;const n=this.findTrackableElement(t);if(!n)return;if(this.shouldIgnore(n))return void this.logger.log("log","ClickTracker: Element ignored",n);if(this.privacyGuard.isSensitive(n))return void this.logger.log("warn","ClickTracker: Sensitive element not tracked",n);if(this.isDebounced(n))return void this.logger.log("log","ClickTracker: Click debounced",n);const i=this.extractTrackingData(n);i&&(this.logger.log("log","ClickTracker: Tracking click",i),this.callback(i))}findTrackableElement(e){const t=this.config.selectors||C;try{const n=e.closest('[data-lucia-track]:not([data-lucia-track="false"])');if(n&&n!==document.body&&document.body.contains(n)){if(this.config.selectors&&this.config.selectors!==C){return t.some(e=>{try{return n.matches(e)}catch(e){return!1}})?n:null}return n}const i=t.join(", "),r=e.closest(i);return r&&r!==document.body&&document.body.contains(r)?r:null}catch(t){this.logger.log("warn","ClickTracker: Invalid combined selector, using fallback",t);let n=e;for(;n&&n!==document.body;){if(this.isTrackable(n))return n;n=n.parentElement}return null}}isTrackable(e){return(this.config.selectors||C).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid selector "${t}"`,e),!1}})}shouldIgnore(e){return(this.config.ignore||T).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid ignore selector "${t}"`,e),!1}})}isDebounced(e){const t=Date.now(),n=this.debounceTimers.get(e);return!!(n&&t-n<500)||(this.debounceTimers.set(e,t),this.debounceTimers.size>100&&this.cleanupDebounceTimers(),!1)}cleanupDebounceTimers(){const e=Date.now();Array.from(this.debounceTimers.entries()).forEach(([t,n])=>{e-n>1e3&&this.debounceTimers.delete(t)})}extractTrackingData(e){var t;const n=this.getElementIdentifier(e);if(!n)return this.logger.log("warn","ClickTracker: Could not generate identifier for element",e),null;const i={button:n,elementType:this.getElementType(e),timestamp:Date.now()},r=null===(t=e.textContent)||void 0===t?void 0:t.trim();r&&(this.privacyGuard.containsSensitiveData(r)||(i.text=this.sanitizeText(r))),"a"===e.tagName.toLowerCase()?i.href=e.getAttribute("href"):i.href=null;const o=this.extractMetadata(e);return o&&Object.keys(o).length>0&&(i.meta=o),i}getElementIdentifier(e){var t;const n=e.getAttribute("data-lucia-track");if(n&&"false"!==n)return n;const i=e.getAttribute("id");if(i)return i;const r=e.getAttribute("name");if(r)return r;const o=e.getAttribute("aria-label");if(o)return o;if("a"===e.tagName.toLowerCase()){const t=e.getAttribute("href");if(t)return`link:${t}`}const s=null===(t=e.textContent)||void 0===t?void 0:t.trim();if(s)return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using text content as identifier for element. Consider adding data-lucia-track attribute.",e),`text:${this.sanitizeText(s).substring(0,50)}`;const a=this.generateCSSPath(e);return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using CSS path as identifier. Consider adding data-lucia-track attribute.",e),`path:${a}`}getElementType(e){const t=e.tagName.toLowerCase();if("a"===t)return"link";if("button"===t)return"button";const n=e.getAttribute("role");return n||t}sanitizeText(e){return e.trim().replace(/\s+/g," ").substring(0,100)}generateCSSPath(e){const t=[];let n=e;for(;n&&n!==document.body&&t.length<5;){let e=n.tagName.toLowerCase();if(n.id){e+=`#${n.id}`,t.unshift(e);break}const i=n.getAttribute("class");if(i){const t=i.trim().split(/\s+/).slice(0,2);t.length>0&&(e+=`.${t.join(".")}`)}t.unshift(e),n=n.parentElement}return t.join(" > ")}extractMetadata(e){const t={},{attributes:n}=e;return Array.from(n).forEach(e=>{if(e.name.startsWith("data-lucia-meta-")){const n=e.name.replace("data-lucia-meta-","").replace(/-([a-z])/g,e=>e[1].toUpperCase());t[n]=e.value}}),Object.keys(t).length>0?t:null}}const P={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new A(e,t,n,i),normalizeConfig:function(e){return void 0===e||!1===e?null:!0===e?{enabled:!0}:!1===e.enabled?null:e}};function I(){return e(this,void 0,void 0,function*(){if(x)return x;const e={device:{cores:E(()=>navigator.hardwareConcurrency),memory:E(()=>navigator.deviceMemory),cpuClass:E(()=>navigator.cpuClass),touch:O(),devicePixelRatio:E(()=>window.devicePixelRatio)},screen:{width:E(()=>window.screen.width),height:E(()=>window.screen.height),colorDepth:E(()=>window.screen.colorDepth),availHeight:E(()=>window.screen.availHeight),availWidth:E(()=>window.screen.availWidth),orientation:{type:E(()=>window.screen.orientation.type),angle:E(()=>window.screen.orientation.angle)}},browser:{language:E(()=>navigator.language),encoding:E(()=>TextDecoder.encoding),timezone:E(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:E(()=>navigator.plugins.length),pluginNames:E(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:j(),uniqueHash:yield L(),colorGamut:W(),contrastPreference:D()},permissions:{navPer:E(()=>navigator.permissions.webglVersion),renderedPer:E(()=>navigator.permissions.RENDERER),geoPer:E(()=>navigator.permissions.geolocation)},storage:{localStorage:E(()=>!!window.localStorage),indexedDB:E(()=>!!window.indexedDB),openDB:E(()=>window.openDatabase)}};return x=e,e})}function S(){const e=new URL(window.location.href).searchParams,t={};return e.forEach((e,n)=>{(n.startsWith("utm_")||n.includes("id")||"ref"===n||"source"===n)&&(t[n]=e)}),t}function E(e,t){try{return e()}catch(e){return t}}let x=null;function L(){return e(this,void 0,void 0,function*(){try{const t=document.createElement("canvas"),n=t.getContext("2d",{willReadFrequently:!0});if(!n)return;const i=200,r=120;t.width=i,t.height=r,t.style.width=`${i}px`,t.style.height=`${r}px`,n.fillStyle="#ffffff",n.fillRect(0,0,i,r),n.fillStyle="#ff00ff",n.fillRect(10,10,100,100),n.fillStyle="#00ffff",n.beginPath(),n.arc(150,50,40,0,2*Math.PI,!0),n.fill();const{data:o}=n.getImageData(0,0,i,r);return function(t){return e(this,void 0,void 0,function*(){const e=(new TextEncoder).encode(t),n=yield crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("")})}([[20,20],[60,60],[100,100],[150,50],[150,60],[140,50],[5,5]].map(([e,t])=>{const n=4*(t*i+e);return`${o[n]},${o[n+1]},${o[n+2]},${o[n+3]};`}).join(""))}catch(e){return}})}function O(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function j(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function D(){try{const{matchMedia:e}=window,t=t=>e(`(prefers-contrast: ${t})`).matches;return t("no-preference")?"None":t("high")||t("more")?"More":t("low")||t("less")?"Less":t("forced")?"ForcedColors":void 0}catch(e){return}}function W(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const R=new Map;let U=null,$=!1;function M(){return new Map(R)}const _=[{name:"Rabby",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRabby)}},{name:"Brave Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBraveWallet)}},{name:"Rainbow",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRainbow)}},{name:"Coinbase Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoinbaseWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCoinbase)}},{name:"Trust Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTrust)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTrustWallet)}},{name:"TokenPocket",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTokenPocket)}},{name:"Zerion",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isZerion)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isPhantom)}},{name:"OKX Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOkxWallet)}},{name:"Bitget Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBitKeep)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isBitgetWallet)}},{name:"SafePal",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isSafePal)}},{name:"Frontier",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrontier)}},{name:"XDEFI",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isXDEFI)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCtrl)}},{name:"Enkrypt",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isEnkrypt)}},{name:"MetaMask",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMetaMask)}},{name:"WalletConnect",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isWalletConnect)}},{name:"imToken",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isImToken)}},{name:"Status",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isStatus)}},{name:"Tally",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTally)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTallyWallet)}},{name:"AlphaWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isAlphaWallet)}},{name:"Opera",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOpera)}},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoin98)}},{name:"MathWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMathWallet)}},{name:"1inch Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOneInchIOSWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isOneInchAndroidWallet)}},{name:"Frame",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrame)}},{name:"Binance Chain Wallet",detect:()=>!!window.BinanceChain},{name:"MetaMask",detect:()=>{var e;return Object.prototype.hasOwnProperty.call(null!==(e=window.ethereum)&&void 0!==e?e:{},"_metamask")}}],K=[{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.phantom)||void 0===e?void 0:e.solana)}},{name:"Solflare",detect:()=>!!window.solflare},{name:"Backpack",detect:()=>!!window.backpack},{name:"Glow",detect:()=>!!window.glow},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isCoin98)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isPhantom)}}];function N(){var e,t;return window.ethereum&&null!==(t=null===(e=_.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}function q(){var e,t;return null!==(t=null===(e=K.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}w.register(P);let B=class extends m{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}authenticate(){this.httpClient.post("/api/key/auth",{})}init(){return e(this,void 0,void 0,function*(){let e=h();e||(e=v());try{$||($=!0,U=e=>{var t;const n=e.detail;(null===(t=null==n?void 0:n.info)||void 0===t?void 0:t.rdns)&&(null==n?void 0:n.provider)&&R.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",U),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield I(),n=new URL(window.location.href).searchParams.get("lucia"),i={id:e.id};e.hash&&(i.hash=e.hash);const r=yield this.httpClient.post("/api/sdk/init",{user:{name:f()},data:t,session:i,redirectHash:n,utm:S()},!1);r&&(r.lid&&localStorage.setItem("lid",r.lid),r.session&&function(e){const t={id:e.id,hash:e.hash,timestamp:Date.now()};sessionStorage.setItem(d,JSON.stringify(t))}(r.session)),w.initAll(this.store.config,{clicks:this.handleAutoTrackedClick.bind(this)},this.logger),yield this.autoDetectWallets(),this.setupWalletListeners()})}handleAutoTrackedClick(e){const t=e,n={elementType:t.elementType,text:t.text,href:t.href,meta:t.meta};this.buttonClick(t.button,n)}autoDetectWallets(){return e(this,void 0,void 0,function*(){var t,n,i;try{const t=yield function(){return e(this,void 0,void 0,function*(){const e=Array.from(R.values());if(0===e.length)return[];const t=yield Promise.allSettled(e.map(({info:e,provider:t})=>{const n=t.request({method:"eth_accounts"}).then(n=>{const i=n;return Array.isArray(i)?i.filter(e=>"string"==typeof e&&e.length>0).map(n=>({address:n,providerName:e.name,providerRdns:e.rdns,provider:t})):[]}),i=new Promise((t,n)=>setTimeout(()=>n(new Error(`EIP-6963 timeout: ${e.name}`)),3e3));return Promise.race([n,i])})),n=[];for(const e of t)"fulfilled"===e.status&&n.push(...e.value);return n})}();for(const e of t)yield this.sendWalletInfo(e.address,{provider:e.providerName,providerRdns:e.providerRdns})}catch(e){}if(0===M().size&&(null===(t=window.ethereum)||void 0===t?void 0:t.selectedAddress))try{const e=N();yield this.sendWalletInfo(window.ethereum.selectedAddress,{provider:null!=e?e:void 0})}catch(e){}if((null===(n=window.solana)||void 0===n?void 0:n.isConnected)&&(null===(i=window.solana)||void 0===i?void 0:i.publicKey))try{const e=q();yield this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0})}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){var e,t;const n=function(e){const t=t=>{var n;const i=t.detail;(null===(n=null==i?void 0:i.info)||void 0===n?void 0:n.rdns)&&(null==i?void 0:i.provider)&&(R.set(i.info.rdns,i),e(i))};return window.addEventListener("eip6963:announceProvider",t),()=>window.removeEventListener("eip6963:announceProvider",t)}(e=>{this.handleLateEIP6963Provider(e)});if(this.walletListenerCleanups.push(n),(null===(e=window.ethereum)||void 0===e?void 0:e.on)&&0===M().size){const e=e=>{const t=e;if(t[0]){const e=t[0],n=N();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};window.ethereum.on("accountsChanged",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"accountsChanged",e)})}if(null===(t=window.solana)||void 0===t?void 0:t.on){const e=()=>{var e;if(null===(e=window.solana)||void 0===e?void 0:e.publicKey){const e=q();this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0}).catch(()=>{})}};window.solana.on("connect",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"connect",e)})}}setupEIP6963AccountListeners(){const e=M();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e;n.request&&n.request({method:"eth_accounts"}).then(e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})}).catch(()=>{}),this.attachEIP6963AccountsChanged(e)}attachEIP6963AccountsChanged(e){const{info:t,provider:n}=e;if(!n.on)return;const i=e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})};n.on("accountsChanged",i),this.walletListenerCleanups.push(()=>{var e;null===(e=n.removeListener)||void 0===e||e.call(n,"accountsChanged",i)})}userInfo(t,n){return e(this,void 0,void 0,function*(){const e=g(),i=h();t&&localStorage.setItem("luc_uid",t);const r=Object.assign({user:{name:t,userInfo:n},session:i},e&&{lid:e});yield this.httpClient.post("/api/sdk/user",r)})}pageView(t){return e(this,void 0,void 0,function*(){const e=g(),n=h(),i=Object.assign({page:t,user:{name:f()},session:n},e&&{lid:e});yield this.httpClient.post("/api/sdk/page",i)})}trackConversion(t,n,i){return e(this,void 0,void 0,function*(){const e=g(),r=h(),o=Object.assign({tag:t,amount:n,event:i,user:{name:f()},session:r},e&&{lid:e});yield this.httpClient.post("/api/sdk/conversion",o)})}buttonClick(t,n){return e(this,void 0,void 0,function*(){const e=g(),i=h(),r=Object.assign(Object.assign({button:t,user:{name:f()},session:i},e&&{lid:e}),n&&Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n.elementType&&{elementType:n.elementType}),n.text&&{text:n.text}),void 0!==n.href&&{href:n.href}),n.meta&&{meta:n.meta}),{timestamp:Date.now()}));yield this.httpClient.post("/api/sdk/click",r)})}sendWalletInfo(t,n,i){return e(this,void 0,void 0,function*(){var e,r,o;if(!t||"string"!=typeof t)return;const s=t.startsWith("0x")?t.toLowerCase():t;if(this.sentWallets.has(s))return;this.sentWallets.add(s);let a={};n&&"object"==typeof n?a=n:void 0!==n&&(a={chainId:"number"==typeof n?n:void 0,provider:i});const l=g(),c=h(),d=Object.assign(Object.assign(Object.assign(Object.assign({walletAddress:t,provider:null!==(e=a.provider)&&void 0!==e?e:null,providerRdns:null!==(r=a.providerRdns)&&void 0!==r?r:null,connectorType:null!==(o=a.connectorType)&&void 0!==o?o:null},null!=a.chainId&&{chainId:a.chainId}),i&&{walletName:i}),{user:{name:f()},session:c}),l&&{lid:l});try{yield this.httpClient.post("/api/sdk/wallet",d)}catch(e){throw this.sentWallets.delete(s),e}})}trackUserAcquisition(t){return e(this,arguments,void 0,function*(e,t={}){const n=yield I(),i=S(),r=h();yield this.httpClient.post("/api/sdk/acquisition",{user:{name:e},session:r,data:Object.assign({timestamp:(new Date).toISOString(),browserData:n,utmParams:i},t)})})}checkMetaMaskConnection(){var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))}destroy(){w.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),$&&(U&&(window.removeEventListener("eip6963:announceProvider",U),U=null),R.clear(),$=!1)}},z=null;const F=()=>{const e=z||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},Q={init:t=>{if("undefined"==typeof window)return Promise.reject(new Error("LuciaSDK requires a browser environment"));if(z)return z;if(window.__luciaInitPromise)return z=window.__luciaInitPromise,z;if(!(null==t?void 0:t.apiKey))return Promise.reject(new Error("apiKey is required in config"));const n=e(void 0,void 0,void 0,function*(){const e=new B(t);return yield e.init(),e});return z=n,window.__luciaInitPromise=n,n},userInfo:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield F()).userInfo(t,n)}),pageView:t=>e(void 0,void 0,void 0,function*(){return(yield F()).pageView(t)}),trackConversion:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield F()).trackConversion(t,n,i)}),buttonClick:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield F()).buttonClick(t,n)}),sendWalletInfo:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield F()).sendWalletInfo(t,n,i)}),trackUserAcquisition:(t,...n)=>e(void 0,[t,...n],void 0,function*(e,t={}){return(yield F()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>{var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))},VERSION:n};if("undefined"!=typeof window){window.LuciaSDK=Q;const e=()=>{const e=document.currentScript||document.querySelector("script[data-api-key]"),t=null==e?void 0:e.getAttribute("data-api-key");if(!t)return;const n=e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");Q.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{debugURL:n}),"true"===i&&{autoTrackClicks:!r||{enabled:!0,selectors:r.split(",").map(e=>e.trim())}}),"false"===i&&{autoTrackClicks:!1})).catch(e=>console.error("LuciaSDK auto-init failed:",e))};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}exports.__resetInstance=()=>{const e=z||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),z=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,w.reset()},exports.default=Q,exports.detectEvmProvider=N,exports.detectSolanaProvider=q,exports.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},exports.getApplePayAvailable=j,exports.getBrowserData=I,exports.getCanvasFingerprint=L,exports.getColorGamut=W,exports.getContrastPreference=D,exports.getUtmParams=S,exports.isTouchEnabled=O,exports.safeAccess=E;
1
+ "use strict";function e(e,t,n,i){return new(n||(n=Promise))(function(r,o){function s(e){try{l(i.next(e))}catch(e){o(e)}}function a(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((i=i.apply(e,t||[])).next())})}Object.defineProperty(exports,"__esModule",{value:!0}),"function"==typeof SuppressedError&&SuppressedError;class t{constructor(e){this.store=e}log(e,...t){var n;(null===(n=this.store.config)||void 0===n?void 0:n.debug)&&console[e](t)}}const n="0.10.2";class i{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new t(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"http://52.22.177.60/fk":"https://api.clickinsights.xyz"}get(t){return e(this,void 0,void 0,function*(){if(!this.store.config)return this.logger.log("error","Config is not set"),null;try{const e=yield fetch(`${this.baseURL}${t}`,{method:"GET",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":n}});return yield e.json()}catch(e){this.logger.log("error",e)}return null})}post(t,n){return e(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;const i="/api/sdk/init"===e;if(!i&&!this.initComplete)return new Promise((r,o)=>{this.requestQueue.push({url:e,data:t,fireAndForget:n,resolve:r,reject:o,isInit:i}),this.processQueue()});if(i){const i=yield this.executePost(e,t,n);return this.initComplete=!0,yield this.processQueue(),i}return this.executePost(e,t,n)})}processQueue(){return e(this,void 0,void 0,function*(){if(!this.isProcessingQueue&&this.initComplete&&0!==this.requestQueue.length){this.isProcessingQueue=!0;try{const t=()=>e(this,void 0,void 0,function*(){if(0===this.requestQueue.length)return;const e=this.requestQueue.shift();try{const t=yield this.executePost(e.url,e.data,e.fireAndForget);e.resolve(t)}catch(t){e.reject(t)}yield t()});yield t()}finally{this.isProcessingQueue=!1}}})}executePost(t,i){return e(this,arguments,void 0,function*(e,t,i=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;if(i&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon){try{const n=`${this.baseURL}${e}`,i=t&&"object"==typeof t&&!Array.isArray(t)?t:{payload:t},r=JSON.stringify(Object.assign(Object.assign({},i),{_apiKey:this.store.config.apiKey})),o=new Blob([r],{type:"application/json"});navigator.sendBeacon(n,o)||this.logger.log("error","sendBeacon failed")}catch(e){this.logger.log("error",e)}return null}try{const i=yield fetch(`${this.baseURL}${e}`,{method:"POST",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":n},body:JSON.stringify(t)});return yield i.json()}catch(e){this.logger.log("error",e)}return null})}}class r{static dispatch(e){Object.keys(e).forEach(t=>{if(Object.keys(r.store).includes(t)){const n=e[t];r.store[t]="object"==typeof n?Array.isArray(n)?[...n]:Object.assign({},n):n}})}}r.store={isInitialized:!1,config:null,session:null};const o=[];for(let e=0;e<256;++e)o.push((e+256).toString(16).slice(1));let s;const a=new Uint8Array(16);var l={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function c(e,t,n){const i=(e=e||{}).random??e.rng?.()??function(){if(!s){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");s=crypto.getRandomValues.bind(crypto)}return s(a)}();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=15&i[6]|64,i[8]=63&i[8]|128,function(e,t=0){return(o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]).toLowerCase()}(i)}const d="luci_session",u=new t(r.store);function h(){try{const e=sessionStorage.getItem(d);return e?JSON.parse(e):null}catch(e){return u.log("error","Error retrieving session data:",e),null}}function v(){var e;const t={id:l.randomUUID&&!e?l.randomUUID():c(e),timestamp:Date.now()};return sessionStorage.setItem(d,JSON.stringify(t)),t}function g(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function f(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class m{constructor(e){this.store=r.store,this.dispatch=r.dispatch,this.dispatch({config:e}),this.httpClient=new i(this.store),this.logger=new t(this.store)}}class p{constructor(e,t,n,i){this.enabled=!1,this.sdkConfig=e,this.config=t,this.callback=n,this.logger=i}enable(){this.enabled||(this.enabled=!0,this.attachListeners(),this.logger.log("log",`${this.name}: Enabled`))}disable(){this.enabled&&(this.enabled=!1,this.logger.log("log",`${this.name}: Disabled`))}destroy(){this.disable(),this.detachListeners(),this.logger.log("log",`${this.name}: Destroyed`)}isEnabled(){return this.enabled}}const w=new class{constructor(){this.registrations=new Map,this.activeTrackers=new Map,this.logger=null}register(e){this.registrations.set(e.name,e)}initAll(e,t,n){this.logger=n;for(const[i,r]of this.registrations){const o=e[r.configKey],s=r.normalizeConfig(o);if(null===s)continue;const a=t[i];if(a)try{const t=r.factory(e,s,a,n);this.activeTrackers.set(i,t),t.enable(),n.log("log",`AutoTrackerRegistry: Initialized ${i}`)}catch(e){n.log("error",`AutoTrackerRegistry: Failed to initialize ${i}`,e)}else n.log("warn",`AutoTrackerRegistry: No callback registered for ${i}`)}}get(e){return this.activeTrackers.get(e)}enable(e){const t=this.activeTrackers.get(e);return!!t&&(t.enable(),!0)}disable(e){const t=this.activeTrackers.get(e);return!!t&&(t.disable(),!0)}destroyAll(){var e;for(const[t,n]of this.activeTrackers)try{n.destroy()}catch(n){null===(e=this.logger)||void 0===e||e.log("error",`AutoTrackerRegistry: Error destroying ${t}`,n)}this.activeTrackers.clear()}getRegisteredTrackers(){return Array.from(this.registrations.keys())}getActiveTrackers(){return Array.from(this.activeTrackers.keys())}reset(){this.destroyAll(),this.logger=null}},y=['input[type="password"]','input[type="text"][autocomplete*="cc-"]','input[type="text"][autocomplete*="card"]','input[type="text"][name*="card"]','input[type="text"][name*="cvv"]','input[type="text"][name*="cvc"]','input[name*="ssn"]','input[name*="social"]',"[data-sensitive]","[data-private]"],b=[/\b\d{3}-\d{2}-\d{4}\b/,/\b\d{4}[\s-]\d{4}[\s-]\d{4}[\s-]\d{4}\b/,/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i];const k=new class{constructor(e=[]){this.sensitiveSelectors=[...y,...e]}isSensitive(e){if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;let t=e.parentElement;for(;t;){const e=t;if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;t=t.parentElement}return!1}containsSensitiveData(e){return!!e&&b.some(t=>t.test(e))}sanitizeText(e){if(!e)return"";let t=e;return t=t.replace(/\b\d{3}-\d{2}-\d{4}\b/g,"***-**-****"),t=t.replace(/\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,"****-****-****-****"),t=t.replace(/\b([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,})\b/gi,"***@$2"),t}},C=["button","a[href]",'[role="button"]'],T=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class A extends p{constructor(e,t,n,i){var r,o,s;super(e,{enabled:null===(r=t.enabled)||void 0===r||r,selectors:null!==(o=t.selectors)&&void 0!==o?o:C,ignore:null!==(s=t.ignore)&&void 0!==s?s:T},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=k}attachListeners(){this.listenerAttached||("undefined"!=typeof document?(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,{passive:!0,capture:!1}),this.listenerAttached=!0,this.logger.log("log","ClickTracker: Delegated click listener attached")):this.logger.log("warn","ClickTracker: document not available, cannot attach listener"))}detachListeners(){this.listenerAttached&&this.boundHandleClick&&"undefined"!=typeof document&&(document.removeEventListener("click",this.boundHandleClick),this.listenerAttached=!1),this.debounceTimers.clear(),this.boundHandleClick=null}handleClick(e){if(!this.enabled)return;const t=e.target;if(!t)return;const n=this.findTrackableElement(t);if(!n)return;if(this.shouldIgnore(n))return void this.logger.log("log","ClickTracker: Element ignored",n);if(this.privacyGuard.isSensitive(n))return void this.logger.log("warn","ClickTracker: Sensitive element not tracked",n);if(this.isDebounced(n))return void this.logger.log("log","ClickTracker: Click debounced",n);const i=this.extractTrackingData(n);i&&(this.logger.log("log","ClickTracker: Tracking click",i),this.callback(i))}findTrackableElement(e){const t=this.config.selectors||C;try{const n=e.closest('[data-lucia-track]:not([data-lucia-track="false"])');if(n&&n!==document.body&&document.body.contains(n)){if(this.config.selectors&&this.config.selectors!==C){return t.some(e=>{try{return n.matches(e)}catch(e){return!1}})?n:null}return n}const i=t.join(", "),r=e.closest(i);return r&&r!==document.body&&document.body.contains(r)?r:null}catch(t){this.logger.log("warn","ClickTracker: Invalid combined selector, using fallback",t);let n=e;for(;n&&n!==document.body;){if(this.isTrackable(n))return n;n=n.parentElement}return null}}isTrackable(e){return(this.config.selectors||C).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid selector "${t}"`,e),!1}})}shouldIgnore(e){return(this.config.ignore||T).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid ignore selector "${t}"`,e),!1}})}isDebounced(e){const t=Date.now(),n=this.debounceTimers.get(e);return!!(n&&t-n<500)||(this.debounceTimers.set(e,t),this.debounceTimers.size>100&&this.cleanupDebounceTimers(),!1)}cleanupDebounceTimers(){const e=Date.now();Array.from(this.debounceTimers.entries()).forEach(([t,n])=>{e-n>1e3&&this.debounceTimers.delete(t)})}extractTrackingData(e){var t;const n=this.getElementIdentifier(e);if(!n)return this.logger.log("warn","ClickTracker: Could not generate identifier for element",e),null;const i={button:n,elementType:this.getElementType(e),timestamp:Date.now()},r=null===(t=e.textContent)||void 0===t?void 0:t.trim();r&&(this.privacyGuard.containsSensitiveData(r)||(i.text=this.sanitizeText(r))),"a"===e.tagName.toLowerCase()?i.href=e.getAttribute("href"):i.href=null;const o=this.extractMetadata(e);return o&&Object.keys(o).length>0&&(i.meta=o),i}getElementIdentifier(e){var t;const n=e.getAttribute("data-lucia-track");if(n&&"false"!==n)return n;const i=e.getAttribute("id");if(i)return i;const r=e.getAttribute("name");if(r)return r;const o=e.getAttribute("aria-label");if(o)return o;if("a"===e.tagName.toLowerCase()){const t=e.getAttribute("href");if(t)return`link:${t}`}const s=null===(t=e.textContent)||void 0===t?void 0:t.trim();if(s)return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using text content as identifier for element. Consider adding data-lucia-track attribute.",e),`text:${this.sanitizeText(s).substring(0,50)}`;const a=this.generateCSSPath(e);return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using CSS path as identifier. Consider adding data-lucia-track attribute.",e),`path:${a}`}getElementType(e){const t=e.tagName.toLowerCase();if("a"===t)return"link";if("button"===t)return"button";const n=e.getAttribute("role");return n||t}sanitizeText(e){return e.trim().replace(/\s+/g," ").substring(0,100)}generateCSSPath(e){const t=[];let n=e;for(;n&&n!==document.body&&t.length<5;){let e=n.tagName.toLowerCase();if(n.id){e+=`#${n.id}`,t.unshift(e);break}const i=n.getAttribute("class");if(i){const t=i.trim().split(/\s+/).slice(0,2);t.length>0&&(e+=`.${t.join(".")}`)}t.unshift(e),n=n.parentElement}return t.join(" > ")}extractMetadata(e){const t={},{attributes:n}=e;return Array.from(n).forEach(e=>{if(e.name.startsWith("data-lucia-meta-")){const n=e.name.replace("data-lucia-meta-","").replace(/-([a-z])/g,e=>e[1].toUpperCase());t[n]=e.value}}),Object.keys(t).length>0?t:null}}const P={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new A(e,t,n,i),normalizeConfig:function(e){return void 0===e||!1===e?null:!0===e?{enabled:!0}:!1===e.enabled?null:e}};function I(){return e(this,void 0,void 0,function*(){if(x)return x;const e={device:{cores:E(()=>navigator.hardwareConcurrency),memory:E(()=>navigator.deviceMemory),cpuClass:E(()=>navigator.cpuClass),touch:O(),devicePixelRatio:E(()=>window.devicePixelRatio)},screen:{width:E(()=>window.screen.width),height:E(()=>window.screen.height),colorDepth:E(()=>window.screen.colorDepth),availHeight:E(()=>window.screen.availHeight),availWidth:E(()=>window.screen.availWidth),orientation:{type:E(()=>window.screen.orientation.type),angle:E(()=>window.screen.orientation.angle)}},browser:{language:E(()=>navigator.language),encoding:E(()=>TextDecoder.encoding),timezone:E(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:E(()=>navigator.plugins.length),pluginNames:E(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:j(),uniqueHash:yield L(),colorGamut:W(),contrastPreference:D()},permissions:{navPer:E(()=>navigator.permissions.webglVersion),renderedPer:E(()=>navigator.permissions.RENDERER),geoPer:E(()=>navigator.permissions.geolocation)},storage:{localStorage:E(()=>!!window.localStorage),indexedDB:E(()=>!!window.indexedDB),openDB:E(()=>window.openDatabase)}};return x=e,e})}function S(){const e=new URL(window.location.href).searchParams,t={};return e.forEach((e,n)=>{(n.startsWith("utm_")||n.includes("id")||"ref"===n||"source"===n)&&(t[n]=e)}),t}function E(e,t){try{return e()}catch(e){return t}}let x=null;function L(){return e(this,void 0,void 0,function*(){try{const t=document.createElement("canvas"),n=t.getContext("2d",{willReadFrequently:!0});if(!n)return;const i=200,r=120;t.width=i,t.height=r,t.style.width=`${i}px`,t.style.height=`${r}px`,n.fillStyle="#ffffff",n.fillRect(0,0,i,r),n.fillStyle="#ff00ff",n.fillRect(10,10,100,100),n.fillStyle="#00ffff",n.beginPath(),n.arc(150,50,40,0,2*Math.PI,!0),n.fill();const{data:o}=n.getImageData(0,0,i,r);return function(t){return e(this,void 0,void 0,function*(){const e=(new TextEncoder).encode(t),n=yield crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("")})}([[20,20],[60,60],[100,100],[150,50],[150,60],[140,50],[5,5]].map(([e,t])=>{const n=4*(t*i+e);return`${o[n]},${o[n+1]},${o[n+2]},${o[n+3]};`}).join(""))}catch(e){return}})}function O(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function j(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function D(){try{const{matchMedia:e}=window,t=t=>e(`(prefers-contrast: ${t})`).matches;return t("no-preference")?"None":t("high")||t("more")?"More":t("low")||t("less")?"Less":t("forced")?"ForcedColors":void 0}catch(e){return}}function W(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const R=new Map;let U=null,$=!1;function M(){return new Map(R)}const _=[{name:"Rabby",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRabby)}},{name:"Brave Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBraveWallet)}},{name:"Rainbow",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRainbow)}},{name:"Coinbase Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoinbaseWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCoinbase)}},{name:"Trust Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTrust)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTrustWallet)}},{name:"TokenPocket",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTokenPocket)}},{name:"Zerion",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isZerion)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isPhantom)}},{name:"OKX Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOkxWallet)}},{name:"Bitget Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBitKeep)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isBitgetWallet)}},{name:"SafePal",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isSafePal)}},{name:"Frontier",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrontier)}},{name:"XDEFI",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isXDEFI)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCtrl)}},{name:"Enkrypt",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isEnkrypt)}},{name:"MetaMask",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMetaMask)}},{name:"WalletConnect",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isWalletConnect)}},{name:"imToken",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isImToken)}},{name:"Status",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isStatus)}},{name:"Tally",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTally)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTallyWallet)}},{name:"AlphaWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isAlphaWallet)}},{name:"Opera",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOpera)}},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoin98)}},{name:"MathWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMathWallet)}},{name:"1inch Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOneInchIOSWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isOneInchAndroidWallet)}},{name:"Frame",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrame)}},{name:"Binance Chain Wallet",detect:()=>!!window.BinanceChain},{name:"MetaMask",detect:()=>{var e;return Object.prototype.hasOwnProperty.call(null!==(e=window.ethereum)&&void 0!==e?e:{},"_metamask")}}],K=[{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.phantom)||void 0===e?void 0:e.solana)}},{name:"Solflare",detect:()=>!!window.solflare},{name:"Backpack",detect:()=>!!window.backpack},{name:"Glow",detect:()=>!!window.glow},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isCoin98)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isPhantom)}}];function N(){var e,t;return window.ethereum&&null!==(t=null===(e=_.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}function q(){var e,t;return null!==(t=null===(e=K.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}w.register(P);let B=class extends m{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}authenticate(){this.httpClient.post("/api/key/auth",{})}init(){return e(this,void 0,void 0,function*(){let e=h();e||(e=v());try{$||($=!0,U=e=>{var t;const n=e.detail;(null===(t=null==n?void 0:n.info)||void 0===t?void 0:t.rdns)&&(null==n?void 0:n.provider)&&R.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",U),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield I(),n=new URL(window.location.href).searchParams.get("lucia"),i={id:e.id};e.hash&&(i.hash=e.hash);const r=g(),o=yield this.httpClient.post("/api/sdk/init",Object.assign({user:{name:f()},data:t,session:i,redirectHash:n,utm:S()},r&&{lid:r}),!1);o&&(o.lid&&localStorage.setItem("lid",o.lid),o.session&&function(e){const t={id:e.id,hash:e.hash,timestamp:Date.now()};sessionStorage.setItem(d,JSON.stringify(t))}(o.session)),w.initAll(this.store.config,{clicks:this.handleAutoTrackedClick.bind(this)},this.logger),yield this.autoDetectWallets(),this.setupWalletListeners()})}handleAutoTrackedClick(e){const t=e,n={elementType:t.elementType,text:t.text,href:t.href,meta:t.meta};this.buttonClick(t.button,n)}autoDetectWallets(){return e(this,void 0,void 0,function*(){var t,n,i;try{const t=yield function(){return e(this,void 0,void 0,function*(){const e=Array.from(R.values());if(0===e.length)return[];const t=yield Promise.allSettled(e.map(({info:e,provider:t})=>{const n=t.request({method:"eth_accounts"}).then(n=>{const i=n;return Array.isArray(i)?i.filter(e=>"string"==typeof e&&e.length>0).map(n=>({address:n,providerName:e.name,providerRdns:e.rdns,provider:t})):[]}),i=new Promise((t,n)=>setTimeout(()=>n(new Error(`EIP-6963 timeout: ${e.name}`)),3e3));return Promise.race([n,i])})),n=[];for(const e of t)"fulfilled"===e.status&&n.push(...e.value);return n})}();for(const e of t)yield this.sendWalletInfo(e.address,{provider:e.providerName,providerRdns:e.providerRdns})}catch(e){}if(0===M().size&&(null===(t=window.ethereum)||void 0===t?void 0:t.selectedAddress))try{const e=N();yield this.sendWalletInfo(window.ethereum.selectedAddress,{provider:null!=e?e:void 0})}catch(e){}if((null===(n=window.solana)||void 0===n?void 0:n.isConnected)&&(null===(i=window.solana)||void 0===i?void 0:i.publicKey))try{const e=q();yield this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0})}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){var e,t;const n=function(e){const t=t=>{var n;const i=t.detail;(null===(n=null==i?void 0:i.info)||void 0===n?void 0:n.rdns)&&(null==i?void 0:i.provider)&&(R.set(i.info.rdns,i),e(i))};return window.addEventListener("eip6963:announceProvider",t),()=>window.removeEventListener("eip6963:announceProvider",t)}(e=>{this.handleLateEIP6963Provider(e)});if(this.walletListenerCleanups.push(n),(null===(e=window.ethereum)||void 0===e?void 0:e.on)&&0===M().size){const e=e=>{const t=e;if(t[0]){const e=t[0],n=N();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};window.ethereum.on("accountsChanged",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"accountsChanged",e)})}if(null===(t=window.solana)||void 0===t?void 0:t.on){const e=()=>{var e;if(null===(e=window.solana)||void 0===e?void 0:e.publicKey){const e=q();this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0}).catch(()=>{})}};window.solana.on("connect",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"connect",e)})}}setupEIP6963AccountListeners(){const e=M();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e;n.request&&n.request({method:"eth_accounts"}).then(e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})}).catch(()=>{}),this.attachEIP6963AccountsChanged(e)}attachEIP6963AccountsChanged(e){const{info:t,provider:n}=e;if(!n.on)return;const i=e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})};n.on("accountsChanged",i),this.walletListenerCleanups.push(()=>{var e;null===(e=n.removeListener)||void 0===e||e.call(n,"accountsChanged",i)})}userInfo(t,n){return e(this,void 0,void 0,function*(){const e=g(),i=h();t&&localStorage.setItem("luc_uid",t);const r=Object.assign({user:{name:t,userInfo:n},session:i},e&&{lid:e});yield this.httpClient.post("/api/sdk/user",r)})}pageView(t){return e(this,void 0,void 0,function*(){const e=g(),n=h(),i=Object.assign({page:t,user:{name:f()},session:n},e&&{lid:e});yield this.httpClient.post("/api/sdk/page",i)})}trackConversion(t,n,i){return e(this,void 0,void 0,function*(){const e=g(),r=h(),o=Object.assign({tag:t,amount:n,event:i,user:{name:f()},session:r},e&&{lid:e});yield this.httpClient.post("/api/sdk/conversion",o)})}buttonClick(t,n){return e(this,void 0,void 0,function*(){const e=g(),i=h(),r=Object.assign(Object.assign({button:t,user:{name:f()},session:i},e&&{lid:e}),n&&Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n.elementType&&{elementType:n.elementType}),n.text&&{text:n.text}),void 0!==n.href&&{href:n.href}),n.meta&&{meta:n.meta}),{timestamp:Date.now()}));yield this.httpClient.post("/api/sdk/click",r)})}sendWalletInfo(t,n,i){return e(this,void 0,void 0,function*(){var e,r,o;if(!t||"string"!=typeof t)return;const s=t.startsWith("0x")?t.toLowerCase():t;if(this.sentWallets.has(s))return;this.sentWallets.add(s);let a={};n&&"object"==typeof n?a=n:void 0!==n&&(a={chainId:"number"==typeof n?n:void 0,provider:i});const l=g(),c=h(),d=Object.assign(Object.assign(Object.assign(Object.assign({walletAddress:t,provider:null!==(e=a.provider)&&void 0!==e?e:null,providerRdns:null!==(r=a.providerRdns)&&void 0!==r?r:null,connectorType:null!==(o=a.connectorType)&&void 0!==o?o:null},null!=a.chainId&&{chainId:a.chainId}),i&&{walletName:i}),{user:{name:f()},session:c}),l&&{lid:l});try{yield this.httpClient.post("/api/sdk/wallet",d)}catch(e){throw this.sentWallets.delete(s),e}})}trackUserAcquisition(t){return e(this,arguments,void 0,function*(e,t={}){const n=yield I(),i=S(),r=h();yield this.httpClient.post("/api/sdk/acquisition",{user:{name:e},session:r,data:Object.assign({timestamp:(new Date).toISOString(),browserData:n,utmParams:i},t)})})}checkMetaMaskConnection(){var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))}destroy(){w.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),$&&(U&&(window.removeEventListener("eip6963:announceProvider",U),U=null),R.clear(),$=!1)}},z=null;const F=()=>{const e=z||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},Q={init:t=>{if("undefined"==typeof window)return Promise.reject(new Error("LuciaSDK requires a browser environment"));if(z)return z;if(window.__luciaInitPromise)return z=window.__luciaInitPromise,z;if(!(null==t?void 0:t.apiKey))return Promise.reject(new Error("apiKey is required in config"));const n=e(void 0,void 0,void 0,function*(){const e=new B(t);return yield e.init(),e});return z=n,window.__luciaInitPromise=n,n},userInfo:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield F()).userInfo(t,n)}),pageView:t=>e(void 0,void 0,void 0,function*(){return(yield F()).pageView(t)}),trackConversion:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield F()).trackConversion(t,n,i)}),buttonClick:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield F()).buttonClick(t,n)}),sendWalletInfo:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield F()).sendWalletInfo(t,n,i)}),trackUserAcquisition:(t,...n)=>e(void 0,[t,...n],void 0,function*(e,t={}){return(yield F()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>{var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))},VERSION:n};if("undefined"!=typeof window){window.LuciaSDK=Q;const e=()=>{const e=document.currentScript||document.querySelector("script[data-api-key]"),t=null==e?void 0:e.getAttribute("data-api-key");if(!t)return;const n=e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");Q.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{debugURL:n}),"true"===i&&{autoTrackClicks:!r||{enabled:!0,selectors:r.split(",").map(e=>e.trim())}}),"false"===i&&{autoTrackClicks:!1})).catch(e=>console.error("LuciaSDK auto-init failed:",e))};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}exports.__resetInstance=()=>{const e=z||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),z=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,w.reset()},exports.default=Q,exports.detectEvmProvider=N,exports.detectSolanaProvider=q,exports.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},exports.getApplePayAvailable=j,exports.getBrowserData=I,exports.getCanvasFingerprint=L,exports.getColorGamut=W,exports.getContrastPreference=D,exports.getUtmParams=S,exports.isTouchEnabled=O,exports.safeAccess=E;
2
2
  //# sourceMappingURL=index.js.map
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucia-sdk",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "description": "Lucia JavaScript Library",
6
6
  "repository": {
@@ -37,24 +37,24 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@commitlint/config-conventional": "^20.2.0",
40
+ "@eslint/js": "^10.0.1",
40
41
  "@release-it/conventional-changelog": "^10.0.4",
41
42
  "@rollup/plugin-commonjs": "^29.0.0",
42
43
  "@rollup/plugin-node-resolve": "^16.0.3",
43
44
  "@rollup/plugin-replace": "^6.0.3",
44
- "@rollup/plugin-terser": "^0.4.4",
45
+ "@rollup/plugin-terser": "^1.0.0",
45
46
  "@testing-library/jest-dom": "^6.9.1",
46
47
  "@types/jest": "^30.0.0",
47
48
  "@types/uuid": "^11.0.0",
48
49
  "@typescript-eslint/eslint-plugin": "^8.50.1",
49
50
  "@typescript-eslint/parser": "^8.50.1",
50
- "typescript-eslint": "^8.50.1",
51
51
  "commitlint": "^20.2.0",
52
- "eslint": "^9.39.2",
52
+ "eslint": "^10.0.0",
53
53
  "eslint-config-prettier": "^10.1.8",
54
54
  "eslint-plugin-import": "^2.32.0",
55
55
  "eslint-plugin-jest": "^29.11.0",
56
56
  "eslint-plugin-promise": "^7.2.1",
57
- "eslint-plugin-unicorn": "^62.0.0",
57
+ "eslint-plugin-unicorn": "^63.0.0",
58
58
  "eslint-plugin-unused-imports": "^4.3.0",
59
59
  "husky": "^9.1.7",
60
60
  "jest": "^30.2.0",
@@ -66,7 +66,8 @@
66
66
  "rollup": "^4.54.0",
67
67
  "rollup-plugin-typescript2": "^0.36.0",
68
68
  "ts-jest": "^29.4.6",
69
- "typescript": "^5.9.3"
69
+ "typescript": "^5.9.3",
70
+ "typescript-eslint": "^8.50.1"
70
71
  },
71
72
  "dependencies": {
72
73
  "uuid": "^13.0.0"
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LuciaSDK={})}(this,function(e){"use strict";function t(e,t,n,i){return new(n||(n=Promise))(function(r,o){function s(e){try{l(i.next(e))}catch(e){o(e)}}function a(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class n{constructor(e){this.store=e}log(e,...t){var n;(null===(n=this.store.config)||void 0===n?void 0:n.debug)&&console[e](t)}}const i="0.10.0";class r{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new n(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"http://52.22.177.60/fk":"https://api.clickinsights.xyz"}get(e){return t(this,void 0,void 0,function*(){if(!this.store.config)return this.logger.log("error","Config is not set"),null;try{const t=yield fetch(`${this.baseURL}${e}`,{method:"GET",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":i}});return yield t.json()}catch(e){this.logger.log("error",e)}return null})}post(e,n){return t(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;const i="/api/sdk/init"===e;if(!i&&!this.initComplete)return new Promise((r,o)=>{this.requestQueue.push({url:e,data:t,fireAndForget:n,resolve:r,reject:o,isInit:i}),this.processQueue()});if(i){const i=yield this.executePost(e,t,n);return this.initComplete=!0,yield this.processQueue(),i}return this.executePost(e,t,n)})}processQueue(){return t(this,void 0,void 0,function*(){if(!this.isProcessingQueue&&this.initComplete&&0!==this.requestQueue.length){this.isProcessingQueue=!0;try{const e=()=>t(this,void 0,void 0,function*(){if(0===this.requestQueue.length)return;const t=this.requestQueue.shift();try{const e=yield this.executePost(t.url,t.data,t.fireAndForget);t.resolve(e)}catch(e){t.reject(e)}yield e()});yield e()}finally{this.isProcessingQueue=!1}}})}executePost(e,n){return t(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;if(n&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon){try{const n=`${this.baseURL}${e}`,i=t&&"object"==typeof t&&!Array.isArray(t)?t:{payload:t},r=JSON.stringify(Object.assign(Object.assign({},i),{_apiKey:this.store.config.apiKey})),o=new Blob([r],{type:"application/json"});navigator.sendBeacon(n,o)||this.logger.log("error","sendBeacon failed")}catch(e){this.logger.log("error",e)}return null}try{const n=yield fetch(`${this.baseURL}${e}`,{method:"POST",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":i},body:JSON.stringify(t)});return yield n.json()}catch(e){this.logger.log("error",e)}return null})}}class o{static dispatch(e){Object.keys(e).forEach(t=>{if(Object.keys(o.store).includes(t)){const n=e[t];o.store[t]="object"==typeof n?Array.isArray(n)?[...n]:Object.assign({},n):n}})}}o.store={isInitialized:!1,config:null,session:null};const s=[];for(let e=0;e<256;++e)s.push((e+256).toString(16).slice(1));let a;const l=new Uint8Array(16);var c={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function d(e,t,n){const i=(e=e||{}).random??e.rng?.()??function(){if(!a){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");a=crypto.getRandomValues.bind(crypto)}return a(l)}();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=15&i[6]|64,i[8]=63&i[8]|128,function(e,t=0){return(s[e[t+0]]+s[e[t+1]]+s[e[t+2]]+s[e[t+3]]+"-"+s[e[t+4]]+s[e[t+5]]+"-"+s[e[t+6]]+s[e[t+7]]+"-"+s[e[t+8]]+s[e[t+9]]+"-"+s[e[t+10]]+s[e[t+11]]+s[e[t+12]]+s[e[t+13]]+s[e[t+14]]+s[e[t+15]]).toLowerCase()}(i)}const u="luci_session",h=new n(o.store);function v(){try{const e=sessionStorage.getItem(u);return e?JSON.parse(e):null}catch(e){return h.log("error","Error retrieving session data:",e),null}}function g(){var e;const t={id:c.randomUUID&&!e?c.randomUUID():d(e),timestamp:Date.now()};return sessionStorage.setItem(u,JSON.stringify(t)),t}function f(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function m(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class p{constructor(e){this.store=o.store,this.dispatch=o.dispatch,this.dispatch({config:e}),this.httpClient=new r(this.store),this.logger=new n(this.store)}}class w{constructor(e,t,n,i){this.enabled=!1,this.sdkConfig=e,this.config=t,this.callback=n,this.logger=i}enable(){this.enabled||(this.enabled=!0,this.attachListeners(),this.logger.log("log",`${this.name}: Enabled`))}disable(){this.enabled&&(this.enabled=!1,this.logger.log("log",`${this.name}: Disabled`))}destroy(){this.disable(),this.detachListeners(),this.logger.log("log",`${this.name}: Destroyed`)}isEnabled(){return this.enabled}}const y=new class{constructor(){this.registrations=new Map,this.activeTrackers=new Map,this.logger=null}register(e){this.registrations.set(e.name,e)}initAll(e,t,n){this.logger=n;for(const[i,r]of this.registrations){const o=e[r.configKey],s=r.normalizeConfig(o);if(null===s)continue;const a=t[i];if(a)try{const t=r.factory(e,s,a,n);this.activeTrackers.set(i,t),t.enable(),n.log("log",`AutoTrackerRegistry: Initialized ${i}`)}catch(e){n.log("error",`AutoTrackerRegistry: Failed to initialize ${i}`,e)}else n.log("warn",`AutoTrackerRegistry: No callback registered for ${i}`)}}get(e){return this.activeTrackers.get(e)}enable(e){const t=this.activeTrackers.get(e);return!!t&&(t.enable(),!0)}disable(e){const t=this.activeTrackers.get(e);return!!t&&(t.disable(),!0)}destroyAll(){var e;for(const[t,n]of this.activeTrackers)try{n.destroy()}catch(n){null===(e=this.logger)||void 0===e||e.log("error",`AutoTrackerRegistry: Error destroying ${t}`,n)}this.activeTrackers.clear()}getRegisteredTrackers(){return Array.from(this.registrations.keys())}getActiveTrackers(){return Array.from(this.activeTrackers.keys())}reset(){this.destroyAll(),this.logger=null}},b=['input[type="password"]','input[type="text"][autocomplete*="cc-"]','input[type="text"][autocomplete*="card"]','input[type="text"][name*="card"]','input[type="text"][name*="cvv"]','input[type="text"][name*="cvc"]','input[name*="ssn"]','input[name*="social"]',"[data-sensitive]","[data-private]"],k=[/\b\d{3}-\d{2}-\d{4}\b/,/\b\d{4}[\s-]\d{4}[\s-]\d{4}[\s-]\d{4}\b/,/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i];const C=new class{constructor(e=[]){this.sensitiveSelectors=[...b,...e]}isSensitive(e){if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;let t=e.parentElement;for(;t;){const e=t;if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;t=t.parentElement}return!1}containsSensitiveData(e){return!!e&&k.some(t=>t.test(e))}sanitizeText(e){if(!e)return"";let t=e;return t=t.replace(/\b\d{3}-\d{2}-\d{4}\b/g,"***-**-****"),t=t.replace(/\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,"****-****-****-****"),t=t.replace(/\b([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,})\b/gi,"***@$2"),t}},T=["button","a[href]",'[role="button"]'],A=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class P extends w{constructor(e,t,n,i){var r,o,s;super(e,{enabled:null===(r=t.enabled)||void 0===r||r,selectors:null!==(o=t.selectors)&&void 0!==o?o:T,ignore:null!==(s=t.ignore)&&void 0!==s?s:A},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=C}attachListeners(){this.listenerAttached||("undefined"!=typeof document?(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,{passive:!0,capture:!1}),this.listenerAttached=!0,this.logger.log("log","ClickTracker: Delegated click listener attached")):this.logger.log("warn","ClickTracker: document not available, cannot attach listener"))}detachListeners(){this.listenerAttached&&this.boundHandleClick&&"undefined"!=typeof document&&(document.removeEventListener("click",this.boundHandleClick),this.listenerAttached=!1),this.debounceTimers.clear(),this.boundHandleClick=null}handleClick(e){if(!this.enabled)return;const t=e.target;if(!t)return;const n=this.findTrackableElement(t);if(!n)return;if(this.shouldIgnore(n))return void this.logger.log("log","ClickTracker: Element ignored",n);if(this.privacyGuard.isSensitive(n))return void this.logger.log("warn","ClickTracker: Sensitive element not tracked",n);if(this.isDebounced(n))return void this.logger.log("log","ClickTracker: Click debounced",n);const i=this.extractTrackingData(n);i&&(this.logger.log("log","ClickTracker: Tracking click",i),this.callback(i))}findTrackableElement(e){const t=this.config.selectors||T;try{const n=e.closest('[data-lucia-track]:not([data-lucia-track="false"])');if(n&&n!==document.body&&document.body.contains(n)){if(this.config.selectors&&this.config.selectors!==T){return t.some(e=>{try{return n.matches(e)}catch(e){return!1}})?n:null}return n}const i=t.join(", "),r=e.closest(i);return r&&r!==document.body&&document.body.contains(r)?r:null}catch(t){this.logger.log("warn","ClickTracker: Invalid combined selector, using fallback",t);let n=e;for(;n&&n!==document.body;){if(this.isTrackable(n))return n;n=n.parentElement}return null}}isTrackable(e){return(this.config.selectors||T).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid selector "${t}"`,e),!1}})}shouldIgnore(e){return(this.config.ignore||A).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid ignore selector "${t}"`,e),!1}})}isDebounced(e){const t=Date.now(),n=this.debounceTimers.get(e);return!!(n&&t-n<500)||(this.debounceTimers.set(e,t),this.debounceTimers.size>100&&this.cleanupDebounceTimers(),!1)}cleanupDebounceTimers(){const e=Date.now();Array.from(this.debounceTimers.entries()).forEach(([t,n])=>{e-n>1e3&&this.debounceTimers.delete(t)})}extractTrackingData(e){var t;const n=this.getElementIdentifier(e);if(!n)return this.logger.log("warn","ClickTracker: Could not generate identifier for element",e),null;const i={button:n,elementType:this.getElementType(e),timestamp:Date.now()},r=null===(t=e.textContent)||void 0===t?void 0:t.trim();r&&(this.privacyGuard.containsSensitiveData(r)||(i.text=this.sanitizeText(r))),"a"===e.tagName.toLowerCase()?i.href=e.getAttribute("href"):i.href=null;const o=this.extractMetadata(e);return o&&Object.keys(o).length>0&&(i.meta=o),i}getElementIdentifier(e){var t;const n=e.getAttribute("data-lucia-track");if(n&&"false"!==n)return n;const i=e.getAttribute("id");if(i)return i;const r=e.getAttribute("name");if(r)return r;const o=e.getAttribute("aria-label");if(o)return o;if("a"===e.tagName.toLowerCase()){const t=e.getAttribute("href");if(t)return`link:${t}`}const s=null===(t=e.textContent)||void 0===t?void 0:t.trim();if(s)return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using text content as identifier for element. Consider adding data-lucia-track attribute.",e),`text:${this.sanitizeText(s).substring(0,50)}`;const a=this.generateCSSPath(e);return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using CSS path as identifier. Consider adding data-lucia-track attribute.",e),`path:${a}`}getElementType(e){const t=e.tagName.toLowerCase();if("a"===t)return"link";if("button"===t)return"button";const n=e.getAttribute("role");return n||t}sanitizeText(e){return e.trim().replace(/\s+/g," ").substring(0,100)}generateCSSPath(e){const t=[];let n=e;for(;n&&n!==document.body&&t.length<5;){let e=n.tagName.toLowerCase();if(n.id){e+=`#${n.id}`,t.unshift(e);break}const i=n.getAttribute("class");if(i){const t=i.trim().split(/\s+/).slice(0,2);t.length>0&&(e+=`.${t.join(".")}`)}t.unshift(e),n=n.parentElement}return t.join(" > ")}extractMetadata(e){const t={},{attributes:n}=e;return Array.from(n).forEach(e=>{if(e.name.startsWith("data-lucia-meta-")){const n=e.name.replace("data-lucia-meta-","").replace(/-([a-z])/g,e=>e[1].toUpperCase());t[n]=e.value}}),Object.keys(t).length>0?t:null}}const I={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new P(e,t,n,i),normalizeConfig:function(e){return void 0===e||!1===e?null:!0===e?{enabled:!0}:!1===e.enabled?null:e}};function S(){return t(this,void 0,void 0,function*(){if(O)return O;const e={device:{cores:L(()=>navigator.hardwareConcurrency),memory:L(()=>navigator.deviceMemory),cpuClass:L(()=>navigator.cpuClass),touch:D(),devicePixelRatio:L(()=>window.devicePixelRatio)},screen:{width:L(()=>window.screen.width),height:L(()=>window.screen.height),colorDepth:L(()=>window.screen.colorDepth),availHeight:L(()=>window.screen.availHeight),availWidth:L(()=>window.screen.availWidth),orientation:{type:L(()=>window.screen.orientation.type),angle:L(()=>window.screen.orientation.angle)}},browser:{language:L(()=>navigator.language),encoding:L(()=>TextDecoder.encoding),timezone:L(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:L(()=>navigator.plugins.length),pluginNames:L(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:x(),uniqueHash:yield j(),colorGamut:R(),contrastPreference:W()},permissions:{navPer:L(()=>navigator.permissions.webglVersion),renderedPer:L(()=>navigator.permissions.RENDERER),geoPer:L(()=>navigator.permissions.geolocation)},storage:{localStorage:L(()=>!!window.localStorage),indexedDB:L(()=>!!window.indexedDB),openDB:L(()=>window.openDatabase)}};return O=e,e})}function E(){const e=new URL(window.location.href).searchParams,t={};return e.forEach((e,n)=>{(n.startsWith("utm_")||n.includes("id")||"ref"===n||"source"===n)&&(t[n]=e)}),t}function L(e,t){try{return e()}catch(e){return t}}let O=null;function j(){return t(this,void 0,void 0,function*(){try{const e=document.createElement("canvas"),n=e.getContext("2d",{willReadFrequently:!0});if(!n)return;const i=200,r=120;e.width=i,e.height=r,e.style.width=`${i}px`,e.style.height=`${r}px`,n.fillStyle="#ffffff",n.fillRect(0,0,i,r),n.fillStyle="#ff00ff",n.fillRect(10,10,100,100),n.fillStyle="#00ffff",n.beginPath(),n.arc(150,50,40,0,2*Math.PI,!0),n.fill();const{data:o}=n.getImageData(0,0,i,r);return function(e){return t(this,void 0,void 0,function*(){const t=(new TextEncoder).encode(e),n=yield crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("")})}([[20,20],[60,60],[100,100],[150,50],[150,60],[140,50],[5,5]].map(([e,t])=>{const n=4*(t*i+e);return`${o[n]},${o[n+1]},${o[n+2]},${o[n+3]};`}).join(""))}catch(e){return}})}function D(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function x(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function W(){try{const{matchMedia:e}=window,t=t=>e(`(prefers-contrast: ${t})`).matches;return t("no-preference")?"None":t("high")||t("more")?"More":t("low")||t("less")?"Less":t("forced")?"ForcedColors":void 0}catch(e){return}}function R(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const U=new Map;let $=null,M=!1;function _(){return new Map(U)}const K=[{name:"Rabby",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRabby)}},{name:"Brave Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBraveWallet)}},{name:"Rainbow",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRainbow)}},{name:"Coinbase Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoinbaseWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCoinbase)}},{name:"Trust Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTrust)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTrustWallet)}},{name:"TokenPocket",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTokenPocket)}},{name:"Zerion",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isZerion)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isPhantom)}},{name:"OKX Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOkxWallet)}},{name:"Bitget Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBitKeep)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isBitgetWallet)}},{name:"SafePal",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isSafePal)}},{name:"Frontier",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrontier)}},{name:"XDEFI",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isXDEFI)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCtrl)}},{name:"Enkrypt",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isEnkrypt)}},{name:"MetaMask",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMetaMask)}},{name:"WalletConnect",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isWalletConnect)}},{name:"imToken",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isImToken)}},{name:"Status",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isStatus)}},{name:"Tally",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTally)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTallyWallet)}},{name:"AlphaWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isAlphaWallet)}},{name:"Opera",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOpera)}},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoin98)}},{name:"MathWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMathWallet)}},{name:"1inch Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOneInchIOSWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isOneInchAndroidWallet)}},{name:"Frame",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrame)}},{name:"Binance Chain Wallet",detect:()=>!!window.BinanceChain},{name:"MetaMask",detect:()=>{var e;return Object.prototype.hasOwnProperty.call(null!==(e=window.ethereum)&&void 0!==e?e:{},"_metamask")}}],N=[{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.phantom)||void 0===e?void 0:e.solana)}},{name:"Solflare",detect:()=>!!window.solflare},{name:"Backpack",detect:()=>!!window.backpack},{name:"Glow",detect:()=>!!window.glow},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isCoin98)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isPhantom)}}];function q(){var e,t;return window.ethereum&&null!==(t=null===(e=K.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}function B(){var e,t;return null!==(t=null===(e=N.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}y.register(I);let z=class extends p{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}authenticate(){this.httpClient.post("/api/key/auth",{})}init(){return t(this,void 0,void 0,function*(){let e=v();e||(e=g());try{M||(M=!0,$=e=>{var t;const n=e.detail;(null===(t=null==n?void 0:n.info)||void 0===t?void 0:t.rdns)&&(null==n?void 0:n.provider)&&U.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",$),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield S(),n=new URL(window.location.href).searchParams.get("lucia"),i={id:e.id};e.hash&&(i.hash=e.hash);const r=yield this.httpClient.post("/api/sdk/init",{user:{name:m()},data:t,session:i,redirectHash:n,utm:E()},!1);r&&(r.lid&&localStorage.setItem("lid",r.lid),r.session&&function(e){const t={id:e.id,hash:e.hash,timestamp:Date.now()};sessionStorage.setItem(u,JSON.stringify(t))}(r.session)),y.initAll(this.store.config,{clicks:this.handleAutoTrackedClick.bind(this)},this.logger),yield this.autoDetectWallets(),this.setupWalletListeners()})}handleAutoTrackedClick(e){const t=e,n={elementType:t.elementType,text:t.text,href:t.href,meta:t.meta};this.buttonClick(t.button,n)}autoDetectWallets(){return t(this,void 0,void 0,function*(){var e,n,i;try{const e=yield function(){return t(this,void 0,void 0,function*(){const e=Array.from(U.values());if(0===e.length)return[];const t=yield Promise.allSettled(e.map(({info:e,provider:t})=>{const n=t.request({method:"eth_accounts"}).then(n=>{const i=n;return Array.isArray(i)?i.filter(e=>"string"==typeof e&&e.length>0).map(n=>({address:n,providerName:e.name,providerRdns:e.rdns,provider:t})):[]}),i=new Promise((t,n)=>setTimeout(()=>n(new Error(`EIP-6963 timeout: ${e.name}`)),3e3));return Promise.race([n,i])})),n=[];for(const e of t)"fulfilled"===e.status&&n.push(...e.value);return n})}();for(const t of e)yield this.sendWalletInfo(t.address,{provider:t.providerName,providerRdns:t.providerRdns})}catch(e){}if(0===_().size&&(null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress))try{const e=q();yield this.sendWalletInfo(window.ethereum.selectedAddress,{provider:null!=e?e:void 0})}catch(e){}if((null===(n=window.solana)||void 0===n?void 0:n.isConnected)&&(null===(i=window.solana)||void 0===i?void 0:i.publicKey))try{const e=B();yield this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0})}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){var e,t;const n=function(e){const t=t=>{var n;const i=t.detail;(null===(n=null==i?void 0:i.info)||void 0===n?void 0:n.rdns)&&(null==i?void 0:i.provider)&&(U.set(i.info.rdns,i),e(i))};return window.addEventListener("eip6963:announceProvider",t),()=>window.removeEventListener("eip6963:announceProvider",t)}(e=>{this.handleLateEIP6963Provider(e)});if(this.walletListenerCleanups.push(n),(null===(e=window.ethereum)||void 0===e?void 0:e.on)&&0===_().size){const e=e=>{const t=e;if(t[0]){const e=t[0],n=q();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};window.ethereum.on("accountsChanged",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"accountsChanged",e)})}if(null===(t=window.solana)||void 0===t?void 0:t.on){const e=()=>{var e;if(null===(e=window.solana)||void 0===e?void 0:e.publicKey){const e=B();this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0}).catch(()=>{})}};window.solana.on("connect",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"connect",e)})}}setupEIP6963AccountListeners(){const e=_();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e;n.request&&n.request({method:"eth_accounts"}).then(e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})}).catch(()=>{}),this.attachEIP6963AccountsChanged(e)}attachEIP6963AccountsChanged(e){const{info:t,provider:n}=e;if(!n.on)return;const i=e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})};n.on("accountsChanged",i),this.walletListenerCleanups.push(()=>{var e;null===(e=n.removeListener)||void 0===e||e.call(n,"accountsChanged",i)})}userInfo(e,n){return t(this,void 0,void 0,function*(){const t=f(),i=v();e&&localStorage.setItem("luc_uid",e);const r=Object.assign({user:{name:e,userInfo:n},session:i},t&&{lid:t});yield this.httpClient.post("/api/sdk/user",r)})}pageView(e){return t(this,void 0,void 0,function*(){const t=f(),n=v(),i=Object.assign({page:e,user:{name:m()},session:n},t&&{lid:t});yield this.httpClient.post("/api/sdk/page",i)})}trackConversion(e,n,i){return t(this,void 0,void 0,function*(){const t=f(),r=v(),o=Object.assign({tag:e,amount:n,event:i,user:{name:m()},session:r},t&&{lid:t});yield this.httpClient.post("/api/sdk/conversion",o)})}buttonClick(e,n){return t(this,void 0,void 0,function*(){const t=f(),i=v(),r=Object.assign(Object.assign({button:e,user:{name:m()},session:i},t&&{lid:t}),n&&Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n.elementType&&{elementType:n.elementType}),n.text&&{text:n.text}),void 0!==n.href&&{href:n.href}),n.meta&&{meta:n.meta}),{timestamp:Date.now()}));yield this.httpClient.post("/api/sdk/click",r)})}sendWalletInfo(e,n,i){return t(this,void 0,void 0,function*(){var t,r,o;if(!e||"string"!=typeof e)return;const s=e.startsWith("0x")?e.toLowerCase():e;if(this.sentWallets.has(s))return;this.sentWallets.add(s);let a={};n&&"object"==typeof n?a=n:void 0!==n&&(a={chainId:"number"==typeof n?n:void 0,provider:i});const l=f(),c=v(),d=Object.assign(Object.assign(Object.assign(Object.assign({walletAddress:e,provider:null!==(t=a.provider)&&void 0!==t?t:null,providerRdns:null!==(r=a.providerRdns)&&void 0!==r?r:null,connectorType:null!==(o=a.connectorType)&&void 0!==o?o:null},null!=a.chainId&&{chainId:a.chainId}),i&&{walletName:i}),{user:{name:m()},session:c}),l&&{lid:l});try{yield this.httpClient.post("/api/sdk/wallet",d)}catch(e){throw this.sentWallets.delete(s),e}})}trackUserAcquisition(e){return t(this,arguments,void 0,function*(e,t={}){const n=yield S(),i=E(),r=v();yield this.httpClient.post("/api/sdk/acquisition",{user:{name:e},session:r,data:Object.assign({timestamp:(new Date).toISOString(),browserData:n,utmParams:i},t)})})}checkMetaMaskConnection(){var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))}destroy(){y.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),M&&($&&(window.removeEventListener("eip6963:announceProvider",$),$=null),U.clear(),M=!1)}},F=null;const Q=()=>{const e=F||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},H={init:e=>{if("undefined"==typeof window)return Promise.reject(new Error("LuciaSDK requires a browser environment"));if(F)return F;if(window.__luciaInitPromise)return F=window.__luciaInitPromise,F;if(!(null==e?void 0:e.apiKey))return Promise.reject(new Error("apiKey is required in config"));const n=t(void 0,void 0,void 0,function*(){const t=new z(e);return yield t.init(),t});return F=n,window.__luciaInitPromise=n,n},userInfo:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield Q()).userInfo(e,n)}),pageView:e=>t(void 0,void 0,void 0,function*(){return(yield Q()).pageView(e)}),trackConversion:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield Q()).trackConversion(e,n,i)}),buttonClick:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield Q()).buttonClick(e,n)}),sendWalletInfo:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield Q()).sendWalletInfo(e,n,i)}),trackUserAcquisition:(e,...n)=>t(void 0,[e,...n],void 0,function*(e,t={}){return(yield Q()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>{var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))},VERSION:i};if("undefined"!=typeof window){window.LuciaSDK=H;const e=()=>{const e=document.currentScript||document.querySelector("script[data-api-key]"),t=null==e?void 0:e.getAttribute("data-api-key");if(!t)return;const n=e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");H.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{debugURL:n}),"true"===i&&{autoTrackClicks:!r||{enabled:!0,selectors:r.split(",").map(e=>e.trim())}}),"false"===i&&{autoTrackClicks:!1})).catch(e=>console.error("LuciaSDK auto-init failed:",e))};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}e.__resetInstance=()=>{const e=F||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),F=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,y.reset()},e.default=H,e.detectEvmProvider=q,e.detectSolanaProvider=B,e.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},e.getApplePayAvailable=x,e.getBrowserData=S,e.getCanvasFingerprint=j,e.getColorGamut=R,e.getContrastPreference=W,e.getUtmParams=E,e.isTouchEnabled=D,e.safeAccess=L,Object.defineProperty(e,"__esModule",{value:!0})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LuciaSDK={})}(this,function(e){"use strict";function t(e,t,n,i){return new(n||(n=Promise))(function(r,o){function s(e){try{l(i.next(e))}catch(e){o(e)}}function a(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class n{constructor(e){this.store=e}log(e,...t){var n;(null===(n=this.store.config)||void 0===n?void 0:n.debug)&&console[e](t)}}const i="0.10.2";class r{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new n(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"http://52.22.177.60/fk":"https://api.clickinsights.xyz"}get(e){return t(this,void 0,void 0,function*(){if(!this.store.config)return this.logger.log("error","Config is not set"),null;try{const t=yield fetch(`${this.baseURL}${e}`,{method:"GET",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":i}});return yield t.json()}catch(e){this.logger.log("error",e)}return null})}post(e,n){return t(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;const i="/api/sdk/init"===e;if(!i&&!this.initComplete)return new Promise((r,o)=>{this.requestQueue.push({url:e,data:t,fireAndForget:n,resolve:r,reject:o,isInit:i}),this.processQueue()});if(i){const i=yield this.executePost(e,t,n);return this.initComplete=!0,yield this.processQueue(),i}return this.executePost(e,t,n)})}processQueue(){return t(this,void 0,void 0,function*(){if(!this.isProcessingQueue&&this.initComplete&&0!==this.requestQueue.length){this.isProcessingQueue=!0;try{const e=()=>t(this,void 0,void 0,function*(){if(0===this.requestQueue.length)return;const t=this.requestQueue.shift();try{const e=yield this.executePost(t.url,t.data,t.fireAndForget);t.resolve(e)}catch(e){t.reject(e)}yield e()});yield e()}finally{this.isProcessingQueue=!1}}})}executePost(e,n){return t(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;if(n&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon){try{const n=`${this.baseURL}${e}`,i=t&&"object"==typeof t&&!Array.isArray(t)?t:{payload:t},r=JSON.stringify(Object.assign(Object.assign({},i),{_apiKey:this.store.config.apiKey})),o=new Blob([r],{type:"application/json"});navigator.sendBeacon(n,o)||this.logger.log("error","sendBeacon failed")}catch(e){this.logger.log("error",e)}return null}try{const n=yield fetch(`${this.baseURL}${e}`,{method:"POST",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":i},body:JSON.stringify(t)});return yield n.json()}catch(e){this.logger.log("error",e)}return null})}}class o{static dispatch(e){Object.keys(e).forEach(t=>{if(Object.keys(o.store).includes(t)){const n=e[t];o.store[t]="object"==typeof n?Array.isArray(n)?[...n]:Object.assign({},n):n}})}}o.store={isInitialized:!1,config:null,session:null};const s=[];for(let e=0;e<256;++e)s.push((e+256).toString(16).slice(1));let a;const l=new Uint8Array(16);var c={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function d(e,t,n){const i=(e=e||{}).random??e.rng?.()??function(){if(!a){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");a=crypto.getRandomValues.bind(crypto)}return a(l)}();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=15&i[6]|64,i[8]=63&i[8]|128,function(e,t=0){return(s[e[t+0]]+s[e[t+1]]+s[e[t+2]]+s[e[t+3]]+"-"+s[e[t+4]]+s[e[t+5]]+"-"+s[e[t+6]]+s[e[t+7]]+"-"+s[e[t+8]]+s[e[t+9]]+"-"+s[e[t+10]]+s[e[t+11]]+s[e[t+12]]+s[e[t+13]]+s[e[t+14]]+s[e[t+15]]).toLowerCase()}(i)}const u="luci_session",h=new n(o.store);function v(){try{const e=sessionStorage.getItem(u);return e?JSON.parse(e):null}catch(e){return h.log("error","Error retrieving session data:",e),null}}function g(){var e;const t={id:c.randomUUID&&!e?c.randomUUID():d(e),timestamp:Date.now()};return sessionStorage.setItem(u,JSON.stringify(t)),t}function f(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function m(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class p{constructor(e){this.store=o.store,this.dispatch=o.dispatch,this.dispatch({config:e}),this.httpClient=new r(this.store),this.logger=new n(this.store)}}class w{constructor(e,t,n,i){this.enabled=!1,this.sdkConfig=e,this.config=t,this.callback=n,this.logger=i}enable(){this.enabled||(this.enabled=!0,this.attachListeners(),this.logger.log("log",`${this.name}: Enabled`))}disable(){this.enabled&&(this.enabled=!1,this.logger.log("log",`${this.name}: Disabled`))}destroy(){this.disable(),this.detachListeners(),this.logger.log("log",`${this.name}: Destroyed`)}isEnabled(){return this.enabled}}const y=new class{constructor(){this.registrations=new Map,this.activeTrackers=new Map,this.logger=null}register(e){this.registrations.set(e.name,e)}initAll(e,t,n){this.logger=n;for(const[i,r]of this.registrations){const o=e[r.configKey],s=r.normalizeConfig(o);if(null===s)continue;const a=t[i];if(a)try{const t=r.factory(e,s,a,n);this.activeTrackers.set(i,t),t.enable(),n.log("log",`AutoTrackerRegistry: Initialized ${i}`)}catch(e){n.log("error",`AutoTrackerRegistry: Failed to initialize ${i}`,e)}else n.log("warn",`AutoTrackerRegistry: No callback registered for ${i}`)}}get(e){return this.activeTrackers.get(e)}enable(e){const t=this.activeTrackers.get(e);return!!t&&(t.enable(),!0)}disable(e){const t=this.activeTrackers.get(e);return!!t&&(t.disable(),!0)}destroyAll(){var e;for(const[t,n]of this.activeTrackers)try{n.destroy()}catch(n){null===(e=this.logger)||void 0===e||e.log("error",`AutoTrackerRegistry: Error destroying ${t}`,n)}this.activeTrackers.clear()}getRegisteredTrackers(){return Array.from(this.registrations.keys())}getActiveTrackers(){return Array.from(this.activeTrackers.keys())}reset(){this.destroyAll(),this.logger=null}},b=['input[type="password"]','input[type="text"][autocomplete*="cc-"]','input[type="text"][autocomplete*="card"]','input[type="text"][name*="card"]','input[type="text"][name*="cvv"]','input[type="text"][name*="cvc"]','input[name*="ssn"]','input[name*="social"]',"[data-sensitive]","[data-private]"],k=[/\b\d{3}-\d{2}-\d{4}\b/,/\b\d{4}[\s-]\d{4}[\s-]\d{4}[\s-]\d{4}\b/,/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i];const C=new class{constructor(e=[]){this.sensitiveSelectors=[...b,...e]}isSensitive(e){if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;let t=e.parentElement;for(;t;){const e=t;if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;t=t.parentElement}return!1}containsSensitiveData(e){return!!e&&k.some(t=>t.test(e))}sanitizeText(e){if(!e)return"";let t=e;return t=t.replace(/\b\d{3}-\d{2}-\d{4}\b/g,"***-**-****"),t=t.replace(/\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,"****-****-****-****"),t=t.replace(/\b([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,})\b/gi,"***@$2"),t}},T=["button","a[href]",'[role="button"]'],A=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class P extends w{constructor(e,t,n,i){var r,o,s;super(e,{enabled:null===(r=t.enabled)||void 0===r||r,selectors:null!==(o=t.selectors)&&void 0!==o?o:T,ignore:null!==(s=t.ignore)&&void 0!==s?s:A},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=C}attachListeners(){this.listenerAttached||("undefined"!=typeof document?(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,{passive:!0,capture:!1}),this.listenerAttached=!0,this.logger.log("log","ClickTracker: Delegated click listener attached")):this.logger.log("warn","ClickTracker: document not available, cannot attach listener"))}detachListeners(){this.listenerAttached&&this.boundHandleClick&&"undefined"!=typeof document&&(document.removeEventListener("click",this.boundHandleClick),this.listenerAttached=!1),this.debounceTimers.clear(),this.boundHandleClick=null}handleClick(e){if(!this.enabled)return;const t=e.target;if(!t)return;const n=this.findTrackableElement(t);if(!n)return;if(this.shouldIgnore(n))return void this.logger.log("log","ClickTracker: Element ignored",n);if(this.privacyGuard.isSensitive(n))return void this.logger.log("warn","ClickTracker: Sensitive element not tracked",n);if(this.isDebounced(n))return void this.logger.log("log","ClickTracker: Click debounced",n);const i=this.extractTrackingData(n);i&&(this.logger.log("log","ClickTracker: Tracking click",i),this.callback(i))}findTrackableElement(e){const t=this.config.selectors||T;try{const n=e.closest('[data-lucia-track]:not([data-lucia-track="false"])');if(n&&n!==document.body&&document.body.contains(n)){if(this.config.selectors&&this.config.selectors!==T){return t.some(e=>{try{return n.matches(e)}catch(e){return!1}})?n:null}return n}const i=t.join(", "),r=e.closest(i);return r&&r!==document.body&&document.body.contains(r)?r:null}catch(t){this.logger.log("warn","ClickTracker: Invalid combined selector, using fallback",t);let n=e;for(;n&&n!==document.body;){if(this.isTrackable(n))return n;n=n.parentElement}return null}}isTrackable(e){return(this.config.selectors||T).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid selector "${t}"`,e),!1}})}shouldIgnore(e){return(this.config.ignore||A).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid ignore selector "${t}"`,e),!1}})}isDebounced(e){const t=Date.now(),n=this.debounceTimers.get(e);return!!(n&&t-n<500)||(this.debounceTimers.set(e,t),this.debounceTimers.size>100&&this.cleanupDebounceTimers(),!1)}cleanupDebounceTimers(){const e=Date.now();Array.from(this.debounceTimers.entries()).forEach(([t,n])=>{e-n>1e3&&this.debounceTimers.delete(t)})}extractTrackingData(e){var t;const n=this.getElementIdentifier(e);if(!n)return this.logger.log("warn","ClickTracker: Could not generate identifier for element",e),null;const i={button:n,elementType:this.getElementType(e),timestamp:Date.now()},r=null===(t=e.textContent)||void 0===t?void 0:t.trim();r&&(this.privacyGuard.containsSensitiveData(r)||(i.text=this.sanitizeText(r))),"a"===e.tagName.toLowerCase()?i.href=e.getAttribute("href"):i.href=null;const o=this.extractMetadata(e);return o&&Object.keys(o).length>0&&(i.meta=o),i}getElementIdentifier(e){var t;const n=e.getAttribute("data-lucia-track");if(n&&"false"!==n)return n;const i=e.getAttribute("id");if(i)return i;const r=e.getAttribute("name");if(r)return r;const o=e.getAttribute("aria-label");if(o)return o;if("a"===e.tagName.toLowerCase()){const t=e.getAttribute("href");if(t)return`link:${t}`}const s=null===(t=e.textContent)||void 0===t?void 0:t.trim();if(s)return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using text content as identifier for element. Consider adding data-lucia-track attribute.",e),`text:${this.sanitizeText(s).substring(0,50)}`;const a=this.generateCSSPath(e);return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using CSS path as identifier. Consider adding data-lucia-track attribute.",e),`path:${a}`}getElementType(e){const t=e.tagName.toLowerCase();if("a"===t)return"link";if("button"===t)return"button";const n=e.getAttribute("role");return n||t}sanitizeText(e){return e.trim().replace(/\s+/g," ").substring(0,100)}generateCSSPath(e){const t=[];let n=e;for(;n&&n!==document.body&&t.length<5;){let e=n.tagName.toLowerCase();if(n.id){e+=`#${n.id}`,t.unshift(e);break}const i=n.getAttribute("class");if(i){const t=i.trim().split(/\s+/).slice(0,2);t.length>0&&(e+=`.${t.join(".")}`)}t.unshift(e),n=n.parentElement}return t.join(" > ")}extractMetadata(e){const t={},{attributes:n}=e;return Array.from(n).forEach(e=>{if(e.name.startsWith("data-lucia-meta-")){const n=e.name.replace("data-lucia-meta-","").replace(/-([a-z])/g,e=>e[1].toUpperCase());t[n]=e.value}}),Object.keys(t).length>0?t:null}}const I={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new P(e,t,n,i),normalizeConfig:function(e){return void 0===e||!1===e?null:!0===e?{enabled:!0}:!1===e.enabled?null:e}};function S(){return t(this,void 0,void 0,function*(){if(O)return O;const e={device:{cores:L(()=>navigator.hardwareConcurrency),memory:L(()=>navigator.deviceMemory),cpuClass:L(()=>navigator.cpuClass),touch:D(),devicePixelRatio:L(()=>window.devicePixelRatio)},screen:{width:L(()=>window.screen.width),height:L(()=>window.screen.height),colorDepth:L(()=>window.screen.colorDepth),availHeight:L(()=>window.screen.availHeight),availWidth:L(()=>window.screen.availWidth),orientation:{type:L(()=>window.screen.orientation.type),angle:L(()=>window.screen.orientation.angle)}},browser:{language:L(()=>navigator.language),encoding:L(()=>TextDecoder.encoding),timezone:L(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:L(()=>navigator.plugins.length),pluginNames:L(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:x(),uniqueHash:yield j(),colorGamut:R(),contrastPreference:W()},permissions:{navPer:L(()=>navigator.permissions.webglVersion),renderedPer:L(()=>navigator.permissions.RENDERER),geoPer:L(()=>navigator.permissions.geolocation)},storage:{localStorage:L(()=>!!window.localStorage),indexedDB:L(()=>!!window.indexedDB),openDB:L(()=>window.openDatabase)}};return O=e,e})}function E(){const e=new URL(window.location.href).searchParams,t={};return e.forEach((e,n)=>{(n.startsWith("utm_")||n.includes("id")||"ref"===n||"source"===n)&&(t[n]=e)}),t}function L(e,t){try{return e()}catch(e){return t}}let O=null;function j(){return t(this,void 0,void 0,function*(){try{const e=document.createElement("canvas"),n=e.getContext("2d",{willReadFrequently:!0});if(!n)return;const i=200,r=120;e.width=i,e.height=r,e.style.width=`${i}px`,e.style.height=`${r}px`,n.fillStyle="#ffffff",n.fillRect(0,0,i,r),n.fillStyle="#ff00ff",n.fillRect(10,10,100,100),n.fillStyle="#00ffff",n.beginPath(),n.arc(150,50,40,0,2*Math.PI,!0),n.fill();const{data:o}=n.getImageData(0,0,i,r);return function(e){return t(this,void 0,void 0,function*(){const t=(new TextEncoder).encode(e),n=yield crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("")})}([[20,20],[60,60],[100,100],[150,50],[150,60],[140,50],[5,5]].map(([e,t])=>{const n=4*(t*i+e);return`${o[n]},${o[n+1]},${o[n+2]},${o[n+3]};`}).join(""))}catch(e){return}})}function D(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function x(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function W(){try{const{matchMedia:e}=window,t=t=>e(`(prefers-contrast: ${t})`).matches;return t("no-preference")?"None":t("high")||t("more")?"More":t("low")||t("less")?"Less":t("forced")?"ForcedColors":void 0}catch(e){return}}function R(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const U=new Map;let $=null,M=!1;function _(){return new Map(U)}const K=[{name:"Rabby",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRabby)}},{name:"Brave Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBraveWallet)}},{name:"Rainbow",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRainbow)}},{name:"Coinbase Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoinbaseWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCoinbase)}},{name:"Trust Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTrust)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTrustWallet)}},{name:"TokenPocket",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTokenPocket)}},{name:"Zerion",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isZerion)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isPhantom)}},{name:"OKX Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOkxWallet)}},{name:"Bitget Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBitKeep)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isBitgetWallet)}},{name:"SafePal",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isSafePal)}},{name:"Frontier",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrontier)}},{name:"XDEFI",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isXDEFI)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCtrl)}},{name:"Enkrypt",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isEnkrypt)}},{name:"MetaMask",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMetaMask)}},{name:"WalletConnect",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isWalletConnect)}},{name:"imToken",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isImToken)}},{name:"Status",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isStatus)}},{name:"Tally",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTally)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTallyWallet)}},{name:"AlphaWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isAlphaWallet)}},{name:"Opera",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOpera)}},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoin98)}},{name:"MathWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMathWallet)}},{name:"1inch Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOneInchIOSWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isOneInchAndroidWallet)}},{name:"Frame",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrame)}},{name:"Binance Chain Wallet",detect:()=>!!window.BinanceChain},{name:"MetaMask",detect:()=>{var e;return Object.prototype.hasOwnProperty.call(null!==(e=window.ethereum)&&void 0!==e?e:{},"_metamask")}}],N=[{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.phantom)||void 0===e?void 0:e.solana)}},{name:"Solflare",detect:()=>!!window.solflare},{name:"Backpack",detect:()=>!!window.backpack},{name:"Glow",detect:()=>!!window.glow},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isCoin98)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isPhantom)}}];function q(){var e,t;return window.ethereum&&null!==(t=null===(e=K.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}function B(){var e,t;return null!==(t=null===(e=N.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}y.register(I);let z=class extends p{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}authenticate(){this.httpClient.post("/api/key/auth",{})}init(){return t(this,void 0,void 0,function*(){let e=v();e||(e=g());try{M||(M=!0,$=e=>{var t;const n=e.detail;(null===(t=null==n?void 0:n.info)||void 0===t?void 0:t.rdns)&&(null==n?void 0:n.provider)&&U.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",$),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield S(),n=new URL(window.location.href).searchParams.get("lucia"),i={id:e.id};e.hash&&(i.hash=e.hash);const r=f(),o=yield this.httpClient.post("/api/sdk/init",Object.assign({user:{name:m()},data:t,session:i,redirectHash:n,utm:E()},r&&{lid:r}),!1);o&&(o.lid&&localStorage.setItem("lid",o.lid),o.session&&function(e){const t={id:e.id,hash:e.hash,timestamp:Date.now()};sessionStorage.setItem(u,JSON.stringify(t))}(o.session)),y.initAll(this.store.config,{clicks:this.handleAutoTrackedClick.bind(this)},this.logger),yield this.autoDetectWallets(),this.setupWalletListeners()})}handleAutoTrackedClick(e){const t=e,n={elementType:t.elementType,text:t.text,href:t.href,meta:t.meta};this.buttonClick(t.button,n)}autoDetectWallets(){return t(this,void 0,void 0,function*(){var e,n,i;try{const e=yield function(){return t(this,void 0,void 0,function*(){const e=Array.from(U.values());if(0===e.length)return[];const t=yield Promise.allSettled(e.map(({info:e,provider:t})=>{const n=t.request({method:"eth_accounts"}).then(n=>{const i=n;return Array.isArray(i)?i.filter(e=>"string"==typeof e&&e.length>0).map(n=>({address:n,providerName:e.name,providerRdns:e.rdns,provider:t})):[]}),i=new Promise((t,n)=>setTimeout(()=>n(new Error(`EIP-6963 timeout: ${e.name}`)),3e3));return Promise.race([n,i])})),n=[];for(const e of t)"fulfilled"===e.status&&n.push(...e.value);return n})}();for(const t of e)yield this.sendWalletInfo(t.address,{provider:t.providerName,providerRdns:t.providerRdns})}catch(e){}if(0===_().size&&(null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress))try{const e=q();yield this.sendWalletInfo(window.ethereum.selectedAddress,{provider:null!=e?e:void 0})}catch(e){}if((null===(n=window.solana)||void 0===n?void 0:n.isConnected)&&(null===(i=window.solana)||void 0===i?void 0:i.publicKey))try{const e=B();yield this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0})}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){var e,t;const n=function(e){const t=t=>{var n;const i=t.detail;(null===(n=null==i?void 0:i.info)||void 0===n?void 0:n.rdns)&&(null==i?void 0:i.provider)&&(U.set(i.info.rdns,i),e(i))};return window.addEventListener("eip6963:announceProvider",t),()=>window.removeEventListener("eip6963:announceProvider",t)}(e=>{this.handleLateEIP6963Provider(e)});if(this.walletListenerCleanups.push(n),(null===(e=window.ethereum)||void 0===e?void 0:e.on)&&0===_().size){const e=e=>{const t=e;if(t[0]){const e=t[0],n=q();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};window.ethereum.on("accountsChanged",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"accountsChanged",e)})}if(null===(t=window.solana)||void 0===t?void 0:t.on){const e=()=>{var e;if(null===(e=window.solana)||void 0===e?void 0:e.publicKey){const e=B();this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0}).catch(()=>{})}};window.solana.on("connect",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"connect",e)})}}setupEIP6963AccountListeners(){const e=_();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e;n.request&&n.request({method:"eth_accounts"}).then(e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})}).catch(()=>{}),this.attachEIP6963AccountsChanged(e)}attachEIP6963AccountsChanged(e){const{info:t,provider:n}=e;if(!n.on)return;const i=e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})};n.on("accountsChanged",i),this.walletListenerCleanups.push(()=>{var e;null===(e=n.removeListener)||void 0===e||e.call(n,"accountsChanged",i)})}userInfo(e,n){return t(this,void 0,void 0,function*(){const t=f(),i=v();e&&localStorage.setItem("luc_uid",e);const r=Object.assign({user:{name:e,userInfo:n},session:i},t&&{lid:t});yield this.httpClient.post("/api/sdk/user",r)})}pageView(e){return t(this,void 0,void 0,function*(){const t=f(),n=v(),i=Object.assign({page:e,user:{name:m()},session:n},t&&{lid:t});yield this.httpClient.post("/api/sdk/page",i)})}trackConversion(e,n,i){return t(this,void 0,void 0,function*(){const t=f(),r=v(),o=Object.assign({tag:e,amount:n,event:i,user:{name:m()},session:r},t&&{lid:t});yield this.httpClient.post("/api/sdk/conversion",o)})}buttonClick(e,n){return t(this,void 0,void 0,function*(){const t=f(),i=v(),r=Object.assign(Object.assign({button:e,user:{name:m()},session:i},t&&{lid:t}),n&&Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n.elementType&&{elementType:n.elementType}),n.text&&{text:n.text}),void 0!==n.href&&{href:n.href}),n.meta&&{meta:n.meta}),{timestamp:Date.now()}));yield this.httpClient.post("/api/sdk/click",r)})}sendWalletInfo(e,n,i){return t(this,void 0,void 0,function*(){var t,r,o;if(!e||"string"!=typeof e)return;const s=e.startsWith("0x")?e.toLowerCase():e;if(this.sentWallets.has(s))return;this.sentWallets.add(s);let a={};n&&"object"==typeof n?a=n:void 0!==n&&(a={chainId:"number"==typeof n?n:void 0,provider:i});const l=f(),c=v(),d=Object.assign(Object.assign(Object.assign(Object.assign({walletAddress:e,provider:null!==(t=a.provider)&&void 0!==t?t:null,providerRdns:null!==(r=a.providerRdns)&&void 0!==r?r:null,connectorType:null!==(o=a.connectorType)&&void 0!==o?o:null},null!=a.chainId&&{chainId:a.chainId}),i&&{walletName:i}),{user:{name:m()},session:c}),l&&{lid:l});try{yield this.httpClient.post("/api/sdk/wallet",d)}catch(e){throw this.sentWallets.delete(s),e}})}trackUserAcquisition(e){return t(this,arguments,void 0,function*(e,t={}){const n=yield S(),i=E(),r=v();yield this.httpClient.post("/api/sdk/acquisition",{user:{name:e},session:r,data:Object.assign({timestamp:(new Date).toISOString(),browserData:n,utmParams:i},t)})})}checkMetaMaskConnection(){var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))}destroy(){y.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),M&&($&&(window.removeEventListener("eip6963:announceProvider",$),$=null),U.clear(),M=!1)}},F=null;const Q=()=>{const e=F||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},H={init:e=>{if("undefined"==typeof window)return Promise.reject(new Error("LuciaSDK requires a browser environment"));if(F)return F;if(window.__luciaInitPromise)return F=window.__luciaInitPromise,F;if(!(null==e?void 0:e.apiKey))return Promise.reject(new Error("apiKey is required in config"));const n=t(void 0,void 0,void 0,function*(){const t=new z(e);return yield t.init(),t});return F=n,window.__luciaInitPromise=n,n},userInfo:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield Q()).userInfo(e,n)}),pageView:e=>t(void 0,void 0,void 0,function*(){return(yield Q()).pageView(e)}),trackConversion:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield Q()).trackConversion(e,n,i)}),buttonClick:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield Q()).buttonClick(e,n)}),sendWalletInfo:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield Q()).sendWalletInfo(e,n,i)}),trackUserAcquisition:(e,...n)=>t(void 0,[e,...n],void 0,function*(e,t={}){return(yield Q()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>{var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))},VERSION:i};if("undefined"!=typeof window){window.LuciaSDK=H;const e=()=>{const e=document.currentScript||document.querySelector("script[data-api-key]"),t=null==e?void 0:e.getAttribute("data-api-key");if(!t)return;const n=e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");H.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{debugURL:n}),"true"===i&&{autoTrackClicks:!r||{enabled:!0,selectors:r.split(",").map(e=>e.trim())}}),"false"===i&&{autoTrackClicks:!1})).catch(e=>console.error("LuciaSDK auto-init failed:",e))};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}e.__resetInstance=()=>{const e=F||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),F=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,y.reset()},e.default=H,e.detectEvmProvider=q,e.detectSolanaProvider=B,e.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},e.getApplePayAvailable=x,e.getBrowserData=S,e.getCanvasFingerprint=j,e.getColorGamut=R,e.getContrastPreference=W,e.getUtmParams=E,e.isTouchEnabled=D,e.safeAccess=L,Object.defineProperty(e,"__esModule",{value:!0})});
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LuciaSDK={})}(this,function(e){"use strict";function t(e,t,n,i){return new(n||(n=Promise))(function(r,o){function s(e){try{l(i.next(e))}catch(e){o(e)}}function a(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class n{constructor(e){this.store=e}log(e,...t){var n;(null===(n=this.store.config)||void 0===n?void 0:n.debug)&&console[e](t)}}const i="0.10.0";class r{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new n(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"http://52.22.177.60/fk":"https://api.clickinsights.xyz"}get(e){return t(this,void 0,void 0,function*(){if(!this.store.config)return this.logger.log("error","Config is not set"),null;try{const t=yield fetch(`${this.baseURL}${e}`,{method:"GET",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":i}});return yield t.json()}catch(e){this.logger.log("error",e)}return null})}post(e,n){return t(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;const i="/api/sdk/init"===e;if(!i&&!this.initComplete)return new Promise((r,o)=>{this.requestQueue.push({url:e,data:t,fireAndForget:n,resolve:r,reject:o,isInit:i}),this.processQueue()});if(i){const i=yield this.executePost(e,t,n);return this.initComplete=!0,yield this.processQueue(),i}return this.executePost(e,t,n)})}processQueue(){return t(this,void 0,void 0,function*(){if(!this.isProcessingQueue&&this.initComplete&&0!==this.requestQueue.length){this.isProcessingQueue=!0;try{const e=()=>t(this,void 0,void 0,function*(){if(0===this.requestQueue.length)return;const t=this.requestQueue.shift();try{const e=yield this.executePost(t.url,t.data,t.fireAndForget);t.resolve(e)}catch(e){t.reject(e)}yield e()});yield e()}finally{this.isProcessingQueue=!1}}})}executePost(e,n){return t(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;if(n&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon){try{const n=`${this.baseURL}${e}`,i=t&&"object"==typeof t&&!Array.isArray(t)?t:{payload:t},r=JSON.stringify(Object.assign(Object.assign({},i),{_apiKey:this.store.config.apiKey})),o=new Blob([r],{type:"application/json"});navigator.sendBeacon(n,o)||this.logger.log("error","sendBeacon failed")}catch(e){this.logger.log("error",e)}return null}try{const n=yield fetch(`${this.baseURL}${e}`,{method:"POST",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":i},body:JSON.stringify(t)});return yield n.json()}catch(e){this.logger.log("error",e)}return null})}}class o{static dispatch(e){Object.keys(e).forEach(t=>{if(Object.keys(o.store).includes(t)){const n=e[t];o.store[t]="object"==typeof n?Array.isArray(n)?[...n]:Object.assign({},n):n}})}}o.store={isInitialized:!1,config:null,session:null};const s=[];for(let e=0;e<256;++e)s.push((e+256).toString(16).slice(1));let a;const l=new Uint8Array(16);var c={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function d(e,t,n){const i=(e=e||{}).random??e.rng?.()??function(){if(!a){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");a=crypto.getRandomValues.bind(crypto)}return a(l)}();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=15&i[6]|64,i[8]=63&i[8]|128,function(e,t=0){return(s[e[t+0]]+s[e[t+1]]+s[e[t+2]]+s[e[t+3]]+"-"+s[e[t+4]]+s[e[t+5]]+"-"+s[e[t+6]]+s[e[t+7]]+"-"+s[e[t+8]]+s[e[t+9]]+"-"+s[e[t+10]]+s[e[t+11]]+s[e[t+12]]+s[e[t+13]]+s[e[t+14]]+s[e[t+15]]).toLowerCase()}(i)}const u="luci_session",h=new n(o.store);function v(){try{const e=sessionStorage.getItem(u);return e?JSON.parse(e):null}catch(e){return h.log("error","Error retrieving session data:",e),null}}function g(){var e;const t={id:c.randomUUID&&!e?c.randomUUID():d(e),timestamp:Date.now()};return sessionStorage.setItem(u,JSON.stringify(t)),t}function f(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function m(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class p{constructor(e){this.store=o.store,this.dispatch=o.dispatch,this.dispatch({config:e}),this.httpClient=new r(this.store),this.logger=new n(this.store)}}class w{constructor(e,t,n,i){this.enabled=!1,this.sdkConfig=e,this.config=t,this.callback=n,this.logger=i}enable(){this.enabled||(this.enabled=!0,this.attachListeners(),this.logger.log("log",`${this.name}: Enabled`))}disable(){this.enabled&&(this.enabled=!1,this.logger.log("log",`${this.name}: Disabled`))}destroy(){this.disable(),this.detachListeners(),this.logger.log("log",`${this.name}: Destroyed`)}isEnabled(){return this.enabled}}const y=new class{constructor(){this.registrations=new Map,this.activeTrackers=new Map,this.logger=null}register(e){this.registrations.set(e.name,e)}initAll(e,t,n){this.logger=n;for(const[i,r]of this.registrations){const o=e[r.configKey],s=r.normalizeConfig(o);if(null===s)continue;const a=t[i];if(a)try{const t=r.factory(e,s,a,n);this.activeTrackers.set(i,t),t.enable(),n.log("log",`AutoTrackerRegistry: Initialized ${i}`)}catch(e){n.log("error",`AutoTrackerRegistry: Failed to initialize ${i}`,e)}else n.log("warn",`AutoTrackerRegistry: No callback registered for ${i}`)}}get(e){return this.activeTrackers.get(e)}enable(e){const t=this.activeTrackers.get(e);return!!t&&(t.enable(),!0)}disable(e){const t=this.activeTrackers.get(e);return!!t&&(t.disable(),!0)}destroyAll(){var e;for(const[t,n]of this.activeTrackers)try{n.destroy()}catch(n){null===(e=this.logger)||void 0===e||e.log("error",`AutoTrackerRegistry: Error destroying ${t}`,n)}this.activeTrackers.clear()}getRegisteredTrackers(){return Array.from(this.registrations.keys())}getActiveTrackers(){return Array.from(this.activeTrackers.keys())}reset(){this.destroyAll(),this.logger=null}},b=['input[type="password"]','input[type="text"][autocomplete*="cc-"]','input[type="text"][autocomplete*="card"]','input[type="text"][name*="card"]','input[type="text"][name*="cvv"]','input[type="text"][name*="cvc"]','input[name*="ssn"]','input[name*="social"]',"[data-sensitive]","[data-private]"],k=[/\b\d{3}-\d{2}-\d{4}\b/,/\b\d{4}[\s-]\d{4}[\s-]\d{4}[\s-]\d{4}\b/,/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i];const C=new class{constructor(e=[]){this.sensitiveSelectors=[...b,...e]}isSensitive(e){if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;let t=e.parentElement;for(;t;){const e=t;if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;t=t.parentElement}return!1}containsSensitiveData(e){return!!e&&k.some(t=>t.test(e))}sanitizeText(e){if(!e)return"";let t=e;return t=t.replace(/\b\d{3}-\d{2}-\d{4}\b/g,"***-**-****"),t=t.replace(/\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,"****-****-****-****"),t=t.replace(/\b([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,})\b/gi,"***@$2"),t}},T=["button","a[href]",'[role="button"]'],A=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class P extends w{constructor(e,t,n,i){var r,o,s;super(e,{enabled:null===(r=t.enabled)||void 0===r||r,selectors:null!==(o=t.selectors)&&void 0!==o?o:T,ignore:null!==(s=t.ignore)&&void 0!==s?s:A},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=C}attachListeners(){this.listenerAttached||("undefined"!=typeof document?(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,{passive:!0,capture:!1}),this.listenerAttached=!0,this.logger.log("log","ClickTracker: Delegated click listener attached")):this.logger.log("warn","ClickTracker: document not available, cannot attach listener"))}detachListeners(){this.listenerAttached&&this.boundHandleClick&&"undefined"!=typeof document&&(document.removeEventListener("click",this.boundHandleClick),this.listenerAttached=!1),this.debounceTimers.clear(),this.boundHandleClick=null}handleClick(e){if(!this.enabled)return;const t=e.target;if(!t)return;const n=this.findTrackableElement(t);if(!n)return;if(this.shouldIgnore(n))return void this.logger.log("log","ClickTracker: Element ignored",n);if(this.privacyGuard.isSensitive(n))return void this.logger.log("warn","ClickTracker: Sensitive element not tracked",n);if(this.isDebounced(n))return void this.logger.log("log","ClickTracker: Click debounced",n);const i=this.extractTrackingData(n);i&&(this.logger.log("log","ClickTracker: Tracking click",i),this.callback(i))}findTrackableElement(e){const t=this.config.selectors||T;try{const n=e.closest('[data-lucia-track]:not([data-lucia-track="false"])');if(n&&n!==document.body&&document.body.contains(n)){if(this.config.selectors&&this.config.selectors!==T){return t.some(e=>{try{return n.matches(e)}catch(e){return!1}})?n:null}return n}const i=t.join(", "),r=e.closest(i);return r&&r!==document.body&&document.body.contains(r)?r:null}catch(t){this.logger.log("warn","ClickTracker: Invalid combined selector, using fallback",t);let n=e;for(;n&&n!==document.body;){if(this.isTrackable(n))return n;n=n.parentElement}return null}}isTrackable(e){return(this.config.selectors||T).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid selector "${t}"`,e),!1}})}shouldIgnore(e){return(this.config.ignore||A).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid ignore selector "${t}"`,e),!1}})}isDebounced(e){const t=Date.now(),n=this.debounceTimers.get(e);return!!(n&&t-n<500)||(this.debounceTimers.set(e,t),this.debounceTimers.size>100&&this.cleanupDebounceTimers(),!1)}cleanupDebounceTimers(){const e=Date.now();Array.from(this.debounceTimers.entries()).forEach(([t,n])=>{e-n>1e3&&this.debounceTimers.delete(t)})}extractTrackingData(e){var t;const n=this.getElementIdentifier(e);if(!n)return this.logger.log("warn","ClickTracker: Could not generate identifier for element",e),null;const i={button:n,elementType:this.getElementType(e),timestamp:Date.now()},r=null===(t=e.textContent)||void 0===t?void 0:t.trim();r&&(this.privacyGuard.containsSensitiveData(r)||(i.text=this.sanitizeText(r))),"a"===e.tagName.toLowerCase()?i.href=e.getAttribute("href"):i.href=null;const o=this.extractMetadata(e);return o&&Object.keys(o).length>0&&(i.meta=o),i}getElementIdentifier(e){var t;const n=e.getAttribute("data-lucia-track");if(n&&"false"!==n)return n;const i=e.getAttribute("id");if(i)return i;const r=e.getAttribute("name");if(r)return r;const o=e.getAttribute("aria-label");if(o)return o;if("a"===e.tagName.toLowerCase()){const t=e.getAttribute("href");if(t)return`link:${t}`}const s=null===(t=e.textContent)||void 0===t?void 0:t.trim();if(s)return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using text content as identifier for element. Consider adding data-lucia-track attribute.",e),`text:${this.sanitizeText(s).substring(0,50)}`;const a=this.generateCSSPath(e);return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using CSS path as identifier. Consider adding data-lucia-track attribute.",e),`path:${a}`}getElementType(e){const t=e.tagName.toLowerCase();if("a"===t)return"link";if("button"===t)return"button";const n=e.getAttribute("role");return n||t}sanitizeText(e){return e.trim().replace(/\s+/g," ").substring(0,100)}generateCSSPath(e){const t=[];let n=e;for(;n&&n!==document.body&&t.length<5;){let e=n.tagName.toLowerCase();if(n.id){e+=`#${n.id}`,t.unshift(e);break}const i=n.getAttribute("class");if(i){const t=i.trim().split(/\s+/).slice(0,2);t.length>0&&(e+=`.${t.join(".")}`)}t.unshift(e),n=n.parentElement}return t.join(" > ")}extractMetadata(e){const t={},{attributes:n}=e;return Array.from(n).forEach(e=>{if(e.name.startsWith("data-lucia-meta-")){const n=e.name.replace("data-lucia-meta-","").replace(/-([a-z])/g,e=>e[1].toUpperCase());t[n]=e.value}}),Object.keys(t).length>0?t:null}}const I={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new P(e,t,n,i),normalizeConfig:function(e){return void 0===e||!1===e?null:!0===e?{enabled:!0}:!1===e.enabled?null:e}};function S(){return t(this,void 0,void 0,function*(){if(O)return O;const e={device:{cores:L(()=>navigator.hardwareConcurrency),memory:L(()=>navigator.deviceMemory),cpuClass:L(()=>navigator.cpuClass),touch:D(),devicePixelRatio:L(()=>window.devicePixelRatio)},screen:{width:L(()=>window.screen.width),height:L(()=>window.screen.height),colorDepth:L(()=>window.screen.colorDepth),availHeight:L(()=>window.screen.availHeight),availWidth:L(()=>window.screen.availWidth),orientation:{type:L(()=>window.screen.orientation.type),angle:L(()=>window.screen.orientation.angle)}},browser:{language:L(()=>navigator.language),encoding:L(()=>TextDecoder.encoding),timezone:L(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:L(()=>navigator.plugins.length),pluginNames:L(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:x(),uniqueHash:yield j(),colorGamut:R(),contrastPreference:W()},permissions:{navPer:L(()=>navigator.permissions.webglVersion),renderedPer:L(()=>navigator.permissions.RENDERER),geoPer:L(()=>navigator.permissions.geolocation)},storage:{localStorage:L(()=>!!window.localStorage),indexedDB:L(()=>!!window.indexedDB),openDB:L(()=>window.openDatabase)}};return O=e,e})}function E(){const e=new URL(window.location.href).searchParams,t={};return e.forEach((e,n)=>{(n.startsWith("utm_")||n.includes("id")||"ref"===n||"source"===n)&&(t[n]=e)}),t}function L(e,t){try{return e()}catch(e){return t}}let O=null;function j(){return t(this,void 0,void 0,function*(){try{const e=document.createElement("canvas"),n=e.getContext("2d",{willReadFrequently:!0});if(!n)return;const i=200,r=120;e.width=i,e.height=r,e.style.width=`${i}px`,e.style.height=`${r}px`,n.fillStyle="#ffffff",n.fillRect(0,0,i,r),n.fillStyle="#ff00ff",n.fillRect(10,10,100,100),n.fillStyle="#00ffff",n.beginPath(),n.arc(150,50,40,0,2*Math.PI,!0),n.fill();const{data:o}=n.getImageData(0,0,i,r);return function(e){return t(this,void 0,void 0,function*(){const t=(new TextEncoder).encode(e),n=yield crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("")})}([[20,20],[60,60],[100,100],[150,50],[150,60],[140,50],[5,5]].map(([e,t])=>{const n=4*(t*i+e);return`${o[n]},${o[n+1]},${o[n+2]},${o[n+3]};`}).join(""))}catch(e){return}})}function D(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function x(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function W(){try{const{matchMedia:e}=window,t=t=>e(`(prefers-contrast: ${t})`).matches;return t("no-preference")?"None":t("high")||t("more")?"More":t("low")||t("less")?"Less":t("forced")?"ForcedColors":void 0}catch(e){return}}function R(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const U=new Map;let $=null,M=!1;function _(){return new Map(U)}const K=[{name:"Rabby",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRabby)}},{name:"Brave Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBraveWallet)}},{name:"Rainbow",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRainbow)}},{name:"Coinbase Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoinbaseWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCoinbase)}},{name:"Trust Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTrust)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTrustWallet)}},{name:"TokenPocket",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTokenPocket)}},{name:"Zerion",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isZerion)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isPhantom)}},{name:"OKX Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOkxWallet)}},{name:"Bitget Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBitKeep)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isBitgetWallet)}},{name:"SafePal",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isSafePal)}},{name:"Frontier",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrontier)}},{name:"XDEFI",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isXDEFI)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCtrl)}},{name:"Enkrypt",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isEnkrypt)}},{name:"MetaMask",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMetaMask)}},{name:"WalletConnect",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isWalletConnect)}},{name:"imToken",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isImToken)}},{name:"Status",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isStatus)}},{name:"Tally",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTally)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTallyWallet)}},{name:"AlphaWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isAlphaWallet)}},{name:"Opera",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOpera)}},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoin98)}},{name:"MathWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMathWallet)}},{name:"1inch Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOneInchIOSWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isOneInchAndroidWallet)}},{name:"Frame",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrame)}},{name:"Binance Chain Wallet",detect:()=>!!window.BinanceChain},{name:"MetaMask",detect:()=>{var e;return Object.prototype.hasOwnProperty.call(null!==(e=window.ethereum)&&void 0!==e?e:{},"_metamask")}}],N=[{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.phantom)||void 0===e?void 0:e.solana)}},{name:"Solflare",detect:()=>!!window.solflare},{name:"Backpack",detect:()=>!!window.backpack},{name:"Glow",detect:()=>!!window.glow},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isCoin98)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isPhantom)}}];function q(){var e,t;return window.ethereum&&null!==(t=null===(e=K.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}function B(){var e,t;return null!==(t=null===(e=N.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}y.register(I);let z=class extends p{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}authenticate(){this.httpClient.post("/api/key/auth",{})}init(){return t(this,void 0,void 0,function*(){let e=v();e||(e=g());try{M||(M=!0,$=e=>{var t;const n=e.detail;(null===(t=null==n?void 0:n.info)||void 0===t?void 0:t.rdns)&&(null==n?void 0:n.provider)&&U.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",$),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield S(),n=new URL(window.location.href).searchParams.get("lucia"),i={id:e.id};e.hash&&(i.hash=e.hash);const r=yield this.httpClient.post("/api/sdk/init",{user:{name:m()},data:t,session:i,redirectHash:n,utm:E()},!1);r&&(r.lid&&localStorage.setItem("lid",r.lid),r.session&&function(e){const t={id:e.id,hash:e.hash,timestamp:Date.now()};sessionStorage.setItem(u,JSON.stringify(t))}(r.session)),y.initAll(this.store.config,{clicks:this.handleAutoTrackedClick.bind(this)},this.logger),yield this.autoDetectWallets(),this.setupWalletListeners()})}handleAutoTrackedClick(e){const t=e,n={elementType:t.elementType,text:t.text,href:t.href,meta:t.meta};this.buttonClick(t.button,n)}autoDetectWallets(){return t(this,void 0,void 0,function*(){var e,n,i;try{const e=yield function(){return t(this,void 0,void 0,function*(){const e=Array.from(U.values());if(0===e.length)return[];const t=yield Promise.allSettled(e.map(({info:e,provider:t})=>{const n=t.request({method:"eth_accounts"}).then(n=>{const i=n;return Array.isArray(i)?i.filter(e=>"string"==typeof e&&e.length>0).map(n=>({address:n,providerName:e.name,providerRdns:e.rdns,provider:t})):[]}),i=new Promise((t,n)=>setTimeout(()=>n(new Error(`EIP-6963 timeout: ${e.name}`)),3e3));return Promise.race([n,i])})),n=[];for(const e of t)"fulfilled"===e.status&&n.push(...e.value);return n})}();for(const t of e)yield this.sendWalletInfo(t.address,{provider:t.providerName,providerRdns:t.providerRdns})}catch(e){}if(0===_().size&&(null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress))try{const e=q();yield this.sendWalletInfo(window.ethereum.selectedAddress,{provider:null!=e?e:void 0})}catch(e){}if((null===(n=window.solana)||void 0===n?void 0:n.isConnected)&&(null===(i=window.solana)||void 0===i?void 0:i.publicKey))try{const e=B();yield this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0})}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){var e,t;const n=function(e){const t=t=>{var n;const i=t.detail;(null===(n=null==i?void 0:i.info)||void 0===n?void 0:n.rdns)&&(null==i?void 0:i.provider)&&(U.set(i.info.rdns,i),e(i))};return window.addEventListener("eip6963:announceProvider",t),()=>window.removeEventListener("eip6963:announceProvider",t)}(e=>{this.handleLateEIP6963Provider(e)});if(this.walletListenerCleanups.push(n),(null===(e=window.ethereum)||void 0===e?void 0:e.on)&&0===_().size){const e=e=>{const t=e;if(t[0]){const e=t[0],n=q();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};window.ethereum.on("accountsChanged",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"accountsChanged",e)})}if(null===(t=window.solana)||void 0===t?void 0:t.on){const e=()=>{var e;if(null===(e=window.solana)||void 0===e?void 0:e.publicKey){const e=B();this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0}).catch(()=>{})}};window.solana.on("connect",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"connect",e)})}}setupEIP6963AccountListeners(){const e=_();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e;n.request&&n.request({method:"eth_accounts"}).then(e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})}).catch(()=>{}),this.attachEIP6963AccountsChanged(e)}attachEIP6963AccountsChanged(e){const{info:t,provider:n}=e;if(!n.on)return;const i=e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})};n.on("accountsChanged",i),this.walletListenerCleanups.push(()=>{var e;null===(e=n.removeListener)||void 0===e||e.call(n,"accountsChanged",i)})}userInfo(e,n){return t(this,void 0,void 0,function*(){const t=f(),i=v();e&&localStorage.setItem("luc_uid",e);const r=Object.assign({user:{name:e,userInfo:n},session:i},t&&{lid:t});yield this.httpClient.post("/api/sdk/user",r)})}pageView(e){return t(this,void 0,void 0,function*(){const t=f(),n=v(),i=Object.assign({page:e,user:{name:m()},session:n},t&&{lid:t});yield this.httpClient.post("/api/sdk/page",i)})}trackConversion(e,n,i){return t(this,void 0,void 0,function*(){const t=f(),r=v(),o=Object.assign({tag:e,amount:n,event:i,user:{name:m()},session:r},t&&{lid:t});yield this.httpClient.post("/api/sdk/conversion",o)})}buttonClick(e,n){return t(this,void 0,void 0,function*(){const t=f(),i=v(),r=Object.assign(Object.assign({button:e,user:{name:m()},session:i},t&&{lid:t}),n&&Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n.elementType&&{elementType:n.elementType}),n.text&&{text:n.text}),void 0!==n.href&&{href:n.href}),n.meta&&{meta:n.meta}),{timestamp:Date.now()}));yield this.httpClient.post("/api/sdk/click",r)})}sendWalletInfo(e,n,i){return t(this,void 0,void 0,function*(){var t,r,o;if(!e||"string"!=typeof e)return;const s=e.startsWith("0x")?e.toLowerCase():e;if(this.sentWallets.has(s))return;this.sentWallets.add(s);let a={};n&&"object"==typeof n?a=n:void 0!==n&&(a={chainId:"number"==typeof n?n:void 0,provider:i});const l=f(),c=v(),d=Object.assign(Object.assign(Object.assign(Object.assign({walletAddress:e,provider:null!==(t=a.provider)&&void 0!==t?t:null,providerRdns:null!==(r=a.providerRdns)&&void 0!==r?r:null,connectorType:null!==(o=a.connectorType)&&void 0!==o?o:null},null!=a.chainId&&{chainId:a.chainId}),i&&{walletName:i}),{user:{name:m()},session:c}),l&&{lid:l});try{yield this.httpClient.post("/api/sdk/wallet",d)}catch(e){throw this.sentWallets.delete(s),e}})}trackUserAcquisition(e){return t(this,arguments,void 0,function*(e,t={}){const n=yield S(),i=E(),r=v();yield this.httpClient.post("/api/sdk/acquisition",{user:{name:e},session:r,data:Object.assign({timestamp:(new Date).toISOString(),browserData:n,utmParams:i},t)})})}checkMetaMaskConnection(){var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))}destroy(){y.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),M&&($&&(window.removeEventListener("eip6963:announceProvider",$),$=null),U.clear(),M=!1)}},F=null;const Q=()=>{const e=F||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},H={init:e=>{if("undefined"==typeof window)return Promise.reject(new Error("LuciaSDK requires a browser environment"));if(F)return F;if(window.__luciaInitPromise)return F=window.__luciaInitPromise,F;if(!(null==e?void 0:e.apiKey))return Promise.reject(new Error("apiKey is required in config"));const n=t(void 0,void 0,void 0,function*(){const t=new z(e);return yield t.init(),t});return F=n,window.__luciaInitPromise=n,n},userInfo:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield Q()).userInfo(e,n)}),pageView:e=>t(void 0,void 0,void 0,function*(){return(yield Q()).pageView(e)}),trackConversion:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield Q()).trackConversion(e,n,i)}),buttonClick:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield Q()).buttonClick(e,n)}),sendWalletInfo:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield Q()).sendWalletInfo(e,n,i)}),trackUserAcquisition:(e,...n)=>t(void 0,[e,...n],void 0,function*(e,t={}){return(yield Q()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>{var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))},VERSION:i};if("undefined"!=typeof window){window.LuciaSDK=H;const e=()=>{const e=document.currentScript||document.querySelector("script[data-api-key]"),t=null==e?void 0:e.getAttribute("data-api-key");if(!t)return;const n=e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");H.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{debugURL:n}),"true"===i&&{autoTrackClicks:!r||{enabled:!0,selectors:r.split(",").map(e=>e.trim())}}),"false"===i&&{autoTrackClicks:!1})).catch(e=>console.error("LuciaSDK auto-init failed:",e))};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}e.__resetInstance=()=>{const e=F||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),F=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,y.reset()},e.default=H,e.detectEvmProvider=q,e.detectSolanaProvider=B,e.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},e.getApplePayAvailable=x,e.getBrowserData=S,e.getCanvasFingerprint=j,e.getColorGamut=R,e.getContrastPreference=W,e.getUtmParams=E,e.isTouchEnabled=D,e.safeAccess=L,Object.defineProperty(e,"__esModule",{value:!0})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LuciaSDK={})}(this,function(e){"use strict";function t(e,t,n,i){return new(n||(n=Promise))(function(r,o){function s(e){try{l(i.next(e))}catch(e){o(e)}}function a(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class n{constructor(e){this.store=e}log(e,...t){var n;(null===(n=this.store.config)||void 0===n?void 0:n.debug)&&console[e](t)}}const i="0.10.2";class r{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new n(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"http://52.22.177.60/fk":"https://api.clickinsights.xyz"}get(e){return t(this,void 0,void 0,function*(){if(!this.store.config)return this.logger.log("error","Config is not set"),null;try{const t=yield fetch(`${this.baseURL}${e}`,{method:"GET",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":i}});return yield t.json()}catch(e){this.logger.log("error",e)}return null})}post(e,n){return t(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;const i="/api/sdk/init"===e;if(!i&&!this.initComplete)return new Promise((r,o)=>{this.requestQueue.push({url:e,data:t,fireAndForget:n,resolve:r,reject:o,isInit:i}),this.processQueue()});if(i){const i=yield this.executePost(e,t,n);return this.initComplete=!0,yield this.processQueue(),i}return this.executePost(e,t,n)})}processQueue(){return t(this,void 0,void 0,function*(){if(!this.isProcessingQueue&&this.initComplete&&0!==this.requestQueue.length){this.isProcessingQueue=!0;try{const e=()=>t(this,void 0,void 0,function*(){if(0===this.requestQueue.length)return;const t=this.requestQueue.shift();try{const e=yield this.executePost(t.url,t.data,t.fireAndForget);t.resolve(e)}catch(e){t.reject(e)}yield e()});yield e()}finally{this.isProcessingQueue=!1}}})}executePost(e,n){return t(this,arguments,void 0,function*(e,t,n=!0){if(!this.store.config)return this.logger.log("error","Config is not set"),null;if(n&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon){try{const n=`${this.baseURL}${e}`,i=t&&"object"==typeof t&&!Array.isArray(t)?t:{payload:t},r=JSON.stringify(Object.assign(Object.assign({},i),{_apiKey:this.store.config.apiKey})),o=new Blob([r],{type:"application/json"});navigator.sendBeacon(n,o)||this.logger.log("error","sendBeacon failed")}catch(e){this.logger.log("error",e)}return null}try{const n=yield fetch(`${this.baseURL}${e}`,{method:"POST",headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":i},body:JSON.stringify(t)});return yield n.json()}catch(e){this.logger.log("error",e)}return null})}}class o{static dispatch(e){Object.keys(e).forEach(t=>{if(Object.keys(o.store).includes(t)){const n=e[t];o.store[t]="object"==typeof n?Array.isArray(n)?[...n]:Object.assign({},n):n}})}}o.store={isInitialized:!1,config:null,session:null};const s=[];for(let e=0;e<256;++e)s.push((e+256).toString(16).slice(1));let a;const l=new Uint8Array(16);var c={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function d(e,t,n){const i=(e=e||{}).random??e.rng?.()??function(){if(!a){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");a=crypto.getRandomValues.bind(crypto)}return a(l)}();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=15&i[6]|64,i[8]=63&i[8]|128,function(e,t=0){return(s[e[t+0]]+s[e[t+1]]+s[e[t+2]]+s[e[t+3]]+"-"+s[e[t+4]]+s[e[t+5]]+"-"+s[e[t+6]]+s[e[t+7]]+"-"+s[e[t+8]]+s[e[t+9]]+"-"+s[e[t+10]]+s[e[t+11]]+s[e[t+12]]+s[e[t+13]]+s[e[t+14]]+s[e[t+15]]).toLowerCase()}(i)}const u="luci_session",h=new n(o.store);function v(){try{const e=sessionStorage.getItem(u);return e?JSON.parse(e):null}catch(e){return h.log("error","Error retrieving session data:",e),null}}function g(){var e;const t={id:c.randomUUID&&!e?c.randomUUID():d(e),timestamp:Date.now()};return sessionStorage.setItem(u,JSON.stringify(t)),t}function f(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function m(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class p{constructor(e){this.store=o.store,this.dispatch=o.dispatch,this.dispatch({config:e}),this.httpClient=new r(this.store),this.logger=new n(this.store)}}class w{constructor(e,t,n,i){this.enabled=!1,this.sdkConfig=e,this.config=t,this.callback=n,this.logger=i}enable(){this.enabled||(this.enabled=!0,this.attachListeners(),this.logger.log("log",`${this.name}: Enabled`))}disable(){this.enabled&&(this.enabled=!1,this.logger.log("log",`${this.name}: Disabled`))}destroy(){this.disable(),this.detachListeners(),this.logger.log("log",`${this.name}: Destroyed`)}isEnabled(){return this.enabled}}const y=new class{constructor(){this.registrations=new Map,this.activeTrackers=new Map,this.logger=null}register(e){this.registrations.set(e.name,e)}initAll(e,t,n){this.logger=n;for(const[i,r]of this.registrations){const o=e[r.configKey],s=r.normalizeConfig(o);if(null===s)continue;const a=t[i];if(a)try{const t=r.factory(e,s,a,n);this.activeTrackers.set(i,t),t.enable(),n.log("log",`AutoTrackerRegistry: Initialized ${i}`)}catch(e){n.log("error",`AutoTrackerRegistry: Failed to initialize ${i}`,e)}else n.log("warn",`AutoTrackerRegistry: No callback registered for ${i}`)}}get(e){return this.activeTrackers.get(e)}enable(e){const t=this.activeTrackers.get(e);return!!t&&(t.enable(),!0)}disable(e){const t=this.activeTrackers.get(e);return!!t&&(t.disable(),!0)}destroyAll(){var e;for(const[t,n]of this.activeTrackers)try{n.destroy()}catch(n){null===(e=this.logger)||void 0===e||e.log("error",`AutoTrackerRegistry: Error destroying ${t}`,n)}this.activeTrackers.clear()}getRegisteredTrackers(){return Array.from(this.registrations.keys())}getActiveTrackers(){return Array.from(this.activeTrackers.keys())}reset(){this.destroyAll(),this.logger=null}},b=['input[type="password"]','input[type="text"][autocomplete*="cc-"]','input[type="text"][autocomplete*="card"]','input[type="text"][name*="card"]','input[type="text"][name*="cvv"]','input[type="text"][name*="cvc"]','input[name*="ssn"]','input[name*="social"]',"[data-sensitive]","[data-private]"],k=[/\b\d{3}-\d{2}-\d{4}\b/,/\b\d{4}[\s-]\d{4}[\s-]\d{4}[\s-]\d{4}\b/,/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i];const C=new class{constructor(e=[]){this.sensitiveSelectors=[...b,...e]}isSensitive(e){if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;let t=e.parentElement;for(;t;){const e=t;if(this.sensitiveSelectors.some(t=>{try{return e.matches(t)}catch(e){return!1}}))return!0;t=t.parentElement}return!1}containsSensitiveData(e){return!!e&&k.some(t=>t.test(e))}sanitizeText(e){if(!e)return"";let t=e;return t=t.replace(/\b\d{3}-\d{2}-\d{4}\b/g,"***-**-****"),t=t.replace(/\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,"****-****-****-****"),t=t.replace(/\b([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,})\b/gi,"***@$2"),t}},T=["button","a[href]",'[role="button"]'],A=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class P extends w{constructor(e,t,n,i){var r,o,s;super(e,{enabled:null===(r=t.enabled)||void 0===r||r,selectors:null!==(o=t.selectors)&&void 0!==o?o:T,ignore:null!==(s=t.ignore)&&void 0!==s?s:A},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=C}attachListeners(){this.listenerAttached||("undefined"!=typeof document?(this.boundHandleClick=this.handleClick.bind(this),document.addEventListener("click",this.boundHandleClick,{passive:!0,capture:!1}),this.listenerAttached=!0,this.logger.log("log","ClickTracker: Delegated click listener attached")):this.logger.log("warn","ClickTracker: document not available, cannot attach listener"))}detachListeners(){this.listenerAttached&&this.boundHandleClick&&"undefined"!=typeof document&&(document.removeEventListener("click",this.boundHandleClick),this.listenerAttached=!1),this.debounceTimers.clear(),this.boundHandleClick=null}handleClick(e){if(!this.enabled)return;const t=e.target;if(!t)return;const n=this.findTrackableElement(t);if(!n)return;if(this.shouldIgnore(n))return void this.logger.log("log","ClickTracker: Element ignored",n);if(this.privacyGuard.isSensitive(n))return void this.logger.log("warn","ClickTracker: Sensitive element not tracked",n);if(this.isDebounced(n))return void this.logger.log("log","ClickTracker: Click debounced",n);const i=this.extractTrackingData(n);i&&(this.logger.log("log","ClickTracker: Tracking click",i),this.callback(i))}findTrackableElement(e){const t=this.config.selectors||T;try{const n=e.closest('[data-lucia-track]:not([data-lucia-track="false"])');if(n&&n!==document.body&&document.body.contains(n)){if(this.config.selectors&&this.config.selectors!==T){return t.some(e=>{try{return n.matches(e)}catch(e){return!1}})?n:null}return n}const i=t.join(", "),r=e.closest(i);return r&&r!==document.body&&document.body.contains(r)?r:null}catch(t){this.logger.log("warn","ClickTracker: Invalid combined selector, using fallback",t);let n=e;for(;n&&n!==document.body;){if(this.isTrackable(n))return n;n=n.parentElement}return null}}isTrackable(e){return(this.config.selectors||T).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid selector "${t}"`,e),!1}})}shouldIgnore(e){return(this.config.ignore||A).some(t=>{try{return e.matches(t)}catch(e){return this.logger.log("warn",`ClickTracker: Invalid ignore selector "${t}"`,e),!1}})}isDebounced(e){const t=Date.now(),n=this.debounceTimers.get(e);return!!(n&&t-n<500)||(this.debounceTimers.set(e,t),this.debounceTimers.size>100&&this.cleanupDebounceTimers(),!1)}cleanupDebounceTimers(){const e=Date.now();Array.from(this.debounceTimers.entries()).forEach(([t,n])=>{e-n>1e3&&this.debounceTimers.delete(t)})}extractTrackingData(e){var t;const n=this.getElementIdentifier(e);if(!n)return this.logger.log("warn","ClickTracker: Could not generate identifier for element",e),null;const i={button:n,elementType:this.getElementType(e),timestamp:Date.now()},r=null===(t=e.textContent)||void 0===t?void 0:t.trim();r&&(this.privacyGuard.containsSensitiveData(r)||(i.text=this.sanitizeText(r))),"a"===e.tagName.toLowerCase()?i.href=e.getAttribute("href"):i.href=null;const o=this.extractMetadata(e);return o&&Object.keys(o).length>0&&(i.meta=o),i}getElementIdentifier(e){var t;const n=e.getAttribute("data-lucia-track");if(n&&"false"!==n)return n;const i=e.getAttribute("id");if(i)return i;const r=e.getAttribute("name");if(r)return r;const o=e.getAttribute("aria-label");if(o)return o;if("a"===e.tagName.toLowerCase()){const t=e.getAttribute("href");if(t)return`link:${t}`}const s=null===(t=e.textContent)||void 0===t?void 0:t.trim();if(s)return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using text content as identifier for element. Consider adding data-lucia-track attribute.",e),`text:${this.sanitizeText(s).substring(0,50)}`;const a=this.generateCSSPath(e);return this.sdkConfig.debug&&this.logger.log("warn","ClickTracker: Using CSS path as identifier. Consider adding data-lucia-track attribute.",e),`path:${a}`}getElementType(e){const t=e.tagName.toLowerCase();if("a"===t)return"link";if("button"===t)return"button";const n=e.getAttribute("role");return n||t}sanitizeText(e){return e.trim().replace(/\s+/g," ").substring(0,100)}generateCSSPath(e){const t=[];let n=e;for(;n&&n!==document.body&&t.length<5;){let e=n.tagName.toLowerCase();if(n.id){e+=`#${n.id}`,t.unshift(e);break}const i=n.getAttribute("class");if(i){const t=i.trim().split(/\s+/).slice(0,2);t.length>0&&(e+=`.${t.join(".")}`)}t.unshift(e),n=n.parentElement}return t.join(" > ")}extractMetadata(e){const t={},{attributes:n}=e;return Array.from(n).forEach(e=>{if(e.name.startsWith("data-lucia-meta-")){const n=e.name.replace("data-lucia-meta-","").replace(/-([a-z])/g,e=>e[1].toUpperCase());t[n]=e.value}}),Object.keys(t).length>0?t:null}}const I={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new P(e,t,n,i),normalizeConfig:function(e){return void 0===e||!1===e?null:!0===e?{enabled:!0}:!1===e.enabled?null:e}};function S(){return t(this,void 0,void 0,function*(){if(O)return O;const e={device:{cores:L(()=>navigator.hardwareConcurrency),memory:L(()=>navigator.deviceMemory),cpuClass:L(()=>navigator.cpuClass),touch:D(),devicePixelRatio:L(()=>window.devicePixelRatio)},screen:{width:L(()=>window.screen.width),height:L(()=>window.screen.height),colorDepth:L(()=>window.screen.colorDepth),availHeight:L(()=>window.screen.availHeight),availWidth:L(()=>window.screen.availWidth),orientation:{type:L(()=>window.screen.orientation.type),angle:L(()=>window.screen.orientation.angle)}},browser:{language:L(()=>navigator.language),encoding:L(()=>TextDecoder.encoding),timezone:L(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:L(()=>navigator.plugins.length),pluginNames:L(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:x(),uniqueHash:yield j(),colorGamut:R(),contrastPreference:W()},permissions:{navPer:L(()=>navigator.permissions.webglVersion),renderedPer:L(()=>navigator.permissions.RENDERER),geoPer:L(()=>navigator.permissions.geolocation)},storage:{localStorage:L(()=>!!window.localStorage),indexedDB:L(()=>!!window.indexedDB),openDB:L(()=>window.openDatabase)}};return O=e,e})}function E(){const e=new URL(window.location.href).searchParams,t={};return e.forEach((e,n)=>{(n.startsWith("utm_")||n.includes("id")||"ref"===n||"source"===n)&&(t[n]=e)}),t}function L(e,t){try{return e()}catch(e){return t}}let O=null;function j(){return t(this,void 0,void 0,function*(){try{const e=document.createElement("canvas"),n=e.getContext("2d",{willReadFrequently:!0});if(!n)return;const i=200,r=120;e.width=i,e.height=r,e.style.width=`${i}px`,e.style.height=`${r}px`,n.fillStyle="#ffffff",n.fillRect(0,0,i,r),n.fillStyle="#ff00ff",n.fillRect(10,10,100,100),n.fillStyle="#00ffff",n.beginPath(),n.arc(150,50,40,0,2*Math.PI,!0),n.fill();const{data:o}=n.getImageData(0,0,i,r);return function(e){return t(this,void 0,void 0,function*(){const t=(new TextEncoder).encode(e),n=yield crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("")})}([[20,20],[60,60],[100,100],[150,50],[150,60],[140,50],[5,5]].map(([e,t])=>{const n=4*(t*i+e);return`${o[n]},${o[n+1]},${o[n+2]},${o[n+3]};`}).join(""))}catch(e){return}})}function D(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function x(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function W(){try{const{matchMedia:e}=window,t=t=>e(`(prefers-contrast: ${t})`).matches;return t("no-preference")?"None":t("high")||t("more")?"More":t("low")||t("less")?"Less":t("forced")?"ForcedColors":void 0}catch(e){return}}function R(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const U=new Map;let $=null,M=!1;function _(){return new Map(U)}const K=[{name:"Rabby",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRabby)}},{name:"Brave Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBraveWallet)}},{name:"Rainbow",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isRainbow)}},{name:"Coinbase Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoinbaseWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCoinbase)}},{name:"Trust Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTrust)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTrustWallet)}},{name:"TokenPocket",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTokenPocket)}},{name:"Zerion",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isZerion)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isPhantom)}},{name:"OKX Wallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOkxWallet)}},{name:"Bitget Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isBitKeep)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isBitgetWallet)}},{name:"SafePal",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isSafePal)}},{name:"Frontier",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrontier)}},{name:"XDEFI",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isXDEFI)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isCtrl)}},{name:"Enkrypt",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isEnkrypt)}},{name:"MetaMask",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMetaMask)}},{name:"WalletConnect",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isWalletConnect)}},{name:"imToken",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isImToken)}},{name:"Status",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isStatus)}},{name:"Tally",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isTally)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isTallyWallet)}},{name:"AlphaWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isAlphaWallet)}},{name:"Opera",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOpera)}},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isCoin98)}},{name:"MathWallet",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isMathWallet)}},{name:"1inch Wallet",detect:()=>{var e,t;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isOneInchIOSWallet)||!!(null===(t=window.ethereum)||void 0===t?void 0:t.isOneInchAndroidWallet)}},{name:"Frame",detect:()=>{var e;return!!(null===(e=window.ethereum)||void 0===e?void 0:e.isFrame)}},{name:"Binance Chain Wallet",detect:()=>!!window.BinanceChain},{name:"MetaMask",detect:()=>{var e;return Object.prototype.hasOwnProperty.call(null!==(e=window.ethereum)&&void 0!==e?e:{},"_metamask")}}],N=[{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.phantom)||void 0===e?void 0:e.solana)}},{name:"Solflare",detect:()=>!!window.solflare},{name:"Backpack",detect:()=>!!window.backpack},{name:"Glow",detect:()=>!!window.glow},{name:"Coin98",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isCoin98)}},{name:"Phantom",detect:()=>{var e;return!!(null===(e=window.solana)||void 0===e?void 0:e.isPhantom)}}];function q(){var e,t;return window.ethereum&&null!==(t=null===(e=K.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}function B(){var e,t;return null!==(t=null===(e=N.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}y.register(I);let z=class extends p{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}authenticate(){this.httpClient.post("/api/key/auth",{})}init(){return t(this,void 0,void 0,function*(){let e=v();e||(e=g());try{M||(M=!0,$=e=>{var t;const n=e.detail;(null===(t=null==n?void 0:n.info)||void 0===t?void 0:t.rdns)&&(null==n?void 0:n.provider)&&U.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",$),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield S(),n=new URL(window.location.href).searchParams.get("lucia"),i={id:e.id};e.hash&&(i.hash=e.hash);const r=f(),o=yield this.httpClient.post("/api/sdk/init",Object.assign({user:{name:m()},data:t,session:i,redirectHash:n,utm:E()},r&&{lid:r}),!1);o&&(o.lid&&localStorage.setItem("lid",o.lid),o.session&&function(e){const t={id:e.id,hash:e.hash,timestamp:Date.now()};sessionStorage.setItem(u,JSON.stringify(t))}(o.session)),y.initAll(this.store.config,{clicks:this.handleAutoTrackedClick.bind(this)},this.logger),yield this.autoDetectWallets(),this.setupWalletListeners()})}handleAutoTrackedClick(e){const t=e,n={elementType:t.elementType,text:t.text,href:t.href,meta:t.meta};this.buttonClick(t.button,n)}autoDetectWallets(){return t(this,void 0,void 0,function*(){var e,n,i;try{const e=yield function(){return t(this,void 0,void 0,function*(){const e=Array.from(U.values());if(0===e.length)return[];const t=yield Promise.allSettled(e.map(({info:e,provider:t})=>{const n=t.request({method:"eth_accounts"}).then(n=>{const i=n;return Array.isArray(i)?i.filter(e=>"string"==typeof e&&e.length>0).map(n=>({address:n,providerName:e.name,providerRdns:e.rdns,provider:t})):[]}),i=new Promise((t,n)=>setTimeout(()=>n(new Error(`EIP-6963 timeout: ${e.name}`)),3e3));return Promise.race([n,i])})),n=[];for(const e of t)"fulfilled"===e.status&&n.push(...e.value);return n})}();for(const t of e)yield this.sendWalletInfo(t.address,{provider:t.providerName,providerRdns:t.providerRdns})}catch(e){}if(0===_().size&&(null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress))try{const e=q();yield this.sendWalletInfo(window.ethereum.selectedAddress,{provider:null!=e?e:void 0})}catch(e){}if((null===(n=window.solana)||void 0===n?void 0:n.isConnected)&&(null===(i=window.solana)||void 0===i?void 0:i.publicKey))try{const e=B();yield this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0})}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){var e,t;const n=function(e){const t=t=>{var n;const i=t.detail;(null===(n=null==i?void 0:i.info)||void 0===n?void 0:n.rdns)&&(null==i?void 0:i.provider)&&(U.set(i.info.rdns,i),e(i))};return window.addEventListener("eip6963:announceProvider",t),()=>window.removeEventListener("eip6963:announceProvider",t)}(e=>{this.handleLateEIP6963Provider(e)});if(this.walletListenerCleanups.push(n),(null===(e=window.ethereum)||void 0===e?void 0:e.on)&&0===_().size){const e=e=>{const t=e;if(t[0]){const e=t[0],n=q();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};window.ethereum.on("accountsChanged",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"accountsChanged",e)})}if(null===(t=window.solana)||void 0===t?void 0:t.on){const e=()=>{var e;if(null===(e=window.solana)||void 0===e?void 0:e.publicKey){const e=B();this.sendWalletInfo(window.solana.publicKey.toString(),{provider:null!=e?e:void 0}).catch(()=>{})}};window.solana.on("connect",e),this.walletListenerCleanups.push(()=>{var t,n;null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n||n.call(t,"connect",e)})}}setupEIP6963AccountListeners(){const e=_();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e;n.request&&n.request({method:"eth_accounts"}).then(e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})}).catch(()=>{}),this.attachEIP6963AccountsChanged(e)}attachEIP6963AccountsChanged(e){const{info:t,provider:n}=e;if(!n.on)return;const i=e=>{const n=e;if(Array.isArray(n))for(const e of n)"string"==typeof e&&e.length>0&&this.sendWalletInfo(e,{provider:t.name,providerRdns:t.rdns}).catch(()=>{})};n.on("accountsChanged",i),this.walletListenerCleanups.push(()=>{var e;null===(e=n.removeListener)||void 0===e||e.call(n,"accountsChanged",i)})}userInfo(e,n){return t(this,void 0,void 0,function*(){const t=f(),i=v();e&&localStorage.setItem("luc_uid",e);const r=Object.assign({user:{name:e,userInfo:n},session:i},t&&{lid:t});yield this.httpClient.post("/api/sdk/user",r)})}pageView(e){return t(this,void 0,void 0,function*(){const t=f(),n=v(),i=Object.assign({page:e,user:{name:m()},session:n},t&&{lid:t});yield this.httpClient.post("/api/sdk/page",i)})}trackConversion(e,n,i){return t(this,void 0,void 0,function*(){const t=f(),r=v(),o=Object.assign({tag:e,amount:n,event:i,user:{name:m()},session:r},t&&{lid:t});yield this.httpClient.post("/api/sdk/conversion",o)})}buttonClick(e,n){return t(this,void 0,void 0,function*(){const t=f(),i=v(),r=Object.assign(Object.assign({button:e,user:{name:m()},session:i},t&&{lid:t}),n&&Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n.elementType&&{elementType:n.elementType}),n.text&&{text:n.text}),void 0!==n.href&&{href:n.href}),n.meta&&{meta:n.meta}),{timestamp:Date.now()}));yield this.httpClient.post("/api/sdk/click",r)})}sendWalletInfo(e,n,i){return t(this,void 0,void 0,function*(){var t,r,o;if(!e||"string"!=typeof e)return;const s=e.startsWith("0x")?e.toLowerCase():e;if(this.sentWallets.has(s))return;this.sentWallets.add(s);let a={};n&&"object"==typeof n?a=n:void 0!==n&&(a={chainId:"number"==typeof n?n:void 0,provider:i});const l=f(),c=v(),d=Object.assign(Object.assign(Object.assign(Object.assign({walletAddress:e,provider:null!==(t=a.provider)&&void 0!==t?t:null,providerRdns:null!==(r=a.providerRdns)&&void 0!==r?r:null,connectorType:null!==(o=a.connectorType)&&void 0!==o?o:null},null!=a.chainId&&{chainId:a.chainId}),i&&{walletName:i}),{user:{name:m()},session:c}),l&&{lid:l});try{yield this.httpClient.post("/api/sdk/wallet",d)}catch(e){throw this.sentWallets.delete(s),e}})}trackUserAcquisition(e){return t(this,arguments,void 0,function*(e,t={}){const n=yield S(),i=E(),r=v();yield this.httpClient.post("/api/sdk/acquisition",{user:{name:e},session:r,data:Object.assign({timestamp:(new Date).toISOString(),browserData:n,utmParams:i},t)})})}checkMetaMaskConnection(){var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))}destroy(){y.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),M&&($&&(window.removeEventListener("eip6963:announceProvider",$),$=null),U.clear(),M=!1)}},F=null;const Q=()=>{const e=F||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},H={init:e=>{if("undefined"==typeof window)return Promise.reject(new Error("LuciaSDK requires a browser environment"));if(F)return F;if(window.__luciaInitPromise)return F=window.__luciaInitPromise,F;if(!(null==e?void 0:e.apiKey))return Promise.reject(new Error("apiKey is required in config"));const n=t(void 0,void 0,void 0,function*(){const t=new z(e);return yield t.init(),t});return F=n,window.__luciaInitPromise=n,n},userInfo:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield Q()).userInfo(e,n)}),pageView:e=>t(void 0,void 0,void 0,function*(){return(yield Q()).pageView(e)}),trackConversion:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield Q()).trackConversion(e,n,i)}),buttonClick:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield Q()).buttonClick(e,n)}),sendWalletInfo:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield Q()).sendWalletInfo(e,n,i)}),trackUserAcquisition:(e,...n)=>t(void 0,[e,...n],void 0,function*(e,t={}){return(yield Q()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>{var e,t,n;return!(!(null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.isConnected)||void 0===t?void 0:t.call(e))||!(null===(n=window.ethereum)||void 0===n?void 0:n.selectedAddress))},VERSION:i};if("undefined"!=typeof window){window.LuciaSDK=H;const e=()=>{const e=document.currentScript||document.querySelector("script[data-api-key]"),t=null==e?void 0:e.getAttribute("data-api-key");if(!t)return;const n=e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");H.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{debugURL:n}),"true"===i&&{autoTrackClicks:!r||{enabled:!0,selectors:r.split(",").map(e=>e.trim())}}),"false"===i&&{autoTrackClicks:!1})).catch(e=>console.error("LuciaSDK auto-init failed:",e))};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}e.__resetInstance=()=>{const e=F||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),F=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,y.reset()},e.default=H,e.detectEvmProvider=q,e.detectSolanaProvider=B,e.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},e.getApplePayAvailable=x,e.getBrowserData=S,e.getCanvasFingerprint=j,e.getColorGamut=R,e.getContrastPreference=W,e.getUtmParams=E,e.isTouchEnabled=D,e.safeAccess=L,Object.defineProperty(e,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucia-sdk",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "description": "Lucia JavaScript Library",
6
6
  "repository": {
@@ -37,24 +37,24 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@commitlint/config-conventional": "^20.2.0",
40
+ "@eslint/js": "^10.0.1",
40
41
  "@release-it/conventional-changelog": "^10.0.4",
41
42
  "@rollup/plugin-commonjs": "^29.0.0",
42
43
  "@rollup/plugin-node-resolve": "^16.0.3",
43
44
  "@rollup/plugin-replace": "^6.0.3",
44
- "@rollup/plugin-terser": "^0.4.4",
45
+ "@rollup/plugin-terser": "^1.0.0",
45
46
  "@testing-library/jest-dom": "^6.9.1",
46
47
  "@types/jest": "^30.0.0",
47
48
  "@types/uuid": "^11.0.0",
48
49
  "@typescript-eslint/eslint-plugin": "^8.50.1",
49
50
  "@typescript-eslint/parser": "^8.50.1",
50
- "typescript-eslint": "^8.50.1",
51
51
  "commitlint": "^20.2.0",
52
- "eslint": "^9.39.2",
52
+ "eslint": "^10.0.0",
53
53
  "eslint-config-prettier": "^10.1.8",
54
54
  "eslint-plugin-import": "^2.32.0",
55
55
  "eslint-plugin-jest": "^29.11.0",
56
56
  "eslint-plugin-promise": "^7.2.1",
57
- "eslint-plugin-unicorn": "^62.0.0",
57
+ "eslint-plugin-unicorn": "^63.0.0",
58
58
  "eslint-plugin-unused-imports": "^4.3.0",
59
59
  "husky": "^9.1.7",
60
60
  "jest": "^30.2.0",
@@ -66,7 +66,8 @@
66
66
  "rollup": "^4.54.0",
67
67
  "rollup-plugin-typescript2": "^0.36.0",
68
68
  "ts-jest": "^29.4.6",
69
- "typescript": "^5.9.3"
69
+ "typescript": "^5.9.3",
70
+ "typescript-eslint": "^8.50.1"
70
71
  },
71
72
  "dependencies": {
72
73
  "uuid": "^13.0.0"