@beworke/pixel 0.1.0-rc.12 → 0.1.0-rc.13

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/{Pixel-nqpXzWsc.d.ts → Pixel-BKTvqIwz.d.ts} +3 -3
  3. package/dist/{Pixel-D4Typ_-F.d.mts → Pixel-DgVo0j7D.d.mts} +3 -3
  4. package/dist/{StorageFactory-qycJqKIl.d.mts → StorageFactory-BRtmy983.d.mts} +1 -1
  5. package/dist/{StorageFactory-BEZY4jKp.d.ts → StorageFactory-BcOX0fsg.d.ts} +1 -1
  6. package/dist/browser/index.cjs.js +1 -1
  7. package/dist/browser/index.cjs.js.map +1 -1
  8. package/dist/browser/index.d.mts +5 -5
  9. package/dist/browser/index.d.ts +5 -5
  10. package/dist/browser/index.esm.js +1 -1
  11. package/dist/browser/index.esm.js.map +1 -1
  12. package/dist/browser/pixel.buygoods-checkout.global.js +1 -1
  13. package/dist/browser/pixel.buygoods-checkout.global.js.map +1 -1
  14. package/dist/browser/pixel.buygoods-landing.global.js +1 -1
  15. package/dist/browser/pixel.buygoods-landing.global.js.map +1 -1
  16. package/dist/browser/pixel.global.js +1 -1
  17. package/dist/browser/pixel.global.js.map +1 -1
  18. package/dist/browser/pixel.internal-checkout.global.js +1 -1
  19. package/dist/browser/pixel.internal-checkout.global.js.map +1 -1
  20. package/dist/config/index.cjs.js +1 -1
  21. package/dist/config/index.cjs.js.map +1 -1
  22. package/dist/config/index.d.mts +4 -4
  23. package/dist/config/index.d.ts +4 -4
  24. package/dist/config/index.esm.js +1 -1
  25. package/dist/config/index.esm.js.map +1 -1
  26. package/dist/index.cjs.js +1 -1
  27. package/dist/index.cjs.js.map +1 -1
  28. package/dist/index.d.mts +7 -7
  29. package/dist/index.d.ts +7 -7
  30. package/dist/index.esm.js +1 -1
  31. package/dist/index.esm.js.map +1 -1
  32. package/dist/{pixel-_BSDpx4M.d.mts → pixel-CCHv_ror.d.mts} +17 -1
  33. package/dist/{pixel-DNGbAN5C.d.ts → pixel-CgKoaWS3.d.ts} +17 -1
  34. package/dist/{pixel-default-config-DLRya1tl.d.mts → pixel-default-config-CTtkGKh1.d.mts} +2 -2
  35. package/dist/{pixel-default-config-BMYaqs7i.d.ts → pixel-default-config-D0NZVzDZ.d.ts} +2 -2
  36. package/dist/{pixel-settings-DGxl0MVm.d.mts → pixel-settings-BlhqPyAS.d.mts} +1 -1
  37. package/dist/{pixel-settings-D-t9zQb4.d.ts → pixel-settings-CHyZHDO6.d.ts} +1 -1
  38. package/dist/runtime/index.cjs.js +1 -1
  39. package/dist/runtime/index.cjs.js.map +1 -1
  40. package/dist/runtime/index.d.mts +4 -4
  41. package/dist/runtime/index.d.ts +4 -4
  42. package/dist/runtime/index.esm.js +1 -1
  43. package/dist/runtime/index.esm.js.map +1 -1
  44. package/dist/services/index.cjs.js +1 -1
  45. package/dist/services/index.cjs.js.map +1 -1
  46. package/dist/services/index.d.mts +4 -4
  47. package/dist/services/index.d.ts +4 -4
  48. package/dist/services/index.esm.js +1 -1
  49. package/dist/services/index.esm.js.map +1 -1
  50. package/dist/{types-D57M3IEo.d.mts → types-9Uo3slwh.d.mts} +2 -2
  51. package/dist/{types-DcBG30Tw.d.mts → types-CN1t3kwE.d.mts} +1 -1
  52. package/dist/{types-cVrMwURS.d.ts → types-DaSPqzo_.d.ts} +2 -2
  53. package/dist/{types-Dpe5sArp.d.ts → types-DexAGG5B.d.ts} +1 -1
  54. package/dist/v2/global.global.js +1 -1
  55. package/dist/v2/global.global.js.map +1 -1
  56. package/dist/v2/index.cjs.js +1 -1
  57. package/dist/v2/index.cjs.js.map +1 -1
  58. package/dist/v2/index.d.mts +10 -10
  59. package/dist/v2/index.d.ts +10 -10
  60. package/dist/v2/index.esm.js +1 -1
  61. package/dist/v2/index.esm.js.map +1 -1
  62. package/docs/public/configuration/commerce.md +20 -1
  63. package/package.json +1 -1
@@ -1,10 +1,10 @@
1
- import { D as DispatcherService, F as FingerprintService, S as SessionService, a as SessionData, E as EnsureSessionResult, V as VisitorService } from '../types-DcBG30Tw.mjs';
2
- export { e as CommerceEnrichmentEvent, f as CommerceEventType, C as CommerceResolver, g as CommerceResolverInput, h as CommerceResolverOptions, i as CommerceResolverResult, b as CommerceService, c as CommerceState, j as CommerceStateOptions, k as CommerceStateSnapshot, l as ExtractedProductInput, m as OrderCalculationInput, n as OrderCalculationResult, O as OrderCalculator, o as PageViewCommercePayload, P as PixelRuntimeServices, d as ProductCatalog, p as ProductCatalogOptions, q as ProductCatalogSnapshot, R as ResolvedCommerceItem } from '../types-DcBG30Tw.mjs';
1
+ import { D as DispatcherService, F as FingerprintService, S as SessionService, a as SessionData, E as EnsureSessionResult, V as VisitorService } from '../types-CN1t3kwE.mjs';
2
+ export { e as CommerceEnrichmentEvent, f as CommerceEventType, C as CommerceResolver, g as CommerceResolverInput, h as CommerceResolverOptions, i as CommerceResolverResult, b as CommerceService, c as CommerceState, j as CommerceStateOptions, k as CommerceStateSnapshot, l as ExtractedProductInput, m as OrderCalculationInput, n as OrderCalculationResult, O as OrderCalculator, o as PageViewCommercePayload, P as PixelRuntimeServices, d as ProductCatalog, p as ProductCatalogOptions, q as ProductCatalogSnapshot, R as ResolvedCommerceItem } from '../types-CN1t3kwE.mjs';
3
3
  import { A as AttributionService, S as StorageService, d as AttributionConfig, e as AttributionIdentifiers, B as BrowserMetadataService, f as BrowserMetadata, g as CustomerData, C as CustomerIdentityService, P as PixelEvent, a as StorageAdapter } from '../index-CKZeennc.mjs';
4
4
  export { l as ATTRIBUTION_STORAGE_KEY, h as BasePixelEvent, D as DEFAULT_ATTRIBUTION_CONFIG, i as PageViewEvent, k as SessionExpiredEvent, j as SessionRenewedEvent, m as cloneCustomerData, n as hasCustomerData } from '../index-CKZeennc.mjs';
5
5
  import { P as PixelLogger } from '../PixelLogger-B21lEjep.mjs';
6
- import { P as PixelConfig } from '../pixel-_BSDpx4M.mjs';
7
- export { S as StoragePersistence, c as createStorageAdapter, r as resolveStorageAdapterName } from '../StorageFactory-qycJqKIl.mjs';
6
+ import { P as PixelConfig } from '../pixel-CCHv_ror.mjs';
7
+ export { S as StoragePersistence, c as createStorageAdapter, r as resolveStorageAdapterName } from '../StorageFactory-BRtmy983.mjs';
8
8
  import '../url-context-Ck2LK18V.mjs';
9
9
 
