@ordergroove/offers 2.28.3 → 2.28.4-alpha-PR-687-2.0

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/offers.js CHANGED
@@ -880,6 +880,6 @@ var lib=(()=>{var ta=Object.create;var Xe=Object.defineProperty;var ra=Object.ge
880
880
  <slot name="append"></slot>
881
881
  `:d`
882
882
  <slot name="fallback"></slot>
883
- `}};n(nn,"Price");var vl=n((t,e)=>{var r;return{productPlans:t.productPlans,configDefaultFrequency:(r=t.config)==null?void 0:r.defaultFrequency,frequency:J(e.product)(t)}},"mapStateToProps"),qi=y(vl)(nn);U();function sn(t){Ni(),vs(t);try{customElements.define("og-when",ai),customElements.define("og-text",yi),customElements.define("og-incentive-text",xi),customElements.define("og-offer",Pi),customElements.define("og-select-frequency",Si),customElements.define("og-optout-button",pi),customElements.define("og-optin-toggle",gi),customElements.define("og-optin-status",li),customElements.define("og-optin-button",ui),customElements.define("og-optin-select",fi),customElements.define("og-upsell-button",hi),customElements.define("og-frequency-status",di),customElements.define("og-modal",Sr),customElements.define("og-select",Tr),customElements.define("og-tooltip",vr),customElements.define("og-upsell-modal",mi),customElements.define("og-next-upcoming-order",vi),customElements.define("og-price",qi)}catch{console.info("OG WebComponents already registered, skipping.")}let e=!1,r={store:t,isReady:()=>e,setEnvironment(o){return t.dispatch(Vr(o)),this},setMerchantId(o){return t.dispatch(Jn(o)),this},setAuthUrl(o){return t.dispatch(Qn(o)),this},getProductsForPurchasePost(o=[]){return Jr(t.getState(),o)},getOptins(o=[]){return Jr(t.getState(),o)},clear(){t.dispatch(es())},addOptinChangedCallback(o){typeof o=="function"&&document.addEventListener("optin-changed",s=>o(s.detail))},disableOptinChangedCallbacks(){document.addEventListener("optin-changed",o=>o.stopPropagation(),!0)},register(){},previewMode(o){return window.og=window.og||{},o===!1?delete window.og:window.og.previewMode=!0,this},config(o){return t.dispatch(os(o)),this},setLocale(o){return t.dispatch(rs(o)),this},addTemplate(o,s,i){return t.dispatch(ns(o,s,i)),this},setTemplates(o){return t.dispatch(ss(o)),this},setPublicPath(o){return this},resolveSettings(o,s,i,a=t){if(o&&s&&i){let c=[];i.product?c.push(i.product):i.cart&&Array.isArray(i.cart.products)&&(c=c.concat(i.cart.products));let{apiUrl:l}=Ot({},Vr(s)),{sessionId:u}=a.getState();u&&c.forEach(h=>{let p=R(h);se.fetchOffer(l,o,u,`${p}`,ge)}),i.product_discounts&&typeof i.product_discounts=="object"&&a.dispatch({type:K,payload:i.product_discounts})}},initialize(o,s,i){var c;e?console.warn("og.offers has been initialized already. Skipping."):r.resolveSettings(o,s,window.og_settings,t);let a=t.getState();return o&&o!==a.merchantId&&r.setMerchantId(o),s&&s!==((c=a.environment)==null?void 0:c.name)&&r.setEnvironment(s),i&&r.setAuthUrl(i),e=!0,this}};return window.OG=window.OG||{},Object.assign(window.OG,r),Object.assign(r.initialize,r),Yr(window.opener,r),r}n(sn,"makeApi");M();U();var Ze=n(t=>t===null?"":`$${t.toString().replace(/(\d\d)$/,".$1")}`,"money"),Ol=n(t=>`${t}%`,"percentage"),wl=n(t=>{var r,o;let e="";return((r=t.price_adjustments[0])==null?void 0:r.value_type)==="percentage"?e=Ol(t.price_adjustments[0].value):((o=t.price_adjustments[0])==null?void 0:o.value)?e=Ze(t.price_adjustments[0].value):t.compare_at_price&&(e=Ze(t.compare_at_price-t.price)),e?[Ze(t.compare_at_price),e,Ze(t.price)]:[Ze(t.price),"",Ze(t.price)]},"mapSellingPlanToDiscount"),ki=n((t,e,r)=>{let o=Object.keys(t).filter(s=>s.startsWith(e.toString()));return o.length?{...t,...o.reduce((s,i)=>({...s,[i]:r}),{})}:t},"overrideLineKey"),Fi=n((t,e,r)=>{if(!r)return null;if(!je(r))return r;if(Kt(t,e)){let o=Y(t,e,r);return o||xe(t)}return r},"getDefaultSellingPlan"),Cl=n((t,e)=>t.map(r=>{var o,s,i,a,c,l,u;return je(r==null?void 0:r.frequency)?{...r,frequency:Kt((o=e==null?void 0:e.config)==null?void 0:o.frequencies,(s=e==null?void 0:e.config)==null?void 0:s.frequenciesEveryPeriod)?Y((i=e==null?void 0:e.config)==null?void 0:i.frequencies,(a=e==null?void 0:e.config)==null?void 0:a.frequenciesEveryPeriod,r.frequency)||Y((c=e==null?void 0:e.config)==null?void 0:c.frequencies,(l=e==null?void 0:e.config)==null?void 0:l.frequenciesEveryPeriod,e.defaultFrequency)||xe((u=e==null?void 0:e.config)==null?void 0:u.frequencies):r.frequency}:r}),"mapExistingOptinsFromOfferResponse"),Pl=n(({autoship:t={},autoship_by_default:e={},default_frequencies:r={},in_stock:o={}},s,i)=>Object.keys(t).reduce((a,c)=>{if(!s.some(l=>l.id===c)){if(!(t[c]&&e[c]&&o[c]))return a;let{config:{frequencies:l,frequenciesEveryPeriod:u}={},defaultFrequency:h}=i,p=r[c],m;return r[c]&&Kt(l,u)?m=Y(l,u,`${p.every}_${p.every_period}`)||Fi(l,u,h)||xe(l):r[c]?m=`${p.every}_${p.every_period}`:m=Fi(l,u,h)||"_",a.concat({id:c,frequency:m})}return a},[]),"reduceNewOptinsFromOfferResponse"),Ui=n(t=>t==null?void 0:t.selling_plan_groups.find(r=>r.name==="Subscribe and Save"),"getOGSellingPlanGroup"),Rl=n((t,e)=>({...ki(t,e.id,e.available),[e.id]:e.available}),"productOrVariantInStockReducer"),Di=n((t,[e])=>({...t,[e]:!0}),"productTrue"),Li=n((t,e)=>{var r;return{...t,[e.selling_plan_id||((r=e.selling_plan)==null?void 0:r.id)]:wl(e)}},"sellingPlanAllocationsReducer"),Mi=n((t,e)=>{let r=R(e.key);return{...t,[e.key]:t[r]||null}},"reduceProductCartLine"),Al=n((t={},e)=>{if(K===e.type)return Object.entries(e.payload).reduce(Di,t);if(ne===e.type){let{payload:r}=e;return r.items.reduce(Mi,t)}if(W===e.type){let{payload:{product:r}}=e;return[r,...(r==null?void 0:r.variants)||[]].reduce((o,s)=>{var i,a;return{...ki(o,s.id,((i=s.selling_plan_allocations)==null?void 0:i.length)>0),[s.id]:((a=s.selling_plan_allocations)==null?void 0:a.length)>0}},t)}return t},"autoshipEligible");function Nl(t){let e=["day","week","month"].findIndex(o=>t.toLowerCase().includes(o))+1,r=(t.match(/(\d+)/)||["",1])[1];return r&&e?`${r}_${e}`:null}n(Nl,"textToFreq");function ji(t){var e;return(e=t==null?void 0:t.selling_plans)==null?void 0:e.map(({options:r})=>r||[]).flat().map(({value:r})=>Nl(r))}n(ji,"sellingPlansToEveryPeriod");function Il(t){var e;return(e=t==null?void 0:t.selling_plans)==null?void 0:e.map(({id:r})=>`${r}`)}n(Il,"sellingPlansToFrequencies");var ql=n((t={frequencies:[],offerType:"radio",frequenciesEveryPeriod:[]},e)=>{var r,o,s;if(K===e.type){let i=[...new Set(Object.values(e.payload).map(Object.keys).flat())];return{...t,frequencies:i}}if(W===e.type){let{payload:{offer:i,product:a}}=e,c=Ui(a),l=(r=c==null?void 0:c.selling_plans)==null?void 0:r.map(({id:u})=>`${u}`);if(l==null?void 0:l.length){let u=ji(c),h=((s=(o=c.options)==null?void 0:o[0])==null?void 0:s.values)||l,p=t.defaultFrequency;return p&&je(p)&&(p=Y(l,u,p)||xe(l)||p),{...t,frequenciesEveryPeriod:u,frequencies:l,frequenciesText:h,...p?{defaultFrequency:p}:{}}}}if(P===e.type){let{payload:{offer:i}}=e,{defaultFrequency:a,config:{frequencies:c,frequenciesEveryPeriod:l}={}}=i;return je(a)?{...t,defaultFrequency:Y(c,l,a)||xe(c)||a}:{...t,defaultFrequency:a}}return t},"config"),kl=n((t={},e)=>{if(K===e.type)return Object.entries(e.payload).reduce(Di,t);if(ne===e.type)return e.payload.items.reduce(Mi,t);if(W===e.type){let{payload:{product:r}}=e;return[r,...r==null?void 0:r.variants].reduce(Rl,t)||t}return z===e.type&&e.payload.product===null?{...t}:t},"inStock"),Fl=n((t={},e)=>t,"offer"),Ul=n((t=[],e)=>{if(ne===e.type){let r=e.payload;return t.filter(o=>!o.id.includes(":")).concat(r.items.reduce((o,s)=>s.selling_plan_allocation?[...o,{id:s.key,frequency:`${s.selling_plan_allocation.selling_plan.id}`}]:o,[]))}if(P===e.type){let{offer:r={},...o}=e.payload,s=Cl(t,r),i=Pl(o,s,r);return[...s,...i]}if(W===e.type){let{product:r}=e.payload,o=Ui(r),s=Il(o),i=ji(o);return t.map(a=>je(a.frequency)?{...a,frequency:Y(s,i,a.frequency)||xe(s)}:a)}return jo(t,e)},"optedin"),Dl=n((t={},e)=>t,"productOffer"),Ll=n((t={},e)=>{if(W===e.type){let{payload:{product:r}}=e;return[r,...r==null?void 0:r.variants].reduce((o,s)=>{var i;return{...o,[s.id]:(i=s.selling_plan_allocations)==null?void 0:i.reduce(Li,{})}},t)||t}return ne===e.type?e.payload.items.reduce((o,s)=>s.selling_plan_allocation?{...o,[s.key]:Li({},s.selling_plan_allocation)}:o,t)||t:K===e.type?{...e.payload}:t},"productPlans"),Ml=Ct({auth:Go,authUrl:Wo,autoshipByDefault:tn,autoshipEligible:Al,config:ql,defaultFrequencies:rn,eligibilityGroups:Ho,environment:Ot,firstOrderPlaceDate:Qo,incentives:Bo,inStock:kl,locale:Zo,merchantId:zo,nextUpcomingOrder:Vo,offer:Fl,offerId:Yo,optedin:Ul,optedout:$o,previewStandardOffer:Xo,previewUpsellOffer:en,productOffer:Dl,productPlans:Ll,productToSubscribe:Ko,sessionId:Jo,templates:on});function an(t,e){return window.og&&window.og.previewMode?wr(t,e):Ml(t,e)}n(an,"shopifyReducer");var $i=re(st()),Vi=re(Rt());M();U();var Wi,Yi,Hi=((Yi=(Wi=window.Shopify)==null?void 0:Wi.routes)==null?void 0:Yi.root)||"/",jl="/cart",$l=`${Hi}cart.js`,Vl=`${Hi}products/`,Hl='[id^="shopify-section-"][id$=__cart-items], [id^="shopify-section-"][id$="__cart-footer"],#cart-live-region-text,#cart-icon-bubble',Bi=(0,Vi.debounce)(100,!1,function(t,e){let{id:r}=Object.fromEntries([...new FormData(t).entries()]);r?e.setAttribute("product",r):e.removeAttribute("product")});async function Bl(t,e){let r=Gl();if(r)try{let s=await zi(r);t.dispatch({type:W,payload:{product:s,offer:e}})}catch(s){console.warn("OG: Unable to fetch product details for PDP",s)}let o=e.closest("form");if(!o){let s=e.parentElement;for(;s&&(o=s.querySelector('form[action$="/cart/add"]'),!(o||s.tagName.toLowerCase()==="body"));)s=s.parentElement}o?(o.addEventListener("change",i=>Bi(o,e)),new MutationObserver(()=>Bi(o,e)).observe(o,{subtree:!0,childList:!0})):console.info("no /cart/add form found for og-offer",e)}n(Bl,"setupPdp");var Gi=n(async()=>await(await fetch($l)).json(),"getCart");function Gl(){return[()=>{var t,e;return(((e=(t=document.querySelector('[href$=".oembed"]'))==null?void 0:t.getAttribute("href"))==null?void 0:e.match(/\/([^\/]+)\.oembed$/))||[])[1]},()=>{var t,e;return(document.querySelector('meta[property="og:type"][content="product"]')&&((e=(t=document.querySelector('meta[property="og:url"][content]'))==null?void 0:t.getAttribute("content"))==null?void 0:e.match(/\/([^\/]+)$/))||[])[1]},()=>{var t;return(t=[...document.querySelectorAll("[type$=json]")].map(e=>JSON.parse(e.textContent||"{}")).find(e=>e.handle&&e.price))==null?void 0:t.handle}].reduce((t,e)=>t||e(),"")}n(Gl,"guessProductHandle");var zi=(0,$i.default)(async t=>(await fetch(`${Vl}${t}.js`)).json());async function zl(t,e){let r=await Gi(),{items:o}=r;t.dispatch({type:ne,payload:r});let s=Number(e.product.id);s<=o.length&&e.setAttribute("product",o[s-1].key),(await Promise.all(Array.from(new Set(o.map(({handle:a})=>a))).map(zi))).forEach(a=>t.dispatch({type:W,payload:{product:a,offer:e}}))}n(zl,"setupCart");async function Wl(t,e){var i,a;let r=t.payload.offer,o=t.payload.frequency||null,s=Yl(t);if(!(r==null?void 0:r.isCart)){r&&Jl(r.product.id,s[0],s[1]);return}try{r.style.pointerEvents="none",r.style.opacity=".7";let c=Array.from(document.querySelectorAll(Hl)),l=t.payload.product.id,u=await Gi(),h=(i=u==null?void 0:u.items)==null?void 0:i.findIndex(g=>g.key===l),p=u.items[h],m=p.quantity,C=R(l),_=await fetch("/cart/change.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l,quantity:m,attributes:Object.fromEntries([s]),properties:p.properties,selling_plan:o||null,sections:c.map(g=>g.id.replace(/^shopify-section-/,""))})});if(_.status!==200)throw new Error("Cart not updated");let f=await _.json(),E=u.items.length===f.items.length?f.items[h].key:(a=f.items.find(g=>g.quantity===m&&g.product_id===C&&(!o&&!g.selling_plan_allocation||(g==null?void 0:g.selling_plan_allocation.selling_plan.id)===o)))==null?void 0:a.key;E&&r.setAttribute("product",E),e.dispatch({type:ne,payload:f});let w=new CustomEvent(An,{bubbles:!0,cancelable:!0});if(r.dispatchEvent(w),w.defaultPrevented)return;let b=f.sections;Object.values(b).length?c.forEach(g=>{let wt=g.id.replace(/^shopify-section-/,"");if(!(wt in b))return;let ea=b[wt],ln=new DOMParser().parseFromString(ea.toString()||"","text/html").getElementById(g.id);ln&&(g.innerHTML=ln.innerHTML)}):window.location.pathname.startsWith(jl)&&window.location.reload()}catch(c){console.log("OG Error updating cart",c)}finally{r.style.pointerEvents="auto",r.style.opacity="1"}}n(Wl,"synchronizeCartOptin");function Yl(t){var a,c;let e=t.payload.product.id;if(!e)return[];let r=`og__${Math.ceil(new Date().getTime()/1e3)}`,o=((a=t.payload.offer)==null?void 0:a.location)||"",s=((c=t.payload.offer)==null?void 0:c.variationId)||"",i=[e,t.type.toLowerCase(),o];switch(t.type){case z:case k:i.push(""),i.push(s);break;case q:case F:i.push(t.payload.frequency),i.push(s);break;default:return[]}return[r,i.join(",")]}n(Yl,"getTrackingEvent");function Jl(t,e,r){let o=`[name="id"][value="${t}"]`,s=`form[action="/cart/add"] option[value="${t}"]`;if(!e)return;let i=document.querySelectorAll(o);i.length||(i=document.querySelectorAll(s)),[...i].forEach(a=>{let c=a.form,l=c==null?void 0:c.querySelector(`[name="${e}"]`);l||(l=document.createElement("input"),l.type="hidden",l.name=`attributes[${e}]`,c==null||c.appendChild(l)),l.value=r})}n(Jl,"updateTrackingInputs");function Ql(t,e,r){let o=t.querySelector(`[name="${e}"]`);if(o&&!r){o.remove();return}!o&&r&&(o=document.createElement("input"),o.type="hidden",o.name=e,t.appendChild(o)),o&&(o.value=r)}n(Ql,"getOrCreateHidden");function Kl(t,e){[...document.querySelectorAll('form[action$="/cart/add"] [name=id]')].forEach(r=>{var a;let o=r.value,i=(a=rr({id:o})(t.getState()))==null?void 0:a.frequency;Ql(r.form,"selling_plan",i)})}n(Kl,"synchronizeSellingPlan");function cn(t){return e=>r=>{var o;switch(r.type){case q:case k:case F:break;case z:((o=r.payload.offer)==null?void 0:o.isCart)?zl(t,r.payload.offer):Bl(t,r.payload.offer);break;default:}switch(e(r),r.type){case q:case k:case F:Wl(r,t);case z:case P:case W:Kl(t,r.payload.offer);break;default:}}}n(cn,"shopifyMiddleware");ut();U();A();U();var Zl="/apps/subscriptions/auth/",Ji="og_auth_begin",Xl="og_auth_end",eu=n(t=>{let[e,r,o,s]=atob(t).split("|");return{id:e,signature:o,timestamp:r,email:s}},"parseIntegrationTempAuth");async function Qi({store:t}){var s;let[e]=Lr(),r=pt(),o=(r==null?void 0:r.dataset.customer)?eu(r.dataset.customer):(s=window.ogShopifyConfig)==null?void 0:s.customer;if(o){let i=await ru(o);if(i){let[a,c,l]=i.split("|");t.dispatch(dt(e,a,Number(c),l))}}else Gn("og_auth")}n(Qi,"authorizeShopifyCustomer");async function tu(t){try{let r=await(await fetch(`${Zl}?customer=${t.id}&customer_signature=${t.signature}&customer_timestamp=${t.timestamp}`)).text(),o=r.lastIndexOf(Ji);if(o<0)throw"Invalid response from OG auth endpoint";return JSON.parse(r.substring(o+Ji.length,r.lastIndexOf(Xl)))}catch(e){console.error(e)}}n(tu,"fetchOGSignature");async function ru(t){let e=zn("og_auth");if(e)return e;let{customerId:r,timestamp:o,signature:s}=await tu(t);if(!r)return"";let i=new Date,a=btoa(s);i.setTime(i.getTime()+2*60*60*1e3);let c=`${r}|${o}|${a};expires=${i.toUTCString()}`;return document.cookie=`og_auth=${c};secure;path=/`,c}n(ru,"getOrCreateAuthCookie");var Zi,Ki=Es(...((Zi=j)==null?void 0:Zi.shopify_selling_plans)?[an,cn]:[wr]),x=sn(Ki),ou=x.isReady,nu=x.addOptinChangedCallback,su=x.addTemplate,iu=x.clear,au=x.config,cu=x.disableOptinChangedCallbacks,lu=x.getOptins,uu=x.getProductsForPurchasePost,pu=x.initialize,du=x.previewMode,fu=x.register,hu=x.resolveSettings,mu=x.setAuthUrl,gu=x.setEnvironment,yu=x.setLocale,bu=x.setMerchantId,_u=x.setPublicPath,Eu=x.setTemplates,xu=x.setupCart,Su=x.setupProduct,Tu=x.setupProducts,vu=n(()=>Bn(x),"autoInit");var Ou=x.initialize,Xi;((Xi=j)==null?void 0:Xi.shopify_selling_plans)&&Qt(()=>Qi(x));return wu;})();
883
+ `}};n(nn,"Price");var vl=n((t,e)=>{var r;return{productPlans:t.productPlans,configDefaultFrequency:(r=t.config)==null?void 0:r.defaultFrequency,frequency:J(e.product)(t)}},"mapStateToProps"),qi=y(vl)(nn);U();function sn(t){Ni(),vs(t);try{customElements.define("og-when",ai),customElements.define("og-text",yi),customElements.define("og-incentive-text",xi),customElements.define("og-offer",Pi),customElements.define("og-select-frequency",Si),customElements.define("og-optout-button",pi),customElements.define("og-optin-toggle",gi),customElements.define("og-optin-status",li),customElements.define("og-optin-button",ui),customElements.define("og-optin-select",fi),customElements.define("og-upsell-button",hi),customElements.define("og-frequency-status",di),customElements.define("og-modal",Sr),customElements.define("og-select",Tr),customElements.define("og-tooltip",vr),customElements.define("og-upsell-modal",mi),customElements.define("og-next-upcoming-order",vi),customElements.define("og-price",qi)}catch{console.info("OG WebComponents already registered, skipping.")}let e=!1,r={store:t,isReady:()=>e,setEnvironment(o){return t.dispatch(Vr(o)),this},setMerchantId(o){return t.dispatch(Jn(o)),this},setAuthUrl(o){return t.dispatch(Qn(o)),this},getProductsForPurchasePost(o=[]){return Jr(t.getState(),o)},getOptins(o=[]){return Jr(t.getState(),o)},clear(){t.dispatch(es())},addOptinChangedCallback(o){typeof o=="function"&&document.addEventListener("optin-changed",s=>o(s.detail))},disableOptinChangedCallbacks(){document.addEventListener("optin-changed",o=>o.stopPropagation(),!0)},register(){},previewMode(o){return window.og=window.og||{},o===!1?delete window.og:window.og.previewMode=!0,this},config(o){return t.dispatch(os(o)),this},setLocale(o){return t.dispatch(rs(o)),this},addTemplate(o,s,i){return t.dispatch(ns(o,s,i)),this},setTemplates(o){return t.dispatch(ss(o)),this},setPublicPath(o){return this},resolveSettings(o,s,i,a=t){if(o&&s&&i){let c=[];i.product?c.push(i.product):i.cart&&Array.isArray(i.cart.products)&&(c=c.concat(i.cart.products));let{apiUrl:l}=Ot({},Vr(s)),{sessionId:u}=a.getState();u&&c.forEach(h=>{let p=R(h);se.fetchOffer(l,o,u,`${p}`,ge)}),i.product_discounts&&typeof i.product_discounts=="object"&&a.dispatch({type:K,payload:i.product_discounts})}},initialize(o,s,i){var c;e?console.warn("og.offers has been initialized already. Skipping."):r.resolveSettings(o,s,window.og_settings,t);let a=t.getState();return o&&o!==a.merchantId&&r.setMerchantId(o),s&&s!==((c=a.environment)==null?void 0:c.name)&&r.setEnvironment(s),i&&r.setAuthUrl(i),e=!0,this}};return window.OG=window.OG||{},Object.assign(window.OG,r),Object.assign(r.initialize,r),Yr(window.opener,r),r}n(sn,"makeApi");M();U();var Ze=n(t=>t===null?"":`$${t.toString().replace(/(\d\d)$/,".$1")}`,"money"),Ol=n(t=>`${t}%`,"percentage"),wl=n(t=>{var r,o;let e="";return((r=t.price_adjustments[0])==null?void 0:r.value_type)==="percentage"?e=Ol(t.price_adjustments[0].value):((o=t.price_adjustments[0])==null?void 0:o.value)?e=Ze(t.price_adjustments[0].value):t.compare_at_price&&(e=Ze(t.compare_at_price-t.price)),e?[Ze(t.compare_at_price),e,Ze(t.price)]:[Ze(t.price),"",Ze(t.price)]},"mapSellingPlanToDiscount"),ki=n((t,e,r)=>{let o=Object.keys(t).filter(s=>s.startsWith(e.toString()));return o.length?{...t,...o.reduce((s,i)=>({...s,[i]:r}),{})}:t},"overrideLineKey"),Fi=n((t,e,r)=>{if(!r)return null;if(!je(r))return r;if(Kt(t,e)){let o=Y(t,e,r);return o||xe(t)}return r},"getDefaultSellingPlan"),Cl=n((t,e)=>t.map(r=>{var o,s,i,a,c,l,u;return je(r==null?void 0:r.frequency)?{...r,frequency:Kt((o=e==null?void 0:e.config)==null?void 0:o.frequencies,(s=e==null?void 0:e.config)==null?void 0:s.frequenciesEveryPeriod)?Y((i=e==null?void 0:e.config)==null?void 0:i.frequencies,(a=e==null?void 0:e.config)==null?void 0:a.frequenciesEveryPeriod,r.frequency)||Y((c=e==null?void 0:e.config)==null?void 0:c.frequencies,(l=e==null?void 0:e.config)==null?void 0:l.frequenciesEveryPeriod,e.defaultFrequency)||xe((u=e==null?void 0:e.config)==null?void 0:u.frequencies):r.frequency}:r}),"mapExistingOptinsFromOfferResponse"),Pl=n(({autoship:t={},autoship_by_default:e={},default_frequencies:r={},in_stock:o={}},s,i)=>Object.keys(t).reduce((a,c)=>{if(!s.some(l=>l.id===c)){if(!(t[c]&&e[c]&&o[c]))return a;let{config:{frequencies:l,frequenciesEveryPeriod:u}={},defaultFrequency:h}=i,p=r[c],m;return r[c]&&Kt(l,u)?m=Y(l,u,`${p.every}_${p.every_period}`)||Fi(l,u,h)||xe(l):r[c]?m=`${p.every}_${p.every_period}`:m=Fi(l,u,h)||"_",a.concat({id:c,frequency:m})}return a},[]),"reduceNewOptinsFromOfferResponse"),Ui=n(t=>t==null?void 0:t.selling_plan_groups.find(r=>r.name==="Subscribe and Save"),"getOGSellingPlanGroup"),Rl=n((t,e)=>({...ki(t,e.id,e.available),[e.id]:e.available}),"productOrVariantInStockReducer"),Di=n((t,[e])=>({...t,[e]:!0}),"productTrue"),Li=n((t,e)=>{var r;return{...t,[e.selling_plan_id||((r=e.selling_plan)==null?void 0:r.id)]:wl(e)}},"sellingPlanAllocationsReducer"),Mi=n((t,e)=>{let r=R(e.key);return{...t,[e.key]:t[r]||null}},"reduceProductCartLine"),Al=n((t={},e)=>{if(K===e.type)return Object.entries(e.payload).reduce(Di,t);if(ne===e.type){let{payload:r}=e;return r.items.reduce(Mi,t)}if(W===e.type){let{payload:{product:r}}=e;return[r,...(r==null?void 0:r.variants)||[]].reduce((o,s)=>{var i,a;return{...ki(o,s.id,((i=s.selling_plan_allocations)==null?void 0:i.length)>0),[s.id]:((a=s.selling_plan_allocations)==null?void 0:a.length)>0}},t)}return t},"autoshipEligible");function Nl(t){let e=["day","week","month"].findIndex(o=>t.toLowerCase().includes(o))+1,r=(t.match(/(\d+)/)||["",1])[1];return r&&e?`${r}_${e}`:null}n(Nl,"textToFreq");function ji(t){var e;return(e=t==null?void 0:t.selling_plans)==null?void 0:e.map(({options:r})=>r||[]).flat().map(({value:r})=>Nl(r))}n(ji,"sellingPlansToEveryPeriod");function Il(t){var e;return(e=t==null?void 0:t.selling_plans)==null?void 0:e.map(({id:r})=>`${r}`)}n(Il,"sellingPlansToFrequencies");var ql=n((t={frequencies:[],offerType:"radio",frequenciesEveryPeriod:[]},e)=>{var r,o,s;if(K===e.type){let i=[...new Set(Object.values(e.payload).map(Object.keys).flat())];return{...t,frequencies:i}}if(W===e.type){let{payload:{offer:i,product:a}}=e,c=Ui(a),l=(r=c==null?void 0:c.selling_plans)==null?void 0:r.map(({id:u})=>`${u}`);if(l==null?void 0:l.length){let u=ji(c),h=((s=(o=c.options)==null?void 0:o[0])==null?void 0:s.values)||l,p=t.defaultFrequency;return p&&je(p)&&(p=Y(l,u,p)||xe(l)||p),{...t,frequenciesEveryPeriod:u,frequencies:l,frequenciesText:h,...p?{defaultFrequency:p}:{}}}}if(P===e.type){let{payload:{offer:i}}=e,{defaultFrequency:a,config:{frequencies:c,frequenciesEveryPeriod:l}={}}=i;return je(a)?{...t,defaultFrequency:Y(c,l,a)||xe(c)||a}:{...t,defaultFrequency:a}}return t},"config"),kl=n((t={},e)=>{if(K===e.type)return Object.entries(e.payload).reduce(Di,t);if(ne===e.type)return e.payload.items.reduce(Mi,t);if(W===e.type){let{payload:{product:r}}=e;return[r,...r==null?void 0:r.variants].reduce(Rl,t)||t}return z===e.type&&e.payload.product===null?{...t}:t},"inStock"),Fl=n((t={},e)=>t,"offer"),Ul=n((t=[],e)=>{if(ne===e.type){let r=e.payload;return t.filter(o=>!o.id.includes(":")).concat(r.items.reduce((o,s)=>s.selling_plan_allocation?[...o,{id:s.key,frequency:`${s.selling_plan_allocation.selling_plan.id}`}]:o,[]))}if(P===e.type){let{offer:r={},...o}=e.payload,s=Cl(t,r),i=Pl(o,s,r);return[...s,...i]}if(W===e.type){let{product:r}=e.payload,o=Ui(r),s=Il(o),i=ji(o);return t.map(a=>je(a.frequency)?{...a,frequency:Y(s,i,a.frequency)||xe(s)}:a)}return jo(t,e)},"optedin"),Dl=n((t={},e)=>t,"productOffer"),Ll=n((t={},e)=>{if(W===e.type){let{payload:{product:r}}=e;return[r,...r==null?void 0:r.variants].reduce((o,s)=>{var i;return{...o,[s.id]:(i=s.selling_plan_allocations)==null?void 0:i.reduce(Li,{})}},t)||t}return ne===e.type?e.payload.items.reduce((o,s)=>s.selling_plan_allocation?{...o,[s.key]:Li({},s.selling_plan_allocation)}:o,t)||t:K===e.type?{...e.payload}:t},"productPlans"),Ml=Ct({auth:Go,authUrl:Wo,autoshipByDefault:tn,autoshipEligible:Al,config:ql,defaultFrequencies:rn,eligibilityGroups:Ho,environment:Ot,firstOrderPlaceDate:Qo,incentives:Bo,inStock:kl,locale:Zo,merchantId:zo,nextUpcomingOrder:Vo,offer:Fl,offerId:Yo,optedin:Ul,optedout:$o,previewStandardOffer:Xo,previewUpsellOffer:en,productOffer:Dl,productPlans:Ll,productToSubscribe:Ko,sessionId:Jo,templates:on});function an(t,e){return window.og&&window.og.previewMode?wr(t,e):Ml(t,e)}n(an,"shopifyReducer");var $i=re(st()),Vi=re(Rt());M();U();var Wi,Yi,Hi=((Yi=(Wi=window.Shopify)==null?void 0:Wi.routes)==null?void 0:Yi.root)||"/",jl="/cart",$l=`${Hi}cart.js`,Vl=`${Hi}products/`,Hl='[id^="shopify-section-"][id$=__cart-items], [id^="shopify-section-"][id$="__cart-footer"],#cart-live-region-text,#cart-icon-bubble',Bi=(0,Vi.debounce)(100,!1,function(t,e){let{id:r}=Object.fromEntries([...new FormData(t).entries()]);r?e.setAttribute("product",r):e.removeAttribute("product")});async function Bl(t,e){let r=Gl();if(r)try{let s=await zi(r);t.dispatch({type:W,payload:{product:s,offer:e}})}catch(s){console.warn("OG: Unable to fetch product details for PDP",s)}let o=e.closest("form");if(!o){let s=e.parentElement;for(;s&&(o=s.querySelector('form[action$="/cart/add"]'),!(o||s.tagName.toLowerCase()==="body"));)s=s.parentElement}o?(o.addEventListener("change",i=>Bi(o,e)),new MutationObserver(()=>Bi(o,e)).observe(o,{subtree:!0,childList:!0})):console.info("no /cart/add form found for og-offer",e)}n(Bl,"setupPdp");var Gi=n(async()=>await(await fetch($l)).json(),"getCart");function Gl(){return[()=>{var t,e;return(((e=(t=document.querySelector('[href$=".oembed"]'))==null?void 0:t.getAttribute("href"))==null?void 0:e.match(/\/([^\/]+)\.oembed$/))||[])[1]},()=>{var t,e;return(document.querySelector('meta[property="og:type"][content="product"]')&&((e=(t=document.querySelector('meta[property="og:url"][content]'))==null?void 0:t.getAttribute("content"))==null?void 0:e.match(/\/([^\/]+)$/))||[])[1]},()=>{var t;return(t=[...document.querySelectorAll("[type$=json]")].map(e=>JSON.parse(e.textContent||"{}")).find(e=>e.handle&&e.price))==null?void 0:t.handle}].reduce((t,e)=>t||e(),"")}n(Gl,"guessProductHandle");var zi=(0,$i.default)(async t=>(await fetch(`${Vl}${t}.js`)).json());async function zl(t,e){let r=await Gi(),{items:o}=r;t.dispatch({type:ne,payload:r});let s=Number(e.product.id);s<=o.length&&e.setAttribute("product",o[s-1].key),(await Promise.all(Array.from(new Set(o.map(({handle:a})=>a))).map(zi))).forEach(a=>t.dispatch({type:W,payload:{product:a,offer:e}}))}n(zl,"setupCart");async function Wl(t,e){var i,a;let r=t.payload.offer,o=t.payload.frequency||null,s=Yl(t);if(!(r==null?void 0:r.isCart)){r&&Jl(r.product.id,s[0],s[1]);return}try{r.style.pointerEvents="none",r.style.opacity=".7";let c=Array.from(document.querySelectorAll(Hl)),l=t.payload.product.id,u=await Gi(),h=(i=u==null?void 0:u.items)==null?void 0:i.findIndex(g=>g.key===l),p=u.items[h],m=p.quantity,C=R(l),_=await fetch("/cart/change.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l,quantity:m,attributes:Object.fromEntries([s]),properties:p.properties,selling_plan:o||null,sections:c.map(g=>g.id.replace(/^shopify-section-/,""))})});if(_.status!==200)throw new Error("Cart not updated");let f=await _.json(),E=u.items.length===f.items.length?f.items[h].key:(a=f.items.find(g=>g.quantity===m&&g.product_id===C&&(!o&&!g.selling_plan_allocation||(g==null?void 0:g.selling_plan_allocation.selling_plan.id)===o)))==null?void 0:a.key;E&&r.setAttribute("product",E),e.dispatch({type:ne,payload:f});let w=new CustomEvent(An,{bubbles:!0,cancelable:!0});if(r.dispatchEvent(w),w.defaultPrevented)return;let b=f.sections;Object.values(b).length?c.forEach(g=>{let wt=g.id.replace(/^shopify-section-/,"");if(!(wt in b))return;let ea=b[wt],ln=new DOMParser().parseFromString(ea.toString()||"","text/html").getElementById(g.id);ln&&(g.innerHTML=ln.innerHTML)}):window.location.pathname.startsWith(jl)&&window.location.reload()}catch(c){console.log("OG Error updating cart",c)}finally{r.style.pointerEvents="auto",r.style.opacity="1"}}n(Wl,"synchronizeCartOptin");function Yl(t){var a,c;let e=t.payload.product.id;if(!e)return[];let r=`og__${Math.ceil(new Date().getTime()/1e3)}`,o=((a=t.payload.offer)==null?void 0:a.location)||"",s=((c=t.payload.offer)==null?void 0:c.variationId)||"",i=[e,t.type.toLowerCase(),o];switch(t.type){case z:case k:i.push(""),i.push(s);break;case q:case F:i.push(t.payload.frequency),i.push(s);break;default:return[]}return[r,i.join(",")]}n(Yl,"getTrackingEvent");function Jl(t,e,r){let o=`[name="id"][value="${t}"]`,s=`form[action="/cart/add"] option[value="${t}"]`;if(!e)return;let i=document.querySelectorAll(o);i.length||(i=document.querySelectorAll(s)),[...i].forEach(a=>{let c=a.form,l=c==null?void 0:c.querySelector(`[name="${e}"]`);l||(l=document.createElement("input"),l.type="hidden",l.name=`attributes[${e}]`,c==null||c.appendChild(l)),l.value=r})}n(Jl,"updateTrackingInputs");function Ql(t,e,r){let o=t.querySelector(`[name="${e}"]`);if(o&&!r){o.remove();return}!o&&r&&(o=document.createElement("input"),o.type="hidden",o.name=e,t.appendChild(o)),o&&(o.value=r)}n(Ql,"getOrCreateHidden");function Kl(t,e){e.isCart||[...document.querySelectorAll('form[action$="/cart/add"] [name=id]')].forEach(r=>{var a;let o=r.value,i=(a=rr({id:o})(t.getState()))==null?void 0:a.frequency;Ql(r.form,"selling_plan",i)})}n(Kl,"synchronizeSellingPlan");function cn(t){return e=>r=>{var o;switch(r.type){case q:case k:case F:break;case z:((o=r.payload.offer)==null?void 0:o.isCart)?zl(t,r.payload.offer):Bl(t,r.payload.offer);break;default:}switch(e(r),r.type){case q:case k:case F:Wl(r,t);case z:case P:case W:Kl(t,r.payload.offer);break;default:}}}n(cn,"shopifyMiddleware");ut();U();A();U();var Zl="/apps/subscriptions/auth/",Ji="og_auth_begin",Xl="og_auth_end",eu=n(t=>{let[e,r,o,s]=atob(t).split("|");return{id:e,signature:o,timestamp:r,email:s}},"parseIntegrationTempAuth");async function Qi({store:t}){var s;let[e]=Lr(),r=pt(),o=(r==null?void 0:r.dataset.customer)?eu(r.dataset.customer):(s=window.ogShopifyConfig)==null?void 0:s.customer;if(o){let i=await ru(o);if(i){let[a,c,l]=i.split("|");t.dispatch(dt(e,a,Number(c),l))}}else Gn("og_auth")}n(Qi,"authorizeShopifyCustomer");async function tu(t){try{let r=await(await fetch(`${Zl}?customer=${t.id}&customer_signature=${t.signature}&customer_timestamp=${t.timestamp}`)).text(),o=r.lastIndexOf(Ji);if(o<0)throw"Invalid response from OG auth endpoint";return JSON.parse(r.substring(o+Ji.length,r.lastIndexOf(Xl)))}catch(e){console.error(e)}}n(tu,"fetchOGSignature");async function ru(t){let e=zn("og_auth");if(e)return e;let{customerId:r,timestamp:o,signature:s}=await tu(t);if(!r)return"";let i=new Date,a=btoa(s);i.setTime(i.getTime()+2*60*60*1e3);let c=`${r}|${o}|${a};expires=${i.toUTCString()}`;return document.cookie=`og_auth=${c};secure;path=/`,c}n(ru,"getOrCreateAuthCookie");var Zi,Ki=Es(...((Zi=j)==null?void 0:Zi.shopify_selling_plans)?[an,cn]:[wr]),x=sn(Ki),ou=x.isReady,nu=x.addOptinChangedCallback,su=x.addTemplate,iu=x.clear,au=x.config,cu=x.disableOptinChangedCallbacks,lu=x.getOptins,uu=x.getProductsForPurchasePost,pu=x.initialize,du=x.previewMode,fu=x.register,hu=x.resolveSettings,mu=x.setAuthUrl,gu=x.setEnvironment,yu=x.setLocale,bu=x.setMerchantId,_u=x.setPublicPath,Eu=x.setTemplates,xu=x.setupCart,Su=x.setupProduct,Tu=x.setupProducts,vu=n(()=>Bn(x),"autoInit");var Ou=x.initialize,Xi;((Xi=j)==null?void 0:Xi.shopify_selling_plans)&&Qt(()=>Qi(x));return wu;})();
884
884
  ; return lib; });
885
885
  //# sourceMappingURL=offers.js.map