UNPKG

@beamimpact/web-sdk

Version:

The Beam SDK enables brands to connect with their customers over shared values, not transactional discounts, to build stronger loyalty. Our integration achieves this by allowing customers to (a) choose a nonprofit where the brand will donate part of their

3 lines (2 loc) 1.79 kB
import{d as B,i as g}from"./lodash-P8OIs-at.esm.js";import{D as A,b as v}from"./routes-o1QpF40R.esm.js";import{B as K}from"./beam-errors-P-Lu07Ce.esm.js";import{d as J,f as S}from"./events-6Z5MkCRr.esm.js";import{createScopedLocalStorage as _}from"../utils/local-storage.js";import{setCookieValue as L}from"../utils/cookies.js";import{getRemoteSession as U}from"../utils/remote-session.js";import{memoizeLast as x}from"../utils/memoize-last.js";import{B as f}from"./cart-contents-h60geKWa.esm.js";import{getBeamCartId as D}from"../utils/cart.js";const R=50,T=B(x(async function(t,m,l=!1){try{const e=_({apiKey:t.apiKey}),E=t.baseUrl??A,o=e.getItemJson("cart"),a=D(f,t),h=U(t)??void 0,{cartId:n,subtotal:i,itemCount:c,currencyCode:d,content:{items:u=[],discounts:C=[]}={},schema:p={source:"generic"}}=m,r={cartId:n,subtotal:i,itemCount:c,currencyCode:d,content:{items:u,discounts:C},schema:p,beamCartId:a};if(l&&!o&&m?.itemCount){e.setItemJson("cart",{...r,beamCartId:a});return}if(g(r,{...o,cartId:o?.cartId})||m.itemCount===0&&(!a||o?.itemCount===0)){e.setItemJson("cart",{...r,beamCartId:a});return}const w=await v({baseUrl:E,headers:{authorization:`Api-Key ${t.apiKey}`},requestBody:{beamCartId:a,storeId:t.storeId,remoteSessionId:h,cartId:n,subtotal:i,itemCount:c,currencyCode:d}}),{beamCartId:s,expiresAt:I,beamCartCreated:y}=w;s&&I&&await L({name:f,domain:t.domain,value:s,path:"/",expires:new Date(I).getTime()}),e.setItemJson("cart",{...r,beamCartId:s});const b={schema:p,content:{items:u,discounts:C},subtotal:i,itemCount:c,currencyCode:d,cartId:n,beamCartId:s};window.dispatchEvent(new J(b)),y&&window.dispatchEvent(new S(b))}catch(e){throw new K("Could not update cart in Beam",{cause:e})}}),R,{leading:!0});export{T as J}; //# sourceMappingURL=update-cart-EGTcbNRX.esm.js.map