@topsort/toppie-sdk
Advanced tools
+11
-10
@@ -1,2 +0,2 @@ | ||
| (function(E,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(E=typeof globalThis<"u"?globalThis:E||self,p(E.ts={}))})(this,function(E){"use strict";const p={debug:window.TS_TOPPIE.debug||!1,baseURL:window.TS_TOPPIE.baseURL,appId:window.TS_TOPPIE.appId,getUserId:window.TS_TOPPIE.getUserId||void 0,cookieName:window.TS_TOPPIE.cookieName||"tsuid",deviceType:typeof window<"u"&&window.navigator.userAgent.includes("Mobile")?"mobile":"desktop",features:window.TS_TOPPIE.features||{}};function c(o,e){if(!p.debug)return;console.log(o,e);let t=document.getElementById("debug-container");if(!t){t=document.createElement("div"),t.id="debug-container",t.style.position="fixed",t.style.top="20px",t.style.right="20px",t.style.padding="10px",t.style.backgroundColor="rgba(0, 0, 0, 0.8)",t.style.color="white",t.style.borderRadius="5px",t.style.width="500px",t.style.maxWidth="500px",t.style.maxHeight="90vh",t.style.overflow="auto",t.style.zIndex="9999";const s=document.createElement("div");s.id="debug-header",s.style.display="flex",s.style.justifyContent="space-between";const u=document.createElement("div");u.innerHTML="Debug",s.appendChild(u);const h=document.createElement("div"),y=document.createElement("button");y.innerHTML="clear",y.onclick=()=>{const f=document.getElementById("debug-logs");f&&(f.innerHTML="")},h.appendChild(y);const w=document.createElement("button");w.innerHTML="hide",w.onclick=()=>{const f=document.getElementById("debug-logs");f&&(f.style.display==="none"?f.style.display="block":f.style.display="none")},h.appendChild(w),s.appendChild(h),t.appendChild(s);const g=document.createElement("div");g.id="debug-logs",t.appendChild(g),document.body.appendChild(t)}const n=document.getElementById("debug-logs");if(!n)return;const r=document.createElement("details");r.style.marginBottom="5px",r.setAttribute("open",""),r.style.borderBottom="1px solid rgba(255, 255, 255, 0.2)",r.style.paddingBottom="5px";const l=document.createElement("summary"),a=new Date().toLocaleTimeString();l.textContent=e?`(${e}) ${a}`:`(${a})`,l.style.cursor="pointer",r.appendChild(l);const i=document.createElement("div");i.style.marginTop="5px",i.style.paddingLeft="10px";const d=JSON.stringify(o,null,2);i.textContent=d,r.appendChild(i),n.appendChild(r)}function L(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function P(){var t;const o=p.cookieName;return(t=new RegExp(`(^|;)\\s*${o}\\s*=\\s*([^;]+)`).exec(document.cookie))==null?void 0:t.pop()}function N(o){const e=p.cookieName;document.cookie=`${e}=${o};max-age=31536000`}function I(){if(p.getUserId&&typeof p.getUserId=="function")return p.getUserId();const o=P();if(o)return o;const e=L();return N(e),e}const A=new Map;function O(o,e=void 0){A.set(o,e)}function q(o){return A.has(o)}function _(o,{method:e,body:t,params:n}){let r=`${p.baseURL}${o}`;const l={method:e,body:t,headers:{"Content-Type":"application/json","X-TS-ID":`${p.appId}`}};return n&&(r+=`?${new URLSearchParams(n).toString()}`),fetch(r,l)}class D{constructor(){this.service_url=p.baseURL,this.deviceType=p.deviceType,this.user_id=I()}setUserId(e){this.user_id=e}send(e){return _("v1/events",{method:"POST",body:JSON.stringify({...e})})}event(e,t,n=!1){if("resolvedBidId"in t&&!n){const r=t.resolvedBidId;if(q(`${r}-${e}`)){c({resolvedBidId:r},"resolvedBidId already exists");return}O(`${r}-${e}`,e)}return this.send({[e]:[{id:L(),opaqueUserId:this.user_id,occurredAt:new Date().toISOString(),deviceType:this.deviceType,placement:this.placement(),...t}]})}placement(){let e=window.location.pathname;const t=new URLSearchParams(window.location.search);return t.delete("address"),t.toString()&&(e+=`?${t.toString()}`),{path:e}}}const x=new D;async function T(o){try{const e=await _("v1/auctions",{method:"POST",body:JSON.stringify(o)});return e.ok?await e.json():void 0}catch{return}}function H({url:o}){return` | ||
| (function(I,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(I=typeof globalThis<"u"?globalThis:I||self,f(I.ts={}))})(this,function(I){"use strict";const f={debug:window.TS_TOPPIE.debug||!1,baseURL:window.TS_TOPPIE.baseURL,appId:window.TS_TOPPIE.appId,getUserId:window.TS_TOPPIE.getUserId||void 0,cookieName:window.TS_TOPPIE.cookieName||"tsuid",deviceType:typeof window<"u"&&window.navigator.userAgent.includes("Mobile")?"mobile":"desktop",features:window.TS_TOPPIE.features||{}};function i(r,e){if(!f.debug)return;console.log(r,e);let t=document.getElementById("debug-container");if(!t){t=document.createElement("div"),t.id="debug-container",t.style.position="fixed",t.style.top="20px",t.style.right="20px",t.style.padding="10px",t.style.backgroundColor="rgba(0, 0, 0, 0.8)",t.style.color="white",t.style.borderRadius="5px",t.style.width="500px",t.style.maxWidth="500px",t.style.maxHeight="90vh",t.style.overflow="auto",t.style.zIndex="9999";const c=document.createElement("div");c.id="debug-header",c.style.display="flex",c.style.justifyContent="space-between";const h=document.createElement("div");h.innerHTML="Debug",c.appendChild(h);const d=document.createElement("div"),p=document.createElement("button");p.innerHTML="clear",p.onclick=()=>{const g=document.getElementById("debug-logs");g&&(g.innerHTML="")},d.appendChild(p);const b=document.createElement("button");b.innerHTML="hide",b.onclick=()=>{const g=document.getElementById("debug-logs");g&&(g.style.display==="none"?g.style.display="block":g.style.display="none")},d.appendChild(b),c.appendChild(d),t.appendChild(c);const y=document.createElement("div");y.id="debug-logs",t.appendChild(y),document.body.appendChild(t)}const n=document.getElementById("debug-logs");if(!n)return;const o=document.createElement("details");o.style.marginBottom="5px",o.setAttribute("open",""),o.style.borderBottom="1px solid rgba(255, 255, 255, 0.2)",o.style.paddingBottom="5px";const l=document.createElement("summary"),a=new Date().toLocaleTimeString();l.textContent=e?`(${e}) ${a}`:`(${a})`,l.style.cursor="pointer",o.appendChild(l);const s=document.createElement("div");s.style.marginTop="5px",s.style.paddingLeft="10px";const u=JSON.stringify(r,null,2);s.textContent=u,o.appendChild(s),n.appendChild(o)}function L(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function q(){var t;const r=f.cookieName;return(t=new RegExp(`(^|;)\\s*${r}\\s*=\\s*([^;]+)`).exec(document.cookie))==null?void 0:t.pop()}function P(r){const e=f.cookieName;document.cookie=`${e}=${r};max-age=31536000`}function S(){if(f.getUserId&&typeof f.getUserId=="function")return f.getUserId();const r=q();if(r)return r;const e=L();return P(e),e}const A=new Map;function U(r,e=void 0){A.set(r,e)}function O(r){return A.has(r)}function _(r,{method:e,body:t,params:n}){let o=`${f.baseURL}${r}`;const l={method:e,body:t,headers:{"Content-Type":"application/json","X-TS-ID":`${f.appId}`}};return n&&(o+=`?${new URLSearchParams(n).toString()}`),fetch(o,l)}class D{constructor(){this.service_url=f.baseURL,this.deviceType=f.deviceType,this.user_id=S()}setUserId(e){this.user_id=e}send(e){return _("v1/events",{method:"POST",body:JSON.stringify({...e})})}event(e,t,n=!1){if("resolvedBidId"in t&&!n){const o=t.resolvedBidId;if(O(`${o}-${e}`)){i({resolvedBidId:o},"resolvedBidId already exists");return}U(`${o}-${e}`,e)}return this.send({[e]:[{id:L(),opaqueUserId:this.user_id,occurredAt:new Date().toISOString(),deviceType:this.deviceType,placement:this.placement(),...t}]})}placement(){let e=window.location.pathname;const t=new URLSearchParams(window.location.search);return t.delete("address"),t.toString()&&(e+=`?${t.toString()}`),{path:e}}}const x=new D;async function T(r){try{const e=await _("v1/auctions",{method:"POST",body:JSON.stringify(r)});return e.ok?await e.json():void 0}catch{return}}function H({url:r}){return` | ||
| .ts-banner-wrapper { | ||
@@ -8,3 +8,3 @@ display: block; | ||
| margin: 0 auto; | ||
| background-image: url(${o}); | ||
| background-image: url(${r}); | ||
| background-size: cover; | ||
@@ -44,4 +44,4 @@ background-position: center; | ||
| } | ||
| `}function j({width:o,height:e}){return c({width:o,height:e},"bannerStyleFixed"),` | ||
| .ts-banner-wrapper-${o}-${e} { | ||
| `}function j({width:r,height:e}){return i({width:r,height:e},"bannerStyleFixed"),` | ||
| .ts-banner-wrapper-${r}-${e} { | ||
| display: block; | ||
@@ -52,3 +52,3 @@ width: 100%; | ||
| } | ||
| .ts-banner-wrapper-${o}-${e} a { | ||
| .ts-banner-wrapper-${r}-${e} a { | ||
| display: flex; | ||
@@ -58,8 +58,8 @@ align-items: center; | ||
| } | ||
| .ts-banner-wrapper-${o}-${e} img { | ||
| .ts-banner-wrapper-${r}-${e} img { | ||
| width: 100%; | ||
| max-width: ${o}px; | ||
| max-width: ${r}px; | ||
| max-height: ${e}px; | ||
| } | ||
| `}function F(o,e,t,n,r){let l=320,a=520,i="responsive";r&&(i="fixed",l=r.width,a=r.height);const d=document.createElement("div");d.setAttribute("data-ts-banner",o),d.setAttribute("data-resolved-id",e),i==="responsive"?d.classList.add("ts-banner-wrapper"):d.classList.add(`ts-banner-wrapper-${l}-${a}`);const s=document.createElement("style");s.textContent=i==="responsive"?H({url:n}):j({width:l,height:a}),document.head.appendChild(s),c({sizeStyle:i,width:l,height:a},"bannerWrapper");const u=document.createElement("a");if(u.addEventListener("click",async h=>{h.preventDefault(),await x.event("clicks",{resolvedBidId:e}),window.location.href=t.replace("https://www.delivery.com","")}),u.href=t.replace("https://www.delivery.com",""),i==="fixed"){const h=document.createElement("img");h.src=n,h.alt="Banner",u.appendChild(h)}return d.appendChild(u),d}async function k({appendTo:o,slotId:e,position:t="top",slotSize:n}){var l,a;const r=await T({auctions:[{type:"banners",slots:1,slotId:e,deviceType:p.deviceType,opaqueUserId:I()}]});if(r){for(const i of r.results)if(i.resultType==="banners"){for(const d of i.winners)if(d.rank===1&&((l=d.asset[0])!=null&&l.url)){if(document.querySelector(`[data-ts-banner=${e}]`)){c({id:d.id},"banner already exists");continue}const u=F(e,d.resolvedBidId,d.id,d.asset[0].url,n);return t==="top"?o.insertBefore(u,o.firstChild):t==="bottom"?o.appendChild(u):t==="before"&&((a=o.parentNode)==null||a.insertBefore(u,o)),u}}return null}}const W=5;function X(o){var n,r;const e=document.querySelectorAll(".MenuCategoryCarousels__carousel");for(const l of Array.from(e)){const a=l.querySelector(".MenuCategoryCarousels__subtitle__main");if((n=a==null?void 0:a.textContent)!=null&&n.toLowerCase().includes(o.toLowerCase()))return l}const t=document.querySelectorAll(".MenuCatalog");for(const l of Array.from(t)){const a=l.querySelector(".MenuCatalog__title");if((r=a==null?void 0:a.textContent)!=null&&r.toLowerCase().includes(o.toLowerCase()))return l}return null}async function J(o){try{const e=I(),t=o.map(()=>({type:"banners",slots:1,slotId:"sponsored-listing-banner",opaqueUserId:e,deviceType:p.deviceType}));return await T({auctions:t})}catch{return}}function z(o,e){const t=[];for(const n of o)e[n]&&t.push(e[n].product_id);return t}function B(o,e){const t=e.find(n=>n.value.includes(o));if(t)return t;for(const n of e){const r=B(o,n.children);if(r)return r}return null}function V({resolvedBidId:o,imageUrl:e,productName:t}){const n=document.createElement("div");n.setAttribute("data-resolved-id",o),n.style.display="flex",n.style.justifyContent="center";const r=document.createElement("img");return r.src=e,r.alt=t,r.style.height="160px",r.style.width="fit-content",n.addEventListener("click",()=>{c("bannerElement clicked"),x.event("clicks",{resolvedBidId:o})}),n.appendChild(r),n}async function K(o,e){var t;try{const n=JSON.parse(o),r=window.location.pathname.split("/").pop();if(!r){c("No category found in pathname");return}c(r,"category to find");const l=B(r,n.data.categories);if(!l){c("Category not found in data");return}c(l.value,"category");let a=l.children.slice(0,W);a.length===0&&l.product_ids.length>0&&(c("No children, test with category"),a=[l]),c(a,"childrenCategoriesOnAuction");const i=a.map(s=>({products_ids:z(s.product_ids,n.data.products),slotsNumber:e,category:s})),d=await J(i);if(c(d,"auction"),!d){c("No auction results");return}for(const s of d.results){if(s.winners.length===0){c("No winners found");continue}const u=d.results.indexOf(s),h=i[u];if(!h){c("Auction not found");continue}const y=X(h.category.name);if(!y){c("Category element not found");continue}const w=y.querySelectorAll(".MenuItem");if(!w){c("Product elements not found");continue}for(const g of s.winners){const f=Object.values(n.data.products).find(b=>b.product_id===g.id);if(!f){c("product not found in data.data.products");continue}c(f,"product");const m=h.category.product_ids.findIndex(b=>b===f.id);if(m===-1){c("product not found in auction.category.product_ids");continue}const S=y.querySelector("[data-resolved-id]");let v;if(S?v=S.parentElement:v=w[m],!v){c("productElement not found");continue}if(S)c("sponsored banner already in productElement");else{const b=(t=g.asset)==null?void 0:t[0];if(!b){c("image not found");continue}const le=V({resolvedBidId:g.resolvedBidId,imageUrl:b.url,productName:f.name}),$=v.querySelector("img.MenuItem__image");if(!$){c("originalImage not found");continue}v.replaceChild(le,$);const R=v.querySelector(".MenuItem__sizes");R&&R.remove()}const C=w[g.rank-1];if(!C){c("targetElement not found");continue}try{const b=C.parentElement;b&&b.insertBefore(v,C)}catch(b){c({message:b.message,stack:b.stack},"Unable to insert product element")}}}return}catch(n){c(n,"Unable to handle category");return}}async function G(o){try{const e=I(),t=o.map(()=>({type:"banners",slots:1,slotId:"sponsored-listing-banner",opaqueUserId:e,deviceType:p.deviceType}));return await T({auctions:t})}catch{return}}function Y({resolvedBidId:o,imageUrl:e,productName:t}){const n=document.createElement("div");n.setAttribute("data-resolved-id",o),n.style.display="flex",n.style.justifyContent="center";const r=document.createElement("img");return r.src=e,r.alt=t,r.style.height="160px",r.style.width="fit-content",n.addEventListener("click",()=>{c("bannerElement clicked"),x.event("clicks",{resolvedBidId:o})}),n.appendChild(r),n}async function Q(o,e){var t;try{const n=JSON.parse(o);if(!n.data.search){c("data.data.search not found");return}const r=n.data.search.ids.filter(s=>s!==null),l=[];for(const s of r)n.data.products[s]&&l.push(n.data.products[s].product_id);const a=await G([{products_ids:l,slotsNumber:e}]);if(c(a,"auction"),!a||!a.results){c("No winners found");return}const i=document.querySelector(".MenuCatalog__container");if(!i){c("catalogElement not found");return}const d=i.querySelectorAll(".MenuItem");if(!d){c("productElements not found");return}for(const s of a.results){if(s.winners.length===0){c("No winners found");continue}for(const u of s.winners){const h=Object.values(n.data.products).find(m=>(m==null?void 0:m.product_id)===u.id);if(!h){c("product not found in data.data.products");continue}const y=r.findIndex(m=>m===h.id);if(c(y,"productIndex"),y===-1){c("product not found in data.data.search.ids");continue}const w=i.querySelector("[data-resolved-id]");let g;if(w?g=w.parentElement:g=d[y],!g){c("productElement not found");continue}if(w)c("sponsored banner already in productElement");else{const m=(t=u.asset)==null?void 0:t[0];if(!m){c("image not found");continue}const S=Y({resolvedBidId:u.resolvedBidId,imageUrl:m.url,productName:h.name}),v=g.querySelector("img.MenuItem__image");if(!v){c("originalImage not found");continue}g.replaceChild(S,v);const C=g.querySelector(".MenuItem__sizes");C&&C.remove()}const f=d[u.rank-1];if(!f){c("targetElement not found");continue}try{const m=f.parentElement;m&&m.insertBefore(g,f)}catch(m){c(m,"Unable to insert product element")}}}return}catch(n){c(n,"error");return}}function U({responseText:o}){try{const e=JSON.parse(o);if(Object.keys(e.data.products).length===0)return;_("v1/products",{method:"POST",body:JSON.stringify({data:{products:e.data.products}})})}catch{c("Unable to process catalog ingestion")}}function Z(){return[{type:"dom",target:".MenuCatalog,.MenuCategoryCarousels,.SearchPage__Content",onEvent:e=>{k({slotId:"search-slot",appendTo:e})},threshold:0},{type:"dom",target:".MenuFeaturedCategories",onEvent:e=>{k({slotId:"alcohol-landing",appendTo:e})},threshold:0},{type:"dom",target:".MerchantPageAside .CartSticky",onEvent:e=>{p.deviceType!=="mobile"&&k({slotId:"merchant-page-aside-slot",appendTo:e,slotSize:{width:320,height:520},position:"bottom"})},threshold:0},{type:"dom",target:"[data-resolved-id]",onEvent:e=>{const t=e.getAttribute("data-resolved-id");t&&x.event("impressions",{resolvedBidId:t})}},{type:"xhr",urlMatcher:e=>{const t=e.includes("/api/data/search"),n=e.includes("keyword=");return!!(t&&n)},methodMatcher:e=>e==="GET",onIntercept:async({response:e})=>{Q(e.responseText,1),p.features.catalogIngestion&&U({responseText:e.responseText})}},{type:"xhr",urlMatcher:e=>{const t=e.includes("/api/data/search"),n=e.includes("keyword=");return!!(t&&!n)},methodMatcher:e=>e==="GET",onIntercept:async({response:e})=>{K(e.responseText,1),p.features.catalogIngestion&&U({responseText:e.responseText})}}]}async function ee({appendTo:o,slotId:e,position:t="top"}){var r,l;console.log("running banner ad: ",e);const n=await T({auctions:[{type:"banners",slots:1,slotId:e,deviceType:p.deviceType,opaqueUserId:I()}]});if(n){for(const a of n.results)if(a.resultType==="banners"){for(const i of a.winners)if(i.rank===1&&((r=i.asset[0])!=null&&r.url)){if(document.querySelector(`[data-ts-banner=${e}]`))continue;const s=document.createElement("div");s.setAttribute("data-ts-banner",e),s.classList.add("ts-banner-wrapper"),s.setAttribute("data-ts-resolved-id",i.resolvedBidId);const u=document.createElement("style");u.textContent=` | ||
| `}function W(r,e,t,n,o){let l=320,a=520,s="responsive";o&&(s="fixed",l=o.width,a=o.height);const u=document.createElement("div");u.setAttribute("data-ts-banner",r),u.setAttribute("data-resolved-id",e),s==="responsive"?u.classList.add("ts-banner-wrapper"):u.classList.add(`ts-banner-wrapper-${l}-${a}`);const c=document.createElement("style");c.textContent=s==="responsive"?H({url:n}):j({width:l,height:a}),document.head.appendChild(c),i({sizeStyle:s,width:l,height:a},"bannerWrapper");const h=document.createElement("a");if(h.addEventListener("click",async d=>{d.preventDefault(),await x.event("clicks",{resolvedBidId:e}),window.location.href=t.replace("https://www.delivery.com","")}),h.href=t.replace("https://www.delivery.com",""),s==="fixed"){const d=document.createElement("img");d.src=n,d.alt="Banner",h.appendChild(d)}return u.appendChild(h),u}async function k({appendTo:r,slotId:e,position:t="top",slotSize:n}){var l,a;const o=await T({auctions:[{type:"banners",slots:1,slotId:e,deviceType:f.deviceType,opaqueUserId:S()}]});if(o){for(const s of o.results)if(s.resultType==="banners"){for(const u of s.winners)if(u.rank===1&&((l=u.asset[0])!=null&&l.url)){if(document.querySelector(`[data-ts-banner=${e}]`)){i({id:u.id},"banner already exists");continue}const h=W(e,u.resolvedBidId,u.id,u.asset[0].url,n);return t==="top"?r.insertBefore(h,r.firstChild):t==="bottom"?r.appendChild(h):t==="before"&&((a=r.parentNode)==null||a.insertBefore(h,r)),h}}return null}}const F=5;function z(r){var n,o;const e=document.querySelectorAll(".MenuCategoryCarousels__carousel");for(const l of Array.from(e)){const a=l.querySelector(".MenuCategoryCarousels__subtitle__main");if((n=a==null?void 0:a.textContent)!=null&&n.toLowerCase().includes(r.toLowerCase()))return l}const t=document.querySelectorAll(".MenuCatalog");for(const l of Array.from(t)){const a=l.querySelector(".MenuCatalog__title");if((o=a==null?void 0:a.textContent)!=null&&o.toLowerCase().includes(r.toLowerCase()))return l}return null}async function X(r){try{const e=S(),t=r.map(()=>({type:"banners",slots:1,slotId:"sponsored-listing-banner",opaqueUserId:e,deviceType:f.deviceType}));return await T({auctions:t})}catch{return}}function J(r,e){const t=[];for(const n of r)e[n]&&t.push(e[n].product_id);return t}function B(r,e){const t=e.find(n=>n.value.includes(r));if(t)return t;for(const n of e){const o=B(r,n.children);if(o)return o}return null}function V({resolvedBidId:r,imageUrl:e,productName:t}){const n=document.createElement("div");n.setAttribute("data-resolved-id",r),n.style.display="flex",n.style.justifyContent="center";const o=document.createElement("img");return o.src=e,o.alt=t,o.style.height="160px",o.style.width="fit-content",n.addEventListener("click",()=>{i("bannerElement clicked"),x.event("clicks",{resolvedBidId:r})}),n.appendChild(o),n}async function G(r,e){var t;try{const n=JSON.parse(r),o=window.location.pathname.split("/").pop();if(!o){i("No category found in pathname");return}i(o,"category to find");const l=B(o,n.data.categories);if(!l){i("Category not found in data");return}i(l.value,"category");let a=l.children.slice(0,F);a.length===0&&l.product_ids.length>0&&(i("No children, test with category"),a=[l]),i(a,"childrenCategoriesOnAuction");const s=a.map(c=>({products_ids:J(c.product_ids,n.data.products),slotsNumber:e,category:c})),u=await X(s);if(i(u,"auction"),!u){i("No auction results");return}for(const c of u.results){if(c.winners.length===0){i("No winners found");continue}const h=u.results.indexOf(c),d=s[h];if(!d){i("Auction not found");continue}const p=z(d.category.name);if(!p){i("Category element not found");continue}const b=p.querySelectorAll(".MenuItem");if(!b){i("Product elements not found");continue}for(const y of c.winners){const g=Object.values(n.data.products).find(w=>w.product_id===y.id);if(!g){i("product not found in data.data.products");continue}i(g,"product");const m=d.category.product_ids.findIndex(w=>w===g.id);if(m===-1){i("product not found in auction.category.product_ids");continue}const E=p.querySelector("[data-resolved-id]");let v;if(E?v=E.parentElement:v=b[m],!v){i("productElement not found");continue}if(E)i("sponsored banner already in productElement");else{const w=(t=y.asset)==null?void 0:t[0];if(!w){i("image not found");continue}const pe=V({resolvedBidId:y.resolvedBidId,imageUrl:w.url,productName:g.name}),N=v.querySelector("img.MenuItem__image");if(!N){i("originalImage not found");continue}v.replaceChild(pe,N);const $=v.querySelector(".MenuItem__sizes");$&&$.remove()}const C=b[y.rank-1];if(!C){i("targetElement not found");continue}try{const w=C.parentElement;w&&w.insertBefore(v,C)}catch(w){i({message:w.message,stack:w.stack},"Unable to insert product element")}}}return}catch(n){i(n,"Unable to handle category");return}}async function K(r){try{const e=S(),t=r.map(()=>({type:"banners",slots:1,slotId:"sponsored-listing-banner",opaqueUserId:e,deviceType:f.deviceType}));return await T({auctions:t})}catch{return}}function Y({resolvedBidId:r,imageUrl:e,productName:t}){const n=document.createElement("div");n.setAttribute("data-resolved-id",r),n.style.display="flex",n.style.justifyContent="center";const o=document.createElement("img");return o.src=e,o.alt=t,o.style.height="160px",o.style.width="fit-content",n.addEventListener("click",()=>{i("bannerElement clicked"),x.event("clicks",{resolvedBidId:r})}),n.appendChild(o),n}async function Q(r,e){var t;try{const n=JSON.parse(r);if(!n.data.search){i("data.data.search not found");return}const o=n.data.search.ids.filter(c=>c!==null),l=[];for(const c of o)n.data.products[c]&&l.push(n.data.products[c].product_id);const a=await K([{products_ids:l,slotsNumber:e}]);if(i(a,"auction"),!a||!a.results){i("No winners found");return}const s=document.querySelector(".MenuCatalog__container");if(!s){i("catalogElement not found");return}const u=s.querySelectorAll(".MenuItem");if(!u){i("productElements not found");return}for(const c of a.results){if(c.winners.length===0){i("No winners found");continue}for(const h of c.winners){const d=Object.values(n.data.products).find(m=>(m==null?void 0:m.product_id)===h.id);if(!d){i("product not found in data.data.products");continue}const p=o.findIndex(m=>m===d.id);if(i(p,"productIndex"),p===-1){i("product not found in data.data.search.ids");continue}const b=s.querySelector("[data-resolved-id]");let y;if(b?y=b.parentElement:y=u[p],!y){i("productElement not found");continue}if(b)i("sponsored banner already in productElement");else{const m=(t=h.asset)==null?void 0:t[0];if(!m){i("image not found");continue}const E=Y({resolvedBidId:h.resolvedBidId,imageUrl:m.url,productName:d.name}),v=y.querySelector("img.MenuItem__image");if(!v){i("originalImage not found");continue}y.replaceChild(E,v);const C=y.querySelector(".MenuItem__sizes");C&&C.remove()}const g=u[h.rank-1];if(!g){i("targetElement not found");continue}try{const m=g.parentElement;m&&m.insertBefore(y,g)}catch(m){i(m,"Unable to insert product element")}}}return}catch(n){i(n,"error");return}}function R({responseText:r}){try{const e=JSON.parse(r);if(Object.keys(e.data.products).length===0)return;_("v1/products",{method:"POST",body:JSON.stringify({data:{products:e.data.products}})})}catch{i("Unable to process catalog ingestion")}}async function Z({orderId:r,clientId:e,authorization:t}){try{return(await fetch(`/api/customer/orders/recent/${r}?include_merchant=true&client_id=${e}`,{headers:{Authorization:t}})).json()}catch{return null}}async function ee({responseText:r,requestHeaders:e,url:t}){var h;const n=Object.keys(e).find(d=>d.toLowerCase()==="authorization");if(!n){i("unable to make auth request: No authorization header found");return}const o=e[n];i(t,"url");const l=t.match(/[?&]client_id=([^&]+)/),a=l?l[1]:null;if(!a){i("unable to make auth request: No clientId found");return}const{orders:s}=JSON.parse(r);if(!s){i("unable to make auth request: No orders found");return}const u=await Promise.all(s.map(async d=>await Z({orderId:d.orderId.toString(),clientId:a,authorization:o}))),c=[];for(const d of u)if((h=d==null?void 0:d.order)!=null&&h.cart)for(const p of d.order.cart)c.push({productId:p.id,unitPrice:Number.parseFloat(p.unit_price),quantity:p.quantity});x.event("purchases",{items:c})}function te(){return[{type:"dom",target:".MenuCatalog,.MenuCategoryCarousels,.SearchPage__Content",onEvent:e=>{k({slotId:"search-slot",appendTo:e})},threshold:0},{type:"dom",target:".MenuFeaturedCategories",onEvent:e=>{k({slotId:"alcohol-landing",appendTo:e})},threshold:0},{type:"dom",target:".MerchantPageAside .StaticCartContainer,.MerchantPageAside .CartSticky",onEvent:e=>{f.deviceType!=="mobile"&&k({slotId:"merchant-page-aside-slot",appendTo:e,slotSize:{width:320,height:520},position:"bottom"})},threshold:0},{type:"dom",target:"[data-resolved-id]",onEvent:e=>{const t=e.getAttribute("data-resolved-id");t&&x.event("impressions",{resolvedBidId:t})}},{type:"xhr",urlMatcher:e=>{const t=e.includes("/api/data/search"),n=e.includes("keyword=");return!!(t&&n)},methodMatcher:e=>e==="GET",onIntercept:async({response:e})=>{Q(e.responseText,1),f.features.catalogIngestion&&R({responseText:e.responseText})}},{type:"xhr",urlMatcher:e=>{const t=e.includes("/api/data/search"),n=e.includes("keyword=");return!!(t&&!n)},methodMatcher:e=>e==="GET",onIntercept:async({response:e})=>{G(e.responseText,1),f.features.catalogIngestion&&R({responseText:e.responseText})}},{type:"xhr",urlMatcher:e=>e.includes("/api/customer/checkout"),methodMatcher:e=>e==="GET",onIntercept:async({response:e,requestHeaders:t,url:n})=>{ee({responseText:e.responseText,requestHeaders:t,url:n})}}]}async function ne({appendTo:r,slotId:e,position:t="top"}){var o,l;console.log("running banner ad: ",e);const n=await T({auctions:[{type:"banners",slots:1,slotId:e,deviceType:f.deviceType,opaqueUserId:S()}]});if(n){for(const a of n.results)if(a.resultType==="banners"){for(const s of a.winners)if(s.rank===1&&((o=s.asset[0])!=null&&o.url)){if(document.querySelector(`[data-ts-banner=${e}]`))continue;const c=document.createElement("div");c.setAttribute("data-ts-banner",e),c.classList.add("ts-banner-wrapper"),c.setAttribute("data-ts-resolved-id",s.resolvedBidId);const h=document.createElement("style");h.textContent=` | ||
| .ts-banner-wrapper { | ||
@@ -71,3 +71,3 @@ display: block; | ||
| margin: 0 auto; | ||
| background-image: url(${i.asset[0].url}); | ||
| background-image: url(${s.asset[0].url}); | ||
| background-size: cover; | ||
@@ -107,2 +107,3 @@ background-position: center; | ||
| } | ||
| `,document.head.appendChild(u);const h=document.createElement("a");return h.addEventListener("click",async y=>{y.preventDefault(),await x.event("clicks",{resolvedBidId:i.resolvedBidId}),window.location.href=h.href}),h.href=i.id.replace("https://www.delivery.com",""),s.appendChild(h),t==="top"?o.insertBefore(s,o.firstChild):t==="bottom"?o.appendChild(s):t==="before"&&((l=o.parentNode)==null||l.insertBefore(s,o)),s}}return null}}function te(){return[{type:"dom",target:"#store-wrapper",onEvent:e=>{ee({slotId:"search-slot",appendTo:e})},threshold:0},{type:"dom",target:"[data-ts-resolved-id]",onEvent:e=>{const t=e.getAttribute("data-ts-resolved-id");t&&x.event("impressions",{resolvedBidId:t})}}]}const ne=.5;function oe({target:o}){const e=new WeakSet,t=new IntersectionObserver(a=>{for(const i of a)i.isIntersecting&&(o.event(i.target),e.add(i.target),t.unobserve(i.target))},{threshold:o.threshold??ne}),n=a=>{for(const i of Array.from(a))e.has(i)||t.observe(i)},r=document.querySelectorAll(o.target);n(r);const l=new MutationObserver(a=>{for(const i of a)if(i.type==="childList"){const d=document.querySelectorAll(o.target);if(!d)return;n(d)}});return l.observe(document.body,{childList:!0,subtree:!0,attributeFilter:[o.target]}),()=>{t.disconnect(),l.disconnect()}}class re{constructor(e){this.targets=[],this.observer=null,this.pollInterval=null,this.lastData=new Map,this.interval=1e3,this.checkCache=()=>{var r;const n=(r=window.__APOLLO_CLIENT__)==null?void 0:r.cache.data;if(n)for(const[l,a]of Object.entries(n))for(const i of this.targets){const d=l.split(":")[0];if(d&&i.cacheKeyMatcher(d)){const s=this.lastData.get(d),u=Object.keys(a).length;u>(s??0)&&(this.lastData.set(d,u),i.onIntercept({data:a,key:d}))}}},e&&(this.interval=e),this.observeCache()}addTarget(e){this.targets.push(e)}clear(){this.targets=[],this.disconnect()}observeCache(){this.checkCache(),this.pollInterval=window.setInterval(this.checkCache,this.interval)}disconnect(){this.observer&&(this.observer.disconnect(),this.observer=null),this.pollInterval&&(window.clearInterval(this.pollInterval),this.pollInterval=null),this.lastData.clear()}}let se=class{constructor(){this.targets=[],this.originalFetch=window.fetch,this.intercept()}clear(){this.targets=[]}addTarget(e){this.targets.push(e)}intercept(){window.fetch=async(e,t)=>{var l;const n=typeof e=="string"?e:e instanceof URL?e.toString():e.url,r=(t==null?void 0:t.method)||"GET";try{let a;if(t!=null&&t.body)try{a=JSON.parse(t.body.toString())}catch{a=t.body}const i=await this.originalFetch(e,t),d=i.clone();for(const s of this.targets)s.urlMatcher(n)&&s.methodMatcher(r)&&await s.onIntercept({response:d,request:{url:n,method:r,headers:new Headers(t==null?void 0:t.headers),body:a}});return i}catch(a){for(const i of this.targets)i.urlMatcher(n)&&i.methodMatcher(r)&&((l=i.onError)==null||l.call(i,a instanceof Error?a:new Error(String(a))));throw a}}}};const ae=window.XMLHttpRequest;class ie{constructor(){this.targets=[],this.intercept()}clear(){this.targets=[]}addTarget(e){this.targets.push(e)}intercept(){const e=this;function t(){const n=new ae,r=n.open,l=n.send;let a="",i="";return n.open=(d,s,...u)=>(a=d,i=s,r.apply(n,[d,s,...u])),n.addEventListener("load",()=>{var d;for(const s of e.targets)s.urlMatcher(i)&&s.methodMatcher(a)&&((d=s.onIntercept)==null||d.call(s,{response:{status:n.status,statusText:n.statusText,responseText:n.responseText,responseURL:n.responseURL}}))}),n.addEventListener("error",()=>{var d;for(const s of e.targets)s.urlMatcher(i)&&s.methodMatcher(a)&&((d=s.onError)==null||d.call(s,new Error(`XHR Error: ${n.statusText}`)))}),n.send=d=>l.call(n,d),n}window.XMLHttpRequest=t}}class ce{constructor(){this.events=[],this.interceptorXHR=new ie,this.interceptorFetch=new se,this.interceptorApolloCache=new re}addEvent(e){e.type==="dom"?(oe({target:{target:e.target,event:e.onEvent,threshold:e.threshold}}),this.events.push({options:e})):e.type==="xhr"?(this.interceptorXHR.addTarget(e),this.events.push({options:e})):e.type==="fetch"?(this.interceptorFetch.addTarget(e),this.events.push({options:e})):e.type==="apollo-cache"&&(this.interceptorApolloCache.addTarget(e),this.events.push({options:e}))}clear(){this.events=[],this.interceptorXHR.clear(),this.interceptorFetch.clear()}}function de(o){switch(o){case"TS1003581":return Z();case"TS1004020":return te();default:return}}function M(){if(!p.appId||!p.baseURL)return;const o=de(p.appId);if(!o)return;const e=new ce;for(const t of o)e.addEvent(t)}/complete|interactive|loaded/.test(document.readyState)?(c(`document is ${document.readyState}`),M()):window.addEventListener("DOMContentLoaded",()=>{c("on DOMContentLoaded"),M()}),E.main=M,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}); | ||
| `,document.head.appendChild(h);const d=document.createElement("a");return d.addEventListener("click",async p=>{p.preventDefault(),await x.event("clicks",{resolvedBidId:s.resolvedBidId}),window.location.href=d.href}),d.href=s.id.replace("https://www.delivery.com",""),c.appendChild(d),t==="top"?r.insertBefore(c,r.firstChild):t==="bottom"?r.appendChild(c):t==="before"&&((l=r.parentNode)==null||l.insertBefore(c,r)),c}}return null}}function re(){return[{type:"dom",target:"#store-wrapper",onEvent:e=>{ne({slotId:"search-slot",appendTo:e})},threshold:0},{type:"dom",target:"[data-ts-resolved-id]",onEvent:e=>{const t=e.getAttribute("data-ts-resolved-id");t&&x.event("impressions",{resolvedBidId:t})}}]}const oe=.5;function se({target:r}){const e=new WeakSet,t=new IntersectionObserver(a=>{for(const s of a)s.isIntersecting&&(r.event(s.target),e.add(s.target),t.unobserve(s.target))},{threshold:r.threshold??oe}),n=a=>{for(const s of Array.from(a))e.has(s)||t.observe(s)},o=document.querySelectorAll(r.target);n(o);const l=new MutationObserver(a=>{for(const s of a)if(s.type==="childList"){const u=document.querySelectorAll(r.target);if(!u)return;n(u)}});return l.observe(document.body,{childList:!0,subtree:!0,attributeFilter:[r.target]}),()=>{t.disconnect(),l.disconnect()}}class ae{constructor(e){this.targets=[],this.observer=null,this.pollInterval=null,this.lastData=new Map,this.interval=1e3,this.checkCache=()=>{var o;const n=(o=window.__APOLLO_CLIENT__)==null?void 0:o.cache.data;if(n)for(const[l,a]of Object.entries(n))for(const s of this.targets){const u=l.split(":")[0];if(u&&s.cacheKeyMatcher(u)){const c=this.lastData.get(u),h=Object.keys(a).length;h>(c??0)&&(this.lastData.set(u,h),s.onIntercept({data:a,key:u}))}}},e&&(this.interval=e),this.observeCache()}addTarget(e){this.targets.push(e)}clear(){this.targets=[],this.disconnect()}observeCache(){this.checkCache(),this.pollInterval=window.setInterval(this.checkCache,this.interval)}disconnect(){this.observer&&(this.observer.disconnect(),this.observer=null),this.pollInterval&&(window.clearInterval(this.pollInterval),this.pollInterval=null),this.lastData.clear()}}let ie=class{constructor(){this.targets=[],this.originalFetch=window.fetch,this.intercept()}clear(){this.targets=[]}addTarget(e){this.targets.push(e)}intercept(){window.fetch=async(e,t)=>{var l;const n=typeof e=="string"?e:e instanceof URL?e.toString():e.url,o=(t==null?void 0:t.method)||"GET";try{let a;if(t!=null&&t.body)try{a=JSON.parse(t.body.toString())}catch{a=t.body}const s=await this.originalFetch(e,t),u=s.clone();for(const c of this.targets)c.urlMatcher(n)&&c.methodMatcher(o)&&await c.onIntercept({response:u,request:{url:n,method:o,headers:new Headers(t==null?void 0:t.headers),body:a}});return s}catch(a){for(const s of this.targets)s.urlMatcher(n)&&s.methodMatcher(o)&&((l=s.onError)==null||l.call(s,a instanceof Error?a:new Error(String(a))));throw a}}}};const ce=window.XMLHttpRequest;class de{constructor(){this.targets=[],this.intercept()}clear(){this.targets=[]}addTarget(e){this.targets.push(e)}intercept(){const e=this;function t(){const n=new ce,o=n.open,l=n.send,a=n.setRequestHeader;let s="",u="",c;const h={};return n.setRequestHeader=(d,p)=>(h[d.toLowerCase()]=p,a.call(n,d,p)),n.open=(d,p,...b)=>(s=d,u=p,o.apply(n,[d,p,...b])),n.addEventListener("load",()=>{var d;for(const p of e.targets)if(p.urlMatcher(u)&&p.methodMatcher(s)){const b={},y=n.getAllResponseHeaders().split(`\r | ||
| `);for(const g of y){const[m,E]=g.split(": ");m&&E&&(b[m.toLowerCase()]=E)}(d=p.onIntercept)==null||d.call(p,{response:{status:n.status,statusText:n.statusText,responseText:n.responseText,responseURL:n.responseURL,headers:b},payload:c,requestHeaders:h,url:u})}}),n.addEventListener("error",()=>{var d;for(const p of e.targets)p.urlMatcher(u)&&p.methodMatcher(s)&&((d=p.onError)==null||d.call(p,new Error(`XHR Error: ${n.statusText}`)))}),n.send=d=>(c=d,l.call(n,d)),n}window.XMLHttpRequest=t}}class le{constructor(){this.events=[],this.interceptorXHR=new de,this.interceptorFetch=new ie,this.interceptorApolloCache=new ae}addEvent(e){e.type==="dom"?(se({target:{target:e.target,event:e.onEvent,threshold:e.threshold}}),this.events.push({options:e})):e.type==="xhr"?(this.interceptorXHR.addTarget(e),this.events.push({options:e})):e.type==="fetch"?(this.interceptorFetch.addTarget(e),this.events.push({options:e})):e.type==="apollo-cache"&&(this.interceptorApolloCache.addTarget(e),this.events.push({options:e}))}clear(){this.events=[],this.interceptorXHR.clear(),this.interceptorFetch.clear()}}function ue(r){switch(r){case"TS1003581":return te();case"TS1004020":return re();default:return}}function M(){if(!f.appId||!f.baseURL)return;const r=ue(f.appId);if(!r)return;const e=new le;for(const t of r)e.addEvent(t)}/complete|interactive|loaded/.test(document.readyState)?(i(`document is ${document.readyState}`),M()):window.addEventListener("DOMContentLoaded",()=>{i("on DOMContentLoaded"),M()}),I.main=M,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})}); |
+352
-267
@@ -1,2 +0,2 @@ | ||
| const h = { | ||
| const f = { | ||
| debug: window.TS_TOPPIE.debug || !1, | ||
@@ -10,4 +10,4 @@ baseURL: window.TS_TOPPIE.baseURL, | ||
| }; | ||
| function d(r, e) { | ||
| if (!h.debug) | ||
| function i(r, e) { | ||
| if (!f.debug) | ||
| return; | ||
@@ -18,18 +18,18 @@ console.log(r, e); | ||
| t = document.createElement("div"), t.id = "debug-container", t.style.position = "fixed", t.style.top = "20px", t.style.right = "20px", t.style.padding = "10px", t.style.backgroundColor = "rgba(0, 0, 0, 0.8)", t.style.color = "white", t.style.borderRadius = "5px", t.style.width = "500px", t.style.maxWidth = "500px", t.style.maxHeight = "90vh", t.style.overflow = "auto", t.style.zIndex = "9999"; | ||
| const s = document.createElement("div"); | ||
| s.id = "debug-header", s.style.display = "flex", s.style.justifyContent = "space-between"; | ||
| const u = document.createElement("div"); | ||
| u.innerHTML = "Debug", s.appendChild(u); | ||
| const p = document.createElement("div"), y = document.createElement("button"); | ||
| y.innerHTML = "clear", y.onclick = () => { | ||
| const f = document.getElementById("debug-logs"); | ||
| f && (f.innerHTML = ""); | ||
| }, p.appendChild(y); | ||
| const w = document.createElement("button"); | ||
| w.innerHTML = "hide", w.onclick = () => { | ||
| const f = document.getElementById("debug-logs"); | ||
| f && (f.style.display === "none" ? f.style.display = "block" : f.style.display = "none"); | ||
| }, p.appendChild(w), s.appendChild(p), t.appendChild(s); | ||
| const g = document.createElement("div"); | ||
| g.id = "debug-logs", t.appendChild(g), document.body.appendChild(t); | ||
| const c = document.createElement("div"); | ||
| c.id = "debug-header", c.style.display = "flex", c.style.justifyContent = "space-between"; | ||
| const h = document.createElement("div"); | ||
| h.innerHTML = "Debug", c.appendChild(h); | ||
| const d = document.createElement("div"), p = document.createElement("button"); | ||
| p.innerHTML = "clear", p.onclick = () => { | ||
| const g = document.getElementById("debug-logs"); | ||
| g && (g.innerHTML = ""); | ||
| }, d.appendChild(p); | ||
| const b = document.createElement("button"); | ||
| b.innerHTML = "hide", b.onclick = () => { | ||
| const g = document.getElementById("debug-logs"); | ||
| g && (g.style.display === "none" ? g.style.display = "block" : g.style.display = "none"); | ||
| }, d.appendChild(b), c.appendChild(d), t.appendChild(c); | ||
| const y = document.createElement("div"); | ||
| y.id = "debug-logs", t.appendChild(y), document.body.appendChild(t); | ||
| } | ||
@@ -43,6 +43,6 @@ const n = document.getElementById("debug-logs"); | ||
| l.textContent = e ? `(${e}) ${a}` : `(${a})`, l.style.cursor = "pointer", o.appendChild(l); | ||
| const i = document.createElement("div"); | ||
| i.style.marginTop = "5px", i.style.paddingLeft = "10px"; | ||
| const c = JSON.stringify(r, null, 2); | ||
| i.textContent = c, o.appendChild(i), n.appendChild(o); | ||
| const s = document.createElement("div"); | ||
| s.style.marginTop = "5px", s.style.paddingLeft = "10px"; | ||
| const u = JSON.stringify(r, null, 2); | ||
| s.textContent = u, o.appendChild(s), n.appendChild(o); | ||
| } | ||
@@ -55,26 +55,26 @@ function B() { | ||
| } | ||
| function N() { | ||
| function q() { | ||
| var t; | ||
| const r = h.cookieName; | ||
| const r = f.cookieName; | ||
| return (t = new RegExp(`(^|;)\\s*${r}\\s*=\\s*([^;]+)`).exec(document.cookie)) == null ? void 0 : t.pop(); | ||
| } | ||
| function P(r) { | ||
| const e = h.cookieName; | ||
| function U(r) { | ||
| const e = f.cookieName; | ||
| document.cookie = `${e}=${r};max-age=31536000`; | ||
| } | ||
| function I() { | ||
| if (h.getUserId && typeof h.getUserId == "function") | ||
| return h.getUserId(); | ||
| const r = N(); | ||
| function C() { | ||
| if (f.getUserId && typeof f.getUserId == "function") | ||
| return f.getUserId(); | ||
| const r = q(); | ||
| if (r) | ||
| return r; | ||
| const e = B(); | ||
| return P(e), e; | ||
| return U(e), e; | ||
| } | ||
| const U = /* @__PURE__ */ new Map(); | ||
| function O(r, e = void 0) { | ||
| U.set(r, e); | ||
| const R = /* @__PURE__ */ new Map(); | ||
| function P(r, e = void 0) { | ||
| R.set(r, e); | ||
| } | ||
| function q(r) { | ||
| return U.has(r); | ||
| function O(r) { | ||
| return R.has(r); | ||
| } | ||
@@ -86,3 +86,3 @@ function _(r, { | ||
| }) { | ||
| let o = `${h.baseURL}${r}`; | ||
| let o = `${f.baseURL}${r}`; | ||
| const l = { | ||
@@ -93,3 +93,3 @@ method: e, | ||
| "Content-Type": "application/json", | ||
| "X-TS-ID": `${h.appId}` | ||
| "X-TS-ID": `${f.appId}` | ||
| } | ||
@@ -101,3 +101,3 @@ }; | ||
| constructor() { | ||
| this.service_url = h.baseURL, this.deviceType = h.deviceType, this.user_id = I(); | ||
| this.service_url = f.baseURL, this.deviceType = f.deviceType, this.user_id = C(); | ||
| } | ||
@@ -118,7 +118,7 @@ setUserId(e) { | ||
| const o = t.resolvedBidId; | ||
| if (q(`${o}-${e}`)) { | ||
| d({ resolvedBidId: o }, "resolvedBidId already exists"); | ||
| if (O(`${o}-${e}`)) { | ||
| i({ resolvedBidId: o }, "resolvedBidId already exists"); | ||
| return; | ||
| } | ||
| O(`${o}-${e}`, e); | ||
| P(`${o}-${e}`, e); | ||
| } | ||
@@ -202,3 +202,3 @@ return this.send({ | ||
| function j({ width: r, height: e }) { | ||
| return d({ width: r, height: e }, "bannerStyleFixed"), ` | ||
| return i({ width: r, height: e }, "bannerStyleFixed"), ` | ||
| .ts-banner-wrapper-${r}-${e} { | ||
@@ -222,19 +222,19 @@ display: block; | ||
| } | ||
| function F(r, e, t, n, o) { | ||
| let l = 320, a = 520, i = "responsive"; | ||
| o && (i = "fixed", l = o.width, a = o.height); | ||
| const c = document.createElement("div"); | ||
| c.setAttribute("data-ts-banner", r), c.setAttribute("data-resolved-id", e), i === "responsive" ? c.classList.add("ts-banner-wrapper") : c.classList.add(`ts-banner-wrapper-${l}-${a}`); | ||
| const s = document.createElement("style"); | ||
| s.textContent = i === "responsive" ? H({ url: n }) : j({ width: l, height: a }), document.head.appendChild(s), d({ sizeStyle: i, width: l, height: a }, "bannerWrapper"); | ||
| const u = document.createElement("a"); | ||
| if (u.addEventListener("click", async (p) => { | ||
| p.preventDefault(), await x.event("clicks", { | ||
| function W(r, e, t, n, o) { | ||
| let l = 320, a = 520, s = "responsive"; | ||
| o && (s = "fixed", l = o.width, a = o.height); | ||
| const u = document.createElement("div"); | ||
| u.setAttribute("data-ts-banner", r), u.setAttribute("data-resolved-id", e), s === "responsive" ? u.classList.add("ts-banner-wrapper") : u.classList.add(`ts-banner-wrapper-${l}-${a}`); | ||
| const c = document.createElement("style"); | ||
| c.textContent = s === "responsive" ? H({ url: n }) : j({ width: l, height: a }), document.head.appendChild(c), i({ sizeStyle: s, width: l, height: a }, "bannerWrapper"); | ||
| const h = document.createElement("a"); | ||
| if (h.addEventListener("click", async (d) => { | ||
| d.preventDefault(), await x.event("clicks", { | ||
| resolvedBidId: e | ||
| }), window.location.href = t.replace("https://www.delivery.com", ""); | ||
| }), u.href = t.replace("https://www.delivery.com", ""), i === "fixed") { | ||
| const p = document.createElement("img"); | ||
| p.src = n, p.alt = "Banner", u.appendChild(p); | ||
| }), h.href = t.replace("https://www.delivery.com", ""), s === "fixed") { | ||
| const d = document.createElement("img"); | ||
| d.src = n, d.alt = "Banner", h.appendChild(d); | ||
| } | ||
| return c.appendChild(u), c; | ||
| return u.appendChild(h), u; | ||
| } | ||
@@ -254,4 +254,4 @@ async function T({ | ||
| slotId: e, | ||
| deviceType: h.deviceType, | ||
| opaqueUserId: I() | ||
| deviceType: f.deviceType, | ||
| opaqueUserId: C() | ||
| } | ||
@@ -261,18 +261,18 @@ ] | ||
| if (o) { | ||
| for (const i of o.results) | ||
| if (i.resultType === "banners") { | ||
| for (const c of i.winners) | ||
| if (c.rank === 1 && ((l = c.asset[0]) != null && l.url)) { | ||
| for (const s of o.results) | ||
| if (s.resultType === "banners") { | ||
| for (const u of s.winners) | ||
| if (u.rank === 1 && ((l = u.asset[0]) != null && l.url)) { | ||
| if (document.querySelector(`[data-ts-banner=${e}]`)) { | ||
| d({ id: c.id }, "banner already exists"); | ||
| i({ id: u.id }, "banner already exists"); | ||
| continue; | ||
| } | ||
| const u = F( | ||
| const h = W( | ||
| e, | ||
| c.resolvedBidId, | ||
| c.id, | ||
| c.asset[0].url, | ||
| u.resolvedBidId, | ||
| u.id, | ||
| u.asset[0].url, | ||
| n | ||
| ); | ||
| return t === "top" ? r.insertBefore(u, r.firstChild) : t === "bottom" ? r.appendChild(u) : t === "before" && ((a = r.parentNode) == null || a.insertBefore(u, r)), u; | ||
| return t === "top" ? r.insertBefore(h, r.firstChild) : t === "bottom" ? r.appendChild(h) : t === "before" && ((a = r.parentNode) == null || a.insertBefore(h, r)), h; | ||
| } | ||
@@ -283,4 +283,4 @@ } | ||
| } | ||
| const W = 5; | ||
| function X(r) { | ||
| const F = 5; | ||
| function z(r) { | ||
| var n, o; | ||
@@ -301,5 +301,5 @@ const e = document.querySelectorAll(".MenuCategoryCarousels__carousel"); | ||
| } | ||
| async function J(r) { | ||
| async function X(r) { | ||
| try { | ||
| const e = I(), t = r.map(() => ({ | ||
| const e = C(), t = r.map(() => ({ | ||
| type: "banners", | ||
@@ -309,3 +309,3 @@ slots: 1, | ||
| opaqueUserId: e, | ||
| deviceType: h.deviceType | ||
| deviceType: f.deviceType | ||
| })); | ||
@@ -319,3 +319,3 @@ return await S({ | ||
| } | ||
| function z(r, e) { | ||
| function J(r, e) { | ||
| const t = []; | ||
@@ -326,3 +326,3 @@ for (const n of r) | ||
| } | ||
| function $(r, e) { | ||
| function N(r, e) { | ||
| const t = e.find((n) => n.value.includes(r)); | ||
@@ -332,3 +332,3 @@ if (t) | ||
| for (const n of e) { | ||
| const o = $(r, n.children); | ||
| const o = N(r, n.children); | ||
| if (o) | ||
@@ -348,3 +348,3 @@ return o; | ||
| return o.src = e, o.alt = t, o.style.height = "160px", o.style.width = "fit-content", n.addEventListener("click", () => { | ||
| d("bannerElement clicked"), x.event("clicks", { | ||
| i("bannerElement clicked"), x.event("clicks", { | ||
| resolvedBidId: r | ||
@@ -354,3 +354,3 @@ }); | ||
| } | ||
| async function K(r, e) { | ||
| async function G(r, e) { | ||
| var t; | ||
@@ -360,94 +360,94 @@ try { | ||
| if (!o) { | ||
| d("No category found in pathname"); | ||
| i("No category found in pathname"); | ||
| return; | ||
| } | ||
| d(o, "category to find"); | ||
| const l = $(o, n.data.categories); | ||
| i(o, "category to find"); | ||
| const l = N(o, n.data.categories); | ||
| if (!l) { | ||
| d("Category not found in data"); | ||
| i("Category not found in data"); | ||
| return; | ||
| } | ||
| d(l.value, "category"); | ||
| let a = l.children.slice(0, W); | ||
| a.length === 0 && l.product_ids.length > 0 && (d("No children, test with category"), a = [l]), d(a, "childrenCategoriesOnAuction"); | ||
| const i = a.map((s) => ({ | ||
| products_ids: z(s.product_ids, n.data.products), | ||
| i(l.value, "category"); | ||
| let a = l.children.slice(0, F); | ||
| a.length === 0 && l.product_ids.length > 0 && (i("No children, test with category"), a = [l]), i(a, "childrenCategoriesOnAuction"); | ||
| const s = a.map((c) => ({ | ||
| products_ids: J(c.product_ids, n.data.products), | ||
| slotsNumber: e, | ||
| category: s | ||
| })), c = await J(i); | ||
| if (d(c, "auction"), !c) { | ||
| d("No auction results"); | ||
| category: c | ||
| })), u = await X(s); | ||
| if (i(u, "auction"), !u) { | ||
| i("No auction results"); | ||
| return; | ||
| } | ||
| for (const s of c.results) { | ||
| if (s.winners.length === 0) { | ||
| d("No winners found"); | ||
| for (const c of u.results) { | ||
| if (c.winners.length === 0) { | ||
| i("No winners found"); | ||
| continue; | ||
| } | ||
| const u = c.results.indexOf(s), p = i[u]; | ||
| if (!p) { | ||
| d("Auction not found"); | ||
| const h = u.results.indexOf(c), d = s[h]; | ||
| if (!d) { | ||
| i("Auction not found"); | ||
| continue; | ||
| } | ||
| const y = X(p.category.name); | ||
| if (!y) { | ||
| d("Category element not found"); | ||
| const p = z(d.category.name); | ||
| if (!p) { | ||
| i("Category element not found"); | ||
| continue; | ||
| } | ||
| const w = y.querySelectorAll(".MenuItem"); | ||
| if (!w) { | ||
| d("Product elements not found"); | ||
| const b = p.querySelectorAll(".MenuItem"); | ||
| if (!b) { | ||
| i("Product elements not found"); | ||
| continue; | ||
| } | ||
| for (const g of s.winners) { | ||
| const f = Object.values(n.data.products).find( | ||
| (b) => b.product_id === g.id | ||
| for (const y of c.winners) { | ||
| const g = Object.values(n.data.products).find( | ||
| (w) => w.product_id === y.id | ||
| ); | ||
| if (!f) { | ||
| d("product not found in data.data.products"); | ||
| if (!g) { | ||
| i("product not found in data.data.products"); | ||
| continue; | ||
| } | ||
| d(f, "product"); | ||
| const m = p.category.product_ids.findIndex((b) => b === f.id); | ||
| i(g, "product"); | ||
| const m = d.category.product_ids.findIndex((w) => w === g.id); | ||
| if (m === -1) { | ||
| d("product not found in auction.category.product_ids"); | ||
| i("product not found in auction.category.product_ids"); | ||
| continue; | ||
| } | ||
| const C = y.querySelector("[data-resolved-id]"); | ||
| const E = p.querySelector("[data-resolved-id]"); | ||
| let v; | ||
| if (C ? v = C.parentElement : v = w[m], !v) { | ||
| d("productElement not found"); | ||
| if (E ? v = E.parentElement : v = b[m], !v) { | ||
| i("productElement not found"); | ||
| continue; | ||
| } | ||
| if (C) | ||
| d("sponsored banner already in productElement"); | ||
| if (E) | ||
| i("sponsored banner already in productElement"); | ||
| else { | ||
| const b = (t = g.asset) == null ? void 0 : t[0]; | ||
| if (!b) { | ||
| d("image not found"); | ||
| const w = (t = y.asset) == null ? void 0 : t[0]; | ||
| if (!w) { | ||
| i("image not found"); | ||
| continue; | ||
| } | ||
| const R = V({ | ||
| resolvedBidId: g.resolvedBidId, | ||
| imageUrl: b.url, | ||
| productName: f.name | ||
| const $ = V({ | ||
| resolvedBidId: y.resolvedBidId, | ||
| imageUrl: w.url, | ||
| productName: g.name | ||
| }), k = v.querySelector("img.MenuItem__image"); | ||
| if (!k) { | ||
| d("originalImage not found"); | ||
| i("originalImage not found"); | ||
| continue; | ||
| } | ||
| v.replaceChild(R, k); | ||
| v.replaceChild($, k); | ||
| const M = v.querySelector(".MenuItem__sizes"); | ||
| M && M.remove(); | ||
| } | ||
| const E = w[g.rank - 1]; | ||
| if (!E) { | ||
| d("targetElement not found"); | ||
| const I = b[y.rank - 1]; | ||
| if (!I) { | ||
| i("targetElement not found"); | ||
| continue; | ||
| } | ||
| try { | ||
| const b = E.parentElement; | ||
| b && b.insertBefore(v, E); | ||
| } catch (b) { | ||
| d({ message: b.message, stack: b.stack }, "Unable to insert product element"); | ||
| const w = I.parentElement; | ||
| w && w.insertBefore(v, I); | ||
| } catch (w) { | ||
| i({ message: w.message, stack: w.stack }, "Unable to insert product element"); | ||
| } | ||
@@ -458,9 +458,9 @@ } | ||
| } catch (n) { | ||
| d(n, "Unable to handle category"); | ||
| i(n, "Unable to handle category"); | ||
| return; | ||
| } | ||
| } | ||
| async function G(r) { | ||
| async function K(r) { | ||
| try { | ||
| const e = I(), t = r.map(() => ({ | ||
| const e = C(), t = r.map(() => ({ | ||
| type: "banners", | ||
@@ -470,3 +470,3 @@ slots: 1, | ||
| opaqueUserId: e, | ||
| deviceType: h.deviceType | ||
| deviceType: f.deviceType | ||
| })); | ||
@@ -489,3 +489,3 @@ return await S({ | ||
| return o.src = e, o.alt = t, o.style.height = "160px", o.style.width = "fit-content", n.addEventListener("click", () => { | ||
| d("bannerElement clicked"), x.event("clicks", { | ||
| i("bannerElement clicked"), x.event("clicks", { | ||
| resolvedBidId: r | ||
@@ -500,78 +500,78 @@ }); | ||
| if (!n.data.search) { | ||
| d("data.data.search not found"); | ||
| i("data.data.search not found"); | ||
| return; | ||
| } | ||
| const o = n.data.search.ids.filter((s) => s !== null), l = []; | ||
| for (const s of o) | ||
| n.data.products[s] && l.push(n.data.products[s].product_id); | ||
| const a = await G([{ products_ids: l, slotsNumber: e }]); | ||
| if (d(a, "auction"), !a || !a.results) { | ||
| d("No winners found"); | ||
| const o = n.data.search.ids.filter((c) => c !== null), l = []; | ||
| for (const c of o) | ||
| n.data.products[c] && l.push(n.data.products[c].product_id); | ||
| const a = await K([{ products_ids: l, slotsNumber: e }]); | ||
| if (i(a, "auction"), !a || !a.results) { | ||
| i("No winners found"); | ||
| return; | ||
| } | ||
| const i = document.querySelector(".MenuCatalog__container"); | ||
| if (!i) { | ||
| d("catalogElement not found"); | ||
| const s = document.querySelector(".MenuCatalog__container"); | ||
| if (!s) { | ||
| i("catalogElement not found"); | ||
| return; | ||
| } | ||
| const c = i.querySelectorAll(".MenuItem"); | ||
| if (!c) { | ||
| d("productElements not found"); | ||
| const u = s.querySelectorAll(".MenuItem"); | ||
| if (!u) { | ||
| i("productElements not found"); | ||
| return; | ||
| } | ||
| for (const s of a.results) { | ||
| if (s.winners.length === 0) { | ||
| d("No winners found"); | ||
| for (const c of a.results) { | ||
| if (c.winners.length === 0) { | ||
| i("No winners found"); | ||
| continue; | ||
| } | ||
| for (const u of s.winners) { | ||
| const p = Object.values(n.data.products).find( | ||
| (m) => (m == null ? void 0 : m.product_id) === u.id | ||
| for (const h of c.winners) { | ||
| const d = Object.values(n.data.products).find( | ||
| (m) => (m == null ? void 0 : m.product_id) === h.id | ||
| ); | ||
| if (!p) { | ||
| d("product not found in data.data.products"); | ||
| if (!d) { | ||
| i("product not found in data.data.products"); | ||
| continue; | ||
| } | ||
| const y = o.findIndex((m) => m === p.id); | ||
| if (d(y, "productIndex"), y === -1) { | ||
| d("product not found in data.data.search.ids"); | ||
| const p = o.findIndex((m) => m === d.id); | ||
| if (i(p, "productIndex"), p === -1) { | ||
| i("product not found in data.data.search.ids"); | ||
| continue; | ||
| } | ||
| const w = i.querySelector("[data-resolved-id]"); | ||
| let g; | ||
| if (w ? g = w.parentElement : g = c[y], !g) { | ||
| d("productElement not found"); | ||
| const b = s.querySelector("[data-resolved-id]"); | ||
| let y; | ||
| if (b ? y = b.parentElement : y = u[p], !y) { | ||
| i("productElement not found"); | ||
| continue; | ||
| } | ||
| if (w) | ||
| d("sponsored banner already in productElement"); | ||
| if (b) | ||
| i("sponsored banner already in productElement"); | ||
| else { | ||
| const m = (t = u.asset) == null ? void 0 : t[0]; | ||
| const m = (t = h.asset) == null ? void 0 : t[0]; | ||
| if (!m) { | ||
| d("image not found"); | ||
| i("image not found"); | ||
| continue; | ||
| } | ||
| const C = Y({ | ||
| resolvedBidId: u.resolvedBidId, | ||
| const E = Y({ | ||
| resolvedBidId: h.resolvedBidId, | ||
| imageUrl: m.url, | ||
| productName: p.name | ||
| }), v = g.querySelector("img.MenuItem__image"); | ||
| productName: d.name | ||
| }), v = y.querySelector("img.MenuItem__image"); | ||
| if (!v) { | ||
| d("originalImage not found"); | ||
| i("originalImage not found"); | ||
| continue; | ||
| } | ||
| g.replaceChild(C, v); | ||
| const E = g.querySelector(".MenuItem__sizes"); | ||
| E && E.remove(); | ||
| y.replaceChild(E, v); | ||
| const I = y.querySelector(".MenuItem__sizes"); | ||
| I && I.remove(); | ||
| } | ||
| const f = c[u.rank - 1]; | ||
| if (!f) { | ||
| d("targetElement not found"); | ||
| const g = u[h.rank - 1]; | ||
| if (!g) { | ||
| i("targetElement not found"); | ||
| continue; | ||
| } | ||
| try { | ||
| const m = f.parentElement; | ||
| m && m.insertBefore(g, f); | ||
| const m = g.parentElement; | ||
| m && m.insertBefore(y, g); | ||
| } catch (m) { | ||
| d(m, "Unable to insert product element"); | ||
| i(m, "Unable to insert product element"); | ||
| } | ||
@@ -582,3 +582,3 @@ } | ||
| } catch (n) { | ||
| d(n, "error"); | ||
| i(n, "error"); | ||
| return; | ||
@@ -597,6 +597,68 @@ } | ||
| } catch { | ||
| d("Unable to process catalog ingestion"); | ||
| i("Unable to process catalog ingestion"); | ||
| } | ||
| } | ||
| function Z() { | ||
| async function Z({ | ||
| orderId: r, | ||
| clientId: e, | ||
| authorization: t | ||
| }) { | ||
| try { | ||
| return (await fetch( | ||
| `/api/customer/orders/recent/${r}?include_merchant=true&client_id=${e}`, | ||
| { | ||
| headers: { | ||
| Authorization: t | ||
| } | ||
| } | ||
| )).json(); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
| async function ee({ | ||
| responseText: r, | ||
| requestHeaders: e, | ||
| url: t | ||
| }) { | ||
| var h; | ||
| const n = Object.keys(e).find( | ||
| (d) => d.toLowerCase() === "authorization" | ||
| ); | ||
| if (!n) { | ||
| i("unable to make auth request: No authorization header found"); | ||
| return; | ||
| } | ||
| const o = e[n]; | ||
| i(t, "url"); | ||
| const l = t.match(/[?&]client_id=([^&]+)/), a = l ? l[1] : null; | ||
| if (!a) { | ||
| i("unable to make auth request: No clientId found"); | ||
| return; | ||
| } | ||
| const { orders: s } = JSON.parse(r); | ||
| if (!s) { | ||
| i("unable to make auth request: No orders found"); | ||
| return; | ||
| } | ||
| const u = await Promise.all( | ||
| s.map(async (d) => await Z({ | ||
| orderId: d.orderId.toString(), | ||
| clientId: a, | ||
| authorization: o | ||
| })) | ||
| ), c = []; | ||
| for (const d of u) | ||
| if ((h = d == null ? void 0 : d.order) != null && h.cart) | ||
| for (const p of d.order.cart) | ||
| c.push({ | ||
| productId: p.id, | ||
| unitPrice: Number.parseFloat(p.unit_price), | ||
| quantity: p.quantity | ||
| }); | ||
| x.event("purchases", { | ||
| items: c | ||
| }); | ||
| } | ||
| function te() { | ||
| return [ | ||
@@ -634,6 +696,5 @@ /** | ||
| type: "dom", | ||
| //target: ".MerchantPageAside .StaticCartContainer,.MerchantPageAside .CartSticky", | ||
| target: ".MerchantPageAside .CartSticky", | ||
| target: ".MerchantPageAside .StaticCartContainer,.MerchantPageAside .CartSticky", | ||
| onEvent: (e) => { | ||
| h.deviceType !== "mobile" && T({ | ||
| f.deviceType !== "mobile" && T({ | ||
| slotId: "merchant-page-aside-slot", | ||
@@ -671,3 +732,3 @@ appendTo: e, | ||
| onIntercept: async ({ response: e }) => { | ||
| Q(e.responseText, 1), h.features.catalogIngestion && L({ responseText: e.responseText }); | ||
| Q(e.responseText, 1), f.features.catalogIngestion && L({ responseText: e.responseText }); | ||
| } | ||
@@ -686,8 +747,19 @@ }, | ||
| onIntercept: async ({ response: e }) => { | ||
| K(e.responseText, 1), h.features.catalogIngestion && L({ responseText: e.responseText }); | ||
| G(e.responseText, 1), f.features.catalogIngestion && L({ responseText: e.responseText }); | ||
| } | ||
| }, | ||
| /** | ||
| * Checkout/purchase event | ||
| */ | ||
| { | ||
| type: "xhr", | ||
| urlMatcher: (e) => e.includes("/api/customer/checkout"), | ||
| methodMatcher: (e) => e === "GET", | ||
| onIntercept: async ({ response: e, requestHeaders: t, url: n }) => { | ||
| ee({ responseText: e.responseText, requestHeaders: t, url: n }); | ||
| } | ||
| } | ||
| ]; | ||
| } | ||
| async function ee({ | ||
| async function ne({ | ||
| appendTo: r, | ||
@@ -705,4 +777,4 @@ slotId: e, | ||
| slotId: e, | ||
| deviceType: h.deviceType, | ||
| opaqueUserId: I() | ||
| deviceType: f.deviceType, | ||
| opaqueUserId: C() | ||
| } | ||
@@ -714,10 +786,10 @@ ] | ||
| if (a.resultType === "banners") { | ||
| for (const i of a.winners) | ||
| if (i.rank === 1 && ((o = i.asset[0]) != null && o.url)) { | ||
| for (const s of a.winners) | ||
| if (s.rank === 1 && ((o = s.asset[0]) != null && o.url)) { | ||
| if (document.querySelector(`[data-ts-banner=${e}]`)) | ||
| continue; | ||
| const s = document.createElement("div"); | ||
| s.setAttribute("data-ts-banner", e), s.classList.add("ts-banner-wrapper"), s.setAttribute("data-ts-resolved-id", i.resolvedBidId); | ||
| const u = document.createElement("style"); | ||
| u.textContent = ` | ||
| const c = document.createElement("div"); | ||
| c.setAttribute("data-ts-banner", e), c.classList.add("ts-banner-wrapper"), c.setAttribute("data-ts-resolved-id", s.resolvedBidId); | ||
| const h = document.createElement("style"); | ||
| h.textContent = ` | ||
| .ts-banner-wrapper { | ||
@@ -729,3 +801,3 @@ display: block; | ||
| margin: 0 auto; | ||
| background-image: url(${i.asset[0].url}); | ||
| background-image: url(${s.asset[0].url}); | ||
| background-size: cover; | ||
@@ -765,9 +837,9 @@ background-position: center; | ||
| } | ||
| `, document.head.appendChild(u); | ||
| const p = document.createElement("a"); | ||
| return p.addEventListener("click", async (y) => { | ||
| y.preventDefault(), await x.event("clicks", { | ||
| resolvedBidId: i.resolvedBidId | ||
| }), window.location.href = p.href; | ||
| }), p.href = i.id.replace("https://www.delivery.com", ""), s.appendChild(p), t === "top" ? r.insertBefore(s, r.firstChild) : t === "bottom" ? r.appendChild(s) : t === "before" && ((l = r.parentNode) == null || l.insertBefore(s, r)), s; | ||
| `, document.head.appendChild(h); | ||
| const d = document.createElement("a"); | ||
| return d.addEventListener("click", async (p) => { | ||
| p.preventDefault(), await x.event("clicks", { | ||
| resolvedBidId: s.resolvedBidId | ||
| }), window.location.href = d.href; | ||
| }), d.href = s.id.replace("https://www.delivery.com", ""), c.appendChild(d), t === "top" ? r.insertBefore(c, r.firstChild) : t === "bottom" ? r.appendChild(c) : t === "before" && ((l = r.parentNode) == null || l.insertBefore(c, r)), c; | ||
| } | ||
@@ -778,3 +850,3 @@ } | ||
| } | ||
| function te() { | ||
| function re() { | ||
| return [ | ||
@@ -790,3 +862,3 @@ /** | ||
| onEvent: (e) => { | ||
| ee({ slotId: "search-slot", appendTo: e }); | ||
| ne({ slotId: "search-slot", appendTo: e }); | ||
| }, | ||
@@ -842,4 +914,4 @@ threshold: 0 | ||
| } | ||
| const ne = 0.5; | ||
| function re({ | ||
| const oe = 0.5; | ||
| function se({ | ||
| target: r | ||
@@ -849,19 +921,19 @@ }) { | ||
| (a) => { | ||
| for (const i of a) | ||
| i.isIntersecting && (r.event(i.target), e.add(i.target), t.unobserve(i.target)); | ||
| for (const s of a) | ||
| s.isIntersecting && (r.event(s.target), e.add(s.target), t.unobserve(s.target)); | ||
| }, | ||
| { | ||
| threshold: r.threshold ?? ne | ||
| threshold: r.threshold ?? oe | ||
| } | ||
| ), n = (a) => { | ||
| for (const i of Array.from(a)) | ||
| e.has(i) || t.observe(i); | ||
| for (const s of Array.from(a)) | ||
| e.has(s) || t.observe(s); | ||
| }, o = document.querySelectorAll(r.target); | ||
| n(o); | ||
| const l = new MutationObserver((a) => { | ||
| for (const i of a) | ||
| if (i.type === "childList") { | ||
| const c = document.querySelectorAll(r.target); | ||
| if (!c) return; | ||
| n(c); | ||
| for (const s of a) | ||
| if (s.type === "childList") { | ||
| const u = document.querySelectorAll(r.target); | ||
| if (!u) return; | ||
| n(u); | ||
| } | ||
@@ -877,3 +949,3 @@ }); | ||
| } | ||
| class oe { | ||
| class ae { | ||
| constructor(e) { | ||
@@ -885,7 +957,7 @@ this.targets = [], this.observer = null, this.pollInterval = null, this.lastData = /* @__PURE__ */ new Map(), this.interval = 1e3, this.checkCache = () => { | ||
| for (const [l, a] of Object.entries(n)) | ||
| for (const i of this.targets) { | ||
| const c = l.split(":")[0]; | ||
| if (c && i.cacheKeyMatcher(c)) { | ||
| const s = this.lastData.get(c), u = Object.keys(a).length; | ||
| u > (s ?? 0) && (this.lastData.set(c, u), i.onIntercept({ data: a, key: c })); | ||
| for (const s of this.targets) { | ||
| const u = l.split(":")[0]; | ||
| if (u && s.cacheKeyMatcher(u)) { | ||
| const c = this.lastData.get(u), h = Object.keys(a).length; | ||
| h > (c ?? 0) && (this.lastData.set(u, h), s.onIntercept({ data: a, key: u })); | ||
| } | ||
@@ -908,3 +980,3 @@ } | ||
| } | ||
| let se = class { | ||
| let ie = class { | ||
| constructor() { | ||
@@ -931,6 +1003,6 @@ this.targets = [], this.originalFetch = window.fetch, this.intercept(); | ||
| } | ||
| const i = await this.originalFetch(e, t), c = i.clone(); | ||
| for (const s of this.targets) | ||
| s.urlMatcher(n) && s.methodMatcher(o) && await s.onIntercept({ | ||
| response: c, | ||
| const s = await this.originalFetch(e, t), u = s.clone(); | ||
| for (const c of this.targets) | ||
| c.urlMatcher(n) && c.methodMatcher(o) && await c.onIntercept({ | ||
| response: u, | ||
| request: { | ||
@@ -943,6 +1015,6 @@ url: n, | ||
| }); | ||
| return i; | ||
| return s; | ||
| } catch (a) { | ||
| for (const i of this.targets) | ||
| i.urlMatcher(n) && i.methodMatcher(o) && ((l = i.onError) == null || l.call(i, a instanceof Error ? a : new Error(String(a)))); | ||
| for (const s of this.targets) | ||
| s.urlMatcher(n) && s.methodMatcher(o) && ((l = s.onError) == null || l.call(s, a instanceof Error ? a : new Error(String(a)))); | ||
| throw a; | ||
@@ -953,4 +1025,4 @@ } | ||
| }; | ||
| const ae = window.XMLHttpRequest; | ||
| class ie { | ||
| const ce = window.XMLHttpRequest; | ||
| class de { | ||
| constructor() { | ||
@@ -968,20 +1040,33 @@ this.targets = [], this.intercept(); | ||
| function t() { | ||
| const n = new ae(), o = n.open, l = n.send; | ||
| let a = "", i = ""; | ||
| return n.open = (c, s, ...u) => (a = c, i = s, o.apply(n, [c, s, ...u])), n.addEventListener("load", () => { | ||
| var c; | ||
| for (const s of e.targets) | ||
| s.urlMatcher(i) && s.methodMatcher(a) && ((c = s.onIntercept) == null || c.call(s, { | ||
| response: { | ||
| status: n.status, | ||
| statusText: n.statusText, | ||
| responseText: n.responseText, | ||
| responseURL: n.responseURL | ||
| const n = new ce(), o = n.open, l = n.send, a = n.setRequestHeader; | ||
| let s = "", u = "", c; | ||
| const h = {}; | ||
| return n.setRequestHeader = (d, p) => (h[d.toLowerCase()] = p, a.call(n, d, p)), n.open = (d, p, ...b) => (s = d, u = p, o.apply(n, [d, p, ...b])), n.addEventListener("load", () => { | ||
| var d; | ||
| for (const p of e.targets) | ||
| if (p.urlMatcher(u) && p.methodMatcher(s)) { | ||
| const b = {}, y = n.getAllResponseHeaders().split(`\r | ||
| `); | ||
| for (const g of y) { | ||
| const [m, E] = g.split(": "); | ||
| m && E && (b[m.toLowerCase()] = E); | ||
| } | ||
| })); | ||
| (d = p.onIntercept) == null || d.call(p, { | ||
| response: { | ||
| status: n.status, | ||
| statusText: n.statusText, | ||
| responseText: n.responseText, | ||
| responseURL: n.responseURL, | ||
| headers: b | ||
| }, | ||
| payload: c, | ||
| requestHeaders: h, | ||
| url: u | ||
| }); | ||
| } | ||
| }), n.addEventListener("error", () => { | ||
| var c; | ||
| for (const s of e.targets) | ||
| s.urlMatcher(i) && s.methodMatcher(a) && ((c = s.onError) == null || c.call(s, new Error(`XHR Error: ${n.statusText}`))); | ||
| }), n.send = (c) => l.call(n, c), n; | ||
| var d; | ||
| for (const p of e.targets) | ||
| p.urlMatcher(u) && p.methodMatcher(s) && ((d = p.onError) == null || d.call(p, new Error(`XHR Error: ${n.statusText}`))); | ||
| }), n.send = (d) => (c = d, l.call(n, d)), n; | ||
| } | ||
@@ -991,8 +1076,8 @@ window.XMLHttpRequest = t; | ||
| } | ||
| class ce { | ||
| class le { | ||
| constructor() { | ||
| this.events = [], this.interceptorXHR = new ie(), this.interceptorFetch = new se(), this.interceptorApolloCache = new oe(); | ||
| this.events = [], this.interceptorXHR = new de(), this.interceptorFetch = new ie(), this.interceptorApolloCache = new ae(); | ||
| } | ||
| addEvent(e) { | ||
| e.type === "dom" ? (re({ | ||
| e.type === "dom" ? (se({ | ||
| target: { | ||
@@ -1017,8 +1102,8 @@ target: e.target, | ||
| } | ||
| function de(r) { | ||
| function ue(r) { | ||
| switch (r) { | ||
| case "TS1003581": | ||
| return Z(); | ||
| return te(); | ||
| case "TS1004020": | ||
| return te(); | ||
| return re(); | ||
| default: | ||
@@ -1029,13 +1114,13 @@ return; | ||
| function A() { | ||
| if (!h.appId || !h.baseURL) | ||
| if (!f.appId || !f.baseURL) | ||
| return; | ||
| const r = de(h.appId); | ||
| const r = ue(f.appId); | ||
| if (!r) | ||
| return; | ||
| const e = new ce(); | ||
| const e = new le(); | ||
| for (const t of r) | ||
| e.addEvent(t); | ||
| } | ||
| /complete|interactive|loaded/.test(document.readyState) ? (d(`document is ${document.readyState}`), A()) : window.addEventListener("DOMContentLoaded", () => { | ||
| d("on DOMContentLoaded"), A(); | ||
| /complete|interactive|loaded/.test(document.readyState) ? (i(`document is ${document.readyState}`), A()) : window.addEventListener("DOMContentLoaded", () => { | ||
| i("on DOMContentLoaded"), A(); | ||
| }); | ||
@@ -1042,0 +1127,0 @@ export { |
+1
-1
| { | ||
| "name": "@topsort/toppie-sdk", | ||
| "version": "0.1.21", | ||
| "version": "0.1.22", | ||
| "main": "dist/main.js", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
55564
6.98%1258
7.8%5
25%10
25%