10
10
  declare class AttributionServiceImpl implements AttributionService {
@@ -1,10 +1,10 @@
1
- import { D as DispatcherService, F as FingerprintService, S as SessionService, a as SessionData, E as EnsureSessionResult, V as VisitorService } from '../types-Dpe5sArp.js';
2
- export { e as CommerceEnrichmentEvent, f as CommerceEventType, C as CommerceResolver, g as CommerceResolverInput, h as CommerceResolverOptions, i as CommerceResolverResult, b as CommerceService, c as CommerceState, j as CommerceStateOptions, k as CommerceStateSnapshot, l as ExtractedProductInput, m as OrderCalculationInput, n as OrderCalculationResult, O as OrderCalculator, o as PageViewCommercePayload, P as PixelRuntimeServices, d as ProductCatalog, p as ProductCatalogOptions, q as ProductCatalogSnapshot, R as ResolvedCommerceItem } from '../types-Dpe5sArp.js';
1
+ import { D as DispatcherService, F as FingerprintService, S as SessionService, a as SessionData, E as EnsureSessionResult, V as VisitorService } from '../types-DexAGG5B.js';
2
+ export { e as CommerceEnrichmentEvent, f as CommerceEventType, C as CommerceResolver, g as CommerceResolverInput, h as CommerceResolverOptions, i as CommerceResolverResult, b as CommerceService, c as CommerceState, j as CommerceStateOptions, k as CommerceStateSnapshot, l as ExtractedProductInput, m as OrderCalculationInput, n as OrderCalculationResult, O as OrderCalculator, o as PageViewCommercePayload, P as PixelRuntimeServices, d as ProductCatalog, p as ProductCatalogOptions, q as ProductCatalogSnapshot, R as ResolvedCommerceItem } from '../types-DexAGG5B.js';
3
3
  import { A as AttributionService, S as StorageService, d as AttributionConfig, e as AttributionIdentifiers, B as BrowserMetadataService, f as BrowserMetadata, g as CustomerData, C as CustomerIdentityService, P as PixelEvent, a as StorageAdapter } from '../index-YlvQBRzR.js';
4
4
  export { l as ATTRIBUTION_STORAGE_KEY, h as BasePixelEvent, D as DEFAULT_ATTRIBUTION_CONFIG, i as PageViewEvent, k as SessionExpiredEvent, j as SessionRenewedEvent, m as cloneCustomerData, n as hasCustomerData } from '../index-YlvQBRzR.js';
5
5
  import { P as PixelLogger } from '../PixelLogger-B21lEjep.js';
6
- import { P as PixelConfig } from '../pixel-DNGbAN5C.js';
7
- export { S as StoragePersistence, c as createStorageAdapter, r as resolveStorageAdapterName } from '../StorageFactory-BEZY4jKp.js';
6
+ import { P as PixelConfig } from '../pixel-CgKoaWS3.js';
7
+ export { S as StoragePersistence, c as createStorageAdapter, r as resolveStorageAdapterName } from '../StorageFactory-BcOX0fsg.js';
8
8
  import '../url-context-Ck2LK18V.js';
9
9
 
10
10
  declare class AttributionServiceImpl implements AttributionService {
@@ -1,3 +1,3 @@
1
1
  /* Pixel v2 — SDK de analytics e conversão */
2
- var $=class{constructor(e){this.listeners=new Set;this.lastEvent=null;this.logger=e}dispatch(e){this.lastEvent=e;let t=[...this.listeners];for(let r=0;r<t.length;r+=1){let n=t[r];if(n)try{n(e)}catch(i){this.logger?.warn(ue(i,e.type,r))}}}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}clear(){this.listeners.clear(),this.lastEvent=null}getListenerCount(){return this.listeners.size}getLastEvent(){return this.lastEvent}};function ue(o,e,t){let r=o instanceof Error?o.name:typeof o=="object"&&o!==null&&"name"in o?String(o.name):"Error",n=o instanceof Error?o.message:typeof o=="string"?o:"unknown";return n=n.replace(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,"[redacted]").replace(/\+?\d[\d\s().-]{7,}\d/g,"[redacted]"),n.length>200&&(n=`${n.slice(0,200)}\u2026`),{code:"DISPATCHER_LISTENER_FAILED",eventType:e,listenerIndex:t,errorName:r,message:n,timestamp:Date.now()}}var j=class{getMetadata(){if(typeof window>"u")return{};let e=(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return}})();return{url:location.href,path:location.pathname,hostname:location.hostname,origin:location.origin,title:typeof document<"u"?document.title:void 0,referrer:typeof document<"u"?document.referrer:void 0,language:navigator.language,timezone:e,userAgent:navigator.userAgent,platform:navigator.platform,screenWidth:screen.width,screenHeight:screen.height,colorDepth:screen.colorDepth}}};var de="fingerprint";function le(o){let e=0;for(let n=0;n<o.length;n++)e=(e<<5)-e+o.charCodeAt(n),e|=0;let t=Math.abs(e).toString(16).padStart(8,"0"),r=0;for(let n=o.length-1;n>=0;n--)r=(r<<5)-r+o.charCodeAt(n),r|=0;return`fp_${t}${Math.abs(r).toString(16).padStart(8,"0")}`}function me(o){let e=o.getMetadata(),t=[e.userAgent??"",e.language??"",e.platform??"",String(e.screenWidth??""),String(e.screenHeight??""),String(e.colorDepth??""),e.timezone??""];return le(t.join("|"))}var G=class{constructor(e,t,r){this.storage=e,this.storageKey=t.storage.keys?.fingerprint??de,this.metadataService=r}getFingerprint(){return this.storage.get(this.storageKey)}ensureFingerprint(){let e=this.getFingerprint();if(e)return e;let t=me(this.metadataService);return this.storage.set(this.storageKey,t),t}};function pe(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID().replace(/-/g,""):`${Date.now()}${Math.random().toString(36).slice(2)}`}function R(){return`ses_${pe()}`}var fe="session",Y=class{constructor(e,t){this.storage=e,this.storageKey=t.storage.keys?.session??fe}getSessionId(){return this.getSessionData()?.sessionId??null}getSessionData(){let e=this.storage.get(this.storageKey);if(!e)return null;if(typeof e=="string"){let t=Date.now();return{sessionId:e,lastActivityAt:t,createdAt:t}}return e}getLastActivityAt(){return this.getSessionData()?.lastActivityAt??null}isExpired(e){let t=this.getSessionData();return t?Date.now()-t.lastActivityAt>e:!0}ensureSession(e){let t=this.getSessionData(),r=Date.now();if(!t){let n=R();return this.writeSessionData({sessionId:n,lastActivityAt:r,createdAt:r}),{sessionId:n,expired:!1,created:!0}}if(r-t.lastActivityAt>e){let n=t.sessionId,i=R();return this.writeSessionData({sessionId:i,lastActivityAt:r,createdAt:r}),{sessionId:i,expired:!0,previousSessionId:n,created:!1}}return{sessionId:t.sessionId,expired:!1,created:!1}}ensureSessionId(){return this.ensureSession(Number.MAX_SAFE_INTEGER).sessionId}touchActivity(){let e=this.getSessionData();e&&this.writeSessionData({...e,lastActivityAt:Date.now()})}renew(){let e=Date.now(),t=R();return this.writeSessionData({sessionId:t,lastActivityAt:e,createdAt:e}),t}clear(){this.storage.remove(this.storageKey)}writeSessionData(e){this.storage.set(this.storageKey,e)}};var I=class{constructor(e){this.memoryFallback=new Map;this.storage=typeof window>"u"?null:e}get(e){return this.storage?this.storage.getItem(e):this.memoryFallback.get(e)??null}set(e,t){if(this.storage){this.storage.setItem(e,t);return}this.memoryFallback.set(e,t)}remove(e){if(this.storage){this.storage.removeItem(e);return}this.memoryFallback.delete(e)}clear(){this.storage||this.memoryFallback.clear()}removeKeysMatching(e){if(this.storage){let t=[];for(let r=0;r<this.storage.length;r++){let n=this.storage.key(r);n&&e(n)&&t.push(n)}for(let r of t)this.storage.removeItem(r);return}for(let t of this.memoryFallback.keys())e(t)&&this.memoryFallback.delete(t)}};var y=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()}removeKeysMatching(e){for(let t of this.store.keys())e(t)&&this.store.delete(t)}};function ge(o){return"removeKeysMatching"in o&&typeof o.removeKeysMatching=="function"}var Q=class{constructor(e,t,r){this.adapter=e,this.namespace=t,this.prefix=r}get(e){let t=this.adapter.get(this.createKey(e));if(t===null)return null;try{return JSON.parse(t)}catch{return null}}set(e,t){this.adapter.set(this.createKey(e),JSON.stringify(t))}remove(e){this.adapter.remove(this.createKey(e))}has(e){return this.adapter.get(this.createKey(e))!==null}clear(){let e=this.getNamespaceKeyPrefix();if(ge(this.adapter)){this.adapter.removeKeysMatching(t=>t.startsWith(e));return}this.adapter.clear()}createKey(e){return this.prefix?`${this.prefix}:${this.namespace}:${e}`:`${this.namespace}:${e}`}getNamespaceKeyPrefix(){return this.prefix?`${this.prefix}:${this.namespace}:`:`${this.namespace}:`}};function ye(o){let e=o??"memory";if(typeof window>"u")return new y;switch(e){case"memory":return new y;case"localStorage":return new I(window.localStorage);case"sessionStorage":return new I(window.sessionStorage);case"cookie_localStorage":return new I(window.localStorage);case"cookie":return new y;case"indexedDB":return new y;default:return new y}}function he(o){switch(o??"memory"){case"localStorage":case"sessionStorage":case"cookie_localStorage":return"BrowserStorageAdapter";default:return"MemoryStorageAdapter"}}function ve(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID().replace(/-/g,""):`${Date.now()}${Math.random().toString(36).slice(2)}`}function W(){return`vst_${ve()}`}var Ce="visitor",Z=class{constructor(e,t){this.storage=e,this.storageKey=t.storage.keys?.visitor??Ce}getVisitorId(){return this.storage.get(this.storageKey)}ensureVisitorId(){let e=this.getVisitorId();if(e)return e;let t=W();return this.storage.set(this.storageKey,t),t}clearVisitorId(){this.storage.remove(this.storageKey)}};var N={enabled:!0,ttlDays:90,persist:!0,captureUrlParams:!0,captureCookies:!0,customClickIdParams:[]},O="attribution";var Ie=["fbclid","gclid","gbraid","wbraid","ttclid","msclkid","epik","li_fat_id"],E=class{parse(e=[]){if(typeof window>"u"||!window.location?.search)return{};try{let t=new URLSearchParams(window.location.search),r={},n={};for(let i of Ie){let s=t.get(i);s&&(i==="li_fat_id"?r.liFatId=s:r[i]=s)}for(let i of e){let s=t.get(i);s&&(n[i]=s)}return Object.keys(n).length>0&&(r.customClickIds=n),r}catch{return{}}}synthesizeFbc(e,t){if(t)return t;if(e)return`fb.1.${Date.now()}.${e}`}};var b=class{collectKnown(){if(typeof document>"u")return{};let e=this.parseCookies(),t={},r={_fbp:"fbp",_fbc:"fbc",_ga:"ga",_gid:"gid",_gcl_au:"gclAu",_ttp:"ttp",li_fat_id:"liFatId",epik:"epik"};for(let[n,i]of Object.entries(r)){let s=e[n];s&&(t[i]=s)}return t}parseCookies(){if(typeof document>"u")return{};try{return document.cookie.split(";").reduce((e,t)=>{let[r,...n]=t.trim().split("=");return r&&(e[r]=decodeURIComponent(n.join("=")||"")),e},{})}catch{return{}}}};var A=class{constructor(e={}){this.clickIdParser=new E;this.cookieCollector=new b;this.customParams=e.customParams??[],this.captureUrlParams=e.captureUrlParams!==!1,this.captureCookies=e.captureCookies!==!1}collectFresh(){let e=this.captureUrlParams?this.clickIdParser.parse(this.customParams):{},t=this.captureCookies?this.cookieCollector.collectKnown():{},r={...t,...e},n={...t.customClickIds??{},...e.customClickIds??{}};if(Object.keys(n).length>0&&(r.customClickIds=n),typeof r.fbclid=="string"&&r.fbclid){let i=this.clickIdParser.synthesizeFbc(r.fbclid,typeof r.fbc=="string"?r.fbc:void 0);i&&(r.fbc=i)}if(typeof window<"u")try{r.landingUrl=window.location.href}catch{}if(typeof document<"u")try{document.referrer&&(r.referrer=document.referrer)}catch{}return r}merge(e,t){let r={...e};for(let[i,s]of Object.entries(t))if(!(s==null||s==="")){if(i==="customClickIds"&&typeof s=="object"){r.customClickIds={...e.customClickIds??{},...s};continue}r[i]=s}let n=Date.now();return e.firstCollectedAt||(r.firstCollectedAt=n),r.lastCollectedAt=n,r}};var x=class{constructor(e,t){this.storage=e,this.persist=t.persist,this.ttlMs=t.ttlDays*24*60*60*1e3,this.storageKey=t.storageKey??O}load(){if(!this.persist)return null;try{let e=this.storage.get(this.storageKey);return e?this.isExpired(e)?(this.clear(),null):e:null}catch{return null}}save(e){if(this.persist)try{this.storage.set(this.storageKey,e)}catch{}}clear(){try{this.storage.remove(this.storageKey)}catch{}}isExpired(e){let t=e.lastCollectedAt??e.firstCollectedAt;return t?Date.now()-t>this.ttlMs:!1}};var M=class{constructor(e,t=N){this.snapshot={};this.active=!1;this.enabled=t.enabled!==!1,this.store=new x(e,{persist:t.persist!==!1,ttlDays:t.ttlDays??90}),this.collector=new A({customParams:t.customClickIdParams??[],captureUrlParams:t.captureUrlParams!==!1,captureCookies:t.captureCookies!==!1})}init(){if(this.active||(this.active=!0,!this.enabled))return;let e=this.store.load();e&&(this.snapshot=e),this.collect()}destroy(){this.active&&(this.active=!1)}collect(){if(!this.enabled)return this.snapshot;let e=this.collector.collectFresh();return this.snapshot=this.collector.merge(this.snapshot,e),this.store.save(this.snapshot),this.snapshot}getSnapshot(){return{...this.snapshot}}update(e){return this.snapshot=this.collector.merge(this.snapshot,e),this.store.save(this.snapshot),this.getSnapshot()}clear(){this.snapshot={},this.store.clear()}};function L(o){return o?Object.values(o).some(e=>typeof e=="string"&&e.trim().length>0):!1}function B(o){return{...o}}var V=class{constructor(){this.snapshot={}}update(e){let t={...this.snapshot};for(let[r,n]of Object.entries(e)){if(typeof n!="string")continue;let i=n.trim();i&&(t[r]=i)}!t.name&&t.firstName&&(t.name=[t.firstName,t.lastName].filter(Boolean).join(" ")),this.snapshot=t}getSnapshot(){return L(this.snapshot)?B(this.snapshot):null}clear(){this.snapshot={}}};var Se=/\b(card|cardnumber|card_number|cc[-_]?number|credit[-_]?card|cvv|cvc|security(?:code)?|expir(?:y|ation)|exp(?:date|iry)?|password|senha|secret|token)\b/i;function X(o){return typeof Element<"u"&&o instanceof Element}function J(o){return typeof HTMLFormElement<"u"&&o instanceof HTMLFormElement}function ee(o){return typeof HTMLInputElement<"u"&&o instanceof HTMLInputElement}function w(o){if(o==null)return;let e=String(o).trim();return e.length>0?e:void 0}function ie(o){if(ee(o)&&o.type==="password")return!0;let e=[o.getAttribute("name"),o.getAttribute("id"),o.getAttribute("autocomplete"),o.getAttribute("placeholder"),o.getAttribute("aria-label")].filter(Boolean).join(" ");return Se.test(e)}function se(o,e){for(let t of e){if(!t)continue;let r=(t.startsWith("data-"),t),n=w(o.getAttribute(r));if(n)return n}}function D(o){if(!ie(o)&&(ee(o)||o instanceof HTMLTextAreaElement||o instanceof HTMLSelectElement))return w(o.value)}function ae(o,e){for(let r of e){if(!r)continue;let n=o.querySelector(`input[name="${K(r)}"], textarea[name="${K(r)}"], select[name="${K(r)}"], input[id="${K(r)}"]`);if(n){let i=D(n);if(i)return i}}let t=[];(ee(o)||o instanceof HTMLTextAreaElement||o instanceof HTMLSelectElement)&&t.push(o),t.push(...Array.from(o.querySelectorAll("input, textarea, select")));for(let r of e){let n=r.toLowerCase();for(let i of t){if(ie(i))continue;let s=(i.getAttribute("name")??"").toLowerCase(),c=(i.getAttribute("id")??"").toLowerCase();if(!Ee(s,c,n))continue;let d=D(i);if(d)return d}}}function Ee(o,e,t){return o===t||e===t?!0:t.length<4?!1:o.includes(t)||e.includes(t)}function K(o){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(o):o.replace(/["\\]/g,"\\$&")}function te(...o){let e={};for(let t of o)if(t)for(let[r,n]of Object.entries(t))n==null||n===""||e[r]===void 0&&(e[r]=n);return e}function ce(o,e){let t=new Set,r=[];for(let n of[...o??[],...e]){let i=n?.trim();!i||t.has(i)||(t.add(i),r.push(i))}return r}var be=["email","emailaddress","customerEmail","customer_email","e-mail"],Ae=["phone","telefone","tel","customerPhone","customer_phone","celular","mobile"],xe=["name","nome","fullName","full_name","fullname","billing_name"],ke=["firstName","first_name","firstname","first-name","fname","primeiro","primeiro_nome","given-name"],Te=["lastName","last_name","lastname","last-name","lname","sobrenome","family-name"],_e=["address","street","street_address","billing_address","shipping_address","endereco"],Pe=["address2","address_2","apt","apartment","suite","complement","complemento"],Re=["city","cidade","billing_city","shipping_city"],we=["state","estado","region","billing_state","shipping_state"],De=["postalCode","postal_code","postal","zip","zipcode","zip_code","cep","billing_zip"],Fe=["country","pais","billing_country","country_code"],Ne=["data-email"],Oe=["data-phone","data-telefone"],Me=["data-name","data-nome"],Le=["data-first-name","data-firstname"],Be=["data-last-name","data-lastname"],Ve=["data-address"],Ke=["data-address2","data-apt"],Ue=["data-city"],qe=["data-state"],He=["data-zip","data-postal"],ze=["data-country"],U=class{constructor(e={}){this.fieldMappings=e.fieldMappings??{}}extractFromElement(e){if(!X(e))return{};let t=this.extractFromScope(e),r=e.closest("form"),n=J(r)?this.extractFromScope(r):{},i=this.findCustomerContainer(e),s=i&&i!==e&&i!==r?this.extractFromScope(i):{};return te(t,n,s)}extractFromForm(e){return J(e)?this.extractFromScope(e):{}}extractFromContainer(e){return X(e)?this.extractFromScope(e):{}}extractFromScope(e){let t=this.pick(e,{mappingKey:"firstName",defaults:ke,autocomplete:"given-name",attrs:Le}),r=this.pick(e,{mappingKey:"lastName",defaults:Te,autocomplete:"family-name",attrs:Be}),n=this.pick(e,{mappingKey:"name",defaults:xe,autocomplete:"name",attrs:Me}),i=t&&r?`${t} ${r}`:t??r,s=t&&r?i:n??i;return te({email:this.pick(e,{mappingKey:"email",defaults:be,type:"email",autocomplete:"email",attrs:Ne}),phone:this.pick(e,{mappingKey:"phone",defaults:Ae,type:"tel",autocomplete:"tel",attrs:Oe}),name:w(s),firstName:t,lastName:r,address:this.pick(e,{mappingKey:"address",defaults:_e,autocomplete:["street-address","address-line1"],attrs:Ve}),address2:this.pick(e,{mappingKey:"address2",defaults:Pe,autocomplete:"address-line2",attrs:Ke}),city:this.pick(e,{mappingKey:"city",defaults:Re,autocomplete:"address-level2",attrs:Ue}),state:this.pick(e,{mappingKey:"state",defaults:we,autocomplete:"address-level1",attrs:qe}),postalCode:this.pick(e,{mappingKey:"postalCode",defaults:De,autocomplete:"postal-code",attrs:He}),country:this.pick(e,{mappingKey:"country",defaults:Fe,autocomplete:["country-name","country"],attrs:ze})})}pick(e,t){let r=t.type?this.readTypedInput(e,t.type):void 0,n=t.autocomplete?Array.isArray(t.autocomplete)?t.autocomplete:[t.autocomplete]:[],i;for(let s of n)if(i=this.readAutocomplete(e,s),i)break;return r??i??(t.attrs?se(e,t.attrs):void 0)??ae(e,this.fieldsFor(t.mappingKey,t.defaults))}fieldsFor(e,t){return ce(this.fieldMappings[e],t)}readTypedInput(e,t){let r=`input[type="${t}"]`,n=e.matches(r)?e:e.querySelector(r);return n?D(n):void 0}readAutocomplete(e,t){let r=`input[autocomplete="${t}"], select[autocomplete="${t}"]`,n=e.matches(r)?e:e.querySelector(r);return n?D(n):void 0}findCustomerContainer(e){return e.closest("[data-email], [data-phone], [data-name], [data-track], .lead-form, .checkout-form, #checkout-form, #checkout")}};var $e=200,q=class{constructor(e,t){this.debounceTimer=null;this.started=!1;this.onFormEvent=()=>{this.scheduleScan()};this.identity=e,this.extractor=t??new U}start(){this.started||typeof document>"u"||(this.started=!0,this.scan(),document.addEventListener("input",this.onFormEvent,!0),document.addEventListener("change",this.onFormEvent,!0))}destroy(){this.started&&(this.started=!1,typeof document<"u"&&(document.removeEventListener("input",this.onFormEvent,!0),document.removeEventListener("change",this.onFormEvent,!0)),this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null))}scan(){if(typeof document>"u")return;let e=document.forms;for(let t=0;t<e.length;t+=1)this.identity.update(this.extractor.extractFromForm(e[t]??null));document.body&&this.identity.update(this.extractor.extractFromContainer(document.body))}scheduleScan(){this.debounceTimer!==null&&clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.scan()},$e)}};var k=class{constructor(e=[],t={}){this.productsById=new Map;this.productsBySku=new Map;this.orderedIds=[];this.indexProducts(e??[],t.defaultCurrency)}list(){return this.orderedIds.map(e=>this.cloneProduct(this.productsById.get(e)))}getById(e){if(!e)return null;let t=this.productsById.get(e);return t?this.cloneProduct(t):null}getBySku(e){if(!e)return null;let t=this.productsBySku.get(e);return t?this.cloneProduct(t):null}hasProduct(e){return!!e&&this.productsById.has(e)}getSnapshot(){let e=this.list();return{products:e,count:e.length}}indexProducts(e,t){for(let r of e){if(!r||typeof r!="object")continue;let n=typeof r.id=="string"?r.id.trim():"";if(!n||this.productsById.has(n))continue;let i=this.normalizeProduct(r,n,t);this.productsById.set(n,i),this.orderedIds.push(n);let s=typeof i.sku=="string"?i.sku.trim():"";s&&!this.productsBySku.has(s)&&this.productsBySku.set(s,i)}}normalizeProduct(e,t,r){let n=typeof e.sku=="string"&&e.sku.trim()?e.sku.trim():void 0,i=typeof e.currency=="string"&&e.currency.trim()?e.currency.trim():r,s=typeof e.quantity=="number"&&Number.isFinite(e.quantity)?e.quantity:void 0;return{...e,id:t,...n!==void 0?{sku:n}:{},...i!==void 0?{currency:i}:{},...s!==void 0?{quantity:s}:{},...e.metadata?{metadata:{...e.metadata}}:{}}}cloneProduct(e){return{...e,...e.metadata?{metadata:{...e.metadata}}:{}}}};var T=class{constructor(e=[],t={}){this.itemsByProductId=new Map;this.allowDynamicItems=t.allowDynamicItems!==!1,this.seed(e??[])}getSelectedItems(){return Array.from(this.itemsByProductId.values()).map(e=>this.cloneItem(e))}hasItem(e){return!!e&&this.itemsByProductId.has(e)}getItem(e){if(!e)return null;let t=this.itemsByProductId.get(e);return t?this.cloneItem(t):null}upsertItem(e){if(!e||typeof e!="object")return;let t=typeof e.productId=="string"?e.productId.trim():"";if(!t)return;if(e.selected===!1){this.itemsByProductId.delete(t);return}let r=this.normalizeQuantity(e.quantity);if(r<=0){this.itemsByProductId.delete(t);return}if(!this.itemsByProductId.has(t)&&!this.allowDynamicItems)return;let i=this.itemsByProductId.get(t),s=e.metadata?{...e.metadata}:i?.metadata?{...i.metadata}:void 0,c={...i,...e,productId:t,quantity:r,selected:!0,...s?{metadata:s}:{}};this.itemsByProductId.set(t,c)}removeItem(e){e&&this.itemsByProductId.delete(e)}updateQuantity(e,t){if(!e||!this.itemsByProductId.has(e))return;let r=this.normalizeQuantity(t);if(r<=0){this.itemsByProductId.delete(e);return}let n=this.itemsByProductId.get(e);this.itemsByProductId.set(e,{...n,quantity:r})}clear(){this.itemsByProductId.clear()}getSnapshot(){let e=this.getSelectedItems();return{selectedItems:e,count:e.length}}seed(e){for(let t of e)this.seedItem(t)}seedItem(e){if(!e||typeof e!="object")return;let t=typeof e.productId=="string"?e.productId.trim():"";if(!t||e.selected===!1)return;let r=this.normalizeQuantity(e.quantity);r<=0||this.itemsByProductId.has(t)||this.itemsByProductId.set(t,{...e,productId:t,quantity:r,selected:!0,...e.metadata?{metadata:{...e.metadata}}:{}})}normalizeQuantity(e){return e==null||typeof e!="number"||!Number.isFinite(e)?1:e}cloneItem(e){return{...e,...e.metadata?{metadata:{...e.metadata}}:{}}}};var _=class{calculate(e){let r=(Array.isArray(e.items)?e.items:[]).map(s=>this.cloneItem(s));for(let s of r)(s.quantity==null||!Number.isFinite(s.quantity))&&(s.quantity=1);let n=typeof e.value=="number"&&Number.isFinite(e.value)?e.value:this.sumValue(r),i=this.resolveCurrency(e,r);return{items:r,...n!==void 0?{value:n}:{},...i!==void 0?{currency:i}:{}}}sumValue(e){let t=0,r=!1;for(let n of e){if(typeof n.price!="number"||!Number.isFinite(n.price))continue;let i=typeof n.quantity=="number"&&Number.isFinite(n.quantity)?n.quantity:1;t+=n.price*i,r=!0}return r?t:void 0}resolveCurrency(e,t){if(typeof e.currency=="string"&&e.currency.trim())return e.currency.trim();for(let r of t)if(typeof r.currency=="string"&&r.currency.trim())return r.currency.trim();if(typeof e.defaultCurrency=="string"&&e.defaultCurrency.trim())return e.defaultCurrency.trim()}cloneItem(e){return{...e,...e.metadata?{metadata:{...e.metadata}}:{}}}};var H={pageView:{enabled:!0,source:"cart"},viewContent:{enabled:!0,source:"event_or_cart"},lead:{enabled:!1,source:"event_or_cart"},addToCart:{enabled:!0,source:"event_or_cart"},removeFromCart:{enabled:!0,source:"event_or_cart"},initiateCheckout:{enabled:!0,source:"cart"},addPaymentInfo:{enabled:!0,source:"cart"},purchase:{enabled:!0,source:"cart"}},re={enabled:!0,currency:"BRL",catalog:{products:[]},cart:{mode:"custom",initialItems:[],allowDynamicItems:!0,calculateValueFrom:"cart"},mappings:{attributes:{},fields:{}},enrichment:{...H}};function F(o){switch(o){case"event":case"event_items":return"event";case"manual":return"manual";case"catalog":return"catalog";case"cart":case"selected_items":default:return"cart"}}var P=class{constructor(e){this.catalog=e.catalog,this.state=e.state,this.calculator=e.calculator,this.defaultCurrency=Ge(e.defaultCurrency),this.calculateValueFrom=F(e.calculateValueFrom)}resolve(e){if(e.enrichmentSource==="event")return{data:{...e.payload??{}}};switch(e.eventType){case"ADD_TO_CART":return this.resolveAddToCart(e);case"REMOVE_FROM_CART":return this.resolveRemoveFromCart(e);case"INITIATE_CHECKOUT":return this.resolveCheckoutLike(e,!1);case"PURCHASE":return this.resolveCheckoutLike(e,!0);case"VIEW_CONTENT":return this.resolveViewContent(e);case"ADD_PAYMENT_INFO":return this.resolveCheckoutLike(e,!1);default:return{data:{...e.payload??{}}}}}resolveAddToCart(e){let t=e.payload??{},r=e.extractedProduct??{},n=e.enrichmentSource??"event_or_cart",i=n==="cart"||n==="event_or_cart",s=n==="catalog"||n==="cart"||n==="event_or_cart",c=a(t.priceId)??a(t.productId)??a(r.productId)??(s?this.lookupIdBySku(a(t.sku)??a(r.sku)):void 0),d=!c&&i?this.resolvePrimaryCartItem():null;!c&&d&&(c=d.productId);let u=s&&c?this.catalog.getById(c):s?this.lookupProductBySku(a(t.sku)??a(r.sku)):null,p=c??u?.id,h=i&&p?this.state.getItem(p)??d:null;if(n==="catalog"&&!p&&!u)return{data:{...t}};let S=a(t.productName)??a(r.productName)??u?.name,v=l(t.price)??l(r.price)??(i?l(h?.price):void 0)??u?.price,C=l(t.quantity)??l(r.quantity)??(i?l(h?.quantity):void 0)??u?.quantity??1,g=a(t.currency)??a(r.currency)??(i?a(h?.currency):void 0)??u?.currency??this.defaultCurrency,f=je(u,{priceId:a(t.priceId),productId:p,offerId:a(t.offerId),id:a(t.id)}),m={};f.id&&(m.id=f.id),f.priceId&&(m.priceId=f.priceId),f.productId&&(m.productId=f.productId),f.offerId&&(m.offerId=f.offerId),S&&(m.productName=S),v!==void 0&&(m.price=v),g&&(m.currency=g),C!==void 0&&(m.quantity=C);for(let[ne,oe]of Object.entries(t))oe!==void 0&&(ne in m||(m[ne]=oe));return{data:m}}resolvePrimaryCartItem(){let e=this.state.getSelectedItems();return e.length===0?null:e.length===1?e[0]??null:e.find(r=>this.catalog.getById(r.productId)?.type==="main")??e[0]??null}resolveRemoveFromCart(e){let t=e.payload??{},r=e.extractedProduct??{},n=a(t.productId)??a(r.productId)??this.lookupIdBySku(a(t.sku)??a(r.sku)),i=n?this.catalog.getById(n):null,s=n??i?.id,c=s?this.state.getItem(s):null,d=l(t.quantity)??l(r.quantity)??l(c?.quantity)??1,u={};s&&(u.productId=s),d!==void 0&&(u.quantity=d);for(let[p,h]of Object.entries(t))h!==void 0&&(p in u||(u[p]=h));return{data:u}}resolveCheckoutLike(e,t){let r={...e.payload??{}},n=l(r.value),i=a(r.currency),s=this.readPayloadItems(e),c=e.enrichmentSource,d=this.resolveItemsSource(s,c),u=d.map(f=>this.toPixelItem(f)),p=c!=="catalog"&&this.calculateValueFrom!=="manual",h=n===void 0&&p,S=this.calculator.calculate({items:d,value:h?void 0:n,currency:i,defaultCurrency:this.defaultCurrency}),v=n!==void 0?n:p?S.value:void 0,C=i??S.currency??this.defaultCurrency,g={...r};return u.length>0?g.items=u:s===null&&delete g.items,v!==void 0?g.value=v:delete g.value,C&&(g.currency=C),{data:g,items:S.items,...v!==void 0?{value:v}:{},...C?{currency:C}:{}}}resolveViewContent(e){let t={...e.payload??{}},r=e.enrichmentSource??"event_or_cart";if(r==="cart"||r==="event_or_cart"){let n=this.resolveAddToCart({...e,eventType:"ADD_TO_CART",enrichmentSource:r}),i=this.resolveCheckoutLike({...e,eventType:"INITIATE_CHECKOUT",enrichmentSource:r},!1),s={...t},c=a(t.contentId)??a(n.data.productId)??(Array.isArray(i.data.items)&&i.data.items[0]&&typeof i.data.items[0].id=="string"?i.data.items[0].id:void 0),d=a(t.contentName)??a(n.data.productName)??(Array.isArray(i.data.items)&&i.data.items[0]&&typeof i.data.items[0].name=="string"?i.data.items[0].name:void 0);return c&&(s.contentId=c),d&&(s.contentName=d),l(t.value)===void 0&&i.value!==void 0&&(s.value=i.value),!a(t.currency)&&i.currency&&(s.currency=i.currency),t.items===void 0&&Array.isArray(i.data.items)&&(s.items=i.data.items),{data:s,...i.value!==void 0?{value:i.value}:{},...i.currency?{currency:i.currency}:{},items:i.items}}if(r==="catalog"){let n=this.resolveAddToCart({...e,eventType:"ADD_TO_CART",enrichmentSource:"catalog"}),i={...t};return n.data.productId&&!a(t.contentId)&&(i.contentId=n.data.productId),n.data.productName&&!a(t.contentName)&&(i.contentName=n.data.productName),n.data.price!==void 0&&l(t.value)===void 0&&(i.value=n.data.price),n.data.currency&&!a(t.currency)&&(i.currency=n.data.currency),{data:i}}return{data:t}}readPayloadItems(e){if(e.items)return e.items.map(r=>this.normalizeLooseItem(r));let t=e.payload?.items;return t===void 0||!Array.isArray(t)?null:t.map(r=>this.normalizeLooseItem(r&&typeof r=="object"?r:{}))}resolveItemsSource(e,t){if(e!==null)return e.map(r=>this.enrichItem(r));if(t==="catalog")return[];if(t==="cart"&&this.calculateValueFrom!=="manual"&&this.calculateValueFrom!=="event")return this.state.getSelectedItems().map(r=>this.enrichItem({productId:r.productId,price:r.price,quantity:r.quantity,currency:r.currency}));if(this.calculateValueFrom==="cart")return this.state.getSelectedItems().map(r=>this.enrichItem({productId:r.productId,price:r.price,quantity:r.quantity,currency:r.currency}));if(this.calculateValueFrom==="catalog"){let r=this.state.getSelectedItems();return r.length>0?r.map(n=>this.enrichItem({productId:n.productId,price:n.price,quantity:n.quantity,currency:n.currency})):this.catalog.list().map(n=>this.enrichItem({productId:n.id,price:n.price,quantity:n.quantity??1,currency:n.currency,productName:n.name,sku:n.sku,category:n.category}))}return[]}enrichItem(e){let t=e.productId??this.lookupIdBySku(e.sku)??void 0,r=t?this.catalog.getById(t):this.lookupProductBySku(e.sku),n=t??r?.id;return{...e,...n?{productId:n}:{},productName:e.productName??r?.name,sku:e.sku??r?.sku,price:e.price??r?.price,quantity:e.quantity??r?.quantity??1,currency:e.currency??r?.currency??this.defaultCurrency,category:e.category??r?.category,variant:e.variant??r?.variant,brand:e.brand??r?.brand,type:e.type??r?.type,metadata:e.metadata??r?.metadata}}toPixelItem(e){return{...e.productId?{id:e.productId}:{},...e.productName?{name:e.productName}:{},...e.category?{category:e.category}:{},...e.price!==void 0?{price:e.price}:{},...e.quantity!==void 0?{quantity:e.quantity}:{}}}normalizeLooseItem(e){return{productId:a(e.productId)??a(e.id),sku:a(e.sku),productName:a(e.productName)??a(e.name),price:l(e.price),quantity:l(e.quantity),currency:a(e.currency),category:a(e.category)}}lookupIdBySku(e){if(e)return this.catalog.getBySku(e)?.id}lookupProductBySku(e){return e?this.catalog.getBySku(e):null}};function je(o,e){let t=o?.metadata??{},r=a(t.priceId),n=a(t.productId),i=a(t.offerId),s=e.priceId??r;if(!s){let c=e.productId??o?.id;return{...e.id?{id:e.id}:{},...c?{productId:c}:{},...e.offerId?{offerId:e.offerId}:{}}}return{id:e.id??s,priceId:s,productId:n??e.productId??s,offerId:i??e.offerId??s}}function a(o){if(typeof o!="string")return;let e=o.trim();return e.length>0?e:void 0}function l(o){if(!(typeof o!="number"||!Number.isFinite(o)))return o}function Ge(o){if(typeof o!="string")return;let e=o.trim();return e.length>0?e:void 0}var z=class{constructor(e){this.config={...re,...e,catalog:{products:e?.catalog?.products??[]},cart:{...re.cart,...e?.cart,initialItems:e?.cart?.initialItems?e.cart.initialItems.map(t=>({...t})):[]},mappings:{attributes:{...e?.mappings?.attributes??{}},fields:{...e?.mappings?.fields??{}}},enrichment:{...H,...e?.enrichment}},this.enabled=this.config.enabled===!0,this.catalog=new k(this.config.catalog?.products,{defaultCurrency:this.config.currency}),this.state=new T(this.config.cart?.initialItems,{allowDynamicItems:this.config.cart?.allowDynamicItems!==!1}),this.resolver=new P({catalog:this.catalog,state:this.state,calculator:new _,defaultCurrency:this.config.currency,calculateValueFrom:F(this.config.cart?.calculateValueFrom)})}getEnrichment(e){let t=this.config.enrichment?.[e],r=H[e];return{enabled:t?.enabled??r.enabled,source:t?.source??r.source}}isEnabled(){return this.enabled}isEnrichmentEnabled(e){return this.enabled&&this.getEnrichment(e).enabled===!0}getEnrichmentSource(e){return this.getEnrichment(e).source??"event_or_cart"}resolveForEvent(e,t,r={}){return this.isEnrichmentEnabled(e)?this.resolver.resolve({eventType:t,payload:r,enrichmentSource:this.getEnrichmentSource(e)}).data:null}resolvePageViewEnrichment(){if(!this.isEnrichmentEnabled("pageView")||(this.getEnrichment("pageView").source??"cart")==="event")return null;let t=this.resolver.resolve({eventType:"INITIATE_CHECKOUT",payload:{}}),r=t.data.items??[],n=r[0],i=n&&typeof n.id=="string"?n.id:void 0,s=n&&typeof n.name=="string"?n.name:void 0;return t.value===void 0&&!t.currency&&r.length===0?null:{...t.value!==void 0?{value:t.value}:{},...t.currency?{currency:t.currency}:{},...r.length>0?{items:r}:{},...i?{contentId:i}:{},...s?{contentName:s}:{}}}getResolver(){return this.resolver}getCalculateValueFrom(){return F(this.config.cart?.calculateValueFrom)}getMappings(){return this.config.mappings}};export{O as ATTRIBUTION_STORAGE_KEY,A as AttributionCollector,M as AttributionServiceImpl,x as AttributionStore,j as BrowserMetadataServiceImpl,I as BrowserStorageAdapter,E as ClickIdParser,P as CommerceResolver,z as CommerceService,T as CommerceState,b as CookieCollector,q as CustomerIdentityObserver,V as CustomerIdentityService,N as DEFAULT_ATTRIBUTION_CONFIG,$ as DispatcherServiceImpl,G as FingerprintServiceImpl,y as MemoryStorageAdapter,_ as OrderCalculator,k as ProductCatalog,Y as SessionServiceImpl,Q as StorageServiceImpl,Z as VisitorServiceImpl,B as cloneCustomerData,ye as createStorageAdapter,R as generateSessionId,W as generateVisitorId,L as hasCustomerData,he as resolveStorageAdapterName};
2
+ var $=class{constructor(e){this.listeners=new Set;this.lastEvent=null;this.logger=e}dispatch(e){this.lastEvent=e;let t=[...this.listeners];for(let r=0;r<t.length;r+=1){let n=t[r];if(n)try{n(e)}catch(i){this.logger?.warn(de(i,e.type,r))}}}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}clear(){this.listeners.clear(),this.lastEvent=null}getListenerCount(){return this.listeners.size}getLastEvent(){return this.lastEvent}};function de(o,e,t){let r=o instanceof Error?o.name:typeof o=="object"&&o!==null&&"name"in o?String(o.name):"Error",n=o instanceof Error?o.message:typeof o=="string"?o:"unknown";return n=n.replace(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,"[redacted]").replace(/\+?\d[\d\s().-]{7,}\d/g,"[redacted]"),n.length>200&&(n=`${n.slice(0,200)}\u2026`),{code:"DISPATCHER_LISTENER_FAILED",eventType:e,listenerIndex:t,errorName:r,message:n,timestamp:Date.now()}}var j=class{getMetadata(){if(typeof window>"u")return{};let e=(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return}})();return{url:location.href,path:location.pathname,hostname:location.hostname,origin:location.origin,title:typeof document<"u"?document.title:void 0,referrer:typeof document<"u"?document.referrer:void 0,language:navigator.language,timezone:e,userAgent:navigator.userAgent,platform:navigator.platform,screenWidth:screen.width,screenHeight:screen.height,colorDepth:screen.colorDepth}}};var le="fingerprint";function me(o){let e=0;for(let n=0;n<o.length;n++)e=(e<<5)-e+o.charCodeAt(n),e|=0;let t=Math.abs(e).toString(16).padStart(8,"0"),r=0;for(let n=o.length-1;n>=0;n--)r=(r<<5)-r+o.charCodeAt(n),r|=0;return`fp_${t}${Math.abs(r).toString(16).padStart(8,"0")}`}function pe(o){let e=o.getMetadata(),t=[e.userAgent??"",e.language??"",e.platform??"",String(e.screenWidth??""),String(e.screenHeight??""),String(e.colorDepth??""),e.timezone??""];return me(t.join("|"))}var G=class{constructor(e,t,r){this.storage=e,this.storageKey=t.storage.keys?.fingerprint??le,this.metadataService=r}getFingerprint(){return this.storage.get(this.storageKey)}ensureFingerprint(){let e=this.getFingerprint();if(e)return e;let t=pe(this.metadataService);return this.storage.set(this.storageKey,t),t}};function fe(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID().replace(/-/g,""):`${Date.now()}${Math.random().toString(36).slice(2)}`}function w(){return`ses_${fe()}`}var ge="session",Y=class{constructor(e,t){this.storage=e,this.storageKey=t.storage.keys?.session??ge}getSessionId(){return this.getSessionData()?.sessionId??null}getSessionData(){let e=this.storage.get(this.storageKey);if(!e)return null;if(typeof e=="string"){let t=Date.now();return{sessionId:e,lastActivityAt:t,createdAt:t}}return e}getLastActivityAt(){return this.getSessionData()?.lastActivityAt??null}isExpired(e){let t=this.getSessionData();return t?Date.now()-t.lastActivityAt>e:!0}ensureSession(e){let t=this.getSessionData(),r=Date.now();if(!t){let n=w();return this.writeSessionData({sessionId:n,lastActivityAt:r,createdAt:r}),{sessionId:n,expired:!1,created:!0}}if(r-t.lastActivityAt>e){let n=t.sessionId,i=w();return this.writeSessionData({sessionId:i,lastActivityAt:r,createdAt:r}),{sessionId:i,expired:!0,previousSessionId:n,created:!1}}return{sessionId:t.sessionId,expired:!1,created:!1}}ensureSessionId(){return this.ensureSession(Number.MAX_SAFE_INTEGER).sessionId}touchActivity(){let e=this.getSessionData();e&&this.writeSessionData({...e,lastActivityAt:Date.now()})}renew(){let e=Date.now(),t=w();return this.writeSessionData({sessionId:t,lastActivityAt:e,createdAt:e}),t}clear(){this.storage.remove(this.storageKey)}writeSessionData(e){this.storage.set(this.storageKey,e)}};var I=class{constructor(e){this.memoryFallback=new Map;this.storage=typeof window>"u"?null:e}get(e){return this.storage?this.storage.getItem(e):this.memoryFallback.get(e)??null}set(e,t){if(this.storage){this.storage.setItem(e,t);return}this.memoryFallback.set(e,t)}remove(e){if(this.storage){this.storage.removeItem(e);return}this.memoryFallback.delete(e)}clear(){this.storage||this.memoryFallback.clear()}removeKeysMatching(e){if(this.storage){let t=[];for(let r=0;r<this.storage.length;r++){let n=this.storage.key(r);n&&e(n)&&t.push(n)}for(let r of t)this.storage.removeItem(r);return}for(let t of this.memoryFallback.keys())e(t)&&this.memoryFallback.delete(t)}};var y=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()}removeKeysMatching(e){for(let t of this.store.keys())e(t)&&this.store.delete(t)}};function ye(o){return"removeKeysMatching"in o&&typeof o.removeKeysMatching=="function"}var Q=class{constructor(e,t,r){this.adapter=e,this.namespace=t,this.prefix=r}get(e){let t=this.adapter.get(this.createKey(e));if(t===null)return null;try{return JSON.parse(t)}catch{return null}}set(e,t){this.adapter.set(this.createKey(e),JSON.stringify(t))}remove(e){this.adapter.remove(this.createKey(e))}has(e){return this.adapter.get(this.createKey(e))!==null}clear(){let e=this.getNamespaceKeyPrefix();if(ye(this.adapter)){this.adapter.removeKeysMatching(t=>t.startsWith(e));return}this.adapter.clear()}createKey(e){return this.prefix?`${this.prefix}:${this.namespace}:${e}`:`${this.namespace}:${e}`}getNamespaceKeyPrefix(){return this.prefix?`${this.prefix}:${this.namespace}:`:`${this.namespace}:`}};function he(o){let e=o??"memory";if(typeof window>"u")return new y;switch(e){case"memory":return new y;case"localStorage":return new I(window.localStorage);case"sessionStorage":return new I(window.sessionStorage);case"cookie_localStorage":return new I(window.localStorage);case"cookie":return new y;case"indexedDB":return new y;default:return new y}}function Ce(o){switch(o??"memory"){case"localStorage":case"sessionStorage":case"cookie_localStorage":return"BrowserStorageAdapter";default:return"MemoryStorageAdapter"}}function ve(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID().replace(/-/g,""):`${Date.now()}${Math.random().toString(36).slice(2)}`}function W(){return`vst_${ve()}`}var Ie="visitor",Z=class{constructor(e,t){this.storage=e,this.storageKey=t.storage.keys?.visitor??Ie}getVisitorId(){return this.storage.get(this.storageKey)}ensureVisitorId(){let e=this.getVisitorId();if(e)return e;let t=W();return this.storage.set(this.storageKey,t),t}clearVisitorId(){this.storage.remove(this.storageKey)}};var N={enabled:!0,ttlDays:90,persist:!0,captureUrlParams:!0,captureCookies:!0,customClickIdParams:[]},O="attribution";var Se=["fbclid","gclid","gbraid","wbraid","ttclid","msclkid","epik","li_fat_id"],E=class{parse(e=[]){if(typeof window>"u"||!window.location?.search)return{};try{let t=new URLSearchParams(window.location.search),r={},n={};for(let i of Se){let s=t.get(i);s&&(i==="li_fat_id"?r.liFatId=s:r[i]=s)}for(let i of e){let s=t.get(i);s&&(n[i]=s)}return Object.keys(n).length>0&&(r.customClickIds=n),r}catch{return{}}}synthesizeFbc(e,t){if(t)return t;if(e)return`fb.1.${Date.now()}.${e}`}};var b=class{collectKnown(){if(typeof document>"u")return{};let e=this.parseCookies(),t={},r={_fbp:"fbp",_fbc:"fbc",_ga:"ga",_gid:"gid",_gcl_au:"gclAu",_ttp:"ttp",li_fat_id:"liFatId",epik:"epik"};for(let[n,i]of Object.entries(r)){let s=e[n];s&&(t[i]=s)}return t}parseCookies(){if(typeof document>"u")return{};try{return document.cookie.split(";").reduce((e,t)=>{let[r,...n]=t.trim().split("=");return r&&(e[r]=decodeURIComponent(n.join("=")||"")),e},{})}catch{return{}}}};var A=class{constructor(e={}){this.clickIdParser=new E;this.cookieCollector=new b;this.customParams=e.customParams??[],this.captureUrlParams=e.captureUrlParams!==!1,this.captureCookies=e.captureCookies!==!1}collectFresh(){let e=this.captureUrlParams?this.clickIdParser.parse(this.customParams):{},t=this.captureCookies?this.cookieCollector.collectKnown():{},r={...t,...e},n={...t.customClickIds??{},...e.customClickIds??{}};if(Object.keys(n).length>0&&(r.customClickIds=n),typeof r.fbclid=="string"&&r.fbclid){let i=this.clickIdParser.synthesizeFbc(r.fbclid,typeof r.fbc=="string"?r.fbc:void 0);i&&(r.fbc=i)}if(typeof window<"u")try{r.landingUrl=window.location.href}catch{}if(typeof document<"u")try{document.referrer&&(r.referrer=document.referrer)}catch{}return r}merge(e,t){let r={...e};for(let[i,s]of Object.entries(t))if(!(s==null||s==="")){if(i==="customClickIds"&&typeof s=="object"){r.customClickIds={...e.customClickIds??{},...s};continue}r[i]=s}let n=Date.now();return e.firstCollectedAt||(r.firstCollectedAt=n),r.lastCollectedAt=n,r}};var x=class{constructor(e,t){this.storage=e,this.persist=t.persist,this.ttlMs=t.ttlDays*24*60*60*1e3,this.storageKey=t.storageKey??O}load(){if(!this.persist)return null;try{let e=this.storage.get(this.storageKey);return e?this.isExpired(e)?(this.clear(),null):e:null}catch{return null}}save(e){if(this.persist)try{this.storage.set(this.storageKey,e)}catch{}}clear(){try{this.storage.remove(this.storageKey)}catch{}}isExpired(e){let t=e.lastCollectedAt??e.firstCollectedAt;return t?Date.now()-t>this.ttlMs:!1}};var M=class{constructor(e,t=N){this.snapshot={};this.active=!1;this.enabled=t.enabled!==!1,this.store=new x(e,{persist:t.persist!==!1,ttlDays:t.ttlDays??90}),this.collector=new A({customParams:t.customClickIdParams??[],captureUrlParams:t.captureUrlParams!==!1,captureCookies:t.captureCookies!==!1})}init(){if(this.active||(this.active=!0,!this.enabled))return;let e=this.store.load();e&&(this.snapshot=e),this.collect()}destroy(){this.active&&(this.active=!1)}collect(){if(!this.enabled)return this.snapshot;let e=this.collector.collectFresh();return this.snapshot=this.collector.merge(this.snapshot,e),this.store.save(this.snapshot),this.snapshot}getSnapshot(){return{...this.snapshot}}update(e){return this.snapshot=this.collector.merge(this.snapshot,e),this.store.save(this.snapshot),this.getSnapshot()}clear(){this.snapshot={},this.store.clear()}};function L(o){return o?Object.values(o).some(e=>typeof e=="string"&&e.trim().length>0):!1}function B(o){return{...o}}var V=class{constructor(){this.snapshot={}}update(e){let t={...this.snapshot};for(let[r,n]of Object.entries(e)){if(typeof n!="string")continue;let i=n.trim();i&&(t[r]=i)}!t.name&&t.firstName&&(t.name=[t.firstName,t.lastName].filter(Boolean).join(" ")),this.snapshot=t}getSnapshot(){return L(this.snapshot)?B(this.snapshot):null}clear(){this.snapshot={}}};var Ee=/\b(card|cardnumber|card_number|cc[-_]?number|credit[-_]?card|cvv|cvc|security(?:code)?|expir(?:y|ation)|exp(?:date|iry)?|password|senha|secret|token)\b/i;function X(o){return typeof Element<"u"&&o instanceof Element}function J(o){return typeof HTMLFormElement<"u"&&o instanceof HTMLFormElement}function ee(o){return typeof HTMLInputElement<"u"&&o instanceof HTMLInputElement}function F(o){if(o==null)return;let e=String(o).trim();return e.length>0?e:void 0}function ie(o){if(ee(o)&&o.type==="password")return!0;let e=[o.getAttribute("name"),o.getAttribute("id"),o.getAttribute("autocomplete"),o.getAttribute("placeholder"),o.getAttribute("aria-label")].filter(Boolean).join(" ");return Ee.test(e)}function se(o,e){for(let t of e){if(!t)continue;let r=(t.startsWith("data-"),t),n=F(o.getAttribute(r));if(n)return n}}function k(o){if(!ie(o)&&(ee(o)||o instanceof HTMLTextAreaElement||o instanceof HTMLSelectElement))return F(o.value)}function be(o){return/^[#.\[:]/.test(o)||/[\s>+~]/.test(o)}function ae(o,e){for(let t of e)if(!(!t||!be(t)))try{let r=o.matches(t)?o:o.querySelector(t);if(!r)continue;let n=k(r);if(n)return n}catch{}}function ce(o,e){for(let r of e){if(!r)continue;let n=o.querySelector(`input[name="${K(r)}"], textarea[name="${K(r)}"], select[name="${K(r)}"], input[id="${K(r)}"]`);if(n){let i=k(n);if(i)return i}}let t=[];(ee(o)||o instanceof HTMLTextAreaElement||o instanceof HTMLSelectElement)&&t.push(o),t.push(...Array.from(o.querySelectorAll("input, textarea, select")));for(let r of e){let n=r.toLowerCase();for(let i of t){if(ie(i))continue;let s=(i.getAttribute("name")??"").toLowerCase(),c=(i.getAttribute("id")??"").toLowerCase();if(!Ae(s,c,n))continue;let d=k(i);if(d)return d}}}function Ae(o,e,t){return o===t||e===t?!0:t.length<4?!1:o.includes(t)||e.includes(t)}function K(o){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(o):o.replace(/["\\]/g,"\\$&")}function te(...o){let e={};for(let t of o)if(t)for(let[r,n]of Object.entries(t))n==null||n===""||e[r]===void 0&&(e[r]=n);return e}function ue(o,e){let t=new Set,r=[];for(let n of[...o??[],...e]){let i=n?.trim();!i||t.has(i)||(t.add(i),r.push(i))}return r}var xe=["email","emailaddress","customerEmail","customer_email","e-mail"],ke=["phone","telefone","tel","customerPhone","customer_phone","celular","mobile"],Te=["name","nome","fullName","full_name","fullname","billing_name"],_e=["firstName","first_name","firstname","first-name","fname","primeiro","primeiro_nome","given-name"],Pe=["lastName","last_name","lastname","last-name","lname","sobrenome","family-name"],Re=["address","street","street_address","billing_address","shipping_address","endereco"],we=["address2","address_2","apt","apartment","suite","complement","complemento"],Fe=["city","cidade","billing_city","shipping_city"],De=["state","estado","region","billing_state","shipping_state"],Ne=["postalCode","postal_code","postal","zip","zipcode","zip_code","cep","billing_zip"],Oe=["country","pais","billing_country","country_code"],Me=["data-email"],Le=["data-phone","data-telefone"],Be=["data-name","data-nome"],Ve=["data-first-name","data-firstname"],Ke=["data-last-name","data-lastname"],Ue=["data-address"],qe=["data-address2","data-apt"],He=["data-city"],ze=["data-state"],$e=["data-zip","data-postal"],je=["data-country"],U=class{constructor(e={}){this.fieldMappings=e.fieldMappings??{}}extractFromElement(e){if(!X(e))return{};let t=this.extractFromScope(e),r=e.closest("form"),n=J(r)?this.extractFromScope(r):{},i=this.findCustomerContainer(e),s=i&&i!==e&&i!==r?this.extractFromScope(i):{};return te(t,n,s)}extractFromForm(e){return J(e)?this.extractFromScope(e):{}}extractFromContainer(e){return X(e)?this.extractFromScope(e):{}}extractFromScope(e){let t=this.pick(e,{mappingKey:"firstName",defaults:_e,autocomplete:"given-name",attrs:Ve}),r=this.pick(e,{mappingKey:"lastName",defaults:Pe,autocomplete:"family-name",attrs:Ke}),n=this.pick(e,{mappingKey:"name",defaults:Te,autocomplete:"name",attrs:Be}),i=t&&r?`${t} ${r}`:t??r,s=t&&r?i:n??i;return te({email:this.pick(e,{mappingKey:"email",defaults:xe,type:"email",autocomplete:"email",attrs:Me}),phone:this.pick(e,{mappingKey:"phone",defaults:ke,type:"tel",autocomplete:"tel",attrs:Le}),name:F(s),firstName:t,lastName:r,address:this.pick(e,{mappingKey:"address",defaults:Re,autocomplete:["street-address","address-line1"],attrs:Ue}),address2:this.pick(e,{mappingKey:"address2",defaults:we,autocomplete:"address-line2",attrs:qe}),city:this.pick(e,{mappingKey:"city",defaults:Fe,autocomplete:"address-level2",attrs:He}),state:this.pick(e,{mappingKey:"state",defaults:De,autocomplete:"address-level1",attrs:ze}),postalCode:this.pick(e,{mappingKey:"postalCode",defaults:Ne,autocomplete:"postal-code",attrs:$e}),country:this.pick(e,{mappingKey:"country",defaults:Oe,autocomplete:["country-name","country"],attrs:je})})}pick(e,t){let r=t.type?this.readTypedInput(e,t.type):void 0,n=t.autocomplete?Array.isArray(t.autocomplete)?t.autocomplete:[t.autocomplete]:[],i;for(let c of n)if(i=this.readAutocomplete(e,c),i)break;let s=this.fieldsFor(t.mappingKey,t.defaults);return r??i??(t.attrs?se(e,t.attrs):void 0)??ae(e,s)??ce(e,s)}fieldsFor(e,t){return ue(this.fieldMappings[e],t)}readTypedInput(e,t){let r=`input[type="${t}"]`,n=e.matches(r)?e:e.querySelector(r);return n?k(n):void 0}readAutocomplete(e,t){let r=`input[autocomplete="${t}"], select[autocomplete="${t}"]`,n=e.matches(r)?e:e.querySelector(r);return n?k(n):void 0}findCustomerContainer(e){return e.closest("[data-email], [data-phone], [data-name], [data-track], .lead-form, .checkout-form, #checkout-form, #checkout")}};var Ge=200,q=class{constructor(e,t){this.debounceTimer=null;this.started=!1;this.onFormEvent=()=>{this.scheduleScan()};this.identity=e,this.extractor=t??new U}start(){this.started||typeof document>"u"||(this.started=!0,this.scan(),document.addEventListener("input",this.onFormEvent,!0),document.addEventListener("change",this.onFormEvent,!0))}destroy(){this.started&&(this.started=!1,typeof document<"u"&&(document.removeEventListener("input",this.onFormEvent,!0),document.removeEventListener("change",this.onFormEvent,!0)),this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null))}scan(){if(typeof document>"u")return;let e=document.forms;for(let t=0;t<e.length;t+=1)this.identity.update(this.extractor.extractFromForm(e[t]??null));document.body&&this.identity.update(this.extractor.extractFromContainer(document.body))}scheduleScan(){this.debounceTimer!==null&&clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.scan()},Ge)}};var T=class{constructor(e=[],t={}){this.productsById=new Map;this.productsBySku=new Map;this.orderedIds=[];this.indexProducts(e??[],t.defaultCurrency)}list(){return this.orderedIds.map(e=>this.cloneProduct(this.productsById.get(e)))}getById(e){if(!e)return null;let t=this.productsById.get(e);return t?this.cloneProduct(t):null}getBySku(e){if(!e)return null;let t=this.productsBySku.get(e);return t?this.cloneProduct(t):null}hasProduct(e){return!!e&&this.productsById.has(e)}getSnapshot(){let e=this.list();return{products:e,count:e.length}}indexProducts(e,t){for(let r of e){if(!r||typeof r!="object")continue;let n=typeof r.id=="string"?r.id.trim():"";if(!n||this.productsById.has(n))continue;let i=this.normalizeProduct(r,n,t);this.productsById.set(n,i),this.orderedIds.push(n);let s=typeof i.sku=="string"?i.sku.trim():"";s&&!this.productsBySku.has(s)&&this.productsBySku.set(s,i)}}normalizeProduct(e,t,r){let n=typeof e.sku=="string"&&e.sku.trim()?e.sku.trim():void 0,i=typeof e.currency=="string"&&e.currency.trim()?e.currency.trim():r,s=typeof e.quantity=="number"&&Number.isFinite(e.quantity)?e.quantity:void 0;return{...e,id:t,...n!==void 0?{sku:n}:{},...i!==void 0?{currency:i}:{},...s!==void 0?{quantity:s}:{},...e.metadata?{metadata:{...e.metadata}}:{}}}cloneProduct(e){return{...e,...e.metadata?{metadata:{...e.metadata}}:{}}}};var _=class{constructor(e=[],t={}){this.itemsByProductId=new Map;this.allowDynamicItems=t.allowDynamicItems!==!1,this.seed(e??[])}getSelectedItems(){return Array.from(this.itemsByProductId.values()).map(e=>this.cloneItem(e))}hasItem(e){return!!e&&this.itemsByProductId.has(e)}getItem(e){if(!e)return null;let t=this.itemsByProductId.get(e);return t?this.cloneItem(t):null}upsertItem(e){if(!e||typeof e!="object")return;let t=typeof e.productId=="string"?e.productId.trim():"";if(!t)return;if(e.selected===!1){this.itemsByProductId.delete(t);return}let r=this.normalizeQuantity(e.quantity);if(r<=0){this.itemsByProductId.delete(t);return}if(!this.itemsByProductId.has(t)&&!this.allowDynamicItems)return;let i=this.itemsByProductId.get(t),s=e.metadata?{...e.metadata}:i?.metadata?{...i.metadata}:void 0,c={...i,...e,productId:t,quantity:r,selected:!0,...s?{metadata:s}:{}};this.itemsByProductId.set(t,c)}removeItem(e){e&&this.itemsByProductId.delete(e)}updateQuantity(e,t){if(!e||!this.itemsByProductId.has(e))return;let r=this.normalizeQuantity(t);if(r<=0){this.itemsByProductId.delete(e);return}let n=this.itemsByProductId.get(e);this.itemsByProductId.set(e,{...n,quantity:r})}clear(){this.itemsByProductId.clear()}getSnapshot(){let e=this.getSelectedItems();return{selectedItems:e,count:e.length}}seed(e){for(let t of e)this.seedItem(t)}seedItem(e){if(!e||typeof e!="object")return;let t=typeof e.productId=="string"?e.productId.trim():"";if(!t||e.selected===!1)return;let r=this.normalizeQuantity(e.quantity);r<=0||this.itemsByProductId.has(t)||this.itemsByProductId.set(t,{...e,productId:t,quantity:r,selected:!0,...e.metadata?{metadata:{...e.metadata}}:{}})}normalizeQuantity(e){return e==null||typeof e!="number"||!Number.isFinite(e)?1:e}cloneItem(e){return{...e,...e.metadata?{metadata:{...e.metadata}}:{}}}};var P=class{calculate(e){let r=(Array.isArray(e.items)?e.items:[]).map(s=>this.cloneItem(s));for(let s of r)(s.quantity==null||!Number.isFinite(s.quantity))&&(s.quantity=1);let n=typeof e.value=="number"&&Number.isFinite(e.value)?e.value:this.sumValue(r),i=this.resolveCurrency(e,r);return{items:r,...n!==void 0?{value:n}:{},...i!==void 0?{currency:i}:{}}}sumValue(e){let t=0,r=!1;for(let n of e){if(typeof n.price!="number"||!Number.isFinite(n.price))continue;let i=typeof n.quantity=="number"&&Number.isFinite(n.quantity)?n.quantity:1;t+=n.price*i,r=!0}return r?t:void 0}resolveCurrency(e,t){if(typeof e.currency=="string"&&e.currency.trim())return e.currency.trim();for(let r of t)if(typeof r.currency=="string"&&r.currency.trim())return r.currency.trim();if(typeof e.defaultCurrency=="string"&&e.defaultCurrency.trim())return e.defaultCurrency.trim()}cloneItem(e){return{...e,...e.metadata?{metadata:{...e.metadata}}:{}}}};var H={pageView:{enabled:!0,source:"cart"},viewContent:{enabled:!0,source:"event_or_cart"},lead:{enabled:!1,source:"event_or_cart"},addToCart:{enabled:!0,source:"event_or_cart"},removeFromCart:{enabled:!0,source:"event_or_cart"},initiateCheckout:{enabled:!0,source:"cart"},addPaymentInfo:{enabled:!0,source:"cart"},purchase:{enabled:!0,source:"cart"}},re={enabled:!0,currency:"BRL",catalog:{products:[]},cart:{mode:"custom",initialItems:[],allowDynamicItems:!0,calculateValueFrom:"cart"},mappings:{attributes:{},fields:{}},customer:{fields:{}},enrichment:{...H}};function D(o){switch(o){case"event":case"event_items":return"event";case"manual":return"manual";case"catalog":return"catalog";case"cart":case"selected_items":default:return"cart"}}var R=class{constructor(e){this.catalog=e.catalog,this.state=e.state,this.calculator=e.calculator,this.defaultCurrency=Qe(e.defaultCurrency),this.calculateValueFrom=D(e.calculateValueFrom)}resolve(e){if(e.enrichmentSource==="event")return{data:{...e.payload??{}}};switch(e.eventType){case"ADD_TO_CART":return this.resolveAddToCart(e);case"REMOVE_FROM_CART":return this.resolveRemoveFromCart(e);case"INITIATE_CHECKOUT":return this.resolveCheckoutLike(e,!1);case"PURCHASE":return this.resolveCheckoutLike(e,!0);case"VIEW_CONTENT":return this.resolveViewContent(e);case"ADD_PAYMENT_INFO":return this.resolveCheckoutLike(e,!1);default:return{data:{...e.payload??{}}}}}resolveAddToCart(e){let t=e.payload??{},r=e.extractedProduct??{},n=e.enrichmentSource??"event_or_cart",i=n==="cart"||n==="event_or_cart",s=n==="catalog"||n==="cart"||n==="event_or_cart",c=a(t.priceId)??a(t.productId)??a(r.productId)??(s?this.lookupIdBySku(a(t.sku)??a(r.sku)):void 0),d=!c&&i?this.resolvePrimaryCartItem():null;!c&&d&&(c=d.productId);let u=s&&c?this.catalog.getById(c):s?this.lookupProductBySku(a(t.sku)??a(r.sku)):null,p=c??u?.id,h=i&&p?this.state.getItem(p)??d:null;if(n==="catalog"&&!p&&!u)return{data:{...t}};let S=a(t.productName)??a(r.productName)??u?.name,C=l(t.price)??l(r.price)??(i?l(h?.price):void 0)??u?.price,v=l(t.quantity)??l(r.quantity)??(i?l(h?.quantity):void 0)??u?.quantity??1,g=a(t.currency)??a(r.currency)??(i?a(h?.currency):void 0)??u?.currency??this.defaultCurrency,f=Ye(u,{priceId:a(t.priceId),productId:p,offerId:a(t.offerId),id:a(t.id)}),m={};f.id&&(m.id=f.id),f.priceId&&(m.priceId=f.priceId),f.productId&&(m.productId=f.productId),f.offerId&&(m.offerId=f.offerId),S&&(m.productName=S),C!==void 0&&(m.price=C),g&&(m.currency=g),v!==void 0&&(m.quantity=v);for(let[ne,oe]of Object.entries(t))oe!==void 0&&(ne in m||(m[ne]=oe));return{data:m}}resolvePrimaryCartItem(){let e=this.state.getSelectedItems();return e.length===0?null:e.length===1?e[0]??null:e.find(r=>this.catalog.getById(r.productId)?.type==="main")??e[0]??null}resolveRemoveFromCart(e){let t=e.payload??{},r=e.extractedProduct??{},n=a(t.productId)??a(r.productId)??this.lookupIdBySku(a(t.sku)??a(r.sku)),i=n?this.catalog.getById(n):null,s=n??i?.id,c=s?this.state.getItem(s):null,d=l(t.quantity)??l(r.quantity)??l(c?.quantity)??1,u={};s&&(u.productId=s),d!==void 0&&(u.quantity=d);for(let[p,h]of Object.entries(t))h!==void 0&&(p in u||(u[p]=h));return{data:u}}resolveCheckoutLike(e,t){let r={...e.payload??{}},n=l(r.value),i=a(r.currency),s=this.readPayloadItems(e),c=e.enrichmentSource,d=this.resolveItemsSource(s,c),u=d.map(f=>this.toPixelItem(f)),p=c!=="catalog"&&this.calculateValueFrom!=="manual",h=n===void 0&&p,S=this.calculator.calculate({items:d,value:h?void 0:n,currency:i,defaultCurrency:this.defaultCurrency}),C=n!==void 0?n:p?S.value:void 0,v=i??S.currency??this.defaultCurrency,g={...r};return u.length>0?g.items=u:s===null&&delete g.items,C!==void 0?g.value=C:delete g.value,v&&(g.currency=v),{data:g,items:S.items,...C!==void 0?{value:C}:{},...v?{currency:v}:{}}}resolveViewContent(e){let t={...e.payload??{}},r=e.enrichmentSource??"event_or_cart";if(r==="cart"||r==="event_or_cart"){let n=this.resolveAddToCart({...e,eventType:"ADD_TO_CART",enrichmentSource:r}),i=this.resolveCheckoutLike({...e,eventType:"INITIATE_CHECKOUT",enrichmentSource:r},!1),s={...t},c=a(t.contentId)??a(n.data.productId)??(Array.isArray(i.data.items)&&i.data.items[0]&&typeof i.data.items[0].id=="string"?i.data.items[0].id:void 0),d=a(t.contentName)??a(n.data.productName)??(Array.isArray(i.data.items)&&i.data.items[0]&&typeof i.data.items[0].name=="string"?i.data.items[0].name:void 0);return c&&(s.contentId=c),d&&(s.contentName=d),l(t.value)===void 0&&i.value!==void 0&&(s.value=i.value),!a(t.currency)&&i.currency&&(s.currency=i.currency),t.items===void 0&&Array.isArray(i.data.items)&&(s.items=i.data.items),{data:s,...i.value!==void 0?{value:i.value}:{},...i.currency?{currency:i.currency}:{},items:i.items}}if(r==="catalog"){let n=this.resolveAddToCart({...e,eventType:"ADD_TO_CART",enrichmentSource:"catalog"}),i={...t};return n.data.productId&&!a(t.contentId)&&(i.contentId=n.data.productId),n.data.productName&&!a(t.contentName)&&(i.contentName=n.data.productName),n.data.price!==void 0&&l(t.value)===void 0&&(i.value=n.data.price),n.data.currency&&!a(t.currency)&&(i.currency=n.data.currency),{data:i}}return{data:t}}readPayloadItems(e){if(e.items)return e.items.map(r=>this.normalizeLooseItem(r));let t=e.payload?.items;return t===void 0||!Array.isArray(t)?null:t.map(r=>this.normalizeLooseItem(r&&typeof r=="object"?r:{}))}resolveItemsSource(e,t){if(e!==null)return e.map(r=>this.enrichItem(r));if(t==="catalog")return[];if(t==="cart"&&this.calculateValueFrom!=="manual"&&this.calculateValueFrom!=="event")return this.state.getSelectedItems().map(r=>this.enrichItem({productId:r.productId,price:r.price,quantity:r.quantity,currency:r.currency}));if(this.calculateValueFrom==="cart")return this.state.getSelectedItems().map(r=>this.enrichItem({productId:r.productId,price:r.price,quantity:r.quantity,currency:r.currency}));if(this.calculateValueFrom==="catalog"){let r=this.state.getSelectedItems();return r.length>0?r.map(n=>this.enrichItem({productId:n.productId,price:n.price,quantity:n.quantity,currency:n.currency})):this.catalog.list().map(n=>this.enrichItem({productId:n.id,price:n.price,quantity:n.quantity??1,currency:n.currency,productName:n.name,sku:n.sku,category:n.category}))}return[]}enrichItem(e){let t=e.productId??this.lookupIdBySku(e.sku)??void 0,r=t?this.catalog.getById(t):this.lookupProductBySku(e.sku),n=t??r?.id;return{...e,...n?{productId:n}:{},productName:e.productName??r?.name,sku:e.sku??r?.sku,price:e.price??r?.price,quantity:e.quantity??r?.quantity??1,currency:e.currency??r?.currency??this.defaultCurrency,category:e.category??r?.category,variant:e.variant??r?.variant,brand:e.brand??r?.brand,type:e.type??r?.type,metadata:e.metadata??r?.metadata}}toPixelItem(e){return{...e.productId?{id:e.productId}:{},...e.productName?{name:e.productName}:{},...e.category?{category:e.category}:{},...e.price!==void 0?{price:e.price}:{},...e.quantity!==void 0?{quantity:e.quantity}:{}}}normalizeLooseItem(e){return{productId:a(e.productId)??a(e.id),sku:a(e.sku),productName:a(e.productName)??a(e.name),price:l(e.price),quantity:l(e.quantity),currency:a(e.currency),category:a(e.category)}}lookupIdBySku(e){if(e)return this.catalog.getBySku(e)?.id}lookupProductBySku(e){return e?this.catalog.getBySku(e):null}};function Ye(o,e){let t=o?.metadata??{},r=a(t.priceId),n=a(t.productId),i=a(t.offerId),s=e.priceId??r;if(!s){let c=e.productId??o?.id;return{...e.id?{id:e.id}:{},...c?{productId:c}:{},...e.offerId?{offerId:e.offerId}:{}}}return{id:e.id??s,priceId:s,productId:n??e.productId??s,offerId:i??e.offerId??s}}function a(o){if(typeof o!="string")return;let e=o.trim();return e.length>0?e:void 0}function l(o){if(!(typeof o!="number"||!Number.isFinite(o)))return o}function Qe(o){if(typeof o!="string")return;let e=o.trim();return e.length>0?e:void 0}var z=class{constructor(e){this.config={...re,...e,catalog:{products:e?.catalog?.products??[]},cart:{...re.cart,...e?.cart,initialItems:e?.cart?.initialItems?e.cart.initialItems.map(t=>({...t})):[]},mappings:{attributes:{...e?.mappings?.attributes??{}},fields:{...e?.mappings?.fields??{}}},enrichment:{...H,...e?.enrichment}},this.enabled=this.config.enabled===!0,this.catalog=new T(this.config.catalog?.products,{defaultCurrency:this.config.currency}),this.state=new _(this.config.cart?.initialItems,{allowDynamicItems:this.config.cart?.allowDynamicItems!==!1}),this.resolver=new R({catalog:this.catalog,state:this.state,calculator:new P,defaultCurrency:this.config.currency,calculateValueFrom:D(this.config.cart?.calculateValueFrom)})}getEnrichment(e){let t=this.config.enrichment?.[e],r=H[e];return{enabled:t?.enabled??r.enabled,source:t?.source??r.source}}isEnabled(){return this.enabled}isEnrichmentEnabled(e){return this.enabled&&this.getEnrichment(e).enabled===!0}getEnrichmentSource(e){return this.getEnrichment(e).source??"event_or_cart"}resolveForEvent(e,t,r={}){return this.isEnrichmentEnabled(e)?this.resolver.resolve({eventType:t,payload:r,enrichmentSource:this.getEnrichmentSource(e)}).data:null}resolvePageViewEnrichment(){if(!this.isEnrichmentEnabled("pageView")||(this.getEnrichment("pageView").source??"cart")==="event")return null;let t=this.resolver.resolve({eventType:"INITIATE_CHECKOUT",payload:{}}),r=t.data.items??[],n=r[0],i=n&&typeof n.id=="string"?n.id:void 0,s=n&&typeof n.name=="string"?n.name:void 0;return t.value===void 0&&!t.currency&&r.length===0?null:{...t.value!==void 0?{value:t.value}:{},...t.currency?{currency:t.currency}:{},...r.length>0?{items:r}:{},...i?{contentId:i}:{},...s?{contentName:s}:{}}}getResolver(){return this.resolver}getCalculateValueFrom(){return D(this.config.cart?.calculateValueFrom)}getMappings(){return this.config.mappings}};export{O as ATTRIBUTION_STORAGE_KEY,A as AttributionCollector,M as AttributionServiceImpl,x as AttributionStore,j as BrowserMetadataServiceImpl,I as BrowserStorageAdapter,E as ClickIdParser,R as CommerceResolver,z as CommerceService,_ as CommerceState,b as CookieCollector,q as CustomerIdentityObserver,V as CustomerIdentityService,N as DEFAULT_ATTRIBUTION_CONFIG,$ as DispatcherServiceImpl,G as FingerprintServiceImpl,y as MemoryStorageAdapter,P as OrderCalculator,T as ProductCatalog,Y as SessionServiceImpl,Q as StorageServiceImpl,Z as VisitorServiceImpl,B as cloneCustomerData,he as createStorageAdapter,w as generateSessionId,W as generateVisitorId,L as hasCustomerData,Ce as resolveStorageAdapterName};
3
3
  //# sourceMappingURL=index.esm.js.map