@iheartjane/dm-sdk 2.24.1

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.
@@ -0,0 +1 @@
1
+ var N=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var Z=(p,i,c,t)=>{for(var o=t>1?void 0:t?U(i,c):i,a=p.length-1,u;a>=0;a--)(u=p[a])&&(o=(t?u(i,c,o):u(o))||o);return t&&o&&N(i,c,o),o};var d=(t=>(t.All="all",t.Default="default",t.Off="off",t))(d||{}),m=(s=>(s.Bloom="bloom",s.Default="default",s.Embedded="embedded",s.FramelessEmbed="framelessEmbed",s.Headless="headless",s.Kiosk="kiosk",s.OperatorEmbed="operatorEmbed",s.WhiteLabel="whiteLabel",s))(m||{}),l=(t=>(t.Desktop="desktop",t.Kiosk="kiosk",t.Mobile="mobile",t))(l||{}),g=(i=>(i.UserOptOut="user-opt-out",i))(g||{});var _=(c=>(c.Featured="featured",c.Midgrid="midgrid",c))(_||{}),P=(r=>(r.BestSelling="best_selling",r.BrandSpecials="brand_specials",r.BuyAgainRow="buy_again_row",r.CartToppers="cart_toppers",r.CustomImageRow="custom_image_row",r.FeaturedRow="featured_row",r.MenuDynamicRow="menu_dynamic_row",r.MenuInline="menu_inline",r.MenuInlineTable="menu_inline_table",r.MenuTopRow="menu_top_row",r.PdpRow="pdp_row",r.Sale="sale",r.Specials="specials",r.VirtualBudtenderSearch="virtual_budtender_search",r))(P||{}),R=(n=>(n.Edible="edible",n.Extract="extract",n.Flower="flower",n.Gear="gear",n.Grow="grow",n.Merch="merch",n.PreRoll="pre-roll",n.Tincture="tincture",n.Topical="topical",n.Vape="vape",n))(R||{}),b=(t=>(t.Rating="rating",t.Recent="recent",t.Upvote="upvote",t))(b||{}),x=(e=>(e.BestSellerRank="best-seller-rank",e.CategoryAndNameAsc="category-and-name-asc",e.Default="default",e.PriceAsc="price-asc",e.PriceDesc="price-desc",e.PriceEighthOunceAsc="price-eighth-ounce-asc",e.PriceEighthOunceDesc="price-eighth-ounce-desc",e.PriceGramAsc="price-gram-asc",e.PriceGramDesc="price-gram-desc",e.PriceHalfGramAsc="price-half-gram-asc",e.PriceHalfGramDesc="price-half-gram-desc",e.PriceHalfOunceAsc="price-half-ounce-asc",e.PriceHalfOunceDesc="price-half-ounce-desc",e.PriceOunceAsc="price-ounce-asc",e.PriceOunceDesc="price-ounce-desc",e.PriceQuarterOunceAsc="price-quarter-ounce-asc",e.PriceQuarterOunceDesc="price-quarter-ounce-desc",e.PriceTwoGramAsc="price-two-gram-asc",e.PriceTwoGramDesc="price-two-gram-desc",e.Rating="rating",e.Recommendation="recommendation",e.ThcPotencyAsc="thc-potency-asc",e.ThcPotencyDesc="thc-potency-desc",e))(x||{});var z=50;var f="best-seller-rank",w="category-and-name-asc",v="default",h="price-asc",y="price-desc",C="price-eighth-ounce-asc",I="price-eighth-ounce-desc",q="price-gram-asc",S="price-gram-desc",D="price-half-gram-asc",A="price-half-gram-desc",O="price-half-ounce-asc",M="price-half-ounce-desc",T="price-ounce-asc",B="price-ounce-desc",F="price-quarter-ounce-asc",k="price-quarter-ounce-desc",V="price-two-gram-asc",G="price-two-gram-desc",E="rating",j="recommendation",Q="thc-potency-asc",H="thc-potency-desc",J=[f,w,v,h,y,C,I,q,S,D,A,O,M,T,B,F,k,V,G,E,j,Q,H];var L={click:"/v2/event/2",externalCheckout:"/v2/event/3e",facets:"/v2/facets",fingerprint:"/fp/token",impression:"/v2/event/1",multi:"/v2/multi",page:"/v2/smartpage",product:"/v2/product",productReviews:"/v2/product/reviews",sessionEvent:"/v2/event/session",smart:"/v2/smart",virtualBudtenderQueries:"/v2/virtual-budtender/queries",virtualBudtenderSearch:"/v2/virtual-budtender"};export{Z as a,L as b,d as c,m as d,l as e,g as f,_ as g,P as h,R as i,b as j,x as k,z as l,f as m,w as n,v as o,h as p,y as q,C as r,I as s,q as t,S as u,D as v,A as w,O as x,M as y,T as z,B as A,F as B,k as C,V as D,G as E,E as F,j as G,Q as H,H as I,J};
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var et=Object.create;var ae=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var it=(r,e)=>{for(var t in e)ae(r,t,{get:e[t],enumerable:!0})},Me=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of tt(e))!st.call(r,i)&&i!==t&&ae(r,i,{get:()=>e[i],enumerable:!(s=Ae(e,i))||s.enumerable});return r};var nt=(r,e,t)=>(t=r!=null?et(rt(r)):{},Me(e||!r||!r.__esModule?ae(t,"default",{value:r,enumerable:!0}):t,r)),ot=r=>Me(ae({},"__esModule",{value:!0}),r),S=(r,e,t,s)=>{for(var i=s>1?void 0:s?Ae(e,t):e,a=r.length-1,o;a>=0;a--)(o=r[a])&&(i=(s?o(e,t,i):o(i))||i);return s&&i&&ae(e,t,i),i};var Tt={};it(Tt,{AdMode:()=>M,AppMode:()=>ce,BrandSpecials:()=>me,DEFAULT_PAGE_SIZE:()=>pe,IntendedDisplay:()=>ge,JaneDM:()=>R,JaneDeviceIdSentinel:()=>de,PageContextEnum:()=>he,Placement:()=>I,ProductKindEnum:()=>fe,ReviewSortEnum:()=>Re,SearchSortEnum:()=>ue,SmartSort:()=>A,SmartSortProduct:()=>k,Specials:()=>le,VirtualBudtenderProduct:()=>Pe,bestSellerRank:()=>O,categoryAndNameAsc:()=>B,defaultOrder:()=>E,priceAsc:()=>j,priceDesc:()=>U,priceEighthOunceAsc:()=>V,priceEighthOunceDesc:()=>N,priceGramAsc:()=>G,priceGramDesc:()=>Q,priceHalfGramAsc:()=>z,priceHalfGramDesc:()=>J,priceHalfOunceAsc:()=>L,priceHalfOunceDesc:()=>H,priceOunceAsc:()=>K,priceOunceDesc:()=>$,priceQuarterOunceAsc:()=>W,priceQuarterOunceDesc:()=>Z,priceTwoGramAsc:()=>X,priceTwoGramDesc:()=>Y,rating:()=>ee,recommendation:()=>te,searchSorts:()=>Ie,thcPotencyAsc:()=>re,thcPotencyDesc:()=>se});module.exports=ot(Tt);var P={click:"/v2/event/2",externalCheckout:"/v2/event/3e",facets:"/v2/facets",fingerprint:"/fp/token",impression:"/v2/event/1",multi:"/v2/multi",page:"/v2/smartpage",product:"/v2/product",productReviews:"/v2/product/reviews",sessionEvent:"/v2/event/session",smart:"/v2/smart",virtualBudtenderQueries:"/v2/virtual-budtender/queries",virtualBudtenderSearch:"/v2/virtual-budtender"};var M=(s=>(s.All="all",s.Default="default",s.Off="off",s))(M||{}),ce=(c=>(c.Bloom="bloom",c.Default="default",c.Embedded="embedded",c.FramelessEmbed="framelessEmbed",c.Headless="headless",c.Kiosk="kiosk",c.OperatorEmbed="operatorEmbed",c.WhiteLabel="whiteLabel",c))(ce||{}),ge=(s=>(s.Desktop="desktop",s.Kiosk="kiosk",s.Mobile="mobile",s))(ge||{}),de=(e=>(e.UserOptOut="user-opt-out",e))(de||{});var he=(t=>(t.Featured="featured",t.Midgrid="midgrid",t))(he||{}),I=(u=>(u.BestSelling="best_selling",u.BrandSpecials="brand_specials",u.BuyAgainRow="buy_again_row",u.CartToppers="cart_toppers",u.CustomImageRow="custom_image_row",u.FeaturedRow="featured_row",u.MenuDynamicRow="menu_dynamic_row",u.MenuInline="menu_inline",u.MenuInlineTable="menu_inline_table",u.MenuTopRow="menu_top_row",u.PdpRow="pdp_row",u.Sale="sale",u.Specials="specials",u.VirtualBudtenderSearch="virtual_budtender_search",u))(I||{}),fe=(d=>(d.Edible="edible",d.Extract="extract",d.Flower="flower",d.Gear="gear",d.Grow="grow",d.Merch="merch",d.PreRoll="pre-roll",d.Tincture="tincture",d.Topical="topical",d.Vape="vape",d))(fe||{}),Re=(s=>(s.Rating="rating",s.Recent="recent",s.Upvote="upvote",s))(Re||{}),ue=(h=>(h.BestSellerRank="best-seller-rank",h.CategoryAndNameAsc="category-and-name-asc",h.Default="default",h.PriceAsc="price-asc",h.PriceDesc="price-desc",h.PriceEighthOunceAsc="price-eighth-ounce-asc",h.PriceEighthOunceDesc="price-eighth-ounce-desc",h.PriceGramAsc="price-gram-asc",h.PriceGramDesc="price-gram-desc",h.PriceHalfGramAsc="price-half-gram-asc",h.PriceHalfGramDesc="price-half-gram-desc",h.PriceHalfOunceAsc="price-half-ounce-asc",h.PriceHalfOunceDesc="price-half-ounce-desc",h.PriceOunceAsc="price-ounce-asc",h.PriceOunceDesc="price-ounce-desc",h.PriceQuarterOunceAsc="price-quarter-ounce-asc",h.PriceQuarterOunceDesc="price-quarter-ounce-desc",h.PriceTwoGramAsc="price-two-gram-asc",h.PriceTwoGramDesc="price-two-gram-desc",h.Rating="rating",h.Recommendation="recommendation",h.ThcPotencyAsc="thc-potency-asc",h.ThcPotencyDesc="thc-potency-desc",h))(ue||{});var pe=50;var O="best-seller-rank",B="category-and-name-asc",E="default",j="price-asc",U="price-desc",V="price-eighth-ounce-asc",N="price-eighth-ounce-desc",G="price-gram-asc",Q="price-gram-desc",z="price-half-gram-asc",J="price-half-gram-desc",L="price-half-ounce-asc",H="price-half-ounce-desc",K="price-ounce-asc",$="price-ounce-desc",W="price-quarter-ounce-asc",Z="price-quarter-ounce-desc",X="price-two-gram-asc",Y="price-two-gram-desc",ee="rating",te="recommendation",re="thc-potency-asc",se="thc-potency-desc",Ie=[O,B,E,j,U,V,N,G,Q,z,J,L,H,K,$,W,Z,X,Y,ee,te,re,se];var Be="2.24.1";var ve=(r,e)=>{let{apiKey:t,source:s}=e,i=new URL(r);return i.searchParams.set("jdm_source",s),i.searchParams.set("jdm_version",Be),t&&i.searchParams.set("jdm_api_key",t),i.searchParams.sort(),i.toString()},f=(r,e,t)=>{let s=new URL(r+e);return ve(s.toString(),t)},v=(r,e)=>{let t=new URL(r+P.click),s=new URL(r+P.impression);return{clickEndpoint:ve(t.toString(),e),impressionEndpoint:ve(s.toString(),e)}},xe=class extends Error{response;constructor(e,t){super(e),this.response=t}},Ee=async r=>{if(r.ok){if(r.status===204)return null}else throw new xe("Api Request Failed",r);try{return await r.json()}catch{}},at=async(r,e)=>{let t=await fetch(r,{body:JSON.stringify(e),headers:{Accept:"application/json","Content-Type":"text/plain"},method:"POST"});return Ee(t)},ct=async(r,e={})=>{let{headers:t,...s}=e,i=await fetch(r,{...s,headers:{Accept:"application/json",...t},method:"GET"});return Ee(i)},g={get:ct,post:at};var ke=require("nanoid");var x=()=>typeof window<"u"&&typeof document<"u";var dt=(...r)=>{console.error("[JaneDmSDK]",...r)},ut=(...r)=>{console.info("[JaneDmSDK]",...r)},pt=(...r)=>{console.log("[JaneDmSDK]",...r)},C={error:dt,info:ut,log:pt};var mt=r=>{let e=localStorage.getItem(r);return e!==null?gt(e):e},lt=(r,e)=>localStorage.setItem(r,ht(e)),Pt=r=>localStorage.removeItem(r),q={get:mt,remove:Pt,set:lt},gt=r=>je(r)?r.substring(1,r.length-1):r,ht=r=>je(r)?r:`"${r}"`,je=r=>{let t=r.length-1;return r[0]==='"'&&r[t]==='"'};var De="j_fp_last_run",ft=1440*60*1e3,Rt=20,Ce=new Set,St=(r,e)=>`${r}:${e.apiKey}:${e.source}`;var _t=r=>typeof r=="object"&&r!==null&&typeof r.token=="string"&&typeof r.endpoint=="string"&&typeof r.scriptUrlPattern=="string",yt=async(r,e)=>{try{let t=f(r,P.fingerprint,e),s=await g.get(t);return _t(s)?s:null}catch(t){return C.error("Failed to fetch fingerprint token:",t),null}},bt=async(r,e,t,s)=>{try{let i=await import("@fingerprintjs/fingerprintjs-pro"),o=await i.load({apiKey:r,endpoint:[e,i.defaultEndpoint],region:"us",scriptUrlPattern:[t,i.defaultScriptUrlPattern],storageKey:"eyeD"}),n={tag:{isDmSdk:!0}};s?.linkedId&&(n.linkedId=s.linkedId);let c=await o.get(n);return!c||!c.visitorId?(C.error("Fingerprint JS did not return a valid visitorId"),null):{visitorId:c.visitorId}}catch(i){return C.error("Failed to run Fingerprint JS:",i),null}},Ue=async(r,e,t)=>{if(!x())return(0,ke.nanoid)();let s=q.get("jdid");if(!s)return await Ge(r,e,t)??(0,ke.nanoid)();if(s.length!==Rt)return await Fe(r,e,{linkedId:s}),s;let i=await Ne(r,e,t);if(i)return i;if(Ve()==="error")try{q.set(De,Date.now().toString())}catch{}return s},Ve=()=>{try{let r=q.get(De);if(!r)return"missing";let e=parseInt(r,10);return Number.isNaN(e)?"missing":Date.now()-e>=ft?"expired":"valid"}catch{return"error"}},Ne=async(r,e,t)=>{let s=Ve();return s==="valid"||s==="error"?null:Ge(r,e,t)},Ge=async(r,e,t)=>{let s=St(r,e);if(Ce.has(s))return null;Ce.add(s);try{let i=await yt(r,e);if(!i)return null;let a=await bt(i.token,i.endpoint,i.scriptUrlPattern,t);if(!a)return null;try{q.set(De,Date.now().toString())}catch{}return a.visitorId}catch(i){return C.error("Failed to run fingerprint:",i),null}finally{Ce.delete(s)}},Fe=async(r,e,t)=>{if(x()&&t?.linkedId!=="user-opt-out")try{await Ne(r,e,t)}catch(s){C.error("Failed to run SSR fingerprint:",s)}};var w=class r extends Error{constructor(e){super(`[Jane DM SDK]: ${e}`),this.name="SdkError",Object.setPrototypeOf(this,r.prototype)}};var Te=r=>{switch(r){case O:return"best-seller-rank";case B:return"category-and-name-asc";case j:return"price-asc";case U:return"price-desc";case V:return"price-eighth-ounce-asc";case N:return"price-eighth-ounce-desc";case G:return"price-gram-asc";case Q:return"price-gram-desc";case z:return"price-half-gram-asc";case J:return"price-half-gram-desc";case L:return"price-half-ounce-asc";case H:return"price-half-ounce-desc";case K:return"price-ounce-asc";case $:return"price-ounce-desc";case W:return"price-quarter-ounce-asc";case Z:return"price-quarter-ounce-desc";case X:return"price-two-gram-asc";case Y:return"price-two-gram-desc";case ee:return"rating";case te:return"recommendation";case re:return"thc-potency-asc";case se:return"thc-potency-desc";case E:default:return"default"}};var ie=r=>JSON.parse(r);var qe=class r{isSponsored;objectId;clickPayload;clickUrl;impressPayload;impressUrl;constructor(e){this.objectId=e.objectId,this.impressUrl=e.impressUrl,this.impressPayload=e.impressPayload,this.clickPayload=e.clickPayload,this.clickUrl=e.clickUrl,this.isSponsored=e.isSponsored}static fromJSON(e){return new r(ie(e))}serialize(){return{clickPayload:this.clickPayload,clickUrl:this.clickUrl,impressPayload:this.impressPayload,impressUrl:this.impressUrl,isSponsored:this.isSponsored,objectId:this.objectId}}toJSON(){return JSON.stringify(this.serialize())}},k=class r{attributes;isSponsored;objectId;clickPayload;clickUrl;hasBeenImpressed;impressPayload;impressPromise;impressUrl;constructor(e){this.objectId=e.objectId,this.attributes=e.attributes,this.impressUrl=e.impressUrl,this.impressPayload=e.impressPayload,this.clickPayload=e.clickPayload,this.clickUrl=e.clickUrl,this.isSponsored=e.isSponsored,this.hasBeenImpressed=e.hasBeenImpressed??!1}static fromJSON(e){return new r(ie(e))}click(e={isAddToCart:!1}){let{isAddToCart:t=!1}=e,s={...this.clickPayload,isAddToCart:t};return g.post(this.clickUrl,s)}impress(){return this.hasBeenImpressed?Promise.resolve():(this.impressPromise??=g.post(this.impressUrl,this.impressPayload).then(()=>{this.hasBeenImpressed=!0}).finally(()=>{this.impressPromise=void 0}),this.impressPromise)}serialize(){return{attributes:this.attributes,clickPayload:this.clickPayload,clickUrl:this.clickUrl,hasBeenImpressed:this.hasBeenImpressed,impressPayload:this.impressPayload,impressUrl:this.impressUrl,isSponsored:this.isSponsored,objectId:this.objectId}}toJSON(){return JSON.stringify(this.serialize())}},A=class r{customImages;placement;products;rowId;searchFacets;title;totalProducts;creativeIds;cachedProducts;config;loadPromise;nextPageProps;nextPageUrl;constructor(e){this.rowId=e.rowId,this.searchFacets=e.searchFacets,this.nextPageUrl=e.nextPageUrl,this.nextPageProps=e.nextPageProps,this.products=e.products.map(t=>new k(t)),this.cachedProducts=e.cachedProducts.map(t=>new qe(t)),this.totalProducts=e.totalProducts,this.title=e.title,this.creativeIds=e.creativeIds,this.config=e.config,this.customImages=e.customImages??[],this.placement=e.placement,x()&&!this.config.skipAutoSmartSortOnLoad&&this.onLoad().catch(t=>C.error("Failed to run onLoad:",t))}static fromJSON(e){return new r(ie(e))}hasNextPage(){return this.cachedProducts.length>0}async nextPage(){if(!this.hasNextPage())return;let e=this.cachedProducts.slice(0,this.nextPageProps.pageSize),t={app_mode:this.config.appMode,jane_device_id:this.config.identifier.jdid,object_ids:e.map(a=>a.objectId),search_attributes:this.nextPageProps.searchAttributes},s=await g.post(this.nextPageUrl,t),i=new Map(s.products?.map(a=>[a.object_id,a.search_attributes]));e.forEach(a=>{let o=i.get(a.objectId);o!==void 0&&this.products.push(new k({...a.serialize(),attributes:o}))}),this.cachedProducts=this.cachedProducts.slice(this.nextPageProps.pageSize)}async onLoad(){return this.loadPromise?this.loadPromise:(this.loadPromise=(async()=>{if(!x())return;let e={apiKey:this.config.apiKey,source:this.config.source};await Fe(this.config.eventsEndpoint,e,{linkedId:this.config.identifier.jdid})})(),this.loadPromise)}serialize(){return{cachedProducts:this.cachedProducts.map(e=>e.serialize()),config:this.config,creativeIds:this.creativeIds,customImages:this.customImages,nextPageProps:this.nextPageProps,nextPageUrl:this.nextPageUrl,placement:this.placement,products:this.products.map(e=>e.serialize()),rowId:this.rowId,searchFacets:this.searchFacets,title:this.title,totalProducts:this.totalProducts}}toJSON(){return JSON.stringify(this.serialize())}},ne=class{async createSmartSort(e){let t={apiKey:e.config.apiKey,source:e.config.source},s=f(e.config.endpoint,P.smart,t),i=f(e.config.pageEndpoint,P.page,t),a=this.buildSmartRequest(e),o=await g.post(s,a),{clickEndpoint:n,impressionEndpoint:c}=v(e.config.eventsEndpoint,t),{creative_ids:m,custom_images:d,products:l,row_id:p,search_facets:b,title:u}=o,{cachedProducts:D,products:F}=this.generateProducts({clickUrl:n,identifier:e.config.identifier,impressUrl:c,products:l}),T=(d??[]).map(oe=>this.massageCustomImageData(oe)).filter(oe=>oe!==void 0);return new A({cachedProducts:D,config:e.config,creativeIds:m,customImages:T,nextPageProps:{pageSize:"page_size"in a?a.page_size??60:60,searchAttributes:a.search_attributes??e.searchAttributes},nextPageUrl:i,placement:e.placement,products:F,rowId:p,searchFacets:b,title:u,totalProducts:o.nb_hits??0})}generateProducts(e){let{clickUrl:t,identifier:s,impressUrl:i,products:a}=e,o={cachedProducts:[],products:[]};return a?.forEach(n=>{let c={clickPayload:{adToken:n.ad_token,distinctId:s.mixpanelDistinctId??s.jdid,isAddToCart:!1,janeDeviceId:s.jdid,kevelToken:n.kevel_token,myHighD:n.my_high_d,productId:n.product_id,storeId:n.store_id},clickUrl:t,impressPayload:{distinctId:s.mixpanelDistinctId??s.jdid,engagements:[{adToken:n.ad_token,kevelToken:n.kevel_token,myHighD:n.my_high_d,productId:n.product_id}],janeDeviceId:s.jdid},impressUrl:i,isSponsored:!!n.flight_id,objectId:n.object_id};n.search_attributes!==void 0?o.products.push({...c,attributes:n.search_attributes}):o.cachedProducts.push(c)}),o}massageCustomImageData(e){if(e)return{headline:e.headline,imageUrl:e.image_url,intendedDisplay:e.intended_display,logoUrl:e.logo_url,overlayColor:e.overlay_color,positionX:e.position_x,positionY:e.position_y,scaleNumber:e.scale_number,textColor:e.text_color}}buildSmartRequest(e){let{config:t,searchAttributes:s,...i}=e,a={app_mode:t.appMode,distinct_id:t.identifier.mixpanelDistinctId,jane_device_id:t.identifier.jdid,pos_user_id:t.identifier.posUserId,search_attributes:s,user_id:t.identifier.userId};switch(i.placement){case"cart_toppers":{let{cartProductIds:o,posCartProductIds:n,storeId:c}=i;return{...a,cart_pos_product_ids:n,cart_product_ids:o,placement:"cart_toppers",store_id:c}}case"custom_image_row":{let{searchFilter:o,storeId:n}=i;return{...a,placement:"custom_image_row",search_filter:o,store_id:n}}case"menu_dynamic_row":{let{adMode:o,filterContext:n,pageContext:c,storeId:m}=i;return{...a,ad_mode:o??"default",filter_context:n,page_context:c,placement:"menu_dynamic_row",store_id:m}}case"menu_inline":{let{adMode:o,distinctByProduct:n,metadata:c,numColumns:m,searchFilter:d,searchQuery:l,searchSort:p,storeId:b,storeIds:u}=i;return{...a,ad_mode:o??"default",distinct_by_product:n,metadata:c,num_columns:m,placement:"menu_inline",search_filter:d,search_query:l,search_sort:Te(p),store_ids:u||[b]}}case"menu_inline_table":{let{disableAds:o,distinctByProduct:n,maxProducts:c,metadata:m,numColumns:d,pageSize:l,searchFacets:p,searchFilter:b,searchQuery:u,searchSort:D,storeId:F,storeIds:T}=i;return{...a,disable_ads:o,distinct_by_product:n,max_products:c,metadata:m,num_columns:d,page_size:l,placement:"menu_inline_table",search_attributes:s,search_facets:p,search_filter:b,search_query:u,search_sort:Te(D),store_ids:T||[F]}}case"menu_top_row":{let{searchFilter:o,storeId:n}=i,c=this.extractValidCreativeIds(e);return{...a,exclude_creative_ids:c,placement:"menu_top_row",search_filter:o,store_id:n}}case"pdp_row":{let{posProductId:o,productId:n,storeId:c}=i;return{...a,placement:"pdp_row",pos_product_id:o,product_id:n,store_id:c}}default:throw new w(`Invalid Smart Sort Placement: ${i.placement}`)}}extractValidCreativeIds(e){if(e.placement==="menu_top_row"&&"excludeCreativeIds"in e&&Array.isArray(e.excludeCreativeIds))return e.excludeCreativeIds.filter(t=>typeof t=="number")}};var wt=r=>r.placement==="specials",It=r=>r.placement==="brand_specials",me=class{placement;title;constructor(e){this.title=e,this.placement="brand_specials"}},le=class{placement;title;constructor(e){this.title=e,this.placement="specials"}},Se=class extends ne{async createMultiPlacement(e){let t={apiKey:e.config.apiKey,source:e.config.source},s=f(e.config.endpoint,P.multi,t),i=f(e.config.pageEndpoint,P.page,t),a=this.buildMultiRequest(e),o=await g.post(s,a),{clickEndpoint:n,impressionEndpoint:c}=v(e.config.eventsEndpoint,t),m=[];for(let[d,l]of(o.placements||[]).entries())if(wt(l))m.push(new le(l.title));else if(It(l))m.push(new me(l.title));else{let{creative_ids:p,custom_images:b,placement:u,products:D,row_id:F,search_facets:T,title:oe}=l,{cachedProducts:Ze,products:Xe}=this.generateProducts({clickUrl:n,identifier:e.config.identifier,impressUrl:c,products:D}),Ye=(b??[]).map(we=>this.massageCustomImageData(we)).filter(we=>we!==void 0);m.push(new A({cachedProducts:Ze,config:{...e.config,skipAutoSmartSortOnLoad:d===0?e.config.skipAutoSmartSortOnLoad:!0},creativeIds:p,customImages:Ye,nextPageProps:{pageSize:60,searchAttributes:a.search_attributes||[]},nextPageUrl:i,placement:u,products:Xe,rowId:F,searchFacets:T,title:oe,totalProducts:l.nb_hits??0}))}return m}buildMultiRequest(e){let{config:t,numColumns:s,searchAttributes:i,storeId:a,...o}=e,n={app_mode:t.appMode,distinct_id:t.identifier.mixpanelDistinctId,jane_device_id:t.identifier.jdid,num_columns:s,pos_user_id:t.identifier.posUserId,search_attributes:i,store_id:a,user_id:t.identifier.userId};switch(o.multiRequestType){case"custom":return{...n,placements:this.massageCustomPlacements(o.placements),type:"custom"};case"featured":return{...n,exclude_menu_top_row:o.excludeMenuTopRow??!1,type:"featured"};default:throw new w(`Invalid Multi Type: ${o.multiRequestType}`)}}massageCustomPlacements(e){let t=[];for(let s of e)switch(s.placement){case"best_selling":t.push({placement:"best_selling",title:s.title});break;case"brand_specials":t.push({placement:"brand_specials",title:s.title});break;case"buy_again_row":t.push({placement:"buy_again_row",title:s.title});break;case"custom_image_row":t.push({placement:"custom_image_row",search_filter:s.searchFilter});break;case"featured_row":t.push({placement:"featured_row",row_id:s.rowId});break;case"menu_dynamic_row":t.push({ad_mode:s.adMode??"default",filter_context:s.filterContext,page_context:s.pageContext,placement:"menu_dynamic_row"});break;case"menu_inline":t.push({ad_mode:s.adMode??"default",metadata:s.metadata,placement:"menu_inline",search_filter:s.searchFilter,search_query:s.searchQuery,search_sort:s.searchSort,title:s.title});break;case"menu_inline_table":t.push({disable_ads:s.disableAds,max_products:s.maxProducts,metadata:s.metadata,page_size:s.pageSize,placement:"menu_inline_table",search_facets:s.searchFacets,search_filter:s.searchFilter,search_query:s.searchQuery,search_sort:s.searchSort,title:s.title});break;case"menu_top_row":t.push({placement:"menu_top_row",search_filter:s.searchFilter});break;case"sale":t.push({placement:"sale",title:s.title});break;case"specials":t.push({placement:"specials",title:s.title});break;default:throw new w(`Invalid Custom Placement: ${s.placement}`)}return t}};var We=require("nanoid");var Qe=async r=>{let{apiKey:e,appMode:t,endpoint:s,identifier:i,searchFacets:a,searchFilter:o,searchQuery:n,source:c,storeId:m}=r,{jdid:d}=i||{},l=f(s,P.facets,{apiKey:e,source:c}),p={appMode:t,janeDeviceId:d,searchFacets:a,searchFilter:o,searchQuery:n,storeId:m};return(await g.post(l,p)).searchFacets??{}};var ze=async r=>{let{apiKey:e,endpoint:t,identifier:s,source:i,storeId:a,...o}=r,n=f(t,P.externalCheckout,{apiKey:e,source:i}),c={janeDeviceId:s.jdid,posOrderId:o.posOrderId,posUserId:o.posUserId||s.posUserId,products:o.products,storeId:a};return await g.post(n,c)};var _e=class{async create(e){let{config:t,searchAttributes:s,storeId:i,...a}=e,o={apiKey:t.apiKey,source:t.source},n=f(t.endpoint,P.product,o),{clickEndpoint:c,impressionEndpoint:m}=v(t.eventsEndpoint,o),d={app_mode:t.appMode,distinct_id:t.identifier.mixpanelDistinctId,jane_device_id:t.identifier.jdid,pos_user_id:t.identifier.posUserId,search_attributes:s,store_id:i,user_id:t.identifier.userId},l=a.productId!==void 0?{...d,product_id:a.productId}:{...d,pos_product_id:a.posProductId},p=await g.post(n,l);return new k({attributes:p.search_attributes,clickPayload:{adToken:p.ad_token,distinctId:t.identifier.mixpanelDistinctId,isAddToCart:!1,janeDeviceId:t.identifier.jdid,kevelToken:p.kevel_token,myHighD:p.my_high_d,productId:p.product_id,storeId:i},clickUrl:c,impressPayload:{distinctId:t.identifier.mixpanelDistinctId??t.identifier.jdid,engagements:[{adToken:p.ad_token,kevelToken:p.kevel_token,myHighD:p.my_high_d,productId:p.product_id}],janeDeviceId:t.identifier.jdid},impressUrl:m,isSponsored:!!p.flight_id,objectId:p.object_id})}};var vt=r=>({activities:r.activities,avatar:r.avatar,comment:r.comment,createdAt:r.created_at,feelings:r.feelings,hasComment:r.has_comment,id:r.id,nickname:r.nickname,productId:r.product_id,rating:r.rating,storeId:r.store_id,storeName:r.store_name,updatedAt:r.updated_at,upvoteCount:r.upvote_count}),xt=r=>({activitiesDistribution:r.activities_distribution,averageRating:r.average_rating,distribution:r.distribution,feelingsDistribution:r.feelings_distribution,reviewCount:r.review_count}),Ct=(r,e,t)=>{let s=r.total_count,i=Math.max(1,Math.ceil(s/t));return{aggregate:xt(r.aggregate),items:r.reviews.map(vt),pagination:{currentPage:e,hasNextPage:e<i,hasPreviousPage:e>1,pageSize:t,totalCount:s,totalPages:i},productId:r.product_id}},Je=async r=>{let{activities:e,config:t,feelings:s,hasComment:i,page:a,pageSize:o,productId:n,ratings:c,sort:m}=r,d=a??1,l=o??50,p=f(t.endpoint,P.productReviews,{apiKey:t.apiKey,source:t.source}),b={activities:e,feelings:s,has_comment:i||void 0,page:a,page_size:o,product_id:n,ratings:c,sort:m},u=await g.post(p,b);return Ct(u,d,l)},Le=r=>{let e={[Symbol.asyncIterator]:async function*(){let t=1;for(;;){let s=await r(t);if(yield s,!s.pagination.hasNextPage)return;t+=1}}};return{pages:e,[Symbol.asyncIterator]:async function*(){for await(let t of e)yield*t.items}}};var He=async r=>{let{apiKey:e,eventsEndpoint:t,identifier:s,source:i,...a}=r,o=f(t,P.sessionEvent,{apiKey:e,source:i}),n={distinctId:s.mixpanelDistinctId,events:a.events,janeDeviceId:s.jdid};return await g.post(o,n)};function _(r,e,t){let s=t.value;if(!s)throw new Error("Decorator applied to invalid method descriptor");return t.value=async function(...i){return await this.init(),s.apply(this,i)},t}function y(r,e,t){let s=t.value;if(!s)throw new Error("Decorator applied to invalid method descriptor");return t.value=async function(...i){if(!this.rateLimiter)throw new Error("throttle decorator can only be used on JaneDM class methods");return this.rateLimiter.schedule(async()=>s.apply(this,i))},t}var ye=class{burst;intervalMs;rate;tat=0;toleranceMs;constructor(e,t=1){if(e<=0)throw new w("rate must be > 0");if(t<1)throw new w("burst must be >= 1");this.rate=e,this.burst=Math.floor(t),this.intervalMs=1e3/this.rate,this.toleranceMs=(this.burst-1)*this.intervalMs}async schedule(e){let t=Date.now(),s=Math.max(0,this.tat-this.toleranceMs-t);this.tat=Math.max(this.tat,t)+this.intervalMs;let i=async()=>e();return s>0?new Promise((a,o)=>setTimeout(()=>i().then(a).catch(o),s)):i()}};var kt=/^https?:\/\//,Dt=/^(https?:\/\/)?(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}|localhost)(:\d+)?(\/.*)?$/,be=(r,e)=>{let s=kt.test(r??e)?r??e:`https://${r}`,i=new URL(s);return Dt.test(i.toString())?i.protocol+"//"+i.host:e};var Ke=async r=>{let{apiKey:e,appMode:t,endpoint:s,identifier:i,source:a,storeId:o}=r,{jdid:n}=i;if(!n)throw new w("Jane Device ID (jdid) is required to fetch virtual budtender queries");let c=f(s,P.virtualBudtenderQueries,{apiKey:e,source:a}),m={appMode:t,janeDeviceId:n,storeId:o};return(await g.post(c,m)).queries??[]},$e=async r=>{let{apiKey:e,appMode:t,endpoint:s,eventsEndpoint:i,identifier:a,query:o,searchAttributes:n,source:c,storeId:m}=r,{jdid:d}=a;if(!d)throw new w("Jane Device ID (jdid) is required to perform virtual budtender search");let l={apiKey:e,source:c},p=f(s,P.virtualBudtenderSearch,l),b={app_mode:t,jane_device_id:d,placement:"virtual_budtender_search",query:o,search_attributes:n,store_id:m},u=await g.post(p,b),{clickEndpoint:D,impressionEndpoint:F}=v(i,l),T=Ft({clickUrl:D,identifier:a,impressUrl:F,products:u.products??[],storeId:m});return{htmlResponse:u.htmlResponse,markdownResponse:u.markdownResponse,products:T,query:u.query,totalResults:u.totalResults??0,unformattedResponse:u.unformattedResponse}},Pe=class r{attributes;isSponsored;objectId;reasoning;score;clickPayload;clickUrl;hasBeenImpressed;impressPayload;impressPromise;impressUrl;constructor(e){this.objectId=e.objectId,this.attributes=e.attributes,this.impressUrl=e.impressUrl,this.impressPayload=e.impressPayload,this.clickPayload=e.clickPayload,this.clickUrl=e.clickUrl,this.isSponsored=e.isSponsored,this.hasBeenImpressed=e.hasBeenImpressed??!1,this.score=e.score,this.reasoning=e.reasoning}static fromJSON(e){return new r(ie(e))}click(e={isAddToCart:!1}){let{isAddToCart:t=!1}=e,s={...this.clickPayload,isAddToCart:t};return g.post(this.clickUrl,s)}impress(){return this.hasBeenImpressed?Promise.resolve():(this.impressPromise??=g.post(this.impressUrl,this.impressPayload).then(()=>{this.hasBeenImpressed=!0}).finally(()=>{this.impressPromise=void 0}),this.impressPromise)}serialize(){return{attributes:this.attributes,clickPayload:this.clickPayload,clickUrl:this.clickUrl,hasBeenImpressed:this.hasBeenImpressed,impressPayload:this.impressPayload,impressUrl:this.impressUrl,isSponsored:this.isSponsored,objectId:this.objectId,reasoning:this.reasoning,score:this.score}}toJSON(){return JSON.stringify(this.serialize())}},Ft=r=>{let{clickUrl:e,identifier:t,impressUrl:s,products:i,storeId:a}=r,o=[];return i?.forEach(n=>{let c={attributes:n.search_attributes,clickPayload:{adToken:n.ad_token,distinctId:t.mixpanelDistinctId??t.jdid,isAddToCart:!1,janeDeviceId:t.jdid,kevelToken:n.kevel_token,myHighD:n.my_high_d,productId:n.product_id,storeId:a},clickUrl:e,impressPayload:{distinctId:t.mixpanelDistinctId??t.jdid,engagements:[{adToken:n.ad_token,kevelToken:n.kevel_token,myHighD:n.my_high_d,productId:n.product_id}],janeDeviceId:t.jdid},impressUrl:s,isSponsored:!!n.flight_id,objectId:n.object_id,reasoning:n.reasoning,score:n.score};o.push(new Pe(c))}),o};var R=class{config;rateLimiter;initialized=!1;multiClient;productClient;smartSortClient;userProvidedJdid=!1;constructor(e,t){let{apiKey:s,endpoint:i,identifier:a}=e,{appMode:o="headless",eventsEndpoint:n,pageEndpoint:c,skipAutoSmartSortOnLoad:m=!1,source:d="sdk"}=t??{},l=be(i,"https://dmerch.iheartjane.com"),p=be(n,l),b=be(c,l);this.userProvidedJdid=!!a?.jdid,this.config={apiKey:s,appMode:o,endpoint:l,eventsEndpoint:p,identifier:a??{jdid:""},pageEndpoint:b,skipAutoSmartSortOnLoad:m,source:d},this.smartSortClient=new ne,this.multiClient=new Se,this.productClient=new _e,this.rateLimiter=new ye(10,20)}static generateJaneDeviceId(){return(0,We.nanoid)()}async fetchCartTopperRow(e){return await this.smartSortClient.createSmartSort({...e,config:this.config,placement:"cart_toppers"})}async fetchCustomImageRow(e){return this.smartSortClient.createSmartSort({...e,config:this.config,placement:"custom_image_row"})}async fetchCustomPlacements(e){return await this.multiClient.createMultiPlacement({config:this.config,multiRequestType:"custom",...e})}async fetchFacets(e){return Qe({...e,...this.config})}async fetchFeaturedPlacements(e){return await this.multiClient.createMultiPlacement({config:this.config,multiRequestType:"featured",...e})}async fetchMenuRow(e){return this.smartSortClient.createSmartSort({...e,config:this.config,placement:"menu_inline"})}async fetchMenuTopRow(e){return this.smartSortClient.createSmartSort({...e,config:this.config,placement:"menu_top_row"})}async fetchProduct(e){return this.productClient.create({config:this.config,...e})}async fetchProductReviews(e){return Je({config:this.config,...e})}async fetchRecommendedPDPRow(e){return await this.smartSortClient.createSmartSort({...e,config:this.config,placement:"pdp_row"})}async fetchRecommendedRow(e){return await this.smartSortClient.createSmartSort({...e,config:this.config,placement:"menu_dynamic_row"})}async fetchRecommendedSort(e){return await this.smartSortClient.createSmartSort({...e,config:this.config,placement:"menu_inline_table"})}async fetchVirtualBudtenderQueries(e){return Ke({...e,...this.config})}async fetchVirtualBudtenderSearch(e){return $e({...e,...this.config})}getJaneDeviceId(){return this.config.identifier.jdid}async init(){this.initialized||(x()&&!this.userProvidedJdid&&await this.initializeClientSideJdid(),this.initialized=!0)}iterateProductReviews(e){return Le(t=>this.fetchProductReviews({...e,page:t}))}async sendPosCheckout(e){return ze({...e,...this.config})}async sendSessionEvent(e){return He({...e,...this.config})}async initializeClientSideJdid(){let e={apiKey:this.config.apiKey,source:this.config.source},t=await Ue(this.config.eventsEndpoint,e);q.set("jdid",t),this.config.identifier.jdid=t}};S([_,y],R.prototype,"fetchCartTopperRow",1),S([_,y],R.prototype,"fetchCustomImageRow",1),S([_,y],R.prototype,"fetchCustomPlacements",1),S([_,y],R.prototype,"fetchFacets",1),S([_,y],R.prototype,"fetchFeaturedPlacements",1),S([_,y],R.prototype,"fetchMenuRow",1),S([_,y],R.prototype,"fetchMenuTopRow",1),S([_,y],R.prototype,"fetchProduct",1),S([_,y],R.prototype,"fetchProductReviews",1),S([_,y],R.prototype,"fetchRecommendedPDPRow",1),S([_,y],R.prototype,"fetchRecommendedRow",1),S([_,y],R.prototype,"fetchRecommendedSort",1),S([_,y],R.prototype,"fetchVirtualBudtenderQueries",1),S([_,y],R.prototype,"fetchVirtualBudtenderSearch",1);0&&(module.exports={AdMode,AppMode,BrandSpecials,DEFAULT_PAGE_SIZE,IntendedDisplay,JaneDM,JaneDeviceIdSentinel,PageContextEnum,Placement,ProductKindEnum,ReviewSortEnum,SearchSortEnum,SmartSort,SmartSortProduct,Specials,VirtualBudtenderProduct,bestSellerRank,categoryAndNameAsc,defaultOrder,priceAsc,priceDesc,priceEighthOunceAsc,priceEighthOunceDesc,priceGramAsc,priceGramDesc,priceHalfGramAsc,priceHalfGramDesc,priceHalfOunceAsc,priceHalfOunceDesc,priceOunceAsc,priceOunceDesc,priceQuarterOunceAsc,priceQuarterOunceDesc,priceTwoGramAsc,priceTwoGramDesc,rating,recommendation,searchSorts,thcPotencyAsc,thcPotencyDesc});