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

32 lines (31 loc) 3.2 kB
import{y as i,j as $}from"./lit-WqMxC_PA.esm.js";import{N as g,M as y,B as u}from"./beam-errors-Ci0d3926.esm.js";import{logger as d}from"../utils/logger.js";const b=t=>Object.entries(t).map(([r,n])=>`${r}: ${n};`).join(` `);class x{constructor(r,n){this.data=null,this.loading=!1,this.error=null,(this.host=r).addController(this),this.asyncFn=n}async exec(...r){this.lastArgs=r,this.loading=!0,this.host.requestUpdate();try{this.data=await this.asyncFn(...r),this.error=null}catch(n){n instanceof Error&&(this.error=n,this.data=null)}return this.loading=!1,this.host.requestUpdate(),this.data}async retry(){return this.exec(...this.lastArgs||[])}hostDisconnected(){}}const m={errorTitle:"Beam encountered an error. Please try again.",retry:"Retry"},S=({error:t,retry:r})=>{let n=i``;if(t instanceof g){const o=JSON.stringify({status:t.response.status,statusText:t.response.statusText,url:t.response.url,body:t.body},null,4);n=i` <p><b>Network Response:</b></p> <p>${o}</p> `}return t instanceof y&&(n=i` <p><b>Missing Required Config Options:</b></p> <p>${t.missingConfigKeyNames.join(", ")}</p> `),i`<div class="beam-error" style="text-align: left"> <p>${m.errorTitle} ${r?i` <button type="reset" @click="${r}">${m.retry}</button>`:""}</p> <br /> <details> <div style="white-space: pre-wrap; font-family: monospace; line-height: 1;"> ${n} <p><b>Message:</b> ${t.message||i`<i>None</i>`}</p> <p><b>Stack:</b> ${t.stack}</p> </div> </details> <br /> <p>Help: <a href="https://www.beamimpact.com">www.beamimpact.com</a></p> </div>`},v=(t="",{fontFamily:r="inherit",fontStyle:n="inherit",fontSize:o="inherit",fontWeight:s="inherit",textTransform:a="none",textDecoration:l="none",marginTop:c="0",lineHeight:h="inherit",color:p="inherit",letterSpacing:f="normal"}={})=>{const e=t.startsWith("--beam-")?t:`--beam-${t}`;return{[`${e}-fontFamily`]:r,[`${e}-fontStyle`]:n,[`${e}-fontSize`]:o,[`${e}-fontWeight`]:s,[`${e}-textTransform`]:a,[`${e}-marginTop`]:c,[`${e}-lineHeight`]:h,[`${e}-color`]:p,[`${e}-letterSpacing`]:f,[`${e}-textDecoration`]:l}},T=(t="",{fontFamily:r="inherit",fontStyle:n="inherit",fontSize:o="inherit",fontWeight:s="inherit",textTransform:a="none",textDecoration:l="none",marginTop:c="0",lineHeight:h="inherit",color:p="inherit",letterSpacing:f="normal"}={})=>{const e=t.startsWith("--beam-")?t:`--beam-${t}`;return $(` font-family: var(${e}-fontFamily, ${r}); font-style: var(${e}-fontStyle, ${n}); font-size: var(${e}-fontSize, ${o}); font-weight: var(${e}-fontWeight, ${s}); text-transform: var(${e}-textTransform, ${a}); margin-top: var(${e}-marginTop, ${c}); line-height: var(${e}-lineHeight, ${h}); text-decoration: var(${e}-textDecoration, ${l}); color: var(${e}-color, ${p}); letter-spacing: var(${e}-letterSpacing, ${f}); `)},w=(t,r)=>{if(r.startsWith("{"))try{const n=JSON.parse(r);return n[t]??n.en??r}catch{return d.error(new u("Failed to extract JSON translation from string"),r),r}return r};export{x as A,S as _,b as a,v as d,w as i,T as u}; //# sourceMappingURL=localize-C25pEGnx.esm.js.map