PageSourceSearch

https://www.sunspel.com/cdn/shop/t/532/assets/product-urgency-message.js?v=79409192064097243141789479929

js sunspel.com collected 2026-09-24 17:57:39 UTC 3,723 bytes, 13 lines download raw bytes

1const QUERY=`
2  query VariantInventory($productHandle: String!) {
3    product(handle: $productHandle) {
4      variants (first: 100) {
5        nodes {
6          id
7          quantityAvailable
8        }
9      }
10    }
11  }
12`;class Cache{constructor(){this.cache=new Map}exists(key){return this.cache.has(key)}set(key,value){this.cache.set(key,value)}get(key){return this.cache.get(key)}delete(key){this.cache.delete(key)}}export class ProductUrgencyMessage extends window.BAO.CustomElement(){static get observedAttributes(){return["data-variant-id"]}static get requiredAttributes(){return["data-product-handle","data-variant-id"]}constructor(){super(),this.threshold=parseFloat(this.dataset.threshold),this.lowStockMessage=this.externalEls?.["low-stock-message"]?.element,this.restockAlertsMessage=this.externalEls?.["restock-alerts-message"]?.element,this.message=this.lowStockMessage,this.messageText=this.lowStockMessage?.querySelector?.("[data-variant-message-text]"),this.icon=this.externalEls?.icon?.element,this.isBundle=this.dataset.isBundle==="true",this.selectionMade=!1,this.cache=new Cache}connectedCallback(){super.connectedCallback(),this.getProductData().then(data=>{this.log("getProductData",{data}),this.data=data})}attributeChangedCallback(name,oldValue,newValue){switch(name){case"data-variant-id":{if(typeof this.data>"u"){this.hideMessage(),this.showRestockAlertsMessage();return}if(this.selectionMade&&oldValue===newValue){this.hideMessage(),this.showRestockAlertsMessage();return}this.hideRestockAlertsMessage();const currentVariantQuantity=this.getVariantQuantity(this.data,this.getVariantId(newValue));if(this.log("data-variant-id",{currentVariantQuantity,data:this.data,variantId:this.getVariantId(newValue)}),currentVariantQuantity===void 0)return;this.showMessage(parseFloat(currentVariantQuantity))}}this.selectionMade=!0}async getProductData(){return this.makeStorefrontRequest({body:JSON.stringify({query:QUERY,variables:{productHandle:this.productHandle}})})}getVariantQuantity(data,variantId){return this.log("getVariantQuantity",{data,variantId}),data.product.variants.nodes.find(variant2=>variant2.id===variantId)?.quantityAvailable}showMessage(amount){amount<1?(this.message.setAttribute("aria-hidden",!1),this.messageText.setAttribute("aria-hidden",!0)):(this.message.setAttribute("aria-hidden",amount>this.threshold),this.messageText.setAttribute("aria-hidden",!1),this.textContent=amount.toString()),amount<1?this.icon?.setAttribute?.("aria-hidden",!0):this.icon?.setAttribute?.("aria-hidden",!1)}hideMessage(){this.message.setAttribute("aria-hidden",!0),this.messageText.setAttribute("aria-hidden",!0)}showRestockAlertsMessage(){this.restockAlertsMessage?.setAttribute?.("aria-hidden",!1)}hideRestockAlertsMessage(){this.restockAlertsMessage?.setAttribute?.("aria-hidden",!0)}async makeStorefrontRequest(options){if(this.cache.exists(this.getCacheKey()))return this.cache.get(this.getCacheKey());try{const{data}=await window.BAO.Utils.fetchJSON("/api/2024-01/graphql.json",Object.assign({},{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-Shopify-Storefront-Access-Token":window.theme.storefrontAccessToken}},options));return this.cache.set(this.getCacheKey(),data),data}catch(e){console.error(e)}}getCacheKey(){return`${this.dataset.productId}-${this.dataset.variantId}-${this.productHandle}`}getVariantId(variantId){return`gid://shopify/ProductVariant/${variantId}`}get productHandle(){return this.dataset.productHandle}}customElements.get("product-urgency-message")||customElements.define("product-urgency-message",ProductUrgencyMessage);
13//# sourceMappingURL=/cdn/shop/t/532/assets/product-urgency-message.js.map?v=79409192064097243141789479929

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.