lucia-sdk 0.10.4 → 0.10.5
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 +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/package.json +5 -5
- package/dist/umd/lucia-sdk-0.10.5.min.js +1 -0
- package/dist/umd/lucia-sdk-latest.min.js +1 -1
- package/package.json +5 -5
- package/dist/umd/lucia-sdk-0.10.4.min.js +0 -1
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.4";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 S={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(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:D(),uniqueHash:yield x(),colorGamut:R(),contrastPreference:W()},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 P(){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 x(){return e(this,void 0,void 0,function*(){try{const t=document.createElement("canvas"),n=280,i=60;t.width=n,t.height=i;const r=t.getContext("2d",{willReadFrequently:!0});if(!r)return;const o=r.createLinearGradient(0,0,n,0);o.addColorStop(0,"#ff0000"),o.addColorStop(.5,"#00ff00"),o.addColorStop(1,"#0000ff"),r.fillStyle=o,r.fillRect(0,0,n,i),r.font="14px Arial, sans-serif",r.fillStyle="rgba(100, 200, 50, 0.8)",r.fillText("Cwm fjord bank glyphs vext quiz!",2,20),r.font="18px serif",r.fillText("🏴☠️🍕🎵",2,45),r.globalCompositeOperation="multiply",r.fillStyle="rgba(255, 100, 0, 0.6)",r.beginPath(),r.arc(200,30,25,0,2*Math.PI),r.fill(),r.globalCompositeOperation="source-over",r.strokeStyle="rgba(50, 50, 255, 0.7)",r.lineWidth=1.5,r.beginPath(),r.moveTo(100,5),r.bezierCurveTo(130,55,170,5,200,55),r.stroke();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("")})}(t.toDataURL("image/png"))}catch(e){return}})}function j(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function D(){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 M=null,K=!1;function $(){return new Map(U)}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(S);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{K||(K=!0,M=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",M),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:P()},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(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 e of t)yield this.sendWalletInfo(e.address,{provider:e.providerName,providerRdns:e.providerRdns})}catch(e){}if(0===$().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)&&(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=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=$();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=P(),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(),K&&(M&&(window.removeEventListener("eip6963:announceProvider",M),M=null),U.clear(),K=!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,D as getApplePayAvailable,I as getBrowserData,x as getCanvasFingerprint,R as getColorGamut,W as getContrastPreference,P 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.5";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));const s=new Uint8Array(16);function a(e,t,n){return crypto.randomUUID?crypto.randomUUID():function(e){e=e||{};const t=e.random??e.rng?.()??crypto.getRandomValues(s);if(t.length<16)throw new Error("Random bytes length must be >= 16");return t[6]=15&t[6]|64,t[8]=63&t[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()}(t)}(e)}const l="luci_session",c=new t(r.store);function d(){try{const e=sessionStorage.getItem(l);return e?JSON.parse(e):null}catch(e){return c.log("error","Error retrieving session data:",e),null}}function u(){const e={id:a(),timestamp:Date.now()};return sessionStorage.setItem(l,JSON.stringify(e)),e}function h(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function v(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class g{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 f{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 m=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}},p=['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]"],w=[/\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 y=new class{constructor(e=[]){this.sensitiveSelectors=[...p,...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&&w.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}},b=["button","a[href]",'[role="button"]'],k=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class C extends f{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:b,ignore:null!==(s=t.ignore)&&void 0!==s?s:k},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=y}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||b;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!==b){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||b).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||k).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 T={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new C(e,t,n,i),normalizeConfig:function(e){return void 0===e||!1===e?null:!0===e?{enabled:!0}:!1===e.enabled?null:e}};function A(){return e(this,void 0,void 0,function*(){if(E)return E;const e={device:{cores:P(()=>navigator.hardwareConcurrency),memory:P(()=>navigator.deviceMemory),cpuClass:P(()=>navigator.cpuClass),touch:O(),devicePixelRatio:P(()=>window.devicePixelRatio)},screen:{width:P(()=>window.screen.width),height:P(()=>window.screen.height),colorDepth:P(()=>window.screen.colorDepth),availHeight:P(()=>window.screen.availHeight),availWidth:P(()=>window.screen.availWidth),orientation:{type:P(()=>window.screen.orientation.type),angle:P(()=>window.screen.orientation.angle)}},browser:{language:P(()=>navigator.language),encoding:P(()=>TextDecoder.encoding),timezone:P(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:P(()=>navigator.plugins.length),pluginNames:P(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:x(),uniqueHash:yield L(),colorGamut:j(),contrastPreference:W()},permissions:{navPer:P(()=>navigator.permissions.webglVersion),renderedPer:P(()=>navigator.permissions.RENDERER),geoPer:P(()=>navigator.permissions.geolocation)},storage:{localStorage:P(()=>!!window.localStorage),indexedDB:P(()=>!!window.indexedDB),openDB:P(()=>window.openDatabase)}};return E=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 P(e,t){try{return e()}catch(e){return t}}function I(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t}let E=null;function L(){return e(this,void 0,void 0,function*(){try{const t=document.createElement("canvas"),n=280,i=60;t.width=n,t.height=i;const r=t.getContext("2d",{willReadFrequently:!0});if(!r)return;const o=r.createLinearGradient(0,0,n,0);o.addColorStop(0,"#ff0000"),o.addColorStop(.5,"#00ff00"),o.addColorStop(1,"#0000ff"),r.fillStyle=o,r.fillRect(0,0,n,i),r.font="14px Arial, sans-serif",r.fillStyle="rgba(100, 200, 50, 0.8)",r.fillText("Cwm fjord bank glyphs vext quiz!",2,20),r.font="18px serif",r.fillText("🏴☠️🍕🎵",2,45),r.globalCompositeOperation="multiply",r.fillStyle="rgba(255, 100, 0, 0.6)",r.beginPath(),r.arc(200,30,25,0,2*Math.PI),r.fill(),r.globalCompositeOperation="source-over",r.strokeStyle="rgba(50, 50, 255, 0.7)",r.lineWidth=1.5,r.beginPath(),r.moveTo(100,5),r.bezierCurveTo(130,55,170,5,200,55),r.stroke();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("")})}(t.toDataURL("image/png"))}catch(e){return}})}function O(){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 j(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const D=new Map;let R=null,M=!1;function K(){return new Map(D)}const U=[{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")}}],$=[{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 _(){var e,t;return window.ethereum&&null!==(t=null===(e=U.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}function N(){var e,t;return null!==(t=null===(e=$.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}m.register(T);let q=class extends g{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=d();e||(e=u());try{M||(M=!0,R=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)&&D.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",R),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield A(),n=new URL(window.location.href).searchParams.get("lucia"),i={id:e.id};e.hash&&(i.hash=e.hash);const r=h(),o=yield this.httpClient.post("/api/sdk/init",Object.assign({user:{name:v()},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(l,JSON.stringify(t))}(o.session)),m.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(D.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=_();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=N();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)&&(D.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=_();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=N();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=h(),i=d();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=h(),n=d(),i=Object.assign({page:t,user:{name:v()},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=h(),r=d(),o=Object.assign({tag:t,amount:n,event:i,user:{name:v()},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=h(),i=d(),r=Object.assign(Object.assign({button:t,user:{name:v()},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=h(),c=d(),u=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:v()},session:c}),l&&{lid:l});try{yield this.httpClient.post("/api/sdk/wallet",u)}catch(e){throw this.sentWallets.delete(s),e}})}trackUserAcquisition(t){return e(this,arguments,void 0,function*(e,t={}){const n=yield A(),i=S(),r=d();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(){m.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),M&&(R&&(window.removeEventListener("eip6963:announceProvider",R),R=null),D.clear(),M=!1)}},z=null;const B=()=>{const e=z||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},Q=()=>{const e=z||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),z=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,m.reset()},F={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 q(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 B()).userInfo(t,n)}),pageView:t=>e(void 0,void 0,void 0,function*(){return(yield B()).pageView(t)}),trackConversion:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield B()).trackConversion(t,n,i)}),buttonClick:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield B()).buttonClick(t,n)}),sendWalletInfo:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield B()).sendWalletInfo(t,n,i)}),trackUserAcquisition:(t,...n)=>e(void 0,[t,...n],void 0,function*(e,t={}){return(yield B()).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=F;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");F.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{Q as __resetInstance,F as default,_ as detectEvmProvider,N as detectSolanaProvider,I as filterObject,x as getApplePayAvailable,A as getBrowserData,L as getCanvasFingerprint,j as getColorGamut,W as getContrastPreference,S as getUtmParams,O as isTouchEnabled,P as safeAccess};
|
|
2
2
|
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../node_modules/uuid/dist/stringify.js","../node_modules/uuid/dist/rng.js","../node_modules/uuid/dist/
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../node_modules/uuid/dist/stringify.js","../node_modules/uuid/dist/rng.js","../node_modules/uuid/dist/v4.js"],"sourcesContent":["import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n return (byteToHex[arr[offset + 0]] +\n byteToHex[arr[offset + 1]] +\n byteToHex[arr[offset + 2]] +\n byteToHex[arr[offset + 3]] +\n '-' +\n byteToHex[arr[offset + 4]] +\n byteToHex[arr[offset + 5]] +\n '-' +\n byteToHex[arr[offset + 6]] +\n byteToHex[arr[offset + 7]] +\n '-' +\n byteToHex[arr[offset + 8]] +\n byteToHex[arr[offset + 9]] +\n '-' +\n byteToHex[arr[offset + 10]] +\n byteToHex[arr[offset + 11]] +\n byteToHex[arr[offset + 12]] +\n byteToHex[arr[offset + 13]] +\n byteToHex[arr[offset + 14]] +\n byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset);\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;\n","const rnds8 = new Uint8Array(16);\nexport default function rng() {\n return crypto.getRandomValues(rnds8);\n}\n","import rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (!buf && !options && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n return _v4(options, buf, offset);\n}\nfunction _v4(options, buf, offset) {\n options = options || {};\n const rnds = options.random ?? options.rng?.() ?? rng();\n if (rnds.length < 16) {\n throw new Error('Random bytes length must be >= 16');\n }\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n if (offset < 0 || offset + 16 > buf.length) {\n throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);\n }\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;\n"],"names":["byteToHex","i","push","toString","slice","rnds8","Uint8Array","v4","options","buf","offset","crypto","randomUUID","rnds","random","rng","getRandomValues","length","Error","arr","toLowerCase","unsafeStringify","_v4"],"mappings":"6jGACA,MAAMA,EAAY,GAClB,IAAK,IAAIC,EAAI,EAAGA,EAAI,MAAOA,EACvBD,EAAUE,MAAMD,EAAI,KAAOE,SAAS,IAAIC,MAAM,ICHlD,MAAMC,EAAQ,IAAIC,WAAW,ICE7B,SAASC,EAAGC,EAASC,EAAKC,GACtB,OAAwBC,OAAOC,WACpBD,OAAOC,aAItB,SAAaJ,GACTA,EAAUA,GAAW,CAAA,EACrB,MAAMK,EAAOL,EAAQM,QAAUN,EAAQO,SDRhCJ,OAAOK,gBAAgBX,GCS9B,GAAIQ,EAAKI,OAAS,GACd,MAAM,IAAIC,MAAM,qCAcpB,OAZAL,EAAK,GAAgB,GAAVA,EAAK,GAAa,GAC7BA,EAAK,GAAgB,GAAVA,EAAK,GAAa,IFV1B,SAAyBM,EAAKT,EAAS,GAC1C,OAAQV,EAAUmB,EAAIT,EAAS,IAC3BV,EAAUmB,EAAIT,EAAS,IACvBV,EAAUmB,EAAIT,EAAS,IACvBV,EAAUmB,EAAIT,EAAS,IACvB,IACAV,EAAUmB,EAAIT,EAAS,IACvBV,EAAUmB,EAAIT,EAAS,IACvB,IACAV,EAAUmB,EAAIT,EAAS,IACvBV,EAAUmB,EAAIT,EAAS,IACvB,IACAV,EAAUmB,EAAIT,EAAS,IACvBV,EAAUmB,EAAIT,EAAS,IACvB,IACAV,EAAUmB,EAAIT,EAAS,KACvBV,EAAUmB,EAAIT,EAAS,KACvBV,EAAUmB,EAAIT,EAAS,KACvBV,EAAUmB,EAAIT,EAAS,KACvBV,EAAUmB,EAAIT,EAAS,KACvBV,EAAUmB,EAAIT,EAAS,MAAMU,aACrC,CEAWC,CAAgBR,EAC3B,CArBWS,CAAId,EACf","x_google_ignoreList":[0,1,2]}
|
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.4";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 S(){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 I(){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=280,i=60;t.width=n,t.height=i;const r=t.getContext("2d",{willReadFrequently:!0});if(!r)return;const o=r.createLinearGradient(0,0,n,0);o.addColorStop(0,"#ff0000"),o.addColorStop(.5,"#00ff00"),o.addColorStop(1,"#0000ff"),r.fillStyle=o,r.fillRect(0,0,n,i),r.font="14px Arial, sans-serif",r.fillStyle="rgba(100, 200, 50, 0.8)",r.fillText("Cwm fjord bank glyphs vext quiz!",2,20),r.font="18px serif",r.fillText("🏴☠️🍕🎵",2,45),r.globalCompositeOperation="multiply",r.fillStyle="rgba(255, 100, 0, 0.6)",r.beginPath(),r.arc(200,30,25,0,2*Math.PI),r.fill(),r.globalCompositeOperation="source-over",r.strokeStyle="rgba(50, 50, 255, 0.7)",r.lineWidth=1.5,r.beginPath(),r.moveTo(100,5),r.bezierCurveTo(130,55,170,5,200,55),r.stroke();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("")})}(t.toDataURL("image/png"))}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,M=!1;function _(){return new Map(R)}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")}}],$=[{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=K.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=$.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}w.register(P);let z=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)&&R.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",U),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=g(),o=yield this.httpClient.post("/api/sdk/init",Object.assign({user:{name:f()},data:t,session:i,redirectHash:n,utm:I()},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===_().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===_().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=_();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 S(),i=I(),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),R.clear(),M=!1)}},B=null;const F=()=>{const e=B||"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(B)return B;if(window.__luciaInitPromise)return B=window.__luciaInitPromise,B;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 z(t);return yield e.init(),e});return B=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=B||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),B=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=S,exports.getCanvasFingerprint=L,exports.getColorGamut=W,exports.getContrastPreference=D,exports.getUtmParams=I,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.5";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));const s=new Uint8Array(16);function a(e,t,n){return crypto.randomUUID?crypto.randomUUID():function(e){e=e||{};const t=e.random??e.rng?.()??crypto.getRandomValues(s);if(t.length<16)throw new Error("Random bytes length must be >= 16");return t[6]=15&t[6]|64,t[8]=63&t[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()}(t)}(e)}const l="luci_session",c=new t(r.store);function d(){try{const e=sessionStorage.getItem(l);return e?JSON.parse(e):null}catch(e){return c.log("error","Error retrieving session data:",e),null}}function u(){const e={id:a(),timestamp:Date.now()};return sessionStorage.setItem(l,JSON.stringify(e)),e}function h(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function v(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class g{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 f{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 m=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}},p=['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]"],w=[/\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 y=new class{constructor(e=[]){this.sensitiveSelectors=[...p,...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&&w.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}},b=["button","a[href]",'[role="button"]'],k=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class C extends f{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:b,ignore:null!==(s=t.ignore)&&void 0!==s?s:k},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=y}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||b;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!==b){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||b).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||k).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 T={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new C(e,t,n,i),normalizeConfig:function(e){return void 0===e||!1===e?null:!0===e?{enabled:!0}:!1===e.enabled?null:e}};function A(){return e(this,void 0,void 0,function*(){if(I)return I;const e={device:{cores:S(()=>navigator.hardwareConcurrency),memory:S(()=>navigator.deviceMemory),cpuClass:S(()=>navigator.cpuClass),touch:x(),devicePixelRatio:S(()=>window.devicePixelRatio)},screen:{width:S(()=>window.screen.width),height:S(()=>window.screen.height),colorDepth:S(()=>window.screen.colorDepth),availHeight:S(()=>window.screen.availHeight),availWidth:S(()=>window.screen.availWidth),orientation:{type:S(()=>window.screen.orientation.type),angle:S(()=>window.screen.orientation.angle)}},browser:{language:S(()=>navigator.language),encoding:S(()=>TextDecoder.encoding),timezone:S(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:S(()=>navigator.plugins.length),pluginNames:S(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:L(),uniqueHash:yield E(),colorGamut:j(),contrastPreference:O()},permissions:{navPer:S(()=>navigator.permissions.webglVersion),renderedPer:S(()=>navigator.permissions.RENDERER),geoPer:S(()=>navigator.permissions.geolocation)},storage:{localStorage:S(()=>!!window.localStorage),indexedDB:S(()=>!!window.indexedDB),openDB:S(()=>window.openDatabase)}};return I=e,e})}function P(){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 S(e,t){try{return e()}catch(e){return t}}let I=null;function E(){return e(this,void 0,void 0,function*(){try{const t=document.createElement("canvas"),n=280,i=60;t.width=n,t.height=i;const r=t.getContext("2d",{willReadFrequently:!0});if(!r)return;const o=r.createLinearGradient(0,0,n,0);o.addColorStop(0,"#ff0000"),o.addColorStop(.5,"#00ff00"),o.addColorStop(1,"#0000ff"),r.fillStyle=o,r.fillRect(0,0,n,i),r.font="14px Arial, sans-serif",r.fillStyle="rgba(100, 200, 50, 0.8)",r.fillText("Cwm fjord bank glyphs vext quiz!",2,20),r.font="18px serif",r.fillText("🏴☠️🍕🎵",2,45),r.globalCompositeOperation="multiply",r.fillStyle="rgba(255, 100, 0, 0.6)",r.beginPath(),r.arc(200,30,25,0,2*Math.PI),r.fill(),r.globalCompositeOperation="source-over",r.strokeStyle="rgba(50, 50, 255, 0.7)",r.lineWidth=1.5,r.beginPath(),r.moveTo(100,5),r.bezierCurveTo(130,55,170,5,200,55),r.stroke();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("")})}(t.toDataURL("image/png"))}catch(e){return}})}function x(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function L(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function O(){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 j(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const W=new Map;let D=null,R=!1;function M(){return new Map(W)}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 U(){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 $(){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}m.register(T);let N=class extends g{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=d();e||(e=u());try{R||(R=!0,D=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)&&W.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",D),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield A(),n=new URL(window.location.href).searchParams.get("lucia"),i={id:e.id};e.hash&&(i.hash=e.hash);const r=h(),o=yield this.httpClient.post("/api/sdk/init",Object.assign({user:{name:v()},data:t,session:i,redirectHash:n,utm:P()},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(l,JSON.stringify(t))}(o.session)),m.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(W.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=U();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=$();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)&&(W.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=U();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=$();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=h(),i=d();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=h(),n=d(),i=Object.assign({page:t,user:{name:v()},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=h(),r=d(),o=Object.assign({tag:t,amount:n,event:i,user:{name:v()},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=h(),i=d(),r=Object.assign(Object.assign({button:t,user:{name:v()},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=h(),c=d(),u=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:v()},session:c}),l&&{lid:l});try{yield this.httpClient.post("/api/sdk/wallet",u)}catch(e){throw this.sentWallets.delete(s),e}})}trackUserAcquisition(t){return e(this,arguments,void 0,function*(e,t={}){const n=yield A(),i=P(),r=d();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(){m.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),R&&(D&&(window.removeEventListener("eip6963:announceProvider",D),D=null),W.clear(),R=!1)}},q=null;const z=()=>{const e=q||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},B={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 N(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 z()).userInfo(t,n)}),pageView:t=>e(void 0,void 0,void 0,function*(){return(yield z()).pageView(t)}),trackConversion:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield z()).trackConversion(t,n,i)}),buttonClick:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield z()).buttonClick(t,n)}),sendWalletInfo:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield z()).sendWalletInfo(t,n,i)}),trackUserAcquisition:(t,...n)=>e(void 0,[t,...n],void 0,function*(e,t={}){return(yield z()).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=B;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");B.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=q||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),q=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,m.reset()},exports.default=B,exports.detectEvmProvider=U,exports.detectSolanaProvider=$,exports.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},exports.getApplePayAvailable=L,exports.getBrowserData=A,exports.getCanvasFingerprint=E,exports.getColorGamut=j,exports.getContrastPreference=O,exports.getUtmParams=P,exports.isTouchEnabled=x,exports.safeAccess=S;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../node_modules/uuid/dist/stringify.js","../node_modules/uuid/dist/rng.js","../node_modules/uuid/dist/
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../node_modules/uuid/dist/stringify.js","../node_modules/uuid/dist/rng.js","../node_modules/uuid/dist/v4.js"],"sourcesContent":["import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n return (byteToHex[arr[offset + 0]] +\n byteToHex[arr[offset + 1]] +\n byteToHex[arr[offset + 2]] +\n byteToHex[arr[offset + 3]] +\n '-' +\n byteToHex[arr[offset + 4]] +\n byteToHex[arr[offset + 5]] +\n '-' +\n byteToHex[arr[offset + 6]] +\n byteToHex[arr[offset + 7]] +\n '-' +\n byteToHex[arr[offset + 8]] +\n byteToHex[arr[offset + 9]] +\n '-' +\n byteToHex[arr[offset + 10]] +\n byteToHex[arr[offset + 11]] +\n byteToHex[arr[offset + 12]] +\n byteToHex[arr[offset + 13]] +\n byteToHex[arr[offset + 14]] +\n byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset);\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;\n","const rnds8 = new Uint8Array(16);\nexport default function rng() {\n return crypto.getRandomValues(rnds8);\n}\n","import rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (!buf && !options && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n return _v4(options, buf, offset);\n}\nfunction _v4(options, buf, offset) {\n options = options || {};\n const rnds = options.random ?? options.rng?.() ?? rng();\n if (rnds.length < 16) {\n throw new Error('Random bytes length must be >= 16');\n }\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n if (offset < 0 || offset + 16 > buf.length) {\n throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);\n }\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;\n"],"names":["byteToHex","i","push","toString","slice","rnds8","Uint8Array","v4","options","buf","offset","crypto","randomUUID","rnds","random","rng","getRandomValues","length","Error","arr","toLowerCase","unsafeStringify","_v4"],"mappings":"ioGACA,MAAMA,EAAY,GAClB,IAAK,IAAIC,EAAI,EAAGA,EAAI,MAAOA,EACvBD,EAAUE,MAAMD,EAAI,KAAOE,SAAS,IAAIC,MAAM,ICHlD,MAAMC,EAAQ,IAAIC,WAAW,ICE7B,SAASC,EAAGC,EAASC,EAAKC,GACtB,OAAwBC,OAAOC,WACpBD,OAAOC,aAItB,SAAaJ,GACTA,EAAUA,GAAW,CAAA,EACrB,MAAMK,EAAOL,EAAQM,QAAUN,EAAQO,SDRhCJ,OAAOK,gBAAgBX,GCS9B,GAAIQ,EAAKI,OAAS,GACd,MAAM,IAAIC,MAAM,qCAcpB,OAZAL,EAAK,GAAgB,GAAVA,EAAK,GAAa,GAC7BA,EAAK,GAAgB,GAAVA,EAAK,GAAa,IFV1B,SAAyBM,EAAKT,EAAS,GAC1C,OAAQV,EAAUmB,EAAIT,EAAS,IAC3BV,EAAUmB,EAAIT,EAAS,IACvBV,EAAUmB,EAAIT,EAAS,IACvBV,EAAUmB,EAAIT,EAAS,IACvB,IACAV,EAAUmB,EAAIT,EAAS,IACvBV,EAAUmB,EAAIT,EAAS,IACvB,IACAV,EAAUmB,EAAIT,EAAS,IACvBV,EAAUmB,EAAIT,EAAS,IACvB,IACAV,EAAUmB,EAAIT,EAAS,IACvBV,EAAUmB,EAAIT,EAAS,IACvB,IACAV,EAAUmB,EAAIT,EAAS,KACvBV,EAAUmB,EAAIT,EAAS,KACvBV,EAAUmB,EAAIT,EAAS,KACvBV,EAAUmB,EAAIT,EAAS,KACvBV,EAAUmB,EAAIT,EAAS,KACvBV,EAAUmB,EAAIT,EAAS,MAAMU,aACrC,CEAWC,CAAgBR,EAC3B,CArBWS,CAAId,EACf","x_google_ignoreList":[0,1,2]}
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lucia-sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.5",
|
|
4
4
|
"license": "CC-BY-NC-4.0",
|
|
5
5
|
"description": "Lucia JavaScript Library",
|
|
6
6
|
"repository": {
|
|
@@ -54,7 +54,7 @@
|
|
|
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": "^
|
|
57
|
+
"eslint-plugin-unicorn": "^64.0.0",
|
|
58
58
|
"eslint-plugin-unused-imports": "^4.3.0",
|
|
59
59
|
"husky": "^9.1.7",
|
|
60
60
|
"jest": "^30.2.0",
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"prettier": "^3.7.4",
|
|
65
65
|
"release-it": "^19.2.1",
|
|
66
66
|
"rollup": "^4.54.0",
|
|
67
|
-
"rollup-plugin-typescript2": "^0.
|
|
67
|
+
"rollup-plugin-typescript2": "^0.37.0",
|
|
68
68
|
"ts-jest": "^29.4.6",
|
|
69
|
-
"typescript": "^
|
|
69
|
+
"typescript": "^6.0.3",
|
|
70
70
|
"typescript-eslint": "^8.50.1"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"uuid": "^
|
|
73
|
+
"uuid": "^14.0.0"
|
|
74
74
|
},
|
|
75
75
|
"resolutions": {
|
|
76
76
|
"conventional-changelog-conventionalcommits": "^9.1.0"
|
|
@@ -0,0 +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.5";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));const a=new Uint8Array(16);function l(e,t,n){return crypto.randomUUID?crypto.randomUUID():function(e){e=e||{};const t=e.random??e.rng?.()??crypto.getRandomValues(a);if(t.length<16)throw new Error("Random bytes length must be >= 16");return t[6]=15&t[6]|64,t[8]=63&t[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()}(t)}(e)}const c="luci_session",d=new n(o.store);function u(){try{const e=sessionStorage.getItem(c);return e?JSON.parse(e):null}catch(e){return d.log("error","Error retrieving session data:",e),null}}function h(){const e={id:l(),timestamp:Date.now()};return sessionStorage.setItem(c,JSON.stringify(e)),e}function v(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function g(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class f{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 m{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 p=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}},w=['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]"],y=[/\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 b=new class{constructor(e=[]){this.sensitiveSelectors=[...w,...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&&y.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}},k=["button","a[href]",'[role="button"]'],C=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class T extends m{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:k,ignore:null!==(s=t.ignore)&&void 0!==s?s:C},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=b}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||k;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!==k){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||k).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||C).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 A={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new T(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 t(this,void 0,void 0,function*(){if(E)return E;const e={device:{cores:I(()=>navigator.hardwareConcurrency),memory:I(()=>navigator.deviceMemory),cpuClass:I(()=>navigator.cpuClass),touch:O(),devicePixelRatio:I(()=>window.devicePixelRatio)},screen:{width:I(()=>window.screen.width),height:I(()=>window.screen.height),colorDepth:I(()=>window.screen.colorDepth),availHeight:I(()=>window.screen.availHeight),availWidth:I(()=>window.screen.availWidth),orientation:{type:I(()=>window.screen.orientation.type),angle:I(()=>window.screen.orientation.angle)}},browser:{language:I(()=>navigator.language),encoding:I(()=>TextDecoder.encoding),timezone:I(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:I(()=>navigator.plugins.length),pluginNames:I(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:x(),uniqueHash:yield L(),colorGamut:W(),contrastPreference:j()},permissions:{navPer:I(()=>navigator.permissions.webglVersion),renderedPer:I(()=>navigator.permissions.RENDERER),geoPer:I(()=>navigator.permissions.geolocation)},storage:{localStorage:I(()=>!!window.localStorage),indexedDB:I(()=>!!window.indexedDB),openDB:I(()=>window.openDatabase)}};return E=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 I(e,t){try{return e()}catch(e){return t}}let E=null;function L(){return t(this,void 0,void 0,function*(){try{const e=document.createElement("canvas"),n=280,i=60;e.width=n,e.height=i;const r=e.getContext("2d",{willReadFrequently:!0});if(!r)return;const o=r.createLinearGradient(0,0,n,0);o.addColorStop(0,"#ff0000"),o.addColorStop(.5,"#00ff00"),o.addColorStop(1,"#0000ff"),r.fillStyle=o,r.fillRect(0,0,n,i),r.font="14px Arial, sans-serif",r.fillStyle="rgba(100, 200, 50, 0.8)",r.fillText("Cwm fjord bank glyphs vext quiz!",2,20),r.font="18px serif",r.fillText("🏴☠️🍕🎵",2,45),r.globalCompositeOperation="multiply",r.fillStyle="rgba(255, 100, 0, 0.6)",r.beginPath(),r.arc(200,30,25,0,2*Math.PI),r.fill(),r.globalCompositeOperation="source-over",r.strokeStyle="rgba(50, 50, 255, 0.7)",r.lineWidth=1.5,r.beginPath(),r.moveTo(100,5),r.bezierCurveTo(130,55,170,5,200,55),r.stroke();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("")})}(e.toDataURL("image/png"))}catch(e){return}})}function O(){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 j(){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 D=new Map;let R=null,M=!1;function _(){return new Map(D)}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")}}],U=[{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 $(){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 N(){var e,t;return null!==(t=null===(e=U.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}p.register(A);let q=class extends f{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=u();e||(e=h());try{M||(M=!0,R=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)&&D.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",R),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=v(),o=yield this.httpClient.post("/api/sdk/init",Object.assign({user:{name:g()},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(c,JSON.stringify(t))}(o.session)),p.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(D.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=$();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=N();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)&&(D.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=$();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=N();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=v(),i=u();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=v(),n=u(),i=Object.assign({page:e,user:{name:g()},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=v(),r=u(),o=Object.assign({tag:e,amount:n,event:i,user:{name:g()},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=v(),i=u(),r=Object.assign(Object.assign({button:e,user:{name:g()},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=v(),c=u(),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:g()},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 P(),i=S(),r=u();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(){p.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),M&&(R&&(window.removeEventListener("eip6963:announceProvider",R),R=null),D.clear(),M=!1)}},z=null;const B=()=>{const e=z||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},F={init:e=>{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==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 q(e);return yield t.init(),t});return z=n,window.__luciaInitPromise=n,n},userInfo:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield B()).userInfo(e,n)}),pageView:e=>t(void 0,void 0,void 0,function*(){return(yield B()).pageView(e)}),trackConversion:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield B()).trackConversion(e,n,i)}),buttonClick:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield B()).buttonClick(e,n)}),sendWalletInfo:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield B()).sendWalletInfo(e,n,i)}),trackUserAcquisition:(e,...n)=>t(void 0,[e,...n],void 0,function*(e,t={}){return(yield B()).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=F;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");F.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=z||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),z=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,p.reset()},e.default=F,e.detectEvmProvider=$,e.detectSolanaProvider=N,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=P,e.getCanvasFingerprint=L,e.getColorGamut=W,e.getContrastPreference=j,e.getUtmParams=S,e.isTouchEnabled=O,e.safeAccess=I,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.4";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 S={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 I(){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:x(),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:D(),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=280,i=60;e.width=n,e.height=i;const r=e.getContext("2d",{willReadFrequently:!0});if(!r)return;const o=r.createLinearGradient(0,0,n,0);o.addColorStop(0,"#ff0000"),o.addColorStop(.5,"#00ff00"),o.addColorStop(1,"#0000ff"),r.fillStyle=o,r.fillRect(0,0,n,i),r.font="14px Arial, sans-serif",r.fillStyle="rgba(100, 200, 50, 0.8)",r.fillText("Cwm fjord bank glyphs vext quiz!",2,20),r.font="18px serif",r.fillText("🏴☠️🍕🎵",2,45),r.globalCompositeOperation="multiply",r.fillStyle="rgba(255, 100, 0, 0.6)",r.beginPath(),r.arc(200,30,25,0,2*Math.PI),r.fill(),r.globalCompositeOperation="source-over",r.strokeStyle="rgba(50, 50, 255, 0.7)",r.lineWidth=1.5,r.beginPath(),r.moveTo(100,5),r.bezierCurveTo(130,55,170,5,200,55),r.stroke();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("")})}(e.toDataURL("image/png"))}catch(e){return}})}function x(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function D(){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 M=null,_=!1;function K(){return new Map(U)}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}y.register(S);let B=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{_||(_=!0,M=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",M),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=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===K().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=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)&&(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===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(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 I(),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",M),M=null),U.clear(),_=!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 B(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=z,e.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},e.getApplePayAvailable=D,e.getBrowserData=I,e.getCanvasFingerprint=j,e.getColorGamut=R,e.getContrastPreference=W,e.getUtmParams=E,e.isTouchEnabled=x,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.5";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));const a=new Uint8Array(16);function l(e,t,n){return crypto.randomUUID?crypto.randomUUID():function(e){e=e||{};const t=e.random??e.rng?.()??crypto.getRandomValues(a);if(t.length<16)throw new Error("Random bytes length must be >= 16");return t[6]=15&t[6]|64,t[8]=63&t[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()}(t)}(e)}const c="luci_session",d=new n(o.store);function u(){try{const e=sessionStorage.getItem(c);return e?JSON.parse(e):null}catch(e){return d.log("error","Error retrieving session data:",e),null}}function h(){const e={id:l(),timestamp:Date.now()};return sessionStorage.setItem(c,JSON.stringify(e)),e}function v(){const e=localStorage.getItem("lid");return"undefined"===e||"null"===e?(localStorage.removeItem("lid"),null):e}function g(){const e=localStorage.getItem("luc_uid");return"undefined"===e||"null"===e?(localStorage.removeItem("luc_uid"),null):e}class f{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 m{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 p=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}},w=['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]"],y=[/\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 b=new class{constructor(e=[]){this.sensitiveSelectors=[...w,...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&&y.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}},k=["button","a[href]",'[role="button"]'],C=["[data-lucia-ignore]",'[data-lucia-track="false"]'];class T extends m{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:k,ignore:null!==(s=t.ignore)&&void 0!==s?s:C},n,i),this.name="clicks",this.configKey="autoTrackClicks",this.debounceTimers=new Map,this.listenerAttached=!1,this.boundHandleClick=null,this.privacyGuard=b}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||k;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!==k){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||k).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||C).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 A={name:"clicks",configKey:"autoTrackClicks",factory:(e,t,n,i)=>new T(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 t(this,void 0,void 0,function*(){if(E)return E;const e={device:{cores:I(()=>navigator.hardwareConcurrency),memory:I(()=>navigator.deviceMemory),cpuClass:I(()=>navigator.cpuClass),touch:O(),devicePixelRatio:I(()=>window.devicePixelRatio)},screen:{width:I(()=>window.screen.width),height:I(()=>window.screen.height),colorDepth:I(()=>window.screen.colorDepth),availHeight:I(()=>window.screen.availHeight),availWidth:I(()=>window.screen.availWidth),orientation:{type:I(()=>window.screen.orientation.type),angle:I(()=>window.screen.orientation.angle)}},browser:{language:I(()=>navigator.language),encoding:I(()=>TextDecoder.encoding),timezone:I(()=>-(new Date).getTimezoneOffset()/60),pluginsLength:I(()=>navigator.plugins.length),pluginNames:I(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:x(),uniqueHash:yield L(),colorGamut:W(),contrastPreference:j()},permissions:{navPer:I(()=>navigator.permissions.webglVersion),renderedPer:I(()=>navigator.permissions.RENDERER),geoPer:I(()=>navigator.permissions.geolocation)},storage:{localStorage:I(()=>!!window.localStorage),indexedDB:I(()=>!!window.indexedDB),openDB:I(()=>window.openDatabase)}};return E=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 I(e,t){try{return e()}catch(e){return t}}let E=null;function L(){return t(this,void 0,void 0,function*(){try{const e=document.createElement("canvas"),n=280,i=60;e.width=n,e.height=i;const r=e.getContext("2d",{willReadFrequently:!0});if(!r)return;const o=r.createLinearGradient(0,0,n,0);o.addColorStop(0,"#ff0000"),o.addColorStop(.5,"#00ff00"),o.addColorStop(1,"#0000ff"),r.fillStyle=o,r.fillRect(0,0,n,i),r.font="14px Arial, sans-serif",r.fillStyle="rgba(100, 200, 50, 0.8)",r.fillText("Cwm fjord bank glyphs vext quiz!",2,20),r.font="18px serif",r.fillText("🏴☠️🍕🎵",2,45),r.globalCompositeOperation="multiply",r.fillStyle="rgba(255, 100, 0, 0.6)",r.beginPath(),r.arc(200,30,25,0,2*Math.PI),r.fill(),r.globalCompositeOperation="source-over",r.strokeStyle="rgba(50, 50, 255, 0.7)",r.lineWidth=1.5,r.beginPath(),r.moveTo(100,5),r.bezierCurveTo(130,55,170,5,200,55),r.stroke();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("")})}(e.toDataURL("image/png"))}catch(e){return}})}function O(){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 j(){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 D=new Map;let R=null,M=!1;function _(){return new Map(D)}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")}}],U=[{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 $(){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 N(){var e,t;return null!==(t=null===(e=U.find(e=>e.detect()))||void 0===e?void 0:e.name)&&void 0!==t?t:null}p.register(A);let q=class extends f{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=u();e||(e=h());try{M||(M=!0,R=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)&&D.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",R),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=v(),o=yield this.httpClient.post("/api/sdk/init",Object.assign({user:{name:g()},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(c,JSON.stringify(t))}(o.session)),p.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(D.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=$();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=N();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)&&(D.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=$();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=N();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=v(),i=u();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=v(),n=u(),i=Object.assign({page:e,user:{name:g()},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=v(),r=u(),o=Object.assign({tag:e,amount:n,event:i,user:{name:g()},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=v(),i=u(),r=Object.assign(Object.assign({button:e,user:{name:g()},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=v(),c=u(),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:g()},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 P(),i=S(),r=u();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(){p.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),M&&(R&&(window.removeEventListener("eip6963:announceProvider",R),R=null),D.clear(),M=!1)}},z=null;const B=()=>{const e=z||"undefined"!=typeof window&&window.__luciaInitPromise;if(!e)throw new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first");return e},F={init:e=>{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==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 q(e);return yield t.init(),t});return z=n,window.__luciaInitPromise=n,n},userInfo:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield B()).userInfo(e,n)}),pageView:e=>t(void 0,void 0,void 0,function*(){return(yield B()).pageView(e)}),trackConversion:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield B()).trackConversion(e,n,i)}),buttonClick:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield B()).buttonClick(e,n)}),sendWalletInfo:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield B()).sendWalletInfo(e,n,i)}),trackUserAcquisition:(e,...n)=>t(void 0,[e,...n],void 0,function*(e,t={}){return(yield B()).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=F;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");F.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=z||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),z=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,p.reset()},e.default=F,e.detectEvmProvider=$,e.detectSolanaProvider=N,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=P,e.getCanvasFingerprint=L,e.getColorGamut=W,e.getContrastPreference=j,e.getUtmParams=S,e.isTouchEnabled=O,e.safeAccess=I,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.
|
|
3
|
+
"version": "0.10.5",
|
|
4
4
|
"license": "CC-BY-NC-4.0",
|
|
5
5
|
"description": "Lucia JavaScript Library",
|
|
6
6
|
"repository": {
|
|
@@ -54,7 +54,7 @@
|
|
|
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": "^
|
|
57
|
+
"eslint-plugin-unicorn": "^64.0.0",
|
|
58
58
|
"eslint-plugin-unused-imports": "^4.3.0",
|
|
59
59
|
"husky": "^9.1.7",
|
|
60
60
|
"jest": "^30.2.0",
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"prettier": "^3.7.4",
|
|
65
65
|
"release-it": "^19.2.1",
|
|
66
66
|
"rollup": "^4.54.0",
|
|
67
|
-
"rollup-plugin-typescript2": "^0.
|
|
67
|
+
"rollup-plugin-typescript2": "^0.37.0",
|
|
68
68
|
"ts-jest": "^29.4.6",
|
|
69
|
-
"typescript": "^
|
|
69
|
+
"typescript": "^6.0.3",
|
|
70
70
|
"typescript-eslint": "^8.50.1"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"uuid": "^
|
|
73
|
+
"uuid": "^14.0.0"
|
|
74
74
|
},
|
|
75
75
|
"resolutions": {
|
|
76
76
|
"conventional-changelog-conventionalcommits": "^9.1.0"
|
|
@@ -1 +0,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.4";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 S={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 I(){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:x(),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:D(),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=280,i=60;e.width=n,e.height=i;const r=e.getContext("2d",{willReadFrequently:!0});if(!r)return;const o=r.createLinearGradient(0,0,n,0);o.addColorStop(0,"#ff0000"),o.addColorStop(.5,"#00ff00"),o.addColorStop(1,"#0000ff"),r.fillStyle=o,r.fillRect(0,0,n,i),r.font="14px Arial, sans-serif",r.fillStyle="rgba(100, 200, 50, 0.8)",r.fillText("Cwm fjord bank glyphs vext quiz!",2,20),r.font="18px serif",r.fillText("🏴☠️🍕🎵",2,45),r.globalCompositeOperation="multiply",r.fillStyle="rgba(255, 100, 0, 0.6)",r.beginPath(),r.arc(200,30,25,0,2*Math.PI),r.fill(),r.globalCompositeOperation="source-over",r.strokeStyle="rgba(50, 50, 255, 0.7)",r.lineWidth=1.5,r.beginPath(),r.moveTo(100,5),r.bezierCurveTo(130,55,170,5,200,55),r.stroke();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("")})}(e.toDataURL("image/png"))}catch(e){return}})}function x(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}function D(){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 M=null,_=!1;function K(){return new Map(U)}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}y.register(S);let B=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{_||(_=!0,M=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",M),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=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===K().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=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)&&(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===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(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 I(),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",M),M=null),U.clear(),_=!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 B(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=z,e.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},e.getApplePayAvailable=D,e.getBrowserData=I,e.getCanvasFingerprint=j,e.getColorGamut=R,e.getContrastPreference=W,e.getUtmParams=E,e.isTouchEnabled=x,e.safeAccess=L,Object.defineProperty(e,"__esModule",{value:!0})});
|