veo-sdk 0.2.1 → 0.3.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/dist/veo.js CHANGED
@@ -1,3 +1,3 @@
1
- var veo=(function(exports){'use strict';var x="0.0.1";var O="https://veo-backend-production-8c78.up.railway.app";function g(n){let e=n?.apiUrl;if(typeof e=="string"&&e.trim())return e;let t=globalThis.__VEO_API_URL__;return typeof t=="string"&&t.trim()?t:O}function u(){return typeof window<"u"}function l(){return typeof document<"u"}function P(){try{if(typeof localStorage>"u")return !1;let n="__veo_test__";return localStorage.setItem(n,"1"),localStorage.removeItem(n),!0}catch{return false}}function N(){return typeof navigator<"u"&&typeof navigator.sendBeacon=="function"}var z="veoBuilder";function D(){if(!u())return false;try{return new URLSearchParams(window.location.search).has(z)}catch{return false}}function B(n){if(!u()||!l())return;let e;try{e=new URLSearchParams(window.location.search);}catch{return}if(!e.has(z)||(n.apiKey&&n.apiUrl&&(window.__veoBuilder={apiKey:n.apiKey,apiUrl:n.apiUrl}),window.veoBuilder))return;let t=n.builderUrl??le();if(!t){n.debug&&console.warn("[veo] builder mode pedido pero no pude resolver la URL de veo-builder.js");return}if(document.querySelector(`script[src="${t}"]`))return;let r=document.createElement("script");r.src=t,r.async=true,n.debug&&r.addEventListener("error",()=>console.error("[veo] no pude cargar",t)),document.head.appendChild(r);}function le(){let n=document.querySelectorAll("script[src]");for(let e of Array.from(n))if(/\bveo(\.min)?\.js(\?.*)?$/.test(e.src))return e.src.replace(/\bveo(\.min)?\.js/,"veo-builder$1.js");return null}var G=null;function H(n){return G??(G=ce(n)),G}function ce(n){return new Promise(e=>{if(!u()||!l()){e(null);return}let t=window;if(t.veoGuides){e(t.veoGuides);return}let r=n.guidesUrl??de();if(!r){n.debug&&console.warn("[veo] no pude resolver la URL de veo-guides.js"),e(null);return}let i=()=>e(t.veoGuides??null),o=document.querySelector(`script[src="${r}"]`);if(o){o.addEventListener("load",i),o.addEventListener("error",()=>e(null));return}let s=document.createElement("script");s.src=r,s.async=true,s.addEventListener("load",i),s.addEventListener("error",()=>{n.debug&&console.error("[veo] no pude cargar",r),e(null);}),document.head.appendChild(s);})}function de(){let n=document.querySelectorAll("script[src]");for(let e of Array.from(n))if(/\bveo(\.min)?\.js(\?.*)?$/.test(e.src))return e.src.replace(/\bveo(\.min)?\.js/,"veo-guides$1.js");return null}var pe="veoPreview";function K(){if(!u())return null;try{let n=new URLSearchParams(window.location.search).get(pe);return n||null}catch{return null}}function ge(n){return n}var q={enabled:true,captureClicks:true,captureSubmits:true,captureChanges:true,maskAllInputs:true,maskAllText:false,throttleMs:100,maxTextLength:200,captureElementMetadata:true,captureAncestors:5},F=10,j=["[data-veo-ignore]",".veo-ignore",'input[type="password"]','input[type="email"]','input[type="tel"]','input[type="hidden"]','[autocomplete="cc-number"]','[autocomplete="cc-csc"]','[autocomplete="cc-exp"]','[autocomplete="cc-name"]','[name*="password" i]','[name*="ssn" i]','[name*="credit" i]','[name*="card" i]','[id*="password" i]','[id*="ssn" i]'],Y=["value","data-credit-card","data-ssn","data-password"],W=["id","name","type","role","href","data-action","data-veo-tag","data-testid","aria-label","aria-labelledby"],X=[/^css-[a-z0-9]{4,}$/i,/^_[a-z0-9]+_[a-z0-9]{4,}_\d+$/,/^[a-z]{2,4}-[a-z0-9]{6,}$/i,/^[a-f0-9]{6,}$/i,/^sc-[a-z0-9]+$/i];function v(n,e=[]){let t=[...j,...e],r=n;for(;r&&r!==document.documentElement;){for(let i of t)try{if(r.matches(i))return !0}catch{}r=r.parentElement;}return false}function J(n){let e=n.toLowerCase();return Y.includes(e)||/password|secret|token|ssn|credit/i.test(n)}function Z(n,e,t){if(t)return "";let r=n.tagName.toLowerCase();if(r==="input"||r==="textarea")return "";let o=((n instanceof HTMLElement?n.innerText:"")||n.textContent||"").trim().replace(/\s+/g," ");return o.length>e?`${o.slice(0,e)}\u2026`:o}function fe(n){return X.some(e=>e.test(n))}function f(n){return Array.from(n.classList).filter(e=>!fe(e)&&e.length<64)}var me=["data-testid","data-test","data-cy","name","aria-label","placeholder","alt","title","href","role","type"],he=100;function C(n){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g,"\\$&")}function Q(n){return n.replace(/[\\"]/g,"\\$&")}function ve(n,e){for(let t of me){let r=n.getAttribute(t);if(r&&r.length>0&&r.length<=he)return `${e}[${t}="${Q(r)}"]`}return null}function ye(n){let e=n.tagName.toLowerCase(),t=n.getAttribute("data-veo-tag");if(t)return `${e}[data-veo-tag="${Q(t)}"]`;if(n.id){let s=f(n),a=s.length>0?`.${s.map(C).join(".")}`:"";return `${e}#${C(n.id)}${a}`}let r=ve(n,e);if(r)return r;let i=f(n),o=i.length>0?`.${i.map(C).join(".")}`:"";return `${e}${o}`}function ee(n,e=5){let t=[],r=n,i=0;for(;r&&r!==document.documentElement&&i<=e;)t.unshift(ye(r)),r=r.parentElement,i++;return t.join(" > ")}function we(n){let e={};for(let t of W){let r=n.getAttribute(t);r!==null&&!J(t)&&r.length<256&&(e[t]=r);}return e}function Ee(n,e){let t=n.getBoundingClientRect();return {tag:n.tagName.toLowerCase(),id:n.id||null,classes:f(n),text:Z(n,e.maxTextLength,e.maskAllText),attributes:e.captureElementMetadata?we(n):{},position:{x:Math.round(t.left+window.scrollX),y:Math.round(t.top+window.scrollY),w:Math.round(t.width),h:Math.round(t.height)}}}function Se(n,e){let t=[],r=n.parentElement,i=0;for(;r&&r!==document.documentElement&&i<e;)t.push({tag:r.tagName.toLowerCase(),id:r.id||null,classes:f(r),veoTag:r.getAttribute("data-veo-tag")||null}),r=r.parentElement,i++;return t}function te(n,e,t){return {$event_type:n,$element:Ee(e,t),$ancestors:Se(e,t.captureAncestors),$selector_path:ee(e,t.captureAncestors),$page_url:window.location.href,$page_path:window.location.pathname}}var y=class{constructor(e){this.windowMs=e;this.lastFired=new WeakMap;}shouldFire(e){let t=Date.now(),r=this.lastFired.get(e)??0;return t-r<this.windowMs?false:(this.lastFired.set(e,t),true)}};var w=class{constructor(e,t){this.client=e;this.cleanups=[];let r=q;this.config={enabled:t.enabled??r.enabled,captureClicks:t.captureClicks??r.captureClicks,captureSubmits:t.captureSubmits??r.captureSubmits,captureChanges:t.captureChanges??r.captureChanges,maskAllInputs:t.maskAllInputs??r.maskAllInputs,maskAllText:t.maskAllText??r.maskAllText,blockSelectors:t.blockSelectors??[],throttleMs:t.throttleMs??r.throttleMs,maxTextLength:t.maxTextLength??r.maxTextLength,captureElementMetadata:t.captureElementMetadata??r.captureElementMetadata,captureAncestors:Math.min(t.captureAncestors??r.captureAncestors,F)},this.throttle=new y(this.config.throttleMs);}install(){!l()||!this.config.enabled||(this.config.captureClicks&&this.attach("click",e=>this.handleClick(e)),this.config.captureSubmits&&this.attach("submit",e=>this.handleSubmit(e),true),this.config.captureChanges&&this.attach("change",e=>this.handleChange(e),true));}destroy(){for(let e of this.cleanups)e();this.cleanups=[];}attach(e,t,r=false){let i=o=>{if(o.isTrusted)try{t(o);}catch{}};document.addEventListener(e,i,r),this.cleanups.push(()=>document.removeEventListener(e,i,r));}handleClick(e){let t=e.target;if(!(t instanceof Element))return;let r=this.findMeaningfulAncestor(t);r&&(v(r,this.config.blockSelectors)||this.throttle.shouldFire(r)&&this.emit("click",r));}handleSubmit(e){let t=e.target;!(t instanceof Element)||t.tagName.toLowerCase()!=="form"||v(t,this.config.blockSelectors)||this.throttle.shouldFire(t)&&this.emit("submit",t);}handleChange(e){let t=e.target;if(!(t instanceof Element))return;let r=t.tagName.toLowerCase();r!=="select"&&r!=="input"&&r!=="textarea"||t instanceof HTMLInputElement&&t.type!=="checkbox"&&t.type!=="radio"||v(t,this.config.blockSelectors)||this.throttle.shouldFire(t)&&this.emit("change",t);}findMeaningfulAncestor(e){let t=e,r=0;for(;t&&t!==document.documentElement&&r<5;){let i=t.tagName.toLowerCase();if(i==="button"||i==="a"||i==="input"||i==="select"||i==="textarea"||t.hasAttribute("data-veo-tag")||t.hasAttribute("role")||t.hasAttribute("onclick")||t instanceof HTMLElement&&t.style.cursor==="pointer")return t;t=t.parentElement,r++;}return null}emit(e,t){let r=te(e,t,this.config);this.client.track("$autocapture",r);}};function U(n={}){let e=null;return {name:"autocapture",install(t){e=new w(t,n),e.install();},destroy(){e?.destroy(),e=null;}}}function k(){return {name:"spa-router",install(n){if(!u())return;n.pageview();let e=()=>{queueMicrotask(()=>n.pageview());},t=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(...i){t.apply(this,i),e();},window.history.replaceState=function(...i){r.apply(this,i),e();},window.addEventListener("popstate",e),window.addEventListener("hashchange",e);}}}function p(){let e=Date.now().toString(16).padStart(12,"0"),t=new Uint8Array(10);if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(t);else for(let i=0;i<t.length;i++)t[i]=Math.floor(Math.random()*256);t[0]=(t[0]??0)&15|112,t[2]=(t[2]??0)&63|128;let r=Array.from(t,i=>i.toString(16).padStart(2,"0")).join("");return [e.slice(0,8),e.slice(8,12),r.slice(0,4),r.slice(4,8),r.slice(8,20)].join("-")}var E=class{constructor(e){this.config=e;this.buffer=[];this.timer=null;this.flushing=false;this.retryCount=0;this.retryTimer=null;this.startTimer();}add(e){this.buffer.push(e),this.buffer.length>=this.config.batchSize&&this.flush();}async flush(){if(this.flushing||this.buffer.length===0)return;this.flushing=true;let e=this.buffer.splice(0,this.buffer.length);try{await this.config.transport.send("/v1/events",{events:e}),this.retryCount=0;}catch(t){this.buffer.unshift(...e),this.scheduleRetry(),this.config.onError?.(t);}finally{this.flushing=false;}}flushBeacon(){if(this.buffer.length===0)return;let e=this.buffer.splice(0,this.buffer.length);this.config.transport.sendBeacon("/v1/events",{events:e})||this.buffer.unshift(...e);}destroy(){this.timer&&clearInterval(this.timer),this.retryTimer&&clearTimeout(this.retryTimer),this.timer=null,this.retryTimer=null;}startTimer(){this.timer=setInterval(()=>{this.flush();},this.config.flushIntervalMs);}scheduleRetry(){let e=this.config.maxRetries??3;if(this.retryCount>=e){this.retryCount=0;return}this.retryCount++;let t=Math.min(1e3*2**(this.retryCount-1),3e4);this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=setTimeout(()=>{this.flush();},t);}};var re="anonymous_user_id",R="end_user_id",S="session_id",m="session_last_active",ne=1800*1e3,b=class{constructor(e){this.storage=e;this._endUserId=null;this._anonymousId=this.loadOrCreateAnonymousId(),this._sessionId=this.loadOrCreateSession(),this._endUserId=this.storage.get(R);}get anonymousId(){return this._anonymousId}get sessionId(){return this._sessionId}get endUserId(){return this._endUserId}get effectiveUserId(){return this._endUserId??this._anonymousId}setEndUserId(e){this._endUserId=e,this.storage.set(R,e);}touch(){let e=this.storage.get(m),t=Date.now();e&&t-Number.parseInt(e,10)>ne&&(this._sessionId=p(),this.storage.set(S,this._sessionId)),this.storage.set(m,String(t));}reset(){this._endUserId=null,this.storage.remove(R),this._sessionId=p(),this.storage.set(S,this._sessionId),this.storage.set(m,String(Date.now()));}loadOrCreateAnonymousId(){let e=this.storage.get(re);return e||(e=p(),this.storage.set(re,e)),e}loadOrCreateSession(){let e=this.storage.get(S),t=this.storage.get(m);if(e&&t&&Date.now()-Number.parseInt(t,10)<ne)return e;let r=p();return this.storage.set(S,r),this.storage.set(m,String(Date.now())),r}};var c="veo:",be=365*24*60*60*1e3,A=class{get(e){return localStorage.getItem(c+e)}set(e,t){try{localStorage.setItem(c+e,t);}catch{}}remove(e){localStorage.removeItem(c+e);}clear(){let e=[];for(let t=0;t<localStorage.length;t++){let r=localStorage.key(t);r?.startsWith(c)&&e.push(r);}for(let t of e)localStorage.removeItem(t);}};function ie(){let n=document.cookie;return n===""?[]:n.split("; ")}var I=class{get(e){let t=`${c}${e}=`;for(let r of ie())if(r.startsWith(t))return decodeURIComponent(r.slice(t.length));return null}set(e,t,r){let i=Math.floor((r?.ttlMs??be)/1e3),o=typeof location<"u"&&location.protocol==="https:"?"; Secure":"";document.cookie=`${c}${e}=${encodeURIComponent(t)}; Path=/; Max-Age=${i}; SameSite=Lax${o}`;}remove(e){document.cookie=`${c}${e}=; Path=/; Max-Age=0; SameSite=Lax`;}clear(){for(let e of ie()){let t=e.indexOf("="),r=t===-1?e:e.slice(0,t);r.startsWith(c)&&this.remove(r.slice(c.length));}}},_=class{constructor(){this.store=new Map;}get(e){return this.store.get(e)??null}set(e,t){this.store.set(e,t);}remove(e){this.store.delete(e);}clear(){this.store.clear();}};function oe(n="localStorage"){return n==="localStorage"&&P()?new A:n==="cookie"&&l()?new I:n==="memory"?new _:P()?new A:l()?new I:new _}var V=class extends Error{constructor(t,r){super(t);this.statusCode=r;this.name="TransportError";}},T=class{constructor(e){this.config=e;}async send(e,t){let r=`${this.config.apiUrl}${e}`,i=new AbortController,o=this.config.timeoutMs??1e4,s=setTimeout(()=>i.abort(new DOMException(`Veo request timeout (${o}ms)`,"TimeoutError")),o);try{let a=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json","X-Api-Key":this.config.apiKey,"X-Sdk-Version":this.config.sdkVersion},body:JSON.stringify(t),signal:i.signal});if(!a.ok)throw new V(`HTTP ${a.status}`,a.status);return await a.json()}finally{clearTimeout(s);}}sendBeacon(e,t){if(!N())return false;let r=new URL(`${this.config.apiUrl}${e}`);r.searchParams.set("key",this.config.apiKey),r.searchParams.set("v",this.config.sdkVersion);let i=new Blob([JSON.stringify(t)],{type:"application/json"});return navigator.sendBeacon(r.toString(),i)}};var L="organization_id",se="end_user_id",M="identify_signature";function $(n){return n===null||typeof n!="object"?JSON.stringify(n)??"null":Array.isArray(n)?`[${n.map($).join(",")}]`:`{${Object.keys(n).sort().map(t=>`${JSON.stringify(t)}:${$(n[t])}`).join(",")}}`}var h=class{constructor(e){this.config=e;this.plugins=[];this.currentOrganizationId=null;this.listeners={pageview:new Set,identify:new Set};if(!e.apiKey)throw new Error("apiKey is required");this.storage=oe(e.storage??"localStorage"),this.session=new b(this.storage),this.transport=new T({apiKey:e.apiKey,apiUrl:g(e).replace(/\/$/,""),sdkVersion:x}),this.queue=new E({transport:this.transport,flushIntervalMs:e.flushInterval??5e3,batchSize:e.flushBatchSize??20,onError:i=>{e.debug&&console.error("[veo] flush error:",i);}});let t=this.storage.get(se);t&&this.session.setEndUserId(t);let r=this.storage.get(L);r&&(this.currentOrganizationId=r),this.setupUnloadHandlers(),e.debug&&console.log("[veo] initialized",{anonymousId:this.session.anonymousId,sessionId:this.session.sessionId,endUserId:this.session.endUserId});}identify(e){let{visitor:t,organization:r}=e,i=$({id:t.id,traits:t.traits??{},org:r?{id:r.id,attributes:r.attributes??{}}:null});if(this.session.endUserId===t.id&&this.storage.get(M)===i){this.config.debug&&console.debug("[veo] identify: sin cambios, omitido");return}let o=this.session.endUserId===null?this.session.anonymousId:void 0;this.session.setEndUserId(t.id),r&&(this.currentOrganizationId=r.id,this.storage.set(L,r.id));let a={endUser:{id:t.id,traits:t.traits??{},...o!==void 0?{anonymousId:o}:{}},...r?{organization:{id:r.id,attributes:r.attributes??{}}}:{}};this.transport.send("/v1/identify",a).catch(d=>{this.config.debug&&console.error("[veo] identify failed:",d);}),this.enqueue({actionType:"identify",actionProperties:{traits:t.traits,organizationAttributes:r?.attributes}}),this.storage.set(M,i),this.emit("identify",{endUserId:t.id,sessionId:this.session.sessionId});}track(e,t){if(!e||typeof e!="string"){this.config.debug&&console.error("[veo] track: name is required");return}this.enqueue({actionType:"track",actionName:e,...t!==void 0?{actionProperties:t}:{}});}pageview(e){if(!l())return;let t=window.location.href,r=e??window.location.pathname;this.enqueue({actionType:"pageview",pageUrl:t,pagePath:r,pageTitle:document.title,pageReferrer:document.referrer}),this.emit("pageview",{url:t,path:r,sessionId:this.session.sessionId,endUserId:this.session.endUserId});}reset(){this.session.reset(),this.currentOrganizationId=null,this.storage.remove(L),this.storage.remove(se),this.storage.remove(M);}flush(){return this.queue.flush()}use(e){return this.plugins.push(e),e.install(this),this}getEndUserId(){return this.session.endUserId}getAnonymousId(){return this.session.anonymousId}getSessionId(){return this.session.sessionId}on(e,t){return this.listeners[e].add(t),()=>{this.listeners[e].delete(t);}}emit(e,t){for(let r of this.listeners[e])try{r(t);}catch(i){this.config.debug&&console.error(`[veo] listener for '${e}' failed:`,i);}}enqueue(e){this.session.touch();let t=this.currentOrganizationId??void 0,r=e.pageUrl??(u()?window.location.href:void 0),i=e.pagePath??(u()?window.location.pathname:void 0),o=e.pageTitle??(l()?document.title:void 0),s=e.pageReferrer??(l()?document.referrer:void 0),a={actionId:p(),endUserId:this.session.effectiveUserId,sessionId:this.session.sessionId,actionType:e.actionType,occurredAt:new Date().toISOString(),...t!==void 0?{organizationId:t}:{},...e.actionName!==void 0?{actionName:e.actionName}:{},...r!==void 0?{pageUrl:r}:{},...i!==void 0?{pagePath:i}:{},...o!==void 0?{pageTitle:o}:{},...s!==void 0?{pageReferrer:s}:{},...e.actionProperties!==void 0?{actionProperties:e.actionProperties}:{}};this.queue.add(a);}setupUnloadHandlers(){u()&&(window.addEventListener("pagehide",()=>this.queue.flushBeacon()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.queue.flushBeacon();}));}};function ae(n,e){let t=new h(n);if(t.use(k()),n.autocapture!==false){let r=typeof n.autocapture=="object"?n.autocapture:{};t.use(U(r));}if(e(t),typeof window<"u"){let i=window.veo?._q??[];window.veo=t;for(let o of i){let[s,a]=o;if(s==="init")continue;let d=t[s];if(typeof d=="function")try{d.apply(t,Array.from(a));}catch(ue){n.debug&&console.error("[veo] drain error:",ue);}}B({...n.builderUrl!==void 0?{builderUrl:n.builderUrl}:{},...n.debug!==void 0?{debug:n.debug}:{},...n.apiKey!==void 0?{apiKey:n.apiKey}:{},apiUrl:g(n)});}return t}function Ut(n){let e=g(n);return ae(n,t=>{let r=()=>H({...n.guidesUrl!==void 0?{guidesUrl:n.guidesUrl}:{},...n.debug!==void 0?{debug:n.debug}:{}}),i=K();n.guides===true&&!D()&&i===null&&r().then(o=>{o&&t.use(o.guidesPlugin({apiUrl:e,apiKey:n.apiKey,...n.debug!==void 0?{debug:n.debug}:{}}));}),i!==null&&r().then(o=>o?.runPreviewMode({apiKey:n.apiKey,apiUrl:e,token:i,...n.debug!==void 0?{debug:n.debug}:{}})),t.preview=o=>{let s=null,a=r().then(d=>d?(s=d.previewGuide(o),s.ready):{rendered:false});return {close:()=>s?.close(),ready:a}},t.closePreview=()=>{r().then(o=>o?.closeGuidePreview());};})}
2
- exports.Client=h;exports.SDK_VERSION=x;exports.autocapturePlugin=U;exports.definePlugin=ge;exports.init=Ut;exports.spaRouterPlugin=k;return exports;})({});//# sourceMappingURL=veo.js.map
1
+ var veo=(function(exports){'use strict';var x="0.0.1";var D="https://veo-backend-production-8c78.up.railway.app";function g(r){let e=r?.apiUrl;if(typeof e=="string"&&e.trim())return e;let t=globalThis.__VEO_API_URL__;return typeof t=="string"&&t.trim()?t:D}function u(){return typeof window<"u"}function l(){return typeof document<"u"}function P(){try{if(typeof localStorage>"u")return !1;let r="__veo_test__";return localStorage.setItem(r,"1"),localStorage.removeItem(r),!0}catch{return false}}function z(){return typeof navigator<"u"&&typeof navigator.sendBeacon=="function"}var G="veoBuilder",K="veoBuilderOrigin";var H="veo:builder_token",fe="veo:builder_origin";function q(){try{return window.sessionStorage}catch{return null}}function me(){try{return new URLSearchParams(window.location.search)}catch{return null}}function U(){if(!u())return null;let r=me(),e=r?.get(G);if(e){let t=q();try{t?.setItem(H,e);let n=r?.get(K);n&&t?.setItem(fe,n);}catch{}return e}try{return q()?.getItem(H)??null}catch{return null}}function R(){return U()!==null}function F(r){if(!u()||!l()||U()===null||(r.apiKey&&r.apiUrl&&(window.__veoBuilder={apiKey:r.apiKey,apiUrl:r.apiUrl}),window.veoBuilder))return;let e=r.builderUrl??he();if(e){if(document.querySelector(`script[src="${e}"]`))return;let t=document.createElement("script");t.src=e,t.async=true,r.debug&&t.addEventListener("error",()=>console.error("[veo] no pude cargar",e)),document.head.appendChild(t);return}if(r.loadBuilder){r.loadBuilder().catch(t=>{r.debug&&console.error("[veo] no pude cargar el builder (import din\xE1mico)",t);});return}r.debug&&console.warn("[veo] builder mode pedido pero no pude resolver la URL de veo-builder.js");}function he(){let r=document.querySelectorAll("script[src]");for(let e of Array.from(r))if(/\bveo(\.min)?\.js(\?.*)?$/.test(e.src))return e.src.replace(/\bveo(\.min)?\.js/,"veo-builder$1.js");return null}var j=null;function Y(r){return j??(j=ve(r)),j}function ve(r){return new Promise(e=>{if(!u()||!l()){e(null);return}let t=window;if(t.veoGuides){e(t.veoGuides);return}let n=r.guidesUrl??ye();if(!n){r.debug&&console.warn("[veo] no pude resolver la URL de veo-guides.js"),e(null);return}let i=()=>e(t.veoGuides??null),o=document.querySelector(`script[src="${n}"]`);if(o){o.addEventListener("load",i),o.addEventListener("error",()=>e(null));return}let s=document.createElement("script");s.src=n,s.async=true,s.addEventListener("load",i),s.addEventListener("error",()=>{r.debug&&console.error("[veo] no pude cargar",n),e(null);}),document.head.appendChild(s);})}function ye(){let r=document.querySelectorAll("script[src]");for(let e of Array.from(r))if(/\bveo(\.min)?\.js(\?.*)?$/.test(e.src))return e.src.replace(/\bveo(\.min)?\.js/,"veo-guides$1.js");return null}var we="veoPreview";function W(){if(!u())return null;try{let r=new URLSearchParams(window.location.search).get(we);return r||null}catch{return null}}function Ee(r){return r}var X={enabled:true,captureClicks:true,captureSubmits:true,captureChanges:true,maskAllInputs:true,maskAllText:false,throttleMs:100,maxTextLength:200,captureElementMetadata:true,captureAncestors:5},J=10,Z=["[data-veo-ignore]",".veo-ignore",'input[type="password"]','input[type="email"]','input[type="tel"]','input[type="hidden"]','[autocomplete="cc-number"]','[autocomplete="cc-csc"]','[autocomplete="cc-exp"]','[autocomplete="cc-name"]','[name*="password" i]','[name*="ssn" i]','[name*="credit" i]','[name*="card" i]','[id*="password" i]','[id*="ssn" i]'],Q=["value","data-credit-card","data-ssn","data-password"],ee=["id","name","type","role","href","data-action","data-veo-tag","data-testid","aria-label","aria-labelledby"],te=[/^css-[a-z0-9]{4,}$/i,/^_[a-z0-9]+_[a-z0-9]{4,}_\d+$/,/^[a-z]{2,4}-[a-z0-9]{6,}$/i,/^[a-f0-9]{6,}$/i,/^sc-[a-z0-9]+$/i];function v(r,e=[]){let t=[...Z,...e],n=r;for(;n&&n!==document.documentElement;){for(let i of t)try{if(n.matches(i))return !0}catch{}n=n.parentElement;}return false}function re(r){let e=r.toLowerCase();return Q.includes(e)||/password|secret|token|ssn|credit/i.test(r)}function ne(r,e,t){if(t)return "";let n=r.tagName.toLowerCase();if(n==="input"||n==="textarea")return "";let o=((r instanceof HTMLElement?r.innerText:"")||r.textContent||"").trim().replace(/\s+/g," ");return o.length>e?`${o.slice(0,e)}\u2026`:o}function Se(r){return te.some(e=>e.test(r))}function f(r){return Array.from(r.classList).filter(e=>!Se(e)&&e.length<64)}var Ie=["data-testid","data-test","data-cy","name","aria-label","placeholder","alt","title","href","role","type"],be=100;function C(r){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(r):r.replace(/[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g,"\\$&")}function ie(r){return r.replace(/[\\"]/g,"\\$&")}function Ae(r,e){for(let t of Ie){let n=r.getAttribute(t);if(n&&n.length>0&&n.length<=be)return `${e}[${t}="${ie(n)}"]`}return null}function _e(r){let e=r.tagName.toLowerCase(),t=r.getAttribute("data-veo-tag");if(t)return `${e}[data-veo-tag="${ie(t)}"]`;if(r.id){let s=f(r),a=s.length>0?`.${s.map(C).join(".")}`:"";return `${e}#${C(r.id)}${a}`}let n=Ae(r,e);if(n)return n;let i=f(r),o=i.length>0?`.${i.map(C).join(".")}`:"";return `${e}${o}`}function oe(r,e=5){let t=[],n=r,i=0;for(;n&&n!==document.documentElement&&i<=e;)t.unshift(_e(n)),n=n.parentElement,i++;return t.join(" > ")}function Te(r){let e={};for(let t of ee){let n=r.getAttribute(t);n!==null&&!re(t)&&n.length<256&&(e[t]=n);}return e}function xe(r,e){let t=r.getBoundingClientRect();return {tag:r.tagName.toLowerCase(),id:r.id||null,classes:f(r),text:ne(r,e.maxTextLength,e.maskAllText),attributes:e.captureElementMetadata?Te(r):{},position:{x:Math.round(t.left+window.scrollX),y:Math.round(t.top+window.scrollY),w:Math.round(t.width),h:Math.round(t.height)}}}function Pe(r,e){let t=[],n=r.parentElement,i=0;for(;n&&n!==document.documentElement&&i<e;)t.push({tag:n.tagName.toLowerCase(),id:n.id||null,classes:f(n),veoTag:n.getAttribute("data-veo-tag")||null}),n=n.parentElement,i++;return t}function se(r,e,t){return {$event_type:r,$element:xe(e,t),$ancestors:Pe(e,t.captureAncestors),$selector_path:oe(e,t.captureAncestors),$page_url:window.location.href,$page_path:window.location.pathname}}var y=class{constructor(e){this.windowMs=e;this.lastFired=new WeakMap;}shouldFire(e){let t=Date.now(),n=this.lastFired.get(e)??0;return t-n<this.windowMs?false:(this.lastFired.set(e,t),true)}};var w=class{constructor(e,t){this.client=e;this.cleanups=[];let n=X;this.config={enabled:t.enabled??n.enabled,captureClicks:t.captureClicks??n.captureClicks,captureSubmits:t.captureSubmits??n.captureSubmits,captureChanges:t.captureChanges??n.captureChanges,maskAllInputs:t.maskAllInputs??n.maskAllInputs,maskAllText:t.maskAllText??n.maskAllText,blockSelectors:t.blockSelectors??[],throttleMs:t.throttleMs??n.throttleMs,maxTextLength:t.maxTextLength??n.maxTextLength,captureElementMetadata:t.captureElementMetadata??n.captureElementMetadata,captureAncestors:Math.min(t.captureAncestors??n.captureAncestors,J)},this.throttle=new y(this.config.throttleMs);}install(){!l()||!this.config.enabled||(this.config.captureClicks&&this.attach("click",e=>this.handleClick(e)),this.config.captureSubmits&&this.attach("submit",e=>this.handleSubmit(e),true),this.config.captureChanges&&this.attach("change",e=>this.handleChange(e),true));}destroy(){for(let e of this.cleanups)e();this.cleanups=[];}attach(e,t,n=false){let i=o=>{if(o.isTrusted)try{t(o);}catch{}};document.addEventListener(e,i,n),this.cleanups.push(()=>document.removeEventListener(e,i,n));}handleClick(e){let t=e.target;if(!(t instanceof Element))return;let n=this.findMeaningfulAncestor(t);n&&(v(n,this.config.blockSelectors)||this.throttle.shouldFire(n)&&this.emit("click",n));}handleSubmit(e){let t=e.target;!(t instanceof Element)||t.tagName.toLowerCase()!=="form"||v(t,this.config.blockSelectors)||this.throttle.shouldFire(t)&&this.emit("submit",t);}handleChange(e){let t=e.target;if(!(t instanceof Element))return;let n=t.tagName.toLowerCase();n!=="select"&&n!=="input"&&n!=="textarea"||t instanceof HTMLInputElement&&t.type!=="checkbox"&&t.type!=="radio"||v(t,this.config.blockSelectors)||this.throttle.shouldFire(t)&&this.emit("change",t);}findMeaningfulAncestor(e){let t=e,n=0;for(;t&&t!==document.documentElement&&n<5;){let i=t.tagName.toLowerCase();if(i==="button"||i==="a"||i==="input"||i==="select"||i==="textarea"||t.hasAttribute("data-veo-tag")||t.hasAttribute("role")||t.hasAttribute("onclick")||t instanceof HTMLElement&&t.style.cursor==="pointer")return t;t=t.parentElement,n++;}return null}emit(e,t){let n=se(e,t,this.config);this.client.track("$autocapture",n);}};function k(r={}){let e=null;return {name:"autocapture",install(t){e=new w(t,r),e.install();},destroy(){e?.destroy(),e=null;}}}function L(){return {name:"spa-router",install(r){if(!u())return;r.pageview();let e=()=>{queueMicrotask(()=>r.pageview());},t=window.history.pushState,n=window.history.replaceState;window.history.pushState=function(...i){t.apply(this,i),e();},window.history.replaceState=function(...i){n.apply(this,i),e();},window.addEventListener("popstate",e),window.addEventListener("hashchange",e);}}}function d(){let e=Date.now().toString(16).padStart(12,"0"),t=new Uint8Array(10);if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(t);else for(let i=0;i<t.length;i++)t[i]=Math.floor(Math.random()*256);t[0]=(t[0]??0)&15|112,t[2]=(t[2]??0)&63|128;let n=Array.from(t,i=>i.toString(16).padStart(2,"0")).join("");return [e.slice(0,8),e.slice(8,12),n.slice(0,4),n.slice(4,8),n.slice(8,20)].join("-")}var E=class{constructor(e){this.config=e;this.buffer=[];this.timer=null;this.flushing=false;this.retryCount=0;this.retryTimer=null;this.startTimer();}add(e){this.buffer.push(e),this.buffer.length>=this.config.batchSize&&this.flush();}async flush(){if(this.flushing||this.buffer.length===0)return;this.flushing=true;let e=this.buffer.splice(0,this.buffer.length);try{await this.config.transport.send("/v1/events",{events:e}),this.retryCount=0;}catch(t){this.buffer.unshift(...e),this.scheduleRetry(),this.config.onError?.(t);}finally{this.flushing=false;}}flushBeacon(){if(this.buffer.length===0)return;let e=this.buffer.splice(0,this.buffer.length);this.config.transport.sendBeacon("/v1/events",{events:e})||this.buffer.unshift(...e);}destroy(){this.timer&&clearInterval(this.timer),this.retryTimer&&clearTimeout(this.retryTimer),this.timer=null,this.retryTimer=null;}startTimer(){this.timer=setInterval(()=>{this.flush();},this.config.flushIntervalMs);}scheduleRetry(){let e=this.config.maxRetries??3;if(this.retryCount>=e){this.retryCount=0;return}this.retryCount++;let t=Math.min(1e3*2**(this.retryCount-1),3e4);this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=setTimeout(()=>{this.flush();},t);}};var ae="anonymous_user_id",V="end_user_id",S="session_id",m="session_last_active",ue=1800*1e3,I=class{constructor(e){this.storage=e;this._endUserId=null;this._anonymousId=this.loadOrCreateAnonymousId(),this._sessionId=this.loadOrCreateSession(),this._endUserId=this.storage.get(V);}get anonymousId(){return this._anonymousId}get sessionId(){return this._sessionId}get endUserId(){return this._endUserId}get effectiveUserId(){return this._endUserId??this._anonymousId}setEndUserId(e){this._endUserId=e,this.storage.set(V,e);}touch(){let e=this.storage.get(m),t=Date.now();e&&t-Number.parseInt(e,10)>ue&&(this._sessionId=d(),this.storage.set(S,this._sessionId)),this.storage.set(m,String(t));}reset(){this._endUserId=null,this.storage.remove(V),this._sessionId=d(),this.storage.set(S,this._sessionId),this.storage.set(m,String(Date.now()));}loadOrCreateAnonymousId(){let e=this.storage.get(ae);return e||(e=d(),this.storage.set(ae,e)),e}loadOrCreateSession(){let e=this.storage.get(S),t=this.storage.get(m);if(e&&t&&Date.now()-Number.parseInt(t,10)<ue)return e;let n=d();return this.storage.set(S,n),this.storage.set(m,String(Date.now())),n}};var c="veo:",Ue=365*24*60*60*1e3,b=class{get(e){return localStorage.getItem(c+e)}set(e,t){try{localStorage.setItem(c+e,t);}catch{}}remove(e){localStorage.removeItem(c+e);}clear(){let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n?.startsWith(c)&&e.push(n);}for(let t of e)localStorage.removeItem(t);}};function le(){let r=document.cookie;return r===""?[]:r.split("; ")}var A=class{get(e){let t=`${c}${e}=`;for(let n of le())if(n.startsWith(t))return decodeURIComponent(n.slice(t.length));return null}set(e,t,n){let i=Math.floor((n?.ttlMs??Ue)/1e3),o=typeof location<"u"&&location.protocol==="https:"?"; Secure":"";document.cookie=`${c}${e}=${encodeURIComponent(t)}; Path=/; Max-Age=${i}; SameSite=Lax${o}`;}remove(e){document.cookie=`${c}${e}=; Path=/; Max-Age=0; SameSite=Lax`;}clear(){for(let e of le()){let t=e.indexOf("="),n=t===-1?e:e.slice(0,t);n.startsWith(c)&&this.remove(n.slice(c.length));}}},_=class{constructor(){this.store=new Map;}get(e){return this.store.get(e)??null}set(e,t){this.store.set(e,t);}remove(e){this.store.delete(e);}clear(){this.store.clear();}};function ce(r="localStorage"){return r==="localStorage"&&P()?new b:r==="cookie"&&l()?new A:r==="memory"?new _:P()?new b:l()?new A:new _}var M=class extends Error{constructor(t,n){super(t);this.statusCode=n;this.name="TransportError";}},T=class{constructor(e){this.config=e;}async send(e,t){let n=`${this.config.apiUrl}${e}`,i=new AbortController,o=this.config.timeoutMs??1e4,s=setTimeout(()=>i.abort(new DOMException(`Veo request timeout (${o}ms)`,"TimeoutError")),o);try{let a=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json","X-Api-Key":this.config.apiKey,"X-Sdk-Version":this.config.sdkVersion},body:JSON.stringify(t),signal:i.signal});if(!a.ok)throw new M(`HTTP ${a.status}`,a.status);return await a.json()}finally{clearTimeout(s);}}sendBeacon(e,t){if(!z())return false;let n=new URL(`${this.config.apiUrl}${e}`);n.searchParams.set("key",this.config.apiKey),n.searchParams.set("v",this.config.sdkVersion);let i=new Blob([JSON.stringify(t)],{type:"application/json"});return navigator.sendBeacon(n.toString(),i)}};var O="organization_id",de="end_user_id",$="identify_signature";function N(r){return r===null||typeof r!="object"?JSON.stringify(r)??"null":Array.isArray(r)?`[${r.map(N).join(",")}]`:`{${Object.keys(r).sort().map(t=>`${JSON.stringify(t)}:${N(r[t])}`).join(",")}}`}var h=class{constructor(e){this.config=e;this.plugins=[];this.currentOrganizationId=null;this.listeners={pageview:new Set,identify:new Set};if(!e.apiKey)throw new Error("apiKey is required");this.storage=ce(e.storage??"localStorage"),this.session=new I(this.storage),this.transport=new T({apiKey:e.apiKey,apiUrl:g(e).replace(/\/$/,""),sdkVersion:x}),this.queue=new E({transport:this.transport,flushIntervalMs:e.flushInterval??5e3,batchSize:e.flushBatchSize??20,onError:i=>{e.debug&&console.error("[veo] flush error:",i);}});let t=this.storage.get(de);t&&this.session.setEndUserId(t);let n=this.storage.get(O);n&&(this.currentOrganizationId=n),this.setupUnloadHandlers(),e.debug&&console.log("[veo] initialized",{anonymousId:this.session.anonymousId,sessionId:this.session.sessionId,endUserId:this.session.endUserId});}identify(e){let{visitor:t,organization:n}=e,i=N({id:t.id,traits:t.traits??{},org:n?{id:n.id,attributes:n.attributes??{}}:null});if(this.session.endUserId===t.id&&this.storage.get($)===i){this.config.debug&&console.debug("[veo] identify: sin cambios, omitido");return}let o=this.session.endUserId===null?this.session.anonymousId:void 0;this.session.setEndUserId(t.id),n&&(this.currentOrganizationId=n.id,this.storage.set(O,n.id));let a={endUser:{id:t.id,traits:t.traits??{},...o!==void 0?{anonymousId:o}:{}},...n?{organization:{id:n.id,attributes:n.attributes??{}}}:{}};this.transport.send("/v1/identify",a).catch(p=>{this.config.debug&&console.error("[veo] identify failed:",p);}),this.enqueue({actionType:"identify",actionProperties:{traits:t.traits,organizationAttributes:n?.attributes}}),this.storage.set($,i),this.emit("identify",{endUserId:t.id,sessionId:this.session.sessionId});}track(e,t){if(!e||typeof e!="string"){this.config.debug&&console.error("[veo] track: name is required");return}this.enqueue({actionType:"track",actionName:e,...t!==void 0?{actionProperties:t}:{}});}pageview(e){if(!l())return;let t=window.location.href,n=e??window.location.pathname;this.enqueue({actionType:"pageview",pageUrl:t,pagePath:n,pageTitle:document.title,pageReferrer:document.referrer}),this.emit("pageview",{url:t,path:n,sessionId:this.session.sessionId,endUserId:this.session.endUserId});}reset(){this.session.reset(),this.currentOrganizationId=null,this.storage.remove(O),this.storage.remove(de),this.storage.remove($);}flush(){return this.queue.flush()}use(e){return this.plugins.push(e),e.install(this),this}getEndUserId(){return this.session.endUserId}getAnonymousId(){return this.session.anonymousId}getSessionId(){return this.session.sessionId}on(e,t){return this.listeners[e].add(t),()=>{this.listeners[e].delete(t);}}emit(e,t){for(let n of this.listeners[e])try{n(t);}catch(i){this.config.debug&&console.error(`[veo] listener for '${e}' failed:`,i);}}enqueue(e){this.session.touch();let t=this.currentOrganizationId??void 0,n=e.pageUrl??(u()?window.location.href:void 0),i=e.pagePath??(u()?window.location.pathname:void 0),o=e.pageTitle??(l()?document.title:void 0),s=e.pageReferrer??(l()?document.referrer:void 0),a={actionId:d(),endUserId:this.session.effectiveUserId,sessionId:this.session.sessionId,actionType:e.actionType,occurredAt:new Date().toISOString(),...t!==void 0?{organizationId:t}:{},...e.actionName!==void 0?{actionName:e.actionName}:{},...n!==void 0?{pageUrl:n}:{},...i!==void 0?{pagePath:i}:{},...o!==void 0?{pageTitle:o}:{},...s!==void 0?{pageReferrer:s}:{},...e.actionProperties!==void 0?{actionProperties:e.actionProperties}:{}};this.queue.add(a);}setupUnloadHandlers(){u()&&(window.addEventListener("pagehide",()=>this.queue.flushBeacon()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.queue.flushBeacon();}));}};function pe(r,e,t){let n=new h(r);if(n.use(L()),r.autocapture!==false){let i=typeof r.autocapture=="object"?r.autocapture:{};n.use(k(i));}if(e(n),typeof window<"u"){let o=window.veo?._q??[];window.veo=n;for(let s of o){let[a,p]=s;if(a==="init")continue;let B=n[a];if(typeof B=="function")try{B.apply(n,Array.from(p));}catch(ge){r.debug&&console.error("[veo] drain error:",ge);}}F({...r.builderUrl!==void 0?{builderUrl:r.builderUrl}:{},...r.debug!==void 0?{debug:r.debug}:{},...r.apiKey!==void 0?{apiKey:r.apiKey}:{},apiUrl:g(r),...{}});}return n}function Kt(r){let e=g(r);return pe(r,t=>{let n=()=>Y({...r.guidesUrl!==void 0?{guidesUrl:r.guidesUrl}:{},...r.debug!==void 0?{debug:r.debug}:{}}),i=W();r.guides===true&&!R()&&i===null&&n().then(o=>{o&&t.use(o.guidesPlugin({apiUrl:e,apiKey:r.apiKey,...r.debug!==void 0?{debug:r.debug}:{}}));}),i!==null&&n().then(o=>o?.runPreviewMode({apiKey:r.apiKey,apiUrl:e,token:i,...r.debug!==void 0?{debug:r.debug}:{}})),t.preview=o=>{let s=null,a=n().then(p=>p?(s=p.previewGuide(o),s.ready):{rendered:false});return {close:()=>s?.close(),ready:a}},t.closePreview=()=>{n().then(o=>o?.closeGuidePreview());};})}
2
+ exports.Client=h;exports.SDK_VERSION=x;exports.autocapturePlugin=k;exports.definePlugin=Ee;exports.init=Kt;exports.spaRouterPlugin=L;return exports;})({});//# sourceMappingURL=veo.js.map
3
3
  //# sourceMappingURL=veo.js.map