lucia-sdk 0.12.2 → 0.13.0

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/README.md CHANGED
@@ -35,7 +35,7 @@ The SDK will automatically initialize when you provide the `data-api-key` attrib
35
35
  Optional configuration attributes:
36
36
 
37
37
  - `data-api-key` (required) - Your Lucia API key
38
- - `data-debug-url` (optional) - Custom debug endpoint URL
38
+ - `data-api-host` (optional) - API origin to send events to, e.g. your own first-party domain (default `https://api.luciaprotocol.com`)
39
39
  - `data-auto-track-clicks` (optional) - Enable automatic click tracking (`"true"` or `"false"`)
40
40
  - `data-track-selectors` (optional) - Custom CSS selectors for click tracking (comma-separated)
41
41
 
@@ -48,7 +48,7 @@ Load the script without attributes and initialize programmatically:
48
48
  <script>
49
49
  LuciaSDK.init({
50
50
  apiKey: 'your-api-key-here',
51
- debugURL: 'https://custom-debug-url.com', // optional
51
+ apiHost: 'https://t.your-domain.com', // optional, defaults to https://api.luciaprotocol.com
52
52
  });
53
53
  </script>
54
54
  ```
@@ -62,7 +62,7 @@ Load the script without attributes and initialize programmatically:
62
62
  ```javascript
63
63
  LuciaSDK.init({
64
64
  apiKey: 'your-api-key-here',
65
- debugURL: 'https://custom-debug-url.com', // optional
65
+ apiHost: 'https://t.your-domain.com', // optional, defaults to https://api.luciaprotocol.com
66
66
  });
67
67
  ```
68
68
 
package/dist/README.md CHANGED
@@ -35,7 +35,7 @@ The SDK will automatically initialize when you provide the `data-api-key` attrib
35
35
  Optional configuration attributes:
36
36
 
37
37
  - `data-api-key` (required) - Your Lucia API key
38
- - `data-debug-url` (optional) - Custom debug endpoint URL
38
+ - `data-api-host` (optional) - API origin to send events to, e.g. your own first-party domain (default `https://api.luciaprotocol.com`)
39
39
  - `data-auto-track-clicks` (optional) - Enable automatic click tracking (`"true"` or `"false"`)
40
40
  - `data-track-selectors` (optional) - Custom CSS selectors for click tracking (comma-separated)
41
41
 
@@ -48,7 +48,7 @@ Load the script without attributes and initialize programmatically:
48
48
  <script>
49
49
  LuciaSDK.init({
50
50
  apiKey: 'your-api-key-here',
51
- debugURL: 'https://custom-debug-url.com', // optional
51
+ apiHost: 'https://t.your-domain.com', // optional, defaults to https://api.luciaprotocol.com
52
52
  });
53
53
  </script>
54
54
  ```
@@ -62,7 +62,7 @@ Load the script without attributes and initialize programmatically:
62
62
  ```javascript
63
63
  LuciaSDK.init({
64
64
  apiKey: 'your-api-key-here',
65
- debugURL: 'https://custom-debug-url.com', // optional
65
+ apiHost: 'https://t.your-domain.com', // optional, defaults to https://api.luciaprotocol.com
66
66
  });
