@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.
- package/dist/chunk-VEW5EGZ2.js +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +1181 -0
- package/dist/index.d.ts +1181 -0
- package/dist/index.js +1 -0
- package/dist/smartSort-DJFM0D_n.d.cts +1075 -0
- package/dist/smartSort-DJFM0D_n.d.ts +1075 -0
- package/dist/test-utils.cjs +1 -0
- package/dist/test-utils.d.cts +189 -0
- package/dist/test-utils.d.ts +189 -0
- package/dist/test-utils.js +1 -0
- package/package.json +68 -0
- package/test-utils/package.json +4 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as ne,B as ae,C as ce,D as de,E as ue,F as pe,G as le,H as me,I as he,J as Le,a as S,b as l,c as J,d as be,e as Ge,f as we,g as Je,h as A,i as Qe,j as Ke,k as ve,l as Q,m as K,n as L,o as H,p as $,q as W,r as Z,s as X,t as Y,u as ee,v as te,w as re,x as se,y as ie,z as oe}from"./chunk-VEW5EGZ2.js";var ke="2.24.1";var Pe=(r,e)=>{let{apiKey:t,source:s}=e,i=new URL(r);return i.searchParams.set("jdm_source",s),i.searchParams.set("jdm_version",ke),t&&i.searchParams.set("jdm_api_key",t),i.searchParams.sort(),i.toString()},h=(r,e,t)=>{let s=new URL(r+e);return Pe(s.toString(),t)},w=(r,e)=>{let t=new URL(r+l.click),s=new URL(r+l.impression);return{clickEndpoint:Pe(t.toString(),e),impressionEndpoint:Pe(s.toString(),e)}},ge=class extends Error{response;constructor(e,t){super(e),this.response=t}},_e=async r=>{if(r.ok){if(r.status===204)return null}else throw new ge("Api Request Failed",r);try{return await r.json()}catch{}},He=async(r,e)=>{let t=await fetch(r,{body:JSON.stringify(e),headers:{Accept:"application/json","Content-Type":"text/plain"},method:"POST"});return _e(t)},$e=async(r,e={})=>{let{headers:t,...s}=e,i=await fetch(r,{...s,headers:{Accept:"application/json",...t},method:"GET"});return _e(i)},m={get:$e,post:He};import{nanoid as xe}from"nanoid";var v=()=>typeof window<"u"&&typeof document<"u";var We=(...r)=>{console.error("[JaneDmSDK]",...r)},Ze=(...r)=>{console.info("[JaneDmSDK]",...r)},Xe=(...r)=>{console.log("[JaneDmSDK]",...r)},k={error:We,info:Ze,log:Xe};var Ye=r=>{let e=localStorage.getItem(r);return e!==null?rt(e):e},et=(r,e)=>localStorage.setItem(r,st(e)),tt=r=>localStorage.removeItem(r),F={get:Ye,remove:tt,set:et},rt=r=>Ce(r)?r.substring(1,r.length-1):r,st=r=>Ce(r)?r:`"${r}"`,Ce=r=>{let t=r.length-1;return r[0]==='"'&&r[t]==='"'};var Se="j_fp_last_run",it=1440*60*1e3,ot=20,fe=new Set,nt=(r,e)=>`${r}:${e.apiKey}:${e.source}`;var at=r=>typeof r=="object"&&r!==null&&typeof r.token=="string"&&typeof r.endpoint=="string"&&typeof r.scriptUrlPattern=="string",ct=async(r,e)=>{try{let t=h(r,l.fingerprint,e),s=await m.get(t);return at(s)?s:null}catch(t){return k.error("Failed to fetch fingerprint token:",t),null}},dt=async(r,e,t,s)=>{try{let i=await import("@fingerprintjs/fingerprintjs-pro"),n=await i.load({apiKey:r,endpoint:[e,i.defaultEndpoint],region:"us",scriptUrlPattern:[t,i.defaultScriptUrlPattern],storageKey:"eyeD"}),o={tag:{isDmSdk:!0}};s?.linkedId&&(o.linkedId=s.linkedId);let c=await n.get(o);return!c||!c.visitorId?(k.error("Fingerprint JS did not return a valid visitorId"),null):{visitorId:c.visitorId}}catch(i){return k.error("Failed to run Fingerprint JS:",i),null}},Fe=async(r,e,t)=>{if(!v())return xe();let s=F.get("jdid");if(!s)return await Ee(r,e,t)??xe();if(s.length!==ot)return await Re(r,e,{linkedId:s}),s;let i=await Te(r,e,t);if(i)return i;if(De()==="error")try{F.set(Se,Date.now().toString())}catch{}return s},De=()=>{try{let r=F.get(Se);if(!r)return"missing";let e=parseInt(r,10);return Number.isNaN(e)?"missing":Date.now()-e>=it?"expired":"valid"}catch{return"error"}},Te=async(r,e,t)=>{let s=De();return s==="valid"||s==="error"?null:Ee(r,e,t)},Ee=async(r,e,t)=>{let s=nt(r,e);if(fe.has(s))return null;fe.add(s);try{let i=await ct(r,e);if(!i)return null;let a=await dt(i.token,i.endpoint,i.scriptUrlPattern,t);if(!a)return null;try{F.set(Se,Date.now().toString())}catch{}return a.visitorId}catch(i){return k.error("Failed to run fingerprint:",i),null}finally{fe.delete(s)}},Re=async(r,e,t)=>{if(v()&&t?.linkedId!=="user-opt-out")try{await Te(r,e,t)}catch(s){k.error("Failed to run SSR fingerprint:",s)}};var b=class r extends Error{constructor(e){super(`[Jane DM SDK]: ${e}`),this.name="SdkError",Object.setPrototypeOf(this,r.prototype)}};var ye=r=>{switch(r){case K:return"best-seller-rank";case L:return"category-and-name-asc";case $:return"price-asc";case W:return"price-desc";case Z:return"price-eighth-ounce-asc";case X:return"price-eighth-ounce-desc";case Y:return"price-gram-asc";case ee:return"price-gram-desc";case te:return"price-half-gram-asc";case re:return"price-half-gram-desc";case se:return"price-half-ounce-asc";case ie:return"price-half-ounce-desc";case oe:return"price-ounce-asc";case ne:return"price-ounce-desc";case ae:return"price-quarter-ounce-asc";case ce:return"price-quarter-ounce-desc";case de:return"price-two-gram-asc";case ue:return"price-two-gram-desc";case pe:return"rating";case le:return"recommendation";case me:return"thc-potency-asc";case he:return"thc-potency-desc";case H:default:return"default"}};var T=r=>JSON.parse(r);var Ie=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(T(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())}},D=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(T(e))}click(e={isAddToCart:!1}){let{isAddToCart:t=!1}=e,s={...this.clickPayload,isAddToCart:t};return m.post(this.clickUrl,s)}impress(){return this.hasBeenImpressed?Promise.resolve():(this.impressPromise??=m.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())}},E=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 D(t)),this.cachedProducts=e.cachedProducts.map(t=>new Ie(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,v()&&!this.config.skipAutoSmartSortOnLoad&&this.onLoad().catch(t=>k.error("Failed to run onLoad:",t))}static fromJSON(e){return new r(T(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 m.post(this.nextPageUrl,t),i=new Map(s.products?.map(a=>[a.object_id,a.search_attributes]));e.forEach(a=>{let n=i.get(a.objectId);n!==void 0&&this.products.push(new D({...a.serialize(),attributes:n}))}),this.cachedProducts=this.cachedProducts.slice(this.nextPageProps.pageSize)}async onLoad(){return this.loadPromise?this.loadPromise:(this.loadPromise=(async()=>{if(!v())return;let e={apiKey:this.config.apiKey,source:this.config.source};await Re(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())}},j=class{async createSmartSort(e){let t={apiKey:e.config.apiKey,source:e.config.source},s=h(e.config.endpoint,l.smart,t),i=h(e.config.pageEndpoint,l.page,t),a=this.buildSmartRequest(e),n=await m.post(s,a),{clickEndpoint:o,impressionEndpoint:c}=w(e.config.eventsEndpoint,t),{creative_ids:u,custom_images:P,products:p,row_id:d,search_facets:I,title:f}=n,{cachedProducts:_,products:C}=this.generateProducts({clickUrl:o,identifier:e.config.identifier,impressUrl:c,products:p}),x=(P??[]).map(U=>this.massageCustomImageData(U)).filter(U=>U!==void 0);return new E({cachedProducts:_,config:e.config,creativeIds:u,customImages:x,nextPageProps:{pageSize:"page_size"in a?a.page_size??60:60,searchAttributes:a.search_attributes??e.searchAttributes},nextPageUrl:i,placement:e.placement,products:C,rowId:d,searchFacets:I,title:f,totalProducts:n.nb_hits??0})}generateProducts(e){let{clickUrl:t,identifier:s,impressUrl:i,products:a}=e,n={cachedProducts:[],products:[]};return a?.forEach(o=>{let c={clickPayload:{adToken:o.ad_token,distinctId:s.mixpanelDistinctId??s.jdid,isAddToCart:!1,janeDeviceId:s.jdid,kevelToken:o.kevel_token,myHighD:o.my_high_d,productId:o.product_id,storeId:o.store_id},clickUrl:t,impressPayload:{distinctId:s.mixpanelDistinctId??s.jdid,engagements:[{adToken:o.ad_token,kevelToken:o.kevel_token,myHighD:o.my_high_d,productId:o.product_id}],janeDeviceId:s.jdid},impressUrl:i,isSponsored:!!o.flight_id,objectId:o.object_id};o.search_attributes!==void 0?n.products.push({...c,attributes:o.search_attributes}):n.cachedProducts.push(c)}),n}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:n,posCartProductIds:o,storeId:c}=i;return{...a,cart_pos_product_ids:o,cart_product_ids:n,placement:"cart_toppers",store_id:c}}case"custom_image_row":{let{searchFilter:n,storeId:o}=i;return{...a,placement:"custom_image_row",search_filter:n,store_id:o}}case"menu_dynamic_row":{let{adMode:n,filterContext:o,pageContext:c,storeId:u}=i;return{...a,ad_mode:n??"default",filter_context:o,page_context:c,placement:"menu_dynamic_row",store_id:u}}case"menu_inline":{let{adMode:n,distinctByProduct:o,metadata:c,numColumns:u,searchFilter:P,searchQuery:p,searchSort:d,storeId:I,storeIds:f}=i;return{...a,ad_mode:n??"default",distinct_by_product:o,metadata:c,num_columns:u,placement:"menu_inline",search_filter:P,search_query:p,search_sort:ye(d),store_ids:f||[I]}}case"menu_inline_table":{let{disableAds:n,distinctByProduct:o,maxProducts:c,metadata:u,numColumns:P,pageSize:p,searchFacets:d,searchFilter:I,searchQuery:f,searchSort:_,storeId:C,storeIds:x}=i;return{...a,disable_ads:n,distinct_by_product:o,max_products:c,metadata:u,num_columns:P,page_size:p,placement:"menu_inline_table",search_attributes:s,search_facets:d,search_filter:I,search_query:f,search_sort:ye(_),store_ids:x||[C]}}case"menu_top_row":{let{searchFilter:n,storeId:o}=i,c=this.extractValidCreativeIds(e);return{...a,exclude_creative_ids:c,placement:"menu_top_row",search_filter:n,store_id:o}}case"pdp_row":{let{posProductId:n,productId:o,storeId:c}=i;return{...a,placement:"pdp_row",pos_product_id:n,product_id:o,store_id:c}}default:throw new b(`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 pt=r=>r.placement==="specials",lt=r=>r.placement==="brand_specials",M=class{placement;title;constructor(e){this.title=e,this.placement="brand_specials"}},B=class{placement;title;constructor(e){this.title=e,this.placement="specials"}},O=class extends j{async createMultiPlacement(e){let t={apiKey:e.config.apiKey,source:e.config.source},s=h(e.config.endpoint,l.multi,t),i=h(e.config.pageEndpoint,l.page,t),a=this.buildMultiRequest(e),n=await m.post(s,a),{clickEndpoint:o,impressionEndpoint:c}=w(e.config.eventsEndpoint,t),u=[];for(let[P,p]of(n.placements||[]).entries())if(pt(p))u.push(new B(p.title));else if(lt(p))u.push(new M(p.title));else{let{creative_ids:d,custom_images:I,placement:f,products:_,row_id:C,search_facets:x,title:U}=p,{cachedProducts:Ne,products:Ve}=this.generateProducts({clickUrl:o,identifier:e.config.identifier,impressUrl:c,products:_}),ze=(I??[]).map(G=>this.massageCustomImageData(G)).filter(G=>G!==void 0);u.push(new E({cachedProducts:Ne,config:{...e.config,skipAutoSmartSortOnLoad:P===0?e.config.skipAutoSmartSortOnLoad:!0},creativeIds:d,customImages:ze,nextPageProps:{pageSize:60,searchAttributes:a.search_attributes||[]},nextPageUrl:i,placement:f,products:Ve,rowId:C,searchFacets:x,title:U,totalProducts:p.nb_hits??0}))}return u}buildMultiRequest(e){let{config:t,numColumns:s,searchAttributes:i,storeId:a,...n}=e,o={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(n.multiRequestType){case"custom":return{...o,placements:this.massageCustomPlacements(n.placements),type:"custom"};case"featured":return{...o,exclude_menu_top_row:n.excludeMenuTopRow??!1,type:"featured"};default:throw new b(`Invalid Multi Type: ${n.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 b(`Invalid Custom Placement: ${s.placement}`)}return t}};import{nanoid as Rt}from"nanoid";var je=async r=>{let{apiKey:e,appMode:t,endpoint:s,identifier:i,searchFacets:a,searchFilter:n,searchQuery:o,source:c,storeId:u}=r,{jdid:P}=i||{},p=h(s,l.facets,{apiKey:e,source:c}),d={appMode:t,janeDeviceId:P,searchFacets:a,searchFilter:n,searchQuery:o,storeId:u};return(await m.post(p,d)).searchFacets??{}};var Ue=async r=>{let{apiKey:e,endpoint:t,identifier:s,source:i,storeId:a,...n}=r,o=h(t,l.externalCheckout,{apiKey:e,source:i}),c={janeDeviceId:s.jdid,posOrderId:n.posOrderId,posUserId:n.posUserId||s.posUserId,products:n.products,storeId:a};return await m.post(o,c)};var q=class{async create(e){let{config:t,searchAttributes:s,storeId:i,...a}=e,n={apiKey:t.apiKey,source:t.source},o=h(t.endpoint,l.product,n),{clickEndpoint:c,impressionEndpoint:u}=w(t.eventsEndpoint,n),P={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},p=a.productId!==void 0?{...P,product_id:a.productId}:{...P,pos_product_id:a.posProductId},d=await m.post(o,p);return new D({attributes:d.search_attributes,clickPayload:{adToken:d.ad_token,distinctId:t.identifier.mixpanelDistinctId,isAddToCart:!1,janeDeviceId:t.identifier.jdid,kevelToken:d.kevel_token,myHighD:d.my_high_d,productId:d.product_id,storeId:i},clickUrl:c,impressPayload:{distinctId:t.identifier.mixpanelDistinctId??t.identifier.jdid,engagements:[{adToken:d.ad_token,kevelToken:d.kevel_token,myHighD:d.my_high_d,productId:d.product_id}],janeDeviceId:t.identifier.jdid},impressUrl:u,isSponsored:!!d.flight_id,objectId:d.object_id})}};var mt=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}),ht=r=>({activitiesDistribution:r.activities_distribution,averageRating:r.average_rating,distribution:r.distribution,feelingsDistribution:r.feelings_distribution,reviewCount:r.review_count}),Pt=(r,e,t)=>{let s=r.total_count,i=Math.max(1,Math.ceil(s/t));return{aggregate:ht(r.aggregate),items:r.reviews.map(mt),pagination:{currentPage:e,hasNextPage:e<i,hasPreviousPage:e>1,pageSize:t,totalCount:s,totalPages:i},productId:r.product_id}},Ae=async r=>{let{activities:e,config:t,feelings:s,hasComment:i,page:a,pageSize:n,productId:o,ratings:c,sort:u}=r,P=a??1,p=n??50,d=h(t.endpoint,l.productReviews,{apiKey:t.apiKey,source:t.source}),I={activities:e,feelings:s,has_comment:i||void 0,page:a,page_size:n,product_id:o,ratings:c,sort:u},f=await m.post(d,I);return Pt(f,P,p)},Me=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 Be=async r=>{let{apiKey:e,eventsEndpoint:t,identifier:s,source:i,...a}=r,n=h(t,l.sessionEvent,{apiKey:e,source:i}),o={distinctId:s.mixpanelDistinctId,events:a.events,janeDeviceId:s.jdid};return await m.post(n,o)};function R(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 N=class{burst;intervalMs;rate;tat=0;toleranceMs;constructor(e,t=1){if(e<=0)throw new b("rate must be > 0");if(t<1)throw new b("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,n)=>setTimeout(()=>i().then(a).catch(n),s)):i()}};var gt=/^https?:\/\//,ft=/^(https?:\/\/)?(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}|localhost)(:\d+)?(\/.*)?$/,V=(r,e)=>{let s=gt.test(r??e)?r??e:`https://${r}`,i=new URL(s);return ft.test(i.toString())?i.protocol+"//"+i.host:e};var Oe=async r=>{let{apiKey:e,appMode:t,endpoint:s,identifier:i,source:a,storeId:n}=r,{jdid:o}=i;if(!o)throw new b("Jane Device ID (jdid) is required to fetch virtual budtender queries");let c=h(s,l.virtualBudtenderQueries,{apiKey:e,source:a}),u={appMode:t,janeDeviceId:o,storeId:n};return(await m.post(c,u)).queries??[]},qe=async r=>{let{apiKey:e,appMode:t,endpoint:s,eventsEndpoint:i,identifier:a,query:n,searchAttributes:o,source:c,storeId:u}=r,{jdid:P}=a;if(!P)throw new b("Jane Device ID (jdid) is required to perform virtual budtender search");let p={apiKey:e,source:c},d=h(s,l.virtualBudtenderSearch,p),I={app_mode:t,jane_device_id:P,placement:"virtual_budtender_search",query:n,search_attributes:o,store_id:u},f=await m.post(d,I),{clickEndpoint:_,impressionEndpoint:C}=w(i,p),x=St({clickUrl:_,identifier:a,impressUrl:C,products:f.products??[],storeId:u});return{htmlResponse:f.htmlResponse,markdownResponse:f.markdownResponse,products:x,query:f.query,totalResults:f.totalResults??0,unformattedResponse:f.unformattedResponse}},z=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(T(e))}click(e={isAddToCart:!1}){let{isAddToCart:t=!1}=e,s={...this.clickPayload,isAddToCart:t};return m.post(this.clickUrl,s)}impress(){return this.hasBeenImpressed?Promise.resolve():(this.impressPromise??=m.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())}},St=r=>{let{clickUrl:e,identifier:t,impressUrl:s,products:i,storeId:a}=r,n=[];return i?.forEach(o=>{let c={attributes:o.search_attributes,clickPayload:{adToken:o.ad_token,distinctId:t.mixpanelDistinctId??t.jdid,isAddToCart:!1,janeDeviceId:t.jdid,kevelToken:o.kevel_token,myHighD:o.my_high_d,productId:o.product_id,storeId:a},clickUrl:e,impressPayload:{distinctId:t.mixpanelDistinctId??t.jdid,engagements:[{adToken:o.ad_token,kevelToken:o.kevel_token,myHighD:o.my_high_d,productId:o.product_id}],janeDeviceId:t.jdid},impressUrl:s,isSponsored:!!o.flight_id,objectId:o.object_id,reasoning:o.reasoning,score:o.score};n.push(new z(c))}),n};var g=class{config;rateLimiter;initialized=!1;multiClient;productClient;smartSortClient;userProvidedJdid=!1;constructor(e,t){let{apiKey:s,endpoint:i,identifier:a}=e,{appMode:n="headless",eventsEndpoint:o,pageEndpoint:c,skipAutoSmartSortOnLoad:u=!1,source:P="sdk"}=t??{},p=V(i,"https://dmerch.iheartjane.com"),d=V(o,p),I=V(c,p);this.userProvidedJdid=!!a?.jdid,this.config={apiKey:s,appMode:n,endpoint:p,eventsEndpoint:d,identifier:a??{jdid:""},pageEndpoint:I,skipAutoSmartSortOnLoad:u,source:P},this.smartSortClient=new j,this.multiClient=new O,this.productClient=new q,this.rateLimiter=new N(10,20)}static generateJaneDeviceId(){return Rt()}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 je({...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 Ae({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 Oe({...e,...this.config})}async fetchVirtualBudtenderSearch(e){return qe({...e,...this.config})}getJaneDeviceId(){return this.config.identifier.jdid}async init(){this.initialized||(v()&&!this.userProvidedJdid&&await this.initializeClientSideJdid(),this.initialized=!0)}iterateProductReviews(e){return Me(t=>this.fetchProductReviews({...e,page:t}))}async sendPosCheckout(e){return Ue({...e,...this.config})}async sendSessionEvent(e){return Be({...e,...this.config})}async initializeClientSideJdid(){let e={apiKey:this.config.apiKey,source:this.config.source},t=await Fe(this.config.eventsEndpoint,e);F.set("jdid",t),this.config.identifier.jdid=t}};S([R,y],g.prototype,"fetchCartTopperRow",1),S([R,y],g.prototype,"fetchCustomImageRow",1),S([R,y],g.prototype,"fetchCustomPlacements",1),S([R,y],g.prototype,"fetchFacets",1),S([R,y],g.prototype,"fetchFeaturedPlacements",1),S([R,y],g.prototype,"fetchMenuRow",1),S([R,y],g.prototype,"fetchMenuTopRow",1),S([R,y],g.prototype,"fetchProduct",1),S([R,y],g.prototype,"fetchProductReviews",1),S([R,y],g.prototype,"fetchRecommendedPDPRow",1),S([R,y],g.prototype,"fetchRecommendedRow",1),S([R,y],g.prototype,"fetchRecommendedSort",1),S([R,y],g.prototype,"fetchVirtualBudtenderQueries",1),S([R,y],g.prototype,"fetchVirtualBudtenderSearch",1);export{J as AdMode,be as AppMode,M as BrandSpecials,Q as DEFAULT_PAGE_SIZE,Ge as IntendedDisplay,g as JaneDM,we as JaneDeviceIdSentinel,Je as PageContextEnum,A as Placement,Qe as ProductKindEnum,Ke as ReviewSortEnum,ve as SearchSortEnum,E as SmartSort,D as SmartSortProduct,B as Specials,z as VirtualBudtenderProduct,K as bestSellerRank,L as categoryAndNameAsc,H as defaultOrder,$ as priceAsc,W as priceDesc,Z as priceEighthOunceAsc,X as priceEighthOunceDesc,Y as priceGramAsc,ee as priceGramDesc,te as priceHalfGramAsc,re as priceHalfGramDesc,se as priceHalfOunceAsc,ie as priceHalfOunceDesc,oe as priceOunceAsc,ne as priceOunceDesc,ae as priceQuarterOunceAsc,ce as priceQuarterOunceDesc,de as priceTwoGramAsc,ue as priceTwoGramDesc,pe as rating,le as recommendation,Le as searchSorts,me as thcPotencyAsc,he as thcPotencyDesc};
|