1import{ax as p,af as c}from"./B03cWTNm.js";import{T as o}from"./DEu-jRHo.js";import{installInsiderSdk as l}from"./CshYHFuG.js";function g(s,t,e){let i=t;for(const r of s){if(i===null)return null;i=r(i,e)}return i}class f{constructor(){this.items=[]}enqueue(t){this.items.push(t)}flush(){const t=this.items.filter(n=>n.kind==="user"),e=this.items.filter(n=>n.kind==="currency"),i=this.items.filter(n=>n.kind==="page"),r=this.items.filter(n=>n.kind==="event");this.items=[];const a=t[t.length-1];return{preInit:[...a?[a]:[],...e,...i],postInit:r}}get size(){return this.items.length}get isEmpty(){return this.items.length===0}clear(){this.items=[]}}const m=s=>{if(s.name!=="page_view")return s;const t=s.attributes??{};if(t.page_type!=="confirmation")return s;const e=t.order_id;return typeof e!="string"&&typeof e!="number"?s:p().isOrderConfirmed(String(e))?null:s},y=[m];function _(s,t,e){if(s!=="purchase")return;const i=t.order_id;typeof i!="string"&&typeof i!="number"||e.transition(String(i),"confirmed")}function d(s,t){if(s!=="add_to_cart"&&s!=="remove_from_cart")return;const e=window.Insider?.eventManager;e&&e.dispatch("cart:count:update",{product:{id:t.id,name:t.name,price:t.unit_sale_price??t.unit_price??0,url:t.url??"",img:t.product_image_url??"",quantity:t.quantity??1,taxonomy:t.taxonomy},isAddedToCart:s==="add_to_cart"})}const v=new Set(["home","product","category","search","cart","purchase","other"]),I=new Set(["add_to_cart","remove_from_cart","custom_event"]),T=["cart_item_added"],b=["cart_item_removed"],S=new Set(["v1"]);class q{constructor(t){this.name="insider",this.mappings=null,this.enrichers=[],this.buffer=new f,this.flushed=!1,this.hasInitializedOnce=!1,this.pendingPageFlush=!1,this.lastInsiderPageType="",this.config=t,this.sessionCartEnabled=t.sessionCart!==!1,this.clearCartOnNavigate=t.clearCartOnNavigate===!0,this.backendPurchase=t.backendPurchase===!0}get cart(){return p()}async init(t,e){const i=this.config.slug??"insider-default-v1",r=c.mappings?.get(i);if(!r){console.warn(`[montilla] Insider: no mappings for slug "${i}" â destination inert`);return}if(r.type!=="insider_web_sdk"||!S.has(r.version)){console.warn(`[montilla] Insider: unsupported destination "${i}" (type=${r.type}, version=${r.version}) â destination inert`);return}this.mappings=r;const a=r.config,n=this.config.partnerName??(typeof a.partnerName=="string"?a.partnerName:void 0),u=this.config.partnerId??(typeof a.partnerId=="string"?a.partnerId:void 0),h=this.config.scriptUrl??(typeof a.scriptUrl=="string"?a.scriptUrl:void 0);if(this.mappings.config.partner=n??"",this.enrichers=y,!n||!u){console.warn("[montilla] Insider: partnerName/partnerId missing â destination inert");return}await l({partnerName:n,partnerId:u,scriptUrl:h}),this.injectIdentity()}track(t){if(!this.mappings)return;this.sessionCartEnabled&&this.updateCartStateFromEvent(t);const e=g(this.enrichers,t,c.context);if(!e)return;const i=o(this.mappings,e,c.context);if(i.length!==0){this.sessionCartEnabled&&i.some(r=>r.config.targetType==="cart")&&this.snapshotCartFromEvent(t);for(const{config:r,payload:a}of i){const n=r.targetType;this.dispatchTargetType(n,a)}}}inspect(t){if(!this.mappings)return{fired:!1,reason:"destino inerte (sem mappings)"};try{const e=o(this.mappings,t,c.context);if(e.length===0)return{fired:!1,reason:"sem mapping para este evento"};const i=e[0]?.config?.targetType;return this.backendPurchase&&i==="purchase"?{fired:!0,targetType:"cart",reason:"purchase â cart (backendPurchase: backend já envia o purchase)"}:{fired:!0,targetType:i}}catch{return{fired:!1,reason:"falha ao avaliar o mapping"}}}destroy(){this.buffer.clear(),this.cart.clearCart(),this.flushed=!1,this.hasInitializedOnce=!1}getCartSnapshot(){return this.cart.getCartSnapshot()}dispatchTargetType(t,e){t==="user"?this.dispatchUserTarget(e):v.has(t)?this.dispatchPageTarget(t,e):I.has(t)&&this.dispatchTrackTarget(t,e)}dispatchUserTarget(t){this.flushed||this.buffer.enqueue({kind:"user",data:t})}dispatchPageTarget(t,e){let i=t,r=e;this.backendPurchase&&t==="purchase"&&(i="cart",r={...e,confirmation_view:!0});const a=i==="cart"||i==="purchase";this.clearCartOnNavigate&&!a&&!this.cart.isCartEmpty&&this.flushed&&this.clearCartViaRemovals(),this.buffer.clear(),this.flushed=!1,this.injectIdentity(),this.injectLocale(r),this.buffer.enqueue({kind:"page",data:{type:i,value:r}}),this.lastInsiderPageType=i,this.pendingPageFlush||(this.pendingPageFlush=!0,setTimeout(()=>{this.pendingPageFlush=!1,this.flush(),_(i,r,this.cart),this.lastInsiderPageType==="purchase"&&this.cart.clearCart()}))}dispatchTrackTarget(t,e){const i={type:t,value:e};this.flushed?(this.pushToInsider(i),d(t,e)):this.buffer.enqueue({kind:"event",data:i})}updateCartStateFromEvent(t){const e=t.attributes??{};T.includes(t.name)&&e.product_id&&this.cart.addItem({product_id:String(e.product_id),name:String(e.name??""),price:Number(e.price??0),quantity:Number(e.quantity??1),currency:e.currency?String(e.currency):void 0,category:e.category?String(e.category):void 0,variant:e.variant?String(e.variant):void 0,url:e.url?String(e.url):void 0,product_image_url:e.product_image_url??e.image_url?String(e.product_image_url??e.image_url):void 0}),b.includes(t.name)&&e.product_id&&this.cart.removeItem(String(e.product_id),e.quantity?Number(e.quantity):void 0)}
1snapshotCartFromEvent(t){const e=t.attributes??{};if(!Array.isArray(e.items))return;const i=e.items.map(r=>{const a=r.product_id??r.id;return a?{product_id:String(a),name:String(r.name??""),price:Number(r.price??r.unit_sale_price??r.unit_price??0),quantity:Number(r.quantity??1),currency:r.currency?String(r.currency):void 0,category:r.category?String(r.category):void 0,variant:r.variant?String(r.variant):void 0,url:r.url?String(r.url):void 0,product_image_url:r.product_image_url??r.image_url?String(r.product_image_url??r.image_url):void 0}:null}).filter(r=>r!==null);this.cart.setCart(i)}clearCartViaRemovals(){for(const t of this.cart.getCartItems()){const e={id:t.product_id,name:t.name,unit_price:t.price,unit_sale_price:t.price,quantity:t.quantity,currency:t.currency,taxonomy:t.category?[t.category]:["other"],url:t.url??(typeof window<"u"?window.location.href:""),product_image_url:t.product_image_url??t.url??""};this.pushToInsider({type:"remove_from_cart",value:e}),d("remove_from_cart",e)}this.cart.clearCart()}injectIdentity(){if(!this.mappings)return;const t=c.context;if(!t)return;const e={name:"identify",timestamp:new Date().toISOString(),attributes:{},domain:c.source},i=o(this.mappings,e,t);for(const{config:r,payload:a}of i)r.targetType==="user"&&this.dispatchUserTarget(a)}injectLocale(t){if(typeof t.currency=="string"&&t.currency.trim()!==""){this.buffer.enqueue({kind:"currency",data:t.currency.trim().toUpperCase()});return}this.config.currency&&this.buffer.enqueue({kind:"currency",data:this.config.currency.trim().toUpperCase()})}flush(){const{preInit:t,postInit:e}=this.buffer.flush();for(const i of t)switch(i.kind){case"user":this.pushToInsider({type:"user",value:i.data});break;case"currency":this.pushToInsider({type:"currency",value:i.data});break;case"page":this.pushToInsider(i.data);break}this.pushToInsider({type:"init"});for(const i of e)i.kind==="event"&&this.pushToInsider(i.data);this.flushed=!0,this.hasInitializedOnce=!0}pushToInsider(t){window.InsiderQueue&&window.InsiderQueue.push(t)}}export{q as InsiderDestination};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.