67
67
  ```
68
68
 
@@ -5,7 +5,6 @@ declare class LuciaSDK extends BaseClass {
5
5
  private sentWallets;
6
6
  /** Stored listener references for cleanup */
7
7
  private walletListenerCleanups;
8
- authenticate(): void;
9
8
  /**
10
9
  * Initializes the SDK with the provided configuration
11
10
  */
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.12.2";class i{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new t(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"https://staging.api.clickinsights.xyz":"https://api.luciaprotocol.com"}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 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 f=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]"],p=[/\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=[...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&&p.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 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: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(x)return x;const e={cores:S(()=>navigator.hardwareConcurrency),memory:S(()=>navigator.deviceMemory),cpuClass:S(()=>navigator.cpuClass),touch:j(),maxTouchPoints:S(()=>navigator.maxTouchPoints),platform:S(()=>navigator.platform),devicePixelRatio:S(()=>window.devicePixelRatio)},t={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)}},n=yield R(),i={language:S(()=>navigator.language),languages:S(()=>Array.from(navigator.languages)),encoding:S(()=>TextDecoder.encoding),timezone:S(()=>-(new Date).getTimezoneOffset()/60),timezoneName:S(()=>Intl.DateTimeFormat().resolvedOptions().timeZone),pluginsLength:S(()=>navigator.plugins.length),pluginNames:S(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:_(),uniqueHash:n.uniqueHash,canvasNoisy:n.canvasNoisy,colorGamut:N(),contrastPreference:M()},r={localStorage:S(()=>!!window.localStorage),indexedDB:S(()=>!!window.indexedDB),openDB:S(()=>window.openDatabase)},o={device:e,screen:t,browser:i,webgl:W(),storage:r};return x=o,o})}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 S(e,t){try{return e()}catch(e){return t}}function P(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t}function I(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("")})}let x=null;function L(){const e=document.createElement("canvas");e.width=280,e.height=60;const t=e.getContext("2d",{willReadFrequently:!0});if(!t)return;const n=t.createLinearGradient(0,0,280,0);return n.addColorStop(0,"#ff0000"),n.addColorStop(.5,"#00ff00"),n.addColorStop(1,"#0000ff"),t.fillStyle=n,t.fillRect(0,0,280,60),t.font="14px Arial, sans-serif",t.fillStyle="rgba(100, 200, 50, 0.8)",t.fillText("Cwm fjord bank glyphs vext quiz!",2,20),t.font="18px serif",t.fillText("🏴‍☠️🍕🎵",2,45),t.globalCompositeOperation="multiply",t.fillStyle="rgba(255, 100, 0, 0.6)",t.beginPath(),t.arc(200,30,25,0,2*Math.PI),t.fill(),t.globalCompositeOperation="source-over",t.strokeStyle="rgba(50, 50, 255, 0.7)",t.lineWidth=1.5,t.beginPath(),t.moveTo(100,5),t.bezierCurveTo(130,55,170,5,200,55),t.stroke(),e.toDataURL("image/png")}function O(){return e(this,void 0,void 0,function*(){try{const e=navigator.brave;return!0===(yield null==e?void 0:e.isBrave())}catch(e){return!1}})}function R(){return e(this,void 0,void 0,function*(){try{const e=L();return e?{uniqueHash:yield I(e),canvasNoisy:e!==L()||(yield O())}:{}}catch(e){return{}}})}function D(){return e(this,void 0,void 0,function*(){return(yield R()).uniqueHash})}function W(){var e,t;try{const n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(!i)return;const r=i.getExtension("WEBGL_debug_renderer_info"),o={vendor:i.getParameter(i.VENDOR),renderer:i.getParameter(i.RENDERER),unmaskedVendor:r?i.getParameter(r.UNMASKED_VENDOR_WEBGL):void 0,unmaskedRenderer:r?i.getParameter(r.UNMASKED_RENDERER_WEBGL):void 0,version:i.getParameter(i.VERSION),shadingLanguageVersion:i.getParameter(i.SHADING_LANGUAGE_VERSION),maxTextureSize:i.getParameter(i.MAX_TEXTURE_SIZE),maxRenderbufferSize:i.getParameter(i.MAX_RENDERBUFFER_SIZE),maxViewportDims:Array.from(i.getParameter(i.MAX_VIEWPORT_DIMS)),maxVertexAttribs:i.getParameter(i.MAX_VERTEX_ATTRIBS),extensions:null!==(e=i.getSupportedExtensions())&&void 0!==e?e:[]};return null===(t=i.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext(),o}catch(e){return}}function j(){try{return navigator.maxTouchPoints>0}catch(e){return!1}}function _(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function M(){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 N(){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 K=null,B=!1;function $(){return new Map(U)}const z=[{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")}}],q=[{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 V(e){try{return e()}catch(e){return}}function H(){var e;return null!==(e=V(()=>{var e,t;return window.ethereum&&null!==(t=null===(e=z.find(e=>!0===V(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}))&&void 0!==e?e:null}function F(){var e,t;return null!==(t=null===(e=q.find(e=>!0===V(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}f.register(T);let G,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{B||(B=!0,K=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",K),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: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(l,JSON.stringify(t))}(o.session),n&&function(){const e=new URL(window.location.href);if(e.searchParams.has("lucia")){e.searchParams.delete("lucia");try{window.history.replaceState(window.history.state,"",e.toString())}catch(e){}}}()),f.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*(){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)try{const e=V(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress});if(e){const t=H();yield this.sendWalletInfo(e,{provider:null!=t?t:void 0})}}catch(e){}try{const e=V(()=>{var e,t;return(null===(e=window.solana)||void 0===e?void 0:e.isConnected)?null===(t=window.solana)||void 0===t?void 0:t.publicKey:void 0});if(e){const t=F();yield this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0})}}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){const e=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(e),0===$().size&&V(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.on})){const e=e=>{const t=e;if(t[0]){const e=t[0],n=H();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};V(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"accountsChanged",e)}),this.walletListenerCleanups.push(()=>{V(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"accountsChanged",e)})})}if(V(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.on})){const e=()=>{const e=V(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.publicKey});if(e){const t=F();this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0}).catch(()=>{})}};V(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"connect",e)}),this.walletListenerCleanups.push(()=>{V(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"connect",e)})})}}setupEIP6963AccountListeners(){const e=$();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e,i=V(()=>{var e;return null===(e=n.request)||void 0===e?void 0:e.call(n,{method:"eth_accounts"})});i&&i.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(!V(()=>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(()=>{})};V(()=>{var e;return null===(e=n.on)||void 0===e?void 0:e.call(n,"accountsChanged",i)}),this.walletListenerCleanups.push(()=>{V(()=>{var e;return null===(e=n.removeListener)||void 0===e?void 0: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,r){return e(this,void 0,void 0,function*(){const e=h(),o=d(),s=Object.assign(Object.assign(Object.assign({tag:t,amount:n},r&&{currency:r}),{event:i,user:{name:v()},session:o}),e&&{lid:e});yield this.httpClient.post("/api/sdk/conversion",s)})}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=E(),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(){return!!V(()=>{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(){f.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),B&&(K&&(window.removeEventListener("eip6963:announceProvider",K),K=null),U.clear(),B=!1)}},X=null,Z=null;const J=()=>new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first"),Y=()=>{if("undefined"==typeof window)throw J();const e=X||window.__luciaInitPromise;return e||(null!=Z||(Z=new Promise((e,t)=>{const n=Date.now();G=setInterval(()=>{const i=X||window.__luciaInitPromise;!i&&Date.now()-n<15e3||(clearInterval(G),Z=null,i?e(i):t(J()))},50)})),Z)},ee=()=>{const e=X||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),X=null,clearInterval(G),Z=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,f.reset()},te={init:t=>{if("undefined"==typeof window)return Promise.reject(new Error("LuciaSDK requires a browser environment"));if(X)return X;if(window.__luciaInitPromise)return X=window.__luciaInitPromise,X;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 X=n,window.__luciaInitPromise=n,n},userInfo:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield Y()).userInfo(t,n)}),pageView:t=>e(void 0,void 0,void 0,function*(){return(yield Y()).pageView(t)}),trackConversion:(t,n,i,r)=>e(void 0,void 0,void 0,function*(){return(yield Y()).trackConversion(t,n,i,r)}),buttonClick:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield Y()).buttonClick(t,n)}),sendWalletInfo:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield Y()).sendWalletInfo(t,n,i)}),trackUserAcquisition:(t,...n)=>e(void 0,[t,...n],void 0,function*(e,t={}){return(yield Y()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>!!V(()=>{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=te;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");te.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{ee as __resetInstance,te as default,H as detectEvmProvider,F as detectSolanaProvider,P as filterObject,_ as getApplePayAvailable,A as getBrowserData,D as getCanvasFingerprint,N as getColorGamut,M as getContrastPreference,E as getUtmParams,W as getWebGLInfo,j as isTouchEnabled,S 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.13.0";class i{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new t(this.store)}getBaseURL(){const{config:e}=this.store,t=(null==e?void 0:e.apiHost)||(null==e?void 0:e.debugURL);return t?t.replace(/\/+$/,""):(null==e?void 0:e.testENV)?"https://staging.api.clickinsights.xyz":"https://api.luciaprotocol.com"}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;const r=fetch(`${this.baseURL}${e}`,{method:"POST",keepalive:i,headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":n},body:JSON.stringify(t)});if(i)return r.catch(e=>this.logger.log("error",e)),null;try{const e=yield r;return yield e.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 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 f=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]"],p=[/\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=[...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&&p.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 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: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(x)return x;const e={cores:P(()=>navigator.hardwareConcurrency),memory:P(()=>navigator.deviceMemory),cpuClass:P(()=>navigator.cpuClass),touch:j(),maxTouchPoints:P(()=>navigator.maxTouchPoints),platform:P(()=>navigator.platform),devicePixelRatio:P(()=>window.devicePixelRatio)},t={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)}},n=yield O(),i={language:P(()=>navigator.language),languages:P(()=>Array.from(navigator.languages)),encoding:P(()=>TextDecoder.encoding),timezone:P(()=>-(new Date).getTimezoneOffset()/60),timezoneName:P(()=>Intl.DateTimeFormat().resolvedOptions().timeZone),pluginsLength:P(()=>navigator.plugins.length),pluginNames:P(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:_(),uniqueHash:n.uniqueHash,canvasNoisy:n.canvasNoisy,colorGamut:N(),contrastPreference:M()},r={localStorage:P(()=>!!window.localStorage),indexedDB:P(()=>!!window.indexedDB),openDB:P(()=>window.openDatabase)},o={device:e,screen:t,browser:i,webgl:W(),storage:r};return x=o,o})}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 P(e,t){try{return e()}catch(e){return t}}function S(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t}function I(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("")})}let x=null;function L(){const e=document.createElement("canvas");e.width=280,e.height=60;const t=e.getContext("2d",{willReadFrequently:!0});if(!t)return;const n=t.createLinearGradient(0,0,280,0);return n.addColorStop(0,"#ff0000"),n.addColorStop(.5,"#00ff00"),n.addColorStop(1,"#0000ff"),t.fillStyle=n,t.fillRect(0,0,280,60),t.font="14px Arial, sans-serif",t.fillStyle="rgba(100, 200, 50, 0.8)",t.fillText("Cwm fjord bank glyphs vext quiz!",2,20),t.font="18px serif",t.fillText("🏴‍☠️🍕🎵",2,45),t.globalCompositeOperation="multiply",t.fillStyle="rgba(255, 100, 0, 0.6)",t.beginPath(),t.arc(200,30,25,0,2*Math.PI),t.fill(),t.globalCompositeOperation="source-over",t.strokeStyle="rgba(50, 50, 255, 0.7)",t.lineWidth=1.5,t.beginPath(),t.moveTo(100,5),t.bezierCurveTo(130,55,170,5,200,55),t.stroke(),e.toDataURL("image/png")}function D(){return e(this,void 0,void 0,function*(){try{const e=navigator.brave;return!0===(yield null==e?void 0:e.isBrave())}catch(e){return!1}})}function O(){return e(this,void 0,void 0,function*(){try{const e=L();return e?{uniqueHash:yield I(e),canvasNoisy:e!==L()||(yield D())}:{}}catch(e){return{}}})}function R(){return e(this,void 0,void 0,function*(){return(yield O()).uniqueHash})}function W(){var e,t;try{const n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(!i)return;const r=i.getExtension("WEBGL_debug_renderer_info"),o={vendor:i.getParameter(i.VENDOR),renderer:i.getParameter(i.RENDERER),unmaskedVendor:r?i.getParameter(r.UNMASKED_VENDOR_WEBGL):void 0,unmaskedRenderer:r?i.getParameter(r.UNMASKED_RENDERER_WEBGL):void 0,version:i.getParameter(i.VERSION),shadingLanguageVersion:i.getParameter(i.SHADING_LANGUAGE_VERSION),maxTextureSize:i.getParameter(i.MAX_TEXTURE_SIZE),maxRenderbufferSize:i.getParameter(i.MAX_RENDERBUFFER_SIZE),maxViewportDims:Array.from(i.getParameter(i.MAX_VIEWPORT_DIMS)),maxVertexAttribs:i.getParameter(i.MAX_VERTEX_ATTRIBS),extensions:null!==(e=i.getSupportedExtensions())&&void 0!==e?e:[]};return null===(t=i.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext(),o}catch(e){return}}function j(){try{return navigator.maxTouchPoints>0}catch(e){return!1}}function _(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function M(){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 N(){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 K=null,$=!1;function z(){return new Map(U)}const q=[{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")}}],B=[{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 V(e){try{return e()}catch(e){return}}function H(){var e;return null!==(e=V(()=>{var e,t;return window.ethereum&&null!==(t=null===(e=q.find(e=>!0===V(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}))&&void 0!==e?e:null}function F(){var e,t;return null!==(t=null===(e=B.find(e=>!0===V(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}f.register(T);let G,Q=class extends g{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}init(){return e(this,void 0,void 0,function*(){let e=d();e||(e=u());try{$||($=!0,K=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",K),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: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(l,JSON.stringify(t))}(o.session),n&&function(){const e=new URL(window.location.href);if(e.searchParams.has("lucia")){e.searchParams.delete("lucia");try{window.history.replaceState(window.history.state,"",e.toString())}catch(e){}}}()),f.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*(){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===z().size)try{const e=V(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress});if(e){const t=H();yield this.sendWalletInfo(e,{provider:null!=t?t:void 0})}}catch(e){}try{const e=V(()=>{var e,t;return(null===(e=window.solana)||void 0===e?void 0:e.isConnected)?null===(t=window.solana)||void 0===t?void 0:t.publicKey:void 0});if(e){const t=F();yield this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0})}}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){const e=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(e),0===z().size&&V(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.on})){const e=e=>{const t=e;if(t[0]){const e=t[0],n=H();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};V(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"accountsChanged",e)}),this.walletListenerCleanups.push(()=>{V(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"accountsChanged",e)})})}if(V(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.on})){const e=()=>{const e=V(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.publicKey});if(e){const t=F();this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0}).catch(()=>{})}};V(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"connect",e)}),this.walletListenerCleanups.push(()=>{V(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"connect",e)})})}}setupEIP6963AccountListeners(){const e=z();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e,i=V(()=>{var e;return null===(e=n.request)||void 0===e?void 0:e.call(n,{method:"eth_accounts"})});i&&i.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(!V(()=>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(()=>{})};V(()=>{var e;return null===(e=n.on)||void 0===e?void 0:e.call(n,"accountsChanged",i)}),this.walletListenerCleanups.push(()=>{V(()=>{var e;return null===(e=n.removeListener)||void 0===e?void 0: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,r){return e(this,void 0,void 0,function*(){const e=h(),o=d(),s=Object.assign(Object.assign(Object.assign({tag:t,amount:n},r&&{currency:r}),{event:i,user:{name:v()},session:o}),e&&{lid:e});yield this.httpClient.post("/api/sdk/conversion",s)})}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=E(),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(){return!!V(()=>{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(){f.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),$&&(K&&(window.removeEventListener("eip6963:announceProvider",K),K=null),U.clear(),$=!1)}},X=null,Z=null;const J=()=>new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first"),Y=()=>{if("undefined"==typeof window)throw J();const e=X||window.__luciaInitPromise;return e||(null!=Z||(Z=new Promise((e,t)=>{const n=Date.now();G=setInterval(()=>{const i=X||window.__luciaInitPromise;!i&&Date.now()-n<15e3||(clearInterval(G),Z=null,i?e(i):t(J()))},50)})),Z)},ee=()=>{const e=X||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),X=null,clearInterval(G),Z=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,f.reset()},te={init:t=>{if("undefined"==typeof window)return Promise.reject(new Error("LuciaSDK requires a browser environment"));if(X)return X;if(window.__luciaInitPromise)return X=window.__luciaInitPromise,X;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 X=n,window.__luciaInitPromise=n,n},userInfo:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield Y()).userInfo(t,n)}),pageView:t=>e(void 0,void 0,void 0,function*(){return(yield Y()).pageView(t)}),trackConversion:(t,n,i,r)=>e(void 0,void 0,void 0,function*(){return(yield Y()).trackConversion(t,n,i,r)}),buttonClick:(t,n)=>e(void 0,void 0,void 0,function*(){return(yield Y()).buttonClick(t,n)}),sendWalletInfo:(t,n,i)=>e(void 0,void 0,void 0,function*(){return(yield Y()).sendWalletInfo(t,n,i)}),trackUserAcquisition:(t,...n)=>e(void 0,[t,...n],void 0,function*(e,t={}){return(yield Y()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>!!V(()=>{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=te;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-api-host")||e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");te.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{apiHost: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{ee as __resetInstance,te as default,H as detectEvmProvider,F as detectSolanaProvider,S as filterObject,_ as getApplePayAvailable,A as getBrowserData,R as getCanvasFingerprint,N as getColorGamut,M as getContrastPreference,E as getUtmParams,W as getWebGLInfo,j as isTouchEnabled,P as safeAccess};
2
2
  //# sourceMappingURL=index.es.js.map
@@ -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/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":"4kGACA,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]}
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":"kyFACA,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.12.2";class i{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new t(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"https://staging.api.clickinsights.xyz":"https://api.luciaprotocol.com"}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 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 f=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 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: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={cores:P(()=>navigator.hardwareConcurrency),memory:P(()=>navigator.deviceMemory),cpuClass:P(()=>navigator.cpuClass),touch:D(),maxTouchPoints:P(()=>navigator.maxTouchPoints),platform:P(()=>navigator.platform),devicePixelRatio:P(()=>window.devicePixelRatio)},t={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)}},n=yield O(),i={language:P(()=>navigator.language),languages:P(()=>Array.from(navigator.languages)),encoding:P(()=>TextDecoder.encoding),timezone:P(()=>-(new Date).getTimezoneOffset()/60),timezoneName:P(()=>Intl.DateTimeFormat().resolvedOptions().timeZone),pluginsLength:P(()=>navigator.plugins.length),pluginNames:P(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:W(),uniqueHash:n.uniqueHash,canvasNoisy:n.canvasNoisy,colorGamut:_(),contrastPreference:j()},r={localStorage:P(()=>!!window.localStorage),indexedDB:P(()=>!!window.indexedDB),openDB:P(()=>window.openDatabase)},o={device:e,screen:t,browser:i,webgl:R(),storage:r};return I=o,o})}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 P(e,t){try{return e()}catch(e){return t}}function S(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("")})}let I=null;function x(){const e=document.createElement("canvas");e.width=280,e.height=60;const t=e.getContext("2d",{willReadFrequently:!0});if(!t)return;const n=t.createLinearGradient(0,0,280,0);return n.addColorStop(0,"#ff0000"),n.addColorStop(.5,"#00ff00"),n.addColorStop(1,"#0000ff"),t.fillStyle=n,t.fillRect(0,0,280,60),t.font="14px Arial, sans-serif",t.fillStyle="rgba(100, 200, 50, 0.8)",t.fillText("Cwm fjord bank glyphs vext quiz!",2,20),t.font="18px serif",t.fillText("🏴‍☠️🍕🎵",2,45),t.globalCompositeOperation="multiply",t.fillStyle="rgba(255, 100, 0, 0.6)",t.beginPath(),t.arc(200,30,25,0,2*Math.PI),t.fill(),t.globalCompositeOperation="source-over",t.strokeStyle="rgba(50, 50, 255, 0.7)",t.lineWidth=1.5,t.beginPath(),t.moveTo(100,5),t.bezierCurveTo(130,55,170,5,200,55),t.stroke(),e.toDataURL("image/png")}function L(){return e(this,void 0,void 0,function*(){try{const e=navigator.brave;return!0===(yield null==e?void 0:e.isBrave())}catch(e){return!1}})}function O(){return e(this,void 0,void 0,function*(){try{const e=x();return e?{uniqueHash:yield S(e),canvasNoisy:e!==x()||(yield L())}:{}}catch(e){return{}}})}function R(){var e,t;try{const n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(!i)return;const r=i.getExtension("WEBGL_debug_renderer_info"),o={vendor:i.getParameter(i.VENDOR),renderer:i.getParameter(i.RENDERER),unmaskedVendor:r?i.getParameter(r.UNMASKED_VENDOR_WEBGL):void 0,unmaskedRenderer:r?i.getParameter(r.UNMASKED_RENDERER_WEBGL):void 0,version:i.getParameter(i.VERSION),shadingLanguageVersion:i.getParameter(i.SHADING_LANGUAGE_VERSION),maxTextureSize:i.getParameter(i.MAX_TEXTURE_SIZE),maxRenderbufferSize:i.getParameter(i.MAX_RENDERBUFFER_SIZE),maxViewportDims:Array.from(i.getParameter(i.MAX_VIEWPORT_DIMS)),maxVertexAttribs:i.getParameter(i.MAX_VERTEX_ATTRIBS),extensions:null!==(e=i.getSupportedExtensions())&&void 0!==e?e:[]};return null===(t=i.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext(),o}catch(e){return}}function D(){try{return navigator.maxTouchPoints>0}catch(e){return!1}}function W(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function 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 _(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const M=new Map;let N=null,U=!1;function B(){return new Map(M)}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 z(e){try{return e()}catch(e){return}}function q(){var e;return null!==(e=z(()=>{var e,t;return window.ethereum&&null!==(t=null===(e=K.find(e=>!0===z(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}))&&void 0!==e?e:null}function V(){var e,t;return null!==(t=null===(e=$.find(e=>!0===z(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}f.register(T);let G,F=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{U||(U=!0,N=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)&&M.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",N),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: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(l,JSON.stringify(t))}(o.session),n&&function(){const e=new URL(window.location.href);if(e.searchParams.has("lucia")){e.searchParams.delete("lucia");try{window.history.replaceState(window.history.state,"",e.toString())}catch(e){}}}()),f.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*(){try{const t=yield function(){return e(this,void 0,void 0,function*(){const e=Array.from(M.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===B().size)try{const e=z(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress});if(e){const t=q();yield this.sendWalletInfo(e,{provider:null!=t?t:void 0})}}catch(e){}try{const e=z(()=>{var e,t;return(null===(e=window.solana)||void 0===e?void 0:e.isConnected)?null===(t=window.solana)||void 0===t?void 0:t.publicKey:void 0});if(e){const t=V();yield this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0})}}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){const e=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)&&(M.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(e),0===B().size&&z(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.on})){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(()=>{})}};z(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"accountsChanged",e)}),this.walletListenerCleanups.push(()=>{z(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"accountsChanged",e)})})}if(z(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.on})){const e=()=>{const e=z(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.publicKey});if(e){const t=V();this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0}).catch(()=>{})}};z(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"connect",e)}),this.walletListenerCleanups.push(()=>{z(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"connect",e)})})}}setupEIP6963AccountListeners(){const e=B();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e,i=z(()=>{var e;return null===(e=n.request)||void 0===e?void 0:e.call(n,{method:"eth_accounts"})});i&&i.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(!z(()=>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(()=>{})};z(()=>{var e;return null===(e=n.on)||void 0===e?void 0:e.call(n,"accountsChanged",i)}),this.walletListenerCleanups.push(()=>{z(()=>{var e;return null===(e=n.removeListener)||void 0===e?void 0: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,r){return e(this,void 0,void 0,function*(){const e=h(),o=d(),s=Object.assign(Object.assign(Object.assign({tag:t,amount:n},r&&{currency:r}),{event:i,user:{name:v()},session:o}),e&&{lid:e});yield this.httpClient.post("/api/sdk/conversion",s)})}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=E(),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(){return!!z(()=>{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(){f.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),U&&(N&&(window.removeEventListener("eip6963:announceProvider",N),N=null),M.clear(),U=!1)}},H=null,Q=null;const X=()=>new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first"),Z=()=>{if("undefined"==typeof window)throw X();const e=H||window.__luciaInitPromise;return e||(null!=Q||(Q=new Promise((e,t)=>{const n=Date.now();G=setInterval(()=>{const i=H||window.__luciaInitPromise;!i&&Date.now()-n<15e3||(clearInterval(G),Q=null,i?e(i):t(X()))},50)})),Q)},J={init:t=>{if("undefined"==typeof window)return Promise.reject(new Error("LuciaSDK requires a browser environment"));if(H)return H;if(window.__luciaInitPromise)return H=window.__luciaInitPromise,H;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 F(t);return yield e.init(),e});return H=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,r)=>e(void 0,void 0,void 0,function*(){return(yield Z()).trackConversion(t,n,i,r)}),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:()=>!!z(()=>{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=J;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");J.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=H||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),H=null,clearInterval(G),Q=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,f.reset()},exports.default=J,exports.detectEvmProvider=q,exports.detectSolanaProvider=V,exports.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},exports.getApplePayAvailable=W,exports.getBrowserData=A,exports.getCanvasFingerprint=function(){return e(this,void 0,void 0,function*(){return(yield O()).uniqueHash})},exports.getColorGamut=_,exports.getContrastPreference=j,exports.getUtmParams=E,exports.getWebGLInfo=R,exports.isTouchEnabled=D,exports.safeAccess=P;
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.13.0";class i{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new t(this.store)}getBaseURL(){const{config:e}=this.store,t=(null==e?void 0:e.apiHost)||(null==e?void 0:e.debugURL);return t?t.replace(/\/+$/,""):(null==e?void 0:e.testENV)?"https://staging.api.clickinsights.xyz":"https://api.luciaprotocol.com"}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;const r=fetch(`${this.baseURL}${e}`,{method:"POST",keepalive:i,headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":n},body:JSON.stringify(t)});if(i)return r.catch(e=>this.logger.log("error",e)),null;try{const e=yield r;return yield e.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 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 f=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 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: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={cores:P(()=>navigator.hardwareConcurrency),memory:P(()=>navigator.deviceMemory),cpuClass:P(()=>navigator.cpuClass),touch:R(),maxTouchPoints:P(()=>navigator.maxTouchPoints),platform:P(()=>navigator.platform),devicePixelRatio:P(()=>window.devicePixelRatio)},t={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)}},n=yield O(),i={language:P(()=>navigator.language),languages:P(()=>Array.from(navigator.languages)),encoding:P(()=>TextDecoder.encoding),timezone:P(()=>-(new Date).getTimezoneOffset()/60),timezoneName:P(()=>Intl.DateTimeFormat().resolvedOptions().timeZone),pluginsLength:P(()=>navigator.plugins.length),pluginNames:P(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:W(),uniqueHash:n.uniqueHash,canvasNoisy:n.canvasNoisy,colorGamut:j(),contrastPreference:_()},r={localStorage:P(()=>!!window.localStorage),indexedDB:P(()=>!!window.indexedDB),openDB:P(()=>window.openDatabase)},o={device:e,screen:t,browser:i,webgl:D(),storage:r};return I=o,o})}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 P(e,t){try{return e()}catch(e){return t}}function S(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("")})}let I=null;function x(){const e=document.createElement("canvas");e.width=280,e.height=60;const t=e.getContext("2d",{willReadFrequently:!0});if(!t)return;const n=t.createLinearGradient(0,0,280,0);return n.addColorStop(0,"#ff0000"),n.addColorStop(.5,"#00ff00"),n.addColorStop(1,"#0000ff"),t.fillStyle=n,t.fillRect(0,0,280,60),t.font="14px Arial, sans-serif",t.fillStyle="rgba(100, 200, 50, 0.8)",t.fillText("Cwm fjord bank glyphs vext quiz!",2,20),t.font="18px serif",t.fillText("🏴‍☠️🍕🎵",2,45),t.globalCompositeOperation="multiply",t.fillStyle="rgba(255, 100, 0, 0.6)",t.beginPath(),t.arc(200,30,25,0,2*Math.PI),t.fill(),t.globalCompositeOperation="source-over",t.strokeStyle="rgba(50, 50, 255, 0.7)",t.lineWidth=1.5,t.beginPath(),t.moveTo(100,5),t.bezierCurveTo(130,55,170,5,200,55),t.stroke(),e.toDataURL("image/png")}function L(){return e(this,void 0,void 0,function*(){try{const e=navigator.brave;return!0===(yield null==e?void 0:e.isBrave())}catch(e){return!1}})}function O(){return e(this,void 0,void 0,function*(){try{const e=x();return e?{uniqueHash:yield S(e),canvasNoisy:e!==x()||(yield L())}:{}}catch(e){return{}}})}function D(){var e,t;try{const n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(!i)return;const r=i.getExtension("WEBGL_debug_renderer_info"),o={vendor:i.getParameter(i.VENDOR),renderer:i.getParameter(i.RENDERER),unmaskedVendor:r?i.getParameter(r.UNMASKED_VENDOR_WEBGL):void 0,unmaskedRenderer:r?i.getParameter(r.UNMASKED_RENDERER_WEBGL):void 0,version:i.getParameter(i.VERSION),shadingLanguageVersion:i.getParameter(i.SHADING_LANGUAGE_VERSION),maxTextureSize:i.getParameter(i.MAX_TEXTURE_SIZE),maxRenderbufferSize:i.getParameter(i.MAX_RENDERBUFFER_SIZE),maxViewportDims:Array.from(i.getParameter(i.MAX_VIEWPORT_DIMS)),maxVertexAttribs:i.getParameter(i.MAX_VERTEX_ATTRIBS),extensions:null!==(e=i.getSupportedExtensions())&&void 0!==e?e:[]};return null===(t=i.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext(),o}catch(e){return}}function R(){try{return navigator.maxTouchPoints>0}catch(e){return!1}}function W(){var e;try{return"function"==typeof(null===(e=window.ApplePaySession)||void 0===e?void 0:e.canMakePayments)&&window.ApplePaySession.canMakePayments()}catch(e){return}}function _(){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 M=new Map;let N=null,U=!1;function K(){return new Map(M)}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")}}],z=[{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(e){try{return e()}catch(e){return}}function B(){var e;return null!==(e=q(()=>{var e,t;return window.ethereum&&null!==(t=null===(e=$.find(e=>!0===q(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}))&&void 0!==e?e:null}function V(){var e,t;return null!==(t=null===(e=z.find(e=>!0===q(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}f.register(T);let H,G=class extends g{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}init(){return e(this,void 0,void 0,function*(){let e=d();e||(e=u());try{U||(U=!0,N=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)&&M.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",N),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: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(l,JSON.stringify(t))}(o.session),n&&function(){const e=new URL(window.location.href);if(e.searchParams.has("lucia")){e.searchParams.delete("lucia");try{window.history.replaceState(window.history.state,"",e.toString())}catch(e){}}}()),f.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*(){try{const t=yield function(){return e(this,void 0,void 0,function*(){const e=Array.from(M.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)try{const e=q(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress});if(e){const t=B();yield this.sendWalletInfo(e,{provider:null!=t?t:void 0})}}catch(e){}try{const e=q(()=>{var e,t;return(null===(e=window.solana)||void 0===e?void 0:e.isConnected)?null===(t=window.solana)||void 0===t?void 0:t.publicKey:void 0});if(e){const t=V();yield this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0})}}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){const e=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)&&(M.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(e),0===K().size&&q(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.on})){const e=e=>{const t=e;if(t[0]){const e=t[0],n=B();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};q(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"accountsChanged",e)}),this.walletListenerCleanups.push(()=>{q(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"accountsChanged",e)})})}if(q(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.on})){const e=()=>{const e=q(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.publicKey});if(e){const t=V();this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0}).catch(()=>{})}};q(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"connect",e)}),this.walletListenerCleanups.push(()=>{q(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n?void 0: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,i=q(()=>{var e;return null===(e=n.request)||void 0===e?void 0:e.call(n,{method:"eth_accounts"})});i&&i.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(!q(()=>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(()=>{})};q(()=>{var e;return null===(e=n.on)||void 0===e?void 0:e.call(n,"accountsChanged",i)}),this.walletListenerCleanups.push(()=>{q(()=>{var e;return null===(e=n.removeListener)||void 0===e?void 0: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,r){return e(this,void 0,void 0,function*(){const e=h(),o=d(),s=Object.assign(Object.assign(Object.assign({tag:t,amount:n},r&&{currency:r}),{event:i,user:{name:v()},session:o}),e&&{lid:e});yield this.httpClient.post("/api/sdk/conversion",s)})}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=E(),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(){return!!q(()=>{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(){f.destroyAll(),this.walletListenerCleanups.forEach(e=>e()),this.walletListenerCleanups=[],this.sentWallets.clear(),U&&(N&&(window.removeEventListener("eip6963:announceProvider",N),N=null),M.clear(),U=!1)}},F=null,Q=null;const X=()=>new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first"),Z=()=>{if("undefined"==typeof window)throw X();const e=F||window.__luciaInitPromise;return e||(null!=Q||(Q=new Promise((e,t)=>{const n=Date.now();H=setInterval(()=>{const i=F||window.__luciaInitPromise;!i&&Date.now()-n<15e3||(clearInterval(H),Q=null,i?e(i):t(X()))},50)})),Q)},J={init:t=>{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==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 G(t);return yield e.init(),e});return F=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,r)=>e(void 0,void 0,void 0,function*(){return(yield Z()).trackConversion(t,n,i,r)}),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:()=>!!q(()=>{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=J;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-api-host")||e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");J.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{apiHost: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=F||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),F=null,clearInterval(H),Q=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,f.reset()},exports.default=J,exports.detectEvmProvider=B,exports.detectSolanaProvider=V,exports.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},exports.getApplePayAvailable=W,exports.getBrowserData=A,exports.getCanvasFingerprint=function(){return e(this,void 0,void 0,function*(){return(yield O()).uniqueHash})},exports.getColorGamut=j,exports.getContrastPreference=_,exports.getUtmParams=E,exports.getWebGLInfo=D,exports.isTouchEnabled=R,exports.safeAccess=P;
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/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":"gpGACA,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]}
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":"s2FACA,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.12.2",
3
+ "version": "0.13.0",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "description": "Lucia JavaScript Library",
6
6
  "repository": {
@@ -55,7 +55,7 @@
55
55
  "eslint-plugin-import": "^2.32.0",
56
56
  "eslint-plugin-jest": "^29.11.0",
57
57
  "eslint-plugin-promise": "^7.2.1",
58
- "eslint-plugin-unicorn": "^76.0.0",
58
+ "eslint-plugin-unicorn": "^79.0.0",
59
59
  "eslint-plugin-unused-imports": "^4.3.0",
60
60
  "husky": "^9.1.7",
61
61
  "jest": "^30.2.0",
package/dist/types.d.ts CHANGED
@@ -14,6 +14,8 @@ export interface Config {
14
14
  apiKey: string;
15
15
  debug?: boolean;
16
16
  testENV?: boolean;
17
+ apiHost?: string;
18
+ /** @deprecated Use `apiHost`. */
17
19
  debugURL?: string;
18
20
  autoTrackClicks?: boolean | AutoTrackClicksConfig;
19
21
  }
@@ -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.13.0";class r{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new n(this.store)}getBaseURL(){const{config:e}=this.store,t=(null==e?void 0:e.apiHost)||(null==e?void 0:e.debugURL);return t?t.replace(/\/+$/,""):(null==e?void 0:e.testENV)?"https://staging.api.clickinsights.xyz":"https://api.luciaprotocol.com"}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;const r=fetch(`${this.baseURL}${e}`,{method:"POST",keepalive:n,headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":i},body:JSON.stringify(t)});if(n)return r.catch(e=>this.logger.log("error",e)),null;try{const e=yield r;return yield e.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 m{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 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 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 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: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 E(){return t(this,void 0,void 0,function*(){if(x)return x;const e={cores:S(()=>navigator.hardwareConcurrency),memory:S(()=>navigator.deviceMemory),cpuClass:S(()=>navigator.cpuClass),touch:W(),maxTouchPoints:S(()=>navigator.maxTouchPoints),platform:S(()=>navigator.platform),devicePixelRatio:S(()=>window.devicePixelRatio)},t={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)}},n=yield O(),i={language:S(()=>navigator.language),languages:S(()=>Array.from(navigator.languages)),encoding:S(()=>TextDecoder.encoding),timezone:S(()=>-(new Date).getTimezoneOffset()/60),timezoneName:S(()=>Intl.DateTimeFormat().resolvedOptions().timeZone),pluginsLength:S(()=>navigator.plugins.length),pluginNames:S(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:_(),uniqueHash:n.uniqueHash,canvasNoisy:n.canvasNoisy,colorGamut:M(),contrastPreference:j()},r={localStorage:S(()=>!!window.localStorage),indexedDB:S(()=>!!window.indexedDB),openDB:S(()=>window.openDatabase)},o={device:e,screen:t,browser:i,webgl:R(),storage:r};return x=o,o})}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}}function I(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("")})}let x=null;function L(){const e=document.createElement("canvas");e.width=280,e.height=60;const t=e.getContext("2d",{willReadFrequently:!0});if(!t)return;const n=t.createLinearGradient(0,0,280,0);return n.addColorStop(0,"#ff0000"),n.addColorStop(.5,"#00ff00"),n.addColorStop(1,"#0000ff"),t.fillStyle=n,t.fillRect(0,0,280,60),t.font="14px Arial, sans-serif",t.fillStyle="rgba(100, 200, 50, 0.8)",t.fillText("Cwm fjord bank glyphs vext quiz!",2,20),t.font="18px serif",t.fillText("🏴‍☠️🍕🎵",2,45),t.globalCompositeOperation="multiply",t.fillStyle="rgba(255, 100, 0, 0.6)",t.beginPath(),t.arc(200,30,25,0,2*Math.PI),t.fill(),t.globalCompositeOperation="source-over",t.strokeStyle="rgba(50, 50, 255, 0.7)",t.lineWidth=1.5,t.beginPath(),t.moveTo(100,5),t.bezierCurveTo(130,55,170,5,200,55),t.stroke(),e.toDataURL("image/png")}function D(){return t(this,void 0,void 0,function*(){try{const e=navigator.brave;return!0===(yield null==e?void 0:e.isBrave())}catch(e){return!1}})}function O(){return t(this,void 0,void 0,function*(){try{const e=L();return e?{uniqueHash:yield I(e),canvasNoisy:e!==L()||(yield D())}:{}}catch(e){return{}}})}function R(){var e,t;try{const n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(!i)return;const r=i.getExtension("WEBGL_debug_renderer_info"),o={vendor:i.getParameter(i.VENDOR),renderer:i.getParameter(i.RENDERER),unmaskedVendor:r?i.getParameter(r.UNMASKED_VENDOR_WEBGL):void 0,unmaskedRenderer:r?i.getParameter(r.UNMASKED_RENDERER_WEBGL):void 0,version:i.getParameter(i.VERSION),shadingLanguageVersion:i.getParameter(i.SHADING_LANGUAGE_VERSION),maxTextureSize:i.getParameter(i.MAX_TEXTURE_SIZE),maxRenderbufferSize:i.getParameter(i.MAX_RENDERBUFFER_SIZE),maxViewportDims:Array.from(i.getParameter(i.MAX_VIEWPORT_DIMS)),maxVertexAttribs:i.getParameter(i.MAX_VERTEX_ATTRIBS),extensions:null!==(e=i.getSupportedExtensions())&&void 0!==e?e:[]};return null===(t=i.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext(),o}catch(e){return}}function W(){try{return navigator.maxTouchPoints>0}catch(e){return!1}}function _(){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 M(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const N=new Map;let U=null,K=!1;function $(){return new Map(N)}const z=[{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")}}],q=[{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 B(e){try{return e()}catch(e){return}}function V(){var e;return null!==(e=B(()=>{var e,t;return window.ethereum&&null!==(t=null===(e=z.find(e=>!0===B(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}))&&void 0!==e?e:null}function H(){var e,t;return null!==(t=null===(e=q.find(e=>!0===B(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}p.register(A);let G,F=class extends m{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}init(){return t(this,void 0,void 0,function*(){let e=u();e||(e=h());try{K||(K=!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)&&N.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",U),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield E(),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: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(c,JSON.stringify(t))}(o.session),n&&function(){const e=new URL(window.location.href);if(e.searchParams.has("lucia")){e.searchParams.delete("lucia");try{window.history.replaceState(window.history.state,"",e.toString())}catch(e){}}}()),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*(){try{const e=yield function(){return t(this,void 0,void 0,function*(){const e=Array.from(N.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)try{const e=B(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress});if(e){const t=V();yield this.sendWalletInfo(e,{provider:null!=t?t:void 0})}}catch(e){}try{const e=B(()=>{var e,t;return(null===(e=window.solana)||void 0===e?void 0:e.isConnected)?null===(t=window.solana)||void 0===t?void 0:t.publicKey:void 0});if(e){const t=H();yield this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0})}}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){const e=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)&&(N.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(e),0===$().size&&B(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.on})){const e=e=>{const t=e;if(t[0]){const e=t[0],n=V();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};B(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"accountsChanged",e)}),this.walletListenerCleanups.push(()=>{B(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"accountsChanged",e)})})}if(B(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.on})){const e=()=>{const e=B(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.publicKey});if(e){const t=H();this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0}).catch(()=>{})}};B(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"connect",e)}),this.walletListenerCleanups.push(()=>{B(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"connect",e)})})}}setupEIP6963AccountListeners(){const e=$();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e,i=B(()=>{var e;return null===(e=n.request)||void 0===e?void 0:e.call(n,{method:"eth_accounts"})});i&&i.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(!B(()=>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(()=>{})};B(()=>{var e;return null===(e=n.on)||void 0===e?void 0:e.call(n,"accountsChanged",i)}),this.walletListenerCleanups.push(()=>{B(()=>{var e;return null===(e=n.removeListener)||void 0===e?void 0: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,r){return t(this,void 0,void 0,function*(){const t=v(),o=u(),s=Object.assign(Object.assign(Object.assign({tag:e,amount:n},r&&{currency:r}),{event:i,user:{name:g()},session:o}),t&&{lid:t});yield this.httpClient.post("/api/sdk/conversion",s)})}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 E(),i=P(),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(){return!!B(()=>{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(),K&&(U&&(window.removeEventListener("eip6963:announceProvider",U),U=null),N.clear(),K=!1)}},Q=null,X=null;const Z=()=>new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first"),J=()=>{if("undefined"==typeof window)throw Z();const e=Q||window.__luciaInitPromise;return e||(null!=X||(X=new Promise((e,t)=>{const n=Date.now();G=setInterval(()=>{const i=Q||window.__luciaInitPromise;!i&&Date.now()-n<15e3||(clearInterval(G),X=null,i?e(i):t(Z()))},50)})),X)},Y={init:e=>{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==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 F(e);return yield t.init(),t});return Q=n,window.__luciaInitPromise=n,n},userInfo:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield J()).userInfo(e,n)}),pageView:e=>t(void 0,void 0,void 0,function*(){return(yield J()).pageView(e)}),trackConversion:(e,n,i,r)=>t(void 0,void 0,void 0,function*(){return(yield J()).trackConversion(e,n,i,r)}),buttonClick:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield J()).buttonClick(e,n)}),sendWalletInfo:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield J()).sendWalletInfo(e,n,i)}),trackUserAcquisition:(e,...n)=>t(void 0,[e,...n],void 0,function*(e,t={}){return(yield J()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>!!B(()=>{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=Y;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-api-host")||e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");Y.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{apiHost: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=Q||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),Q=null,clearInterval(G),X=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,p.reset()},e.default=Y,e.detectEvmProvider=V,e.detectSolanaProvider=H,e.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},e.getApplePayAvailable=_,e.getBrowserData=E,e.getCanvasFingerprint=function(){return t(this,void 0,void 0,function*(){return(yield O()).uniqueHash})},e.getColorGamut=M,e.getContrastPreference=j,e.getUtmParams=P,e.getWebGLInfo=R,e.isTouchEnabled=W,e.safeAccess=S,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.12.2";class r{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new n(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"https://staging.api.clickinsights.xyz":"https://api.luciaprotocol.com"}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 E(){return t(this,void 0,void 0,function*(){if(x)return x;const e={cores:S(()=>navigator.hardwareConcurrency),memory:S(()=>navigator.deviceMemory),cpuClass:S(()=>navigator.cpuClass),touch:W(),maxTouchPoints:S(()=>navigator.maxTouchPoints),platform:S(()=>navigator.platform),devicePixelRatio:S(()=>window.devicePixelRatio)},t={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)}},n=yield D(),i={language:S(()=>navigator.language),languages:S(()=>Array.from(navigator.languages)),encoding:S(()=>TextDecoder.encoding),timezone:S(()=>-(new Date).getTimezoneOffset()/60),timezoneName:S(()=>Intl.DateTimeFormat().resolvedOptions().timeZone),pluginsLength:S(()=>navigator.plugins.length),pluginNames:S(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:j(),uniqueHash:n.uniqueHash,canvasNoisy:n.canvasNoisy,colorGamut:M(),contrastPreference:_()},r={localStorage:S(()=>!!window.localStorage),indexedDB:S(()=>!!window.indexedDB),openDB:S(()=>window.openDatabase)},o={device:e,screen:t,browser:i,webgl:R(),storage:r};return x=o,o})}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}}function I(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("")})}let x=null;function L(){const e=document.createElement("canvas");e.width=280,e.height=60;const t=e.getContext("2d",{willReadFrequently:!0});if(!t)return;const n=t.createLinearGradient(0,0,280,0);return n.addColorStop(0,"#ff0000"),n.addColorStop(.5,"#00ff00"),n.addColorStop(1,"#0000ff"),t.fillStyle=n,t.fillRect(0,0,280,60),t.font="14px Arial, sans-serif",t.fillStyle="rgba(100, 200, 50, 0.8)",t.fillText("Cwm fjord bank glyphs vext quiz!",2,20),t.font="18px serif",t.fillText("🏴‍☠️🍕🎵",2,45),t.globalCompositeOperation="multiply",t.fillStyle="rgba(255, 100, 0, 0.6)",t.beginPath(),t.arc(200,30,25,0,2*Math.PI),t.fill(),t.globalCompositeOperation="source-over",t.strokeStyle="rgba(50, 50, 255, 0.7)",t.lineWidth=1.5,t.beginPath(),t.moveTo(100,5),t.bezierCurveTo(130,55,170,5,200,55),t.stroke(),e.toDataURL("image/png")}function O(){return t(this,void 0,void 0,function*(){try{const e=navigator.brave;return!0===(yield null==e?void 0:e.isBrave())}catch(e){return!1}})}function D(){return t(this,void 0,void 0,function*(){try{const e=L();return e?{uniqueHash:yield I(e),canvasNoisy:e!==L()||(yield O())}:{}}catch(e){return{}}})}function R(){var e,t;try{const n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(!i)return;const r=i.getExtension("WEBGL_debug_renderer_info"),o={vendor:i.getParameter(i.VENDOR),renderer:i.getParameter(i.RENDERER),unmaskedVendor:r?i.getParameter(r.UNMASKED_VENDOR_WEBGL):void 0,unmaskedRenderer:r?i.getParameter(r.UNMASKED_RENDERER_WEBGL):void 0,version:i.getParameter(i.VERSION),shadingLanguageVersion:i.getParameter(i.SHADING_LANGUAGE_VERSION),maxTextureSize:i.getParameter(i.MAX_TEXTURE_SIZE),maxRenderbufferSize:i.getParameter(i.MAX_RENDERBUFFER_SIZE),maxViewportDims:Array.from(i.getParameter(i.MAX_VIEWPORT_DIMS)),maxVertexAttribs:i.getParameter(i.MAX_VERTEX_ATTRIBS),extensions:null!==(e=i.getSupportedExtensions())&&void 0!==e?e:[]};return null===(t=i.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext(),o}catch(e){return}}function W(){try{return navigator.maxTouchPoints>0}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 _(){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 M(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const N=new Map;let U=null,K=!1;function B(){return new Map(N)}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")}}],z=[{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(e){try{return e()}catch(e){return}}function V(){var e;return null!==(e=q(()=>{var e,t;return window.ethereum&&null!==(t=null===(e=$.find(e=>!0===q(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}))&&void 0!==e?e:null}function G(){var e,t;return null!==(t=null===(e=z.find(e=>!0===q(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}p.register(A);let F,H=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{K||(K=!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)&&N.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",U),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield E(),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: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(c,JSON.stringify(t))}(o.session),n&&function(){const e=new URL(window.location.href);if(e.searchParams.has("lucia")){e.searchParams.delete("lucia");try{window.history.replaceState(window.history.state,"",e.toString())}catch(e){}}}()),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*(){try{const e=yield function(){return t(this,void 0,void 0,function*(){const e=Array.from(N.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===B().size)try{const e=q(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress});if(e){const t=V();yield this.sendWalletInfo(e,{provider:null!=t?t:void 0})}}catch(e){}try{const e=q(()=>{var e,t;return(null===(e=window.solana)||void 0===e?void 0:e.isConnected)?null===(t=window.solana)||void 0===t?void 0:t.publicKey:void 0});if(e){const t=G();yield this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0})}}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){const e=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)&&(N.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(e),0===B().size&&q(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.on})){const e=e=>{const t=e;if(t[0]){const e=t[0],n=V();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};q(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"accountsChanged",e)}),this.walletListenerCleanups.push(()=>{q(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"accountsChanged",e)})})}if(q(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.on})){const e=()=>{const e=q(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.publicKey});if(e){const t=G();this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0}).catch(()=>{})}};q(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"connect",e)}),this.walletListenerCleanups.push(()=>{q(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"connect",e)})})}}setupEIP6963AccountListeners(){const e=B();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e,i=q(()=>{var e;return null===(e=n.request)||void 0===e?void 0:e.call(n,{method:"eth_accounts"})});i&&i.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(!q(()=>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(()=>{})};q(()=>{var e;return null===(e=n.on)||void 0===e?void 0:e.call(n,"accountsChanged",i)}),this.walletListenerCleanups.push(()=>{q(()=>{var e;return null===(e=n.removeListener)||void 0===e?void 0: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,r){return t(this,void 0,void 0,function*(){const t=v(),o=u(),s=Object.assign(Object.assign(Object.assign({tag:e,amount:n},r&&{currency:r}),{event:i,user:{name:g()},session:o}),t&&{lid:t});yield this.httpClient.post("/api/sdk/conversion",s)})}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 E(),i=P(),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(){return!!q(()=>{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(),K&&(U&&(window.removeEventListener("eip6963:announceProvider",U),U=null),N.clear(),K=!1)}},Q=null,X=null;const Z=()=>new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first"),J=()=>{if("undefined"==typeof window)throw Z();const e=Q||window.__luciaInitPromise;return e||(null!=X||(X=new Promise((e,t)=>{const n=Date.now();F=setInterval(()=>{const i=Q||window.__luciaInitPromise;!i&&Date.now()-n<15e3||(clearInterval(F),X=null,i?e(i):t(Z()))},50)})),X)},Y={init:e=>{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==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 H(e);return yield t.init(),t});return Q=n,window.__luciaInitPromise=n,n},userInfo:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield J()).userInfo(e,n)}),pageView:e=>t(void 0,void 0,void 0,function*(){return(yield J()).pageView(e)}),trackConversion:(e,n,i,r)=>t(void 0,void 0,void 0,function*(){return(yield J()).trackConversion(e,n,i,r)}),buttonClick:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield J()).buttonClick(e,n)}),sendWalletInfo:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield J()).sendWalletInfo(e,n,i)}),trackUserAcquisition:(e,...n)=>t(void 0,[e,...n],void 0,function*(e,t={}){return(yield J()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>!!q(()=>{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=Y;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");Y.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=Q||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),Q=null,clearInterval(F),X=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,p.reset()},e.default=Y,e.detectEvmProvider=V,e.detectSolanaProvider=G,e.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},e.getApplePayAvailable=j,e.getBrowserData=E,e.getCanvasFingerprint=function(){return t(this,void 0,void 0,function*(){return(yield D()).uniqueHash})},e.getColorGamut=M,e.getContrastPreference=_,e.getUtmParams=P,e.getWebGLInfo=R,e.isTouchEnabled=W,e.safeAccess=S,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.13.0";class r{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new n(this.store)}getBaseURL(){const{config:e}=this.store,t=(null==e?void 0:e.apiHost)||(null==e?void 0:e.debugURL);return t?t.replace(/\/+$/,""):(null==e?void 0:e.testENV)?"https://staging.api.clickinsights.xyz":"https://api.luciaprotocol.com"}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;const r=fetch(`${this.baseURL}${e}`,{method:"POST",keepalive:n,headers:{"Content-Type":"application/json","X-API-KEY":this.store.config.apiKey,"SDK-VERSION":i},body:JSON.stringify(t)});if(n)return r.catch(e=>this.logger.log("error",e)),null;try{const e=yield r;return yield e.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 m{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 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 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 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: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 E(){return t(this,void 0,void 0,function*(){if(x)return x;const e={cores:S(()=>navigator.hardwareConcurrency),memory:S(()=>navigator.deviceMemory),cpuClass:S(()=>navigator.cpuClass),touch:W(),maxTouchPoints:S(()=>navigator.maxTouchPoints),platform:S(()=>navigator.platform),devicePixelRatio:S(()=>window.devicePixelRatio)},t={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)}},n=yield O(),i={language:S(()=>navigator.language),languages:S(()=>Array.from(navigator.languages)),encoding:S(()=>TextDecoder.encoding),timezone:S(()=>-(new Date).getTimezoneOffset()/60),timezoneName:S(()=>Intl.DateTimeFormat().resolvedOptions().timeZone),pluginsLength:S(()=>navigator.plugins.length),pluginNames:S(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:_(),uniqueHash:n.uniqueHash,canvasNoisy:n.canvasNoisy,colorGamut:M(),contrastPreference:j()},r={localStorage:S(()=>!!window.localStorage),indexedDB:S(()=>!!window.indexedDB),openDB:S(()=>window.openDatabase)},o={device:e,screen:t,browser:i,webgl:R(),storage:r};return x=o,o})}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}}function I(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("")})}let x=null;function L(){const e=document.createElement("canvas");e.width=280,e.height=60;const t=e.getContext("2d",{willReadFrequently:!0});if(!t)return;const n=t.createLinearGradient(0,0,280,0);return n.addColorStop(0,"#ff0000"),n.addColorStop(.5,"#00ff00"),n.addColorStop(1,"#0000ff"),t.fillStyle=n,t.fillRect(0,0,280,60),t.font="14px Arial, sans-serif",t.fillStyle="rgba(100, 200, 50, 0.8)",t.fillText("Cwm fjord bank glyphs vext quiz!",2,20),t.font="18px serif",t.fillText("🏴‍☠️🍕🎵",2,45),t.globalCompositeOperation="multiply",t.fillStyle="rgba(255, 100, 0, 0.6)",t.beginPath(),t.arc(200,30,25,0,2*Math.PI),t.fill(),t.globalCompositeOperation="source-over",t.strokeStyle="rgba(50, 50, 255, 0.7)",t.lineWidth=1.5,t.beginPath(),t.moveTo(100,5),t.bezierCurveTo(130,55,170,5,200,55),t.stroke(),e.toDataURL("image/png")}function D(){return t(this,void 0,void 0,function*(){try{const e=navigator.brave;return!0===(yield null==e?void 0:e.isBrave())}catch(e){return!1}})}function O(){return t(this,void 0,void 0,function*(){try{const e=L();return e?{uniqueHash:yield I(e),canvasNoisy:e!==L()||(yield D())}:{}}catch(e){return{}}})}function R(){var e,t;try{const n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(!i)return;const r=i.getExtension("WEBGL_debug_renderer_info"),o={vendor:i.getParameter(i.VENDOR),renderer:i.getParameter(i.RENDERER),unmaskedVendor:r?i.getParameter(r.UNMASKED_VENDOR_WEBGL):void 0,unmaskedRenderer:r?i.getParameter(r.UNMASKED_RENDERER_WEBGL):void 0,version:i.getParameter(i.VERSION),shadingLanguageVersion:i.getParameter(i.SHADING_LANGUAGE_VERSION),maxTextureSize:i.getParameter(i.MAX_TEXTURE_SIZE),maxRenderbufferSize:i.getParameter(i.MAX_RENDERBUFFER_SIZE),maxViewportDims:Array.from(i.getParameter(i.MAX_VIEWPORT_DIMS)),maxVertexAttribs:i.getParameter(i.MAX_VERTEX_ATTRIBS),extensions:null!==(e=i.getSupportedExtensions())&&void 0!==e?e:[]};return null===(t=i.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext(),o}catch(e){return}}function W(){try{return navigator.maxTouchPoints>0}catch(e){return!1}}function _(){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 M(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const N=new Map;let U=null,K=!1;function $(){return new Map(N)}const z=[{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")}}],q=[{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 B(e){try{return e()}catch(e){return}}function V(){var e;return null!==(e=B(()=>{var e,t;return window.ethereum&&null!==(t=null===(e=z.find(e=>!0===B(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}))&&void 0!==e?e:null}function H(){var e,t;return null!==(t=null===(e=q.find(e=>!0===B(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}p.register(A);let G,F=class extends m{constructor(){super(...arguments),this.sentWallets=new Set,this.walletListenerCleanups=[]}init(){return t(this,void 0,void 0,function*(){let e=u();e||(e=h());try{K||(K=!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)&&N.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",U),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield E(),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: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(c,JSON.stringify(t))}(o.session),n&&function(){const e=new URL(window.location.href);if(e.searchParams.has("lucia")){e.searchParams.delete("lucia");try{window.history.replaceState(window.history.state,"",e.toString())}catch(e){}}}()),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*(){try{const e=yield function(){return t(this,void 0,void 0,function*(){const e=Array.from(N.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)try{const e=B(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress});if(e){const t=V();yield this.sendWalletInfo(e,{provider:null!=t?t:void 0})}}catch(e){}try{const e=B(()=>{var e,t;return(null===(e=window.solana)||void 0===e?void 0:e.isConnected)?null===(t=window.solana)||void 0===t?void 0:t.publicKey:void 0});if(e){const t=H();yield this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0})}}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){const e=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)&&(N.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(e),0===$().size&&B(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.on})){const e=e=>{const t=e;if(t[0]){const e=t[0],n=V();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};B(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"accountsChanged",e)}),this.walletListenerCleanups.push(()=>{B(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"accountsChanged",e)})})}if(B(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.on})){const e=()=>{const e=B(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.publicKey});if(e){const t=H();this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0}).catch(()=>{})}};B(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"connect",e)}),this.walletListenerCleanups.push(()=>{B(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"connect",e)})})}}setupEIP6963AccountListeners(){const e=$();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e,i=B(()=>{var e;return null===(e=n.request)||void 0===e?void 0:e.call(n,{method:"eth_accounts"})});i&&i.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(!B(()=>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(()=>{})};B(()=>{var e;return null===(e=n.on)||void 0===e?void 0:e.call(n,"accountsChanged",i)}),this.walletListenerCleanups.push(()=>{B(()=>{var e;return null===(e=n.removeListener)||void 0===e?void 0: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,r){return t(this,void 0,void 0,function*(){const t=v(),o=u(),s=Object.assign(Object.assign(Object.assign({tag:e,amount:n},r&&{currency:r}),{event:i,user:{name:g()},session:o}),t&&{lid:t});yield this.httpClient.post("/api/sdk/conversion",s)})}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 E(),i=P(),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(){return!!B(()=>{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(),K&&(U&&(window.removeEventListener("eip6963:announceProvider",U),U=null),N.clear(),K=!1)}},Q=null,X=null;const Z=()=>new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first"),J=()=>{if("undefined"==typeof window)throw Z();const e=Q||window.__luciaInitPromise;return e||(null!=X||(X=new Promise((e,t)=>{const n=Date.now();G=setInterval(()=>{const i=Q||window.__luciaInitPromise;!i&&Date.now()-n<15e3||(clearInterval(G),X=null,i?e(i):t(Z()))},50)})),X)},Y={init:e=>{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==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 F(e);return yield t.init(),t});return Q=n,window.__luciaInitPromise=n,n},userInfo:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield J()).userInfo(e,n)}),pageView:e=>t(void 0,void 0,void 0,function*(){return(yield J()).pageView(e)}),trackConversion:(e,n,i,r)=>t(void 0,void 0,void 0,function*(){return(yield J()).trackConversion(e,n,i,r)}),buttonClick:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield J()).buttonClick(e,n)}),sendWalletInfo:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield J()).sendWalletInfo(e,n,i)}),trackUserAcquisition:(e,...n)=>t(void 0,[e,...n],void 0,function*(e,t={}){return(yield J()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>!!B(()=>{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=Y;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-api-host")||e.getAttribute("data-debug-url"),i=e.getAttribute("data-auto-track-clicks"),r=e.getAttribute("data-track-selectors");Y.init(Object.assign(Object.assign(Object.assign({apiKey:t},n&&{apiHost: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=Q||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),Q=null,clearInterval(G),X=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,p.reset()},e.default=Y,e.detectEvmProvider=V,e.detectSolanaProvider=H,e.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},e.getApplePayAvailable=_,e.getBrowserData=E,e.getCanvasFingerprint=function(){return t(this,void 0,void 0,function*(){return(yield O()).uniqueHash})},e.getColorGamut=M,e.getContrastPreference=j,e.getUtmParams=P,e.getWebGLInfo=R,e.isTouchEnabled=W,e.safeAccess=S,Object.defineProperty(e,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucia-sdk",
3
- "version": "0.12.2",
3
+ "version": "0.13.0",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "description": "Lucia JavaScript Library",
6
6
  "repository": {
@@ -55,7 +55,7 @@
55
55
  "eslint-plugin-import": "^2.32.0",
56
56
  "eslint-plugin-jest": "^29.11.0",
57
57
  "eslint-plugin-promise": "^7.2.1",
58
- "eslint-plugin-unicorn": "^76.0.0",
58
+ "eslint-plugin-unicorn": "^79.0.0",
59
59
  "eslint-plugin-unused-imports": "^4.3.0",
60
60
  "husky": "^9.1.7",
61
61
  "jest": "^30.2.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.12.2";class r{constructor(e){this.requestQueue=[],this.isProcessingQueue=!1,this.initComplete=!1,this.store=e,this.baseURL=this.getBaseURL(),this.logger=new n(this.store)}getBaseURL(){const{config:e}=this.store;return(null==e?void 0:e.debugURL)?e.debugURL:(null==e?void 0:e.testENV)?"https://staging.api.clickinsights.xyz":"https://api.luciaprotocol.com"}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 E(){return t(this,void 0,void 0,function*(){if(x)return x;const e={cores:S(()=>navigator.hardwareConcurrency),memory:S(()=>navigator.deviceMemory),cpuClass:S(()=>navigator.cpuClass),touch:W(),maxTouchPoints:S(()=>navigator.maxTouchPoints),platform:S(()=>navigator.platform),devicePixelRatio:S(()=>window.devicePixelRatio)},t={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)}},n=yield D(),i={language:S(()=>navigator.language),languages:S(()=>Array.from(navigator.languages)),encoding:S(()=>TextDecoder.encoding),timezone:S(()=>-(new Date).getTimezoneOffset()/60),timezoneName:S(()=>Intl.DateTimeFormat().resolvedOptions().timeZone),pluginsLength:S(()=>navigator.plugins.length),pluginNames:S(()=>Array.from(navigator.plugins,e=>e.name)),applePayAvailable:j(),uniqueHash:n.uniqueHash,canvasNoisy:n.canvasNoisy,colorGamut:M(),contrastPreference:_()},r={localStorage:S(()=>!!window.localStorage),indexedDB:S(()=>!!window.indexedDB),openDB:S(()=>window.openDatabase)},o={device:e,screen:t,browser:i,webgl:R(),storage:r};return x=o,o})}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}}function I(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("")})}let x=null;function L(){const e=document.createElement("canvas");e.width=280,e.height=60;const t=e.getContext("2d",{willReadFrequently:!0});if(!t)return;const n=t.createLinearGradient(0,0,280,0);return n.addColorStop(0,"#ff0000"),n.addColorStop(.5,"#00ff00"),n.addColorStop(1,"#0000ff"),t.fillStyle=n,t.fillRect(0,0,280,60),t.font="14px Arial, sans-serif",t.fillStyle="rgba(100, 200, 50, 0.8)",t.fillText("Cwm fjord bank glyphs vext quiz!",2,20),t.font="18px serif",t.fillText("🏴‍☠️🍕🎵",2,45),t.globalCompositeOperation="multiply",t.fillStyle="rgba(255, 100, 0, 0.6)",t.beginPath(),t.arc(200,30,25,0,2*Math.PI),t.fill(),t.globalCompositeOperation="source-over",t.strokeStyle="rgba(50, 50, 255, 0.7)",t.lineWidth=1.5,t.beginPath(),t.moveTo(100,5),t.bezierCurveTo(130,55,170,5,200,55),t.stroke(),e.toDataURL("image/png")}function O(){return t(this,void 0,void 0,function*(){try{const e=navigator.brave;return!0===(yield null==e?void 0:e.isBrave())}catch(e){return!1}})}function D(){return t(this,void 0,void 0,function*(){try{const e=L();return e?{uniqueHash:yield I(e),canvasNoisy:e!==L()||(yield O())}:{}}catch(e){return{}}})}function R(){var e,t;try{const n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");if(!i)return;const r=i.getExtension("WEBGL_debug_renderer_info"),o={vendor:i.getParameter(i.VENDOR),renderer:i.getParameter(i.RENDERER),unmaskedVendor:r?i.getParameter(r.UNMASKED_VENDOR_WEBGL):void 0,unmaskedRenderer:r?i.getParameter(r.UNMASKED_RENDERER_WEBGL):void 0,version:i.getParameter(i.VERSION),shadingLanguageVersion:i.getParameter(i.SHADING_LANGUAGE_VERSION),maxTextureSize:i.getParameter(i.MAX_TEXTURE_SIZE),maxRenderbufferSize:i.getParameter(i.MAX_RENDERBUFFER_SIZE),maxViewportDims:Array.from(i.getParameter(i.MAX_VIEWPORT_DIMS)),maxVertexAttribs:i.getParameter(i.MAX_VERTEX_ATTRIBS),extensions:null!==(e=i.getSupportedExtensions())&&void 0!==e?e:[]};return null===(t=i.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext(),o}catch(e){return}}function W(){try{return navigator.maxTouchPoints>0}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 _(){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 M(){try{return["rec2020","p3","srgb","display-p3","adobe-rgb"].filter(e=>window.matchMedia(`(color-gamut: ${e})`).matches)}catch(e){return[]}}const N=new Map;let U=null,K=!1;function B(){return new Map(N)}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")}}],z=[{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(e){try{return e()}catch(e){return}}function V(){var e;return null!==(e=q(()=>{var e,t;return window.ethereum&&null!==(t=null===(e=$.find(e=>!0===q(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}))&&void 0!==e?e:null}function G(){var e,t;return null!==(t=null===(e=z.find(e=>!0===q(e.detect)))||void 0===e?void 0:e.name)&&void 0!==t?t:null}p.register(A);let F,H=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{K||(K=!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)&&N.set(n.info.rdns,n)},window.addEventListener("eip6963:announceProvider",U),window.dispatchEvent(new Event("eip6963:requestProvider")))}catch(e){}const t=yield E(),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: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(c,JSON.stringify(t))}(o.session),n&&function(){const e=new URL(window.location.href);if(e.searchParams.has("lucia")){e.searchParams.delete("lucia");try{window.history.replaceState(window.history.state,"",e.toString())}catch(e){}}}()),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*(){try{const e=yield function(){return t(this,void 0,void 0,function*(){const e=Array.from(N.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===B().size)try{const e=q(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.selectedAddress});if(e){const t=V();yield this.sendWalletInfo(e,{provider:null!=t?t:void 0})}}catch(e){}try{const e=q(()=>{var e,t;return(null===(e=window.solana)||void 0===e?void 0:e.isConnected)?null===(t=window.solana)||void 0===t?void 0:t.publicKey:void 0});if(e){const t=G();yield this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0})}}catch(e){}this.setupEIP6963AccountListeners()})}setupWalletListeners(){const e=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)&&(N.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(e),0===B().size&&q(()=>{var e;return null===(e=window.ethereum)||void 0===e?void 0:e.on})){const e=e=>{const t=e;if(t[0]){const e=t[0],n=V();this.sendWalletInfo(e,{provider:null!=n?n:void 0}).catch(()=>{})}};q(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"accountsChanged",e)}),this.walletListenerCleanups.push(()=>{q(()=>{var t,n;return null===(n=null===(t=window.ethereum)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"accountsChanged",e)})})}if(q(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.on})){const e=()=>{const e=q(()=>{var e;return null===(e=window.solana)||void 0===e?void 0:e.publicKey});if(e){const t=G();this.sendWalletInfo(e.toString(),{provider:null!=t?t:void 0}).catch(()=>{})}};q(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.on)||void 0===n?void 0:n.call(t,"connect",e)}),this.walletListenerCleanups.push(()=>{q(()=>{var t,n;return null===(n=null===(t=window.solana)||void 0===t?void 0:t.removeListener)||void 0===n?void 0:n.call(t,"connect",e)})})}}setupEIP6963AccountListeners(){const e=B();for(const[,t]of e)this.attachEIP6963AccountsChanged(t)}handleLateEIP6963Provider(e){const{info:t,provider:n}=e,i=q(()=>{var e;return null===(e=n.request)||void 0===e?void 0:e.call(n,{method:"eth_accounts"})});i&&i.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(!q(()=>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(()=>{})};q(()=>{var e;return null===(e=n.on)||void 0===e?void 0:e.call(n,"accountsChanged",i)}),this.walletListenerCleanups.push(()=>{q(()=>{var e;return null===(e=n.removeListener)||void 0===e?void 0: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,r){return t(this,void 0,void 0,function*(){const t=v(),o=u(),s=Object.assign(Object.assign(Object.assign({tag:e,amount:n},r&&{currency:r}),{event:i,user:{name:g()},session:o}),t&&{lid:t});yield this.httpClient.post("/api/sdk/conversion",s)})}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 E(),i=P(),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(){return!!q(()=>{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(),K&&(U&&(window.removeEventListener("eip6963:announceProvider",U),U=null),N.clear(),K=!1)}},Q=null,X=null;const Z=()=>new Error("LuciaSDK not initialized. Please call LuciaSDK.init() first"),J=()=>{if("undefined"==typeof window)throw Z();const e=Q||window.__luciaInitPromise;return e||(null!=X||(X=new Promise((e,t)=>{const n=Date.now();F=setInterval(()=>{const i=Q||window.__luciaInitPromise;!i&&Date.now()-n<15e3||(clearInterval(F),X=null,i?e(i):t(Z()))},50)})),X)},Y={init:e=>{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==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 H(e);return yield t.init(),t});return Q=n,window.__luciaInitPromise=n,n},userInfo:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield J()).userInfo(e,n)}),pageView:e=>t(void 0,void 0,void 0,function*(){return(yield J()).pageView(e)}),trackConversion:(e,n,i,r)=>t(void 0,void 0,void 0,function*(){return(yield J()).trackConversion(e,n,i,r)}),buttonClick:(e,n)=>t(void 0,void 0,void 0,function*(){return(yield J()).buttonClick(e,n)}),sendWalletInfo:(e,n,i)=>t(void 0,void 0,void 0,function*(){return(yield J()).sendWalletInfo(e,n,i)}),trackUserAcquisition:(e,...n)=>t(void 0,[e,...n],void 0,function*(e,t={}){return(yield J()).trackUserAcquisition(e,t)}),checkMetaMaskConnection:()=>!!q(()=>{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=Y;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");Y.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=Q||"undefined"!=typeof window&&window.__luciaInitPromise;e&&e.then(e=>e.destroy()).catch(()=>{}),Q=null,clearInterval(F),X=null,"undefined"!=typeof window&&delete window.__luciaInitPromise,p.reset()},e.default=Y,e.detectEvmProvider=V,e.detectSolanaProvider=G,e.filterObject=function(e){const t={};return Object.keys(e).forEach(n=>{const i=n;e[i]&&(t[i]=e[i])}),t},e.getApplePayAvailable=j,e.getBrowserData=E,e.getCanvasFingerprint=function(){return t(this,void 0,void 0,function*(){return(yield D()).uniqueHash})},e.getColorGamut=M,e.getContrastPreference=_,e.getUtmParams=P,e.getWebGLInfo=R,e.isTouchEnabled=W,e.safeAccess=S,Object.defineProperty(e,"__esModule",{value:!0})});