@whoa-chat/react 0.2.0 → 0.3.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.
@@ -1 +1 @@
1
- import{Fragment as z,jsx as t,jsxs as n}from"react/jsx-runtime";import{useEffect as R,useState as c}from"react";import{useTranslation as A}from"./i18n.js";import{StoreAvatar as S}from"./StoreAvatar.js";import{EditIcon as I}from"./MessageActions.js";import{timeOpts as L}from"./clock.js";const T=e=>e&&/^[A-Z]{2}$/.test(e)?String.fromCodePoint(...[...e].map(o=>127462+o.charCodeAt(0)-65)):"",E=()=>{const[e,o]=c(()=>Date.now());return R(()=>{const l=window.setInterval(()=>o(Date.now()),3e4);return()=>window.clearInterval(l)},[]),e},x=({text:e})=>{const{t:o}=A("home"),[l,p]=c(!1);return t("button",{type:"button",className:"mi-copy","aria-label":o("supportChat.merchant.copy"),onClick:()=>{navigator.clipboard?.writeText(e),p(!0),window.setTimeout(()=>p(!1),1500)},children:l?t("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:t("path",{d:"M5 10.5l3.2 3.2L15 7",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})}):n("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:[t("rect",{x:"6.5",y:"6.5",width:"9",height:"9",rx:"2",fill:"none",stroke:"currentColor",strokeWidth:"1.6"}),t("path",{d:"M13.5 6.5V5a1.5 1.5 0 0 0-1.5-1.5H5A1.5 1.5 0 0 0 3.5 5v7A1.5 1.5 0 0 0 5 13.5h1.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6"})]})})},V=({info:e,look:o,supportUrl:l,linksInHeader:p=!1,onSaveEmail:m,onMarkReview:h})=>{const{t:a,i18n:b}=A("home"),[g,d]=c(null),[s,i]=c(null),w=E(),D=e.timezone?new Date(w).toLocaleTimeString(b.language,L({timeZone:e.timezone,weekday:"short"})):null,v=e.timezone?Number(new Intl.DateTimeFormat("en-GB",{timeZone:e.timezone,hour:"2-digit"}).format(new Date(w))):null,k=v!==null&&(v>=22||v<7),y=[e.city,e.region,e.country].filter(Boolean).join(", "),N=e.firstInstallAt?new Date(e.firstInstallAt).toLocaleDateString(b.language,{day:"numeric",month:"short",year:"numeric"}):null;return n("aside",{className:"mi-panel","aria-label":a("supportChat.merchant.title"),children:[n("div",{className:"mi-hero",children:[t(S,{shop:e.shop,name:e.name??e.shop,look:{favicon:o?.favicon??e.logo??null,development:e.development,reviewed:!!e.reviewed,rating:e.reviewed?.rating??null,locked:e.passwordProtected??null},size:44}),n("div",{children:[t("strong",{children:e.name??e.shop}),e.owner&&t("span",{children:e.owner})]})]}),n("dl",{className:"mi-facts",children:[n("div",{children:[t("dt",{children:a("supportChat.merchant.domain")}),n("dd",{className:"mi-mono",children:[t("span",{children:e.shop}),t(x,{text:e.shop})]})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.location")}),t("dd",{children:y?n(z,{children:[t("span",{className:"mi-flag","aria-hidden":!0,children:T(e.countryCode)}),y]}):t("span",{className:"mi-muted",children:a("supportChat.merchant.unknown")})})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.timezone")}),t("dd",{children:e.timezone?n("span",{className:"mi-time",children:[t("b",{className:k?"mi-night":"mi-day",children:D}),t("span",{children:e.timezone.replace(/_/g," ")}),k&&t("em",{children:a("supportChat.merchant.night")})]}):t("span",{className:"mi-muted",children:a("supportChat.merchant.unknown")})})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.plan")}),n("dd",{children:[e.plan??t("span",{className:"mi-muted",children:a("supportChat.merchant.unknown")}),e.plus&&t("span",{className:"mi-tag mi-tag--plus",children:"Plus"}),e.development&&t("span",{className:"mi-tag",children:a("supportChat.merchant.dev")})]})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.app")}),t("dd",{children:e.installed?N?a("supportChat.merchant.since",{date:N}):a("supportChat.merchant.installed"):t("span",{className:"mi-tag mi-tag--gone",children:a("supportChat.merchant.uninstalled")})})]}),e.foundVia&&n("div",{children:[t("dt",{children:a("supportChat.merchant.foundVia")}),t("dd",{children:e.foundVia})]}),e.uninstallReason&&n("div",{children:[t("dt",{children:a("supportChat.merchant.uninstallReason")}),n("dd",{className:"mi-left",children:[e.uninstallReason.reason&&t("strong",{children:e.uninstallReason.reason}),e.uninstallReason.description&&t("span",{children:e.uninstallReason.description})]})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.review")}),t("dd",{children:e.reviewed?t("span",{className:"mi-tag mi-tag--ok",children:a("supportChat.merchant.reviewed",{rating:e.reviewed.rating??"?"})}):e.development?t("span",{className:"mi-muted",children:a("supportChat.merchant.cannotReview")}):s&&h?n("form",{className:"mi-review-mark",onSubmit:r=>{r.preventDefault(),s.rating&&(i({...s,busy:!0,error:null}),h(s.rating,s.body.trim()).then(()=>i(null),u=>i(C=>C&&{...C,busy:!1,error:u.message})))},children:[t("span",{className:"mi-stars",role:"radiogroup","aria-label":a("supportChat.merchant.markReviewed"),children:[1,2,3,4,5].map(r=>t("button",{type:"button",role:"radio","aria-checked":s.rating===r,"aria-label":`${r}`,className:r<=s.rating?"on":"",onClick:()=>i({...s,rating:r}),children:"\u2605"},r))}),t("textarea",{rows:2,value:s.body,placeholder:a("supportChat.merchant.reviewText"),onChange:r=>i({...s,body:r.target.value})}),s.error&&t("span",{className:"mi-review-error",children:s.error}),n("span",{className:"mi-review-actions",children:[t("button",{type:"button",onClick:()=>i(null),children:a("supportChat.msg.cancelReply")}),t("button",{type:"submit",disabled:!s.rating||s.busy,children:a("supportChat.msg.save")})]})]}):n(z,{children:[t("span",{className:"mi-muted",children:a("supportChat.merchant.notReviewed")}),h&&t("button",{type:"button",className:"mi-review-add",onClick:()=>i({rating:0,body:"",busy:!1,error:null}),children:a("supportChat.merchant.markReviewed")})]})})]}),e.otherApps&&n("div",{children:[t("dt",{children:a("supportChat.merchant.otherApps")}),t("dd",{className:"mi-apps",children:e.otherApps.length?e.otherApps.map(r=>n("span",{className:`mi-app${r.enabled?"":" mi-muted"}`,children:[r.icon?t("img",{className:"mi-app-icon",src:`${r.icon}?width=48&height=48`,alt:"",width:18,height:18,loading:"lazy"}):t("span",{className:"mi-app-icon mi-app-icon--letter","aria-hidden":!0,children:r.name.charAt(0).toUpperCase()}),t("span",{className:"mi-app-name",children:r.name})]},r.name)):t("span",{className:"mi-muted",children:a("supportChat.merchant.otherAppsNone")})})]}),(e.email||m)&&n("div",{children:[t("dt",{children:a("supportChat.merchant.email")}),g!==null&&m?t("dd",{children:n("form",{className:"mi-email-edit",onSubmit:r=>{r.preventDefault();const u=g.trim().toLowerCase();/^[^\s@<>",;]{1,64}@[^\s@<>",;]{1,190}\.[a-z]{2,}$/i.test(u)&&(m(u),d(null))},children:[t("input",{autoFocus:!0,type:"email",value:g,onChange:r=>d(r.target.value),onKeyDown:r=>r.key==="Escape"&&d(null)}),t("button",{type:"submit",children:a("supportChat.msg.save")})]})}):n("dd",{className:"mi-mono",children:[t("span",{children:e.email}),e.email&&t(x,{text:e.email}),m&&t("button",{type:"button",className:"mi-email-pen","aria-label":a("supportChat.msg.edit"),title:a("supportChat.msg.edit"),onClick:()=>d(e.email??""),children:t(I,{size:13})})]})]})]}),n("div",{className:"mi-links",children:[!p&&l&&t("a",{href:`${l}?${new URLSearchParams({switchTo:e.shop})}`,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openSupport")}),e.links.storefront&&t("a",{href:e.links.storefront,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openStore")}),t("a",{href:e.links.admin,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openAdmin")}),t("a",{href:e.links.posthog,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openPosthog")})]}),e.readError&&t("p",{className:"mi-muted mi-note",children:a("supportChat.merchant.readError")})]})};export{V as MerchantPanel};
1
+ import{Fragment as z,jsx as t,jsxs as n}from"react/jsx-runtime";import{useEffect as R,useState as c}from"react";import{useTranslation as A}from"./i18n.js";import{StoreAvatar as S}from"./StoreAvatar.js";import{EditIcon as I}from"./MessageActions.js";import{timeOpts as L}from"./clock.js";const T=e=>e&&/^[A-Z]{2}$/.test(e)?String.fromCodePoint(...[...e].map(o=>127462+o.charCodeAt(0)-65)):"",E=()=>{const[e,o]=c(()=>Date.now());return R(()=>{const l=window.setInterval(()=>o(Date.now()),3e4);return()=>window.clearInterval(l)},[]),e},x=({text:e})=>{const{t:o}=A("home"),[l,p]=c(!1);return t("button",{type:"button",className:"mi-copy","aria-label":o("supportChat.merchant.copy"),onClick:()=>{navigator.clipboard?.writeText(e),p(!0),window.setTimeout(()=>p(!1),1500)},children:l?t("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:t("path",{d:"M5 10.5l3.2 3.2L15 7",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})}):n("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:[t("rect",{x:"6.5",y:"6.5",width:"9",height:"9",rx:"2",fill:"none",stroke:"currentColor",strokeWidth:"1.6"}),t("path",{d:"M13.5 6.5V5a1.5 1.5 0 0 0-1.5-1.5H5A1.5 1.5 0 0 0 3.5 5v7A1.5 1.5 0 0 0 5 13.5h1.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6"})]})})},V=({info:e,look:o,supportUrl:l,linksInHeader:p=!1,onSaveEmail:m,onMarkReview:h})=>{const{t:a,i18n:b}=A("home"),[g,d]=c(null),[s,i]=c(null),w=E(),D=e.timezone?new Date(w).toLocaleTimeString(b.language,L({timeZone:e.timezone,weekday:"short"})):null,v=e.timezone?Number(new Intl.DateTimeFormat("en-GB",{timeZone:e.timezone,hour:"2-digit"}).format(new Date(w))):null,k=v!==null&&(v>=22||v<7),y=[e.city,e.region,e.country].filter(Boolean).join(", "),N=e.firstInstallAt?new Date(e.firstInstallAt).toLocaleDateString(b.language,{day:"numeric",month:"short",year:"numeric"}):null;return n("aside",{className:"mi-panel","aria-label":a("supportChat.merchant.title"),children:[n("div",{className:"mi-hero",children:[t(S,{shop:e.shop,name:e.name??e.shop,look:{favicon:o?.favicon??e.logo??null,development:e.development,reviewed:!!e.reviewed,rating:e.reviewed?.rating??null,locked:e.passwordProtected??null,paying:!!e.paying},size:44}),n("div",{children:[t("strong",{children:e.name??e.shop}),e.owner&&t("span",{children:e.owner})]})]}),n("dl",{className:"mi-facts",children:[n("div",{children:[t("dt",{children:a("supportChat.merchant.domain")}),n("dd",{className:"mi-mono",children:[t("span",{children:e.shop}),t(x,{text:e.shop})]})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.location")}),t("dd",{children:y?n(z,{children:[t("span",{className:"mi-flag","aria-hidden":!0,children:T(e.countryCode)}),y]}):t("span",{className:"mi-muted",children:a("supportChat.merchant.unknown")})})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.timezone")}),t("dd",{children:e.timezone?n("span",{className:"mi-time",children:[t("b",{className:k?"mi-night":"mi-day",children:D}),t("span",{children:e.timezone.replace(/_/g," ")}),k&&t("em",{children:a("supportChat.merchant.night")})]}):t("span",{className:"mi-muted",children:a("supportChat.merchant.unknown")})})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.plan")}),n("dd",{children:[e.plan??t("span",{className:"mi-muted",children:a("supportChat.merchant.unknown")}),e.plus&&t("span",{className:"mi-tag mi-tag--plus",children:"Plus"}),e.development&&t("span",{className:"mi-tag",children:a("supportChat.merchant.dev")})]})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.app")}),t("dd",{children:e.installed?N?a("supportChat.merchant.since",{date:N}):a("supportChat.merchant.installed"):t("span",{className:"mi-tag mi-tag--gone",children:a("supportChat.merchant.uninstalled")})})]}),e.foundVia&&n("div",{children:[t("dt",{children:a("supportChat.merchant.foundVia")}),t("dd",{children:e.foundVia})]}),e.uninstallReason&&n("div",{children:[t("dt",{children:a("supportChat.merchant.uninstallReason")}),n("dd",{className:"mi-left",children:[e.uninstallReason.reason&&t("strong",{children:e.uninstallReason.reason}),e.uninstallReason.description&&t("span",{children:e.uninstallReason.description})]})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.review")}),t("dd",{children:e.reviewed?t("span",{className:"mi-tag mi-tag--ok",children:a("supportChat.merchant.reviewed",{rating:e.reviewed.rating??"?"})}):e.development?t("span",{className:"mi-muted",children:a("supportChat.merchant.cannotReview")}):s&&h?n("form",{className:"mi-review-mark",onSubmit:r=>{r.preventDefault(),s.rating&&(i({...s,busy:!0,error:null}),h(s.rating,s.body.trim()).then(()=>i(null),u=>i(C=>C&&{...C,busy:!1,error:u.message})))},children:[t("span",{className:"mi-stars",role:"radiogroup","aria-label":a("supportChat.merchant.markReviewed"),children:[1,2,3,4,5].map(r=>t("button",{type:"button",role:"radio","aria-checked":s.rating===r,"aria-label":`${r}`,className:r<=s.rating?"on":"",onClick:()=>i({...s,rating:r}),children:"\u2605"},r))}),t("textarea",{rows:2,value:s.body,placeholder:a("supportChat.merchant.reviewText"),onChange:r=>i({...s,body:r.target.value})}),s.error&&t("span",{className:"mi-review-error",children:s.error}),n("span",{className:"mi-review-actions",children:[t("button",{type:"button",onClick:()=>i(null),children:a("supportChat.msg.cancelReply")}),t("button",{type:"submit",disabled:!s.rating||s.busy,children:a("supportChat.msg.save")})]})]}):n(z,{children:[t("span",{className:"mi-muted",children:a("supportChat.merchant.notReviewed")}),h&&t("button",{type:"button",className:"mi-review-add",onClick:()=>i({rating:0,body:"",busy:!1,error:null}),children:a("supportChat.merchant.markReviewed")})]})})]}),e.otherApps&&n("div",{children:[t("dt",{children:a("supportChat.merchant.otherApps")}),t("dd",{className:"mi-apps",children:e.otherApps.length?e.otherApps.map(r=>n("span",{className:`mi-app${r.enabled?"":" mi-muted"}`,children:[r.icon?t("img",{className:"mi-app-icon",src:`${r.icon}?width=48&height=48`,alt:"",width:18,height:18,loading:"lazy"}):t("span",{className:"mi-app-icon mi-app-icon--letter","aria-hidden":!0,children:r.name.charAt(0).toUpperCase()}),t("span",{className:"mi-app-name",children:r.name})]},r.name)):t("span",{className:"mi-muted",children:a("supportChat.merchant.otherAppsNone")})})]}),(e.email||m)&&n("div",{children:[t("dt",{children:a("supportChat.merchant.email")}),g!==null&&m?t("dd",{children:n("form",{className:"mi-email-edit",onSubmit:r=>{r.preventDefault();const u=g.trim().toLowerCase();/^[^\s@<>",;]{1,64}@[^\s@<>",;]{1,190}\.[a-z]{2,}$/i.test(u)&&(m(u),d(null))},children:[t("input",{autoFocus:!0,type:"email",value:g,onChange:r=>d(r.target.value),onKeyDown:r=>r.key==="Escape"&&d(null)}),t("button",{type:"submit",children:a("supportChat.msg.save")})]})}):n("dd",{className:"mi-mono",children:[t("span",{children:e.email}),e.email&&t(x,{text:e.email}),m&&t("button",{type:"button",className:"mi-email-pen","aria-label":a("supportChat.msg.edit"),title:a("supportChat.msg.edit"),onClick:()=>d(e.email??""),children:t(I,{size:13})})]})]})]}),n("div",{className:"mi-links",children:[!p&&l&&t("a",{href:`${l}?${new URLSearchParams({switchTo:e.shop})}`,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openSupport")}),e.links.storefront&&t("a",{href:e.links.storefront,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openStore")}),t("a",{href:e.links.admin,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openAdmin")}),t("a",{href:e.links.posthog,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openPosthog")})]}),e.readError&&t("p",{className:"mi-muted mi-note",children:a("supportChat.merchant.readError")})]})};export{V as MerchantPanel};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as o}from"react/jsx-runtime";import{useEffect as b,useRef as I,useState as d,useMemo as O}from"react";import{useTranslation as q}from"./i18n.js";import{copyToClipboard as E}from"./copyToClipboard.js";import{APP_STORE_REVIEW_URL as u}from"@whoa-chat/core/types";import{awayDetail as U,watchReviewAway as B}from"@whoa-chat/core/reviewAway";import{AgentAvatar as F}from"./agents.js";import{brandVars as V,chatHost as C}from"./host.js";const W=new Set(["already-open","open-in-progress"]),k="M11.128 4.123c-.453-.95-1.803-.95-2.256 0l-1.39 2.912-3.199.421c-1.042.138-1.46 1.422-.697 2.146l2.34 2.222-.587 3.172c-.192 1.034.901 1.828 1.825 1.327l2.836-1.54 2.836 1.54c.924.501 2.017-.293 1.825-1.327l-.587-3.172 2.34-2.222c.762-.724.345-2.008-.697-2.146l-3.2-.421-1.389-2.912Z",j=async()=>{let r="error";try{r=(await shopify.reviews.request()).code}catch{}return W.has(r)?null:r!=="success"&&r!=="cancelled"?(window.open(u,"_blank","noopener"),"app-store"):r},z=async r=>{const a=Date.now(),s=await j();return r&&(s==="success"||s==="app-store")&&B(s==="app-store"?"tab":"dialog",c=>r(U(c)),{startedAt:a,answerMs:Date.now()-a}),s},H=()=>e("svg",{viewBox:"0 0 24 24",width:"13",height:"13","aria-hidden":!0,children:e("path",{className:"srv-check-path",d:"M5 12.5l4.2 4.2L19 7",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"})}),G=({rating:r})=>e("span",{className:"srv-stars","aria-hidden":!0,children:[1,2,3,4,5].map(a=>o("svg",{viewBox:"0 0 20 20",width:"15",height:"15",style:{animationDelay:`${.25+a*.07}s`},children:[e("defs",{children:e("clipPath",{id:`srv-star-${a}`,children:e("rect",{x:"0",y:"0",width:20*Math.max(0,Math.min(1,r-a+1)),height:"20"})})}),e("path",{d:k,fill:"#e3e3e3",transform:"translate(-0.5 -0.6) scale(1.1)"}),e("path",{d:k,fill:"#ffb21e",clipPath:`url(#srv-star-${a})`,transform:"translate(-0.5 -0.6) scale(1.1)"})]},a))}),y=["#7c5cff","#29b6f6","#f5a623","#22c55e","#ff5c8a","#ffd23f"],Z=()=>{const r=O(()=>Array.from({length:70},(a,s)=>({left:Math.random()*100,drift:(Math.random()-.5)*140,spin:(Math.random()-.5)*900,delay:Math.random()*.35,duration:1.6+Math.random()*1.1,colour:y[s%y.length],round:s%3===0})),[]);return e("div",{className:"srv-confetti","aria-hidden":!0,children:r.map((a,s)=>e("i",{className:a.round?"srv-confetti-dot":void 0,style:{left:`${a.left}%`,background:a.colour,animationDelay:`${a.delay}s`,animationDuration:`${a.duration}s`,"--drift":`${a.drift}px`,"--spin":`${a.spin}deg`}},s))})},ae=({message:r,shopOwnerName:a,listing:s,preview:c,onState:v,onAway:S})=>{const{t,i18n:L}=q("home"),i=r.review,l=r.agentName??"Stefan",[m,h]=d(i.state),[x,f]=d(!1),[M,R]=d(!1),[A,P]=d(!1),w=I(!1);b(()=>h(i.state),[i.state]),b(()=>{c||w.current||i.state!=="sent"||(w.current=!0,v?.("seen"))},[c,i.state,v]);const g=(n,p)=>{h(n),v?.(n,p)},_=async()=>{if(c)return;const n=await z(S);n!==null&&(n==="app-store"&&R(!0),P(!0),g("clicked",n))},D=async()=>{c||(await E(u),f(!0),window.setTimeout(()=>f(!1),2500))},N=a?.split(" ")[0],T=s?new Intl.NumberFormat(L.language,{minimumFractionDigits:1,maximumFractionDigits:1}).format(s.rating):null;return m==="clicked"?o("div",{className:"srv-card srv-card--thanks",role:"status",children:[A&&e(Z,{}),e("img",{className:"srv-thanks-logo",src:C().brand.logo,alt:"",width:52,height:52}),e("p",{className:"srv-thanks-title",children:N?t("supportChat.review.thanksNamed",{name:N}):t("supportChat.review.thanks")}),e("p",{className:"srv-thanks-copy",children:t("supportChat.review.thanksCopy",{agent:l})}),e("a",{className:"srv-link",href:u,target:"_blank",rel:"noopener noreferrer",children:t(M?"supportChat.review.openListing":"supportChat.review.openAgain")})]}):m==="issue"?e("div",{className:"srv-card srv-card--quiet",role:"status",children:e("p",{className:"srv-quiet",children:t("supportChat.review.issueAck",{agent:l})})}):m==="dismissed"?e("div",{className:"srv-card srv-card--quiet",children:o("p",{className:"srv-quiet",children:[t("supportChat.review.dismissedAck")," ",e("button",{type:"button",className:"srv-link",onClick:()=>g("seen"),children:t("supportChat.review.showAgain")})]})}):o("article",{className:`srv-card${c?" srv-card--preview":""}`,"aria-label":t("supportChat.review.label"),children:[o("div",{className:"srv-hero",children:[e("span",{className:"srv-blob srv-blob--a","aria-hidden":!0}),e("span",{className:"srv-blob srv-blob--b","aria-hidden":!0}),e("img",{className:"srv-logo",src:C().brand.logo,alt:"",width:56,height:56}),o("div",{className:"srv-app",children:[e("strong",{children:t("supportChat.review.appName",V())}),s?o("span",{className:"srv-rating",children:[e(G,{rating:s.rating}),e("b",{children:T}),e("span",{children:t("supportChat.review.reviewCount",{count:s.reviewCount})})]}):e("span",{className:"srv-rating",children:t("supportChat.review.onAppStore")})]})]}),o("div",{className:"srv-body",children:[i.fixed&&o("div",{className:"srv-fixed",children:[e("span",{className:"srv-check",children:e(H,{})}),o("div",{className:"srv-fixed-main",children:[e("span",{className:"srv-eyebrow",children:t("supportChat.review.fixedBy",{agent:l})}),e("p",{className:"srv-fixed-text",children:i.fixed})]}),e("span",{className:"srv-agent-ring",children:e(F,{name:l,size:40})})]}),i.beforeImageUrl&&i.afterImageUrl&&e("div",{className:"srv-ba",children:[[i.beforeImageUrl,t("supportChat.review.before")],[i.afterImageUrl,t("supportChat.review.after")]].map(([n,p],$)=>o("a",{className:`srv-shot${$?" srv-shot--after":""}`,href:n,target:"_blank",rel:"noopener noreferrer",children:[e("img",{src:n,alt:p,loading:"lazy"}),e("span",{children:p})]},p))}),e("h3",{className:"srv-title",children:i?.title||t("supportChat.review.title")}),e("p",{className:"srv-copy",children:i?.ask||t("supportChat.review.body")}),o("button",{type:"button",className:"srv-primary","data-card-action":"review_clicked",onClick:_,disabled:c,children:[e("span",{children:t("supportChat.review.cta")}),e("span",{className:"srv-primary-icon","aria-hidden":!0,children:e("svg",{viewBox:"0 0 20 20",width:"12",height:"12",children:e("path",{d:"M7 13l6-6M8 7h5v5",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e("p",{className:"srv-time",children:s?t("supportChat.review.joinOthers",{count:s.reviewCount}):t("supportChat.review.time")})]}),o("footer",{className:"srv-owner",children:[e("span",{children:t("supportChat.review.ownerOnly")}),e("button",{type:"button",className:"srv-link",onClick:D,children:t(x?"supportChat.review.copied":"supportChat.review.copyLink")})]})]})};export{ae as ReviewCard,j as requestReview,z as requestReviewTimed};
1
+ import{jsx as e,jsxs as i}from"react/jsx-runtime";import{useEffect as b,useRef as I,useState as d,useMemo as O}from"react";import{useTranslation as q}from"./i18n.js";import{copyToClipboard as E}from"./copyToClipboard.js";import{APP_STORE_REVIEW_URL as u}from"@whoa-chat/core/types";import{awayDetail as U,watchReviewAway as B}from"@whoa-chat/core/reviewAway";import{AgentAvatar as F}from"./agents.js";import{brandVars as V,chatHost as C}from"./host.js";const W=new Set(["already-open","open-in-progress"]),k="M11.128 4.123c-.453-.95-1.803-.95-2.256 0l-1.39 2.912-3.199.421c-1.042.138-1.46 1.422-.697 2.146l2.34 2.222-.587 3.172c-.192 1.034.901 1.828 1.825 1.327l2.836-1.54 2.836 1.54c.924.501 2.017-.293 1.825-1.327l-.587-3.172 2.34-2.222c.762-.724.345-2.008-.697-2.146l-3.2-.421-1.389-2.912Z",j=async()=>{let r="error";try{r=(await shopify.reviews.request()).code}catch{}return W.has(r)?null:r!=="success"&&r!=="cancelled"?(window.open(u,"_blank","noopener"),"app-store"):r},z=async r=>{const a=Date.now(),s=await j();return r&&(s==="success"||s==="app-store")&&B(s==="app-store"?"tab":"dialog",c=>r(U(c)),{startedAt:a,answerMs:Date.now()-a}),s},H=()=>e("svg",{viewBox:"0 0 24 24",width:"10",height:"10","aria-hidden":!0,children:e("path",{className:"srv-check-path",d:"M5 12.5l4.2 4.2L19 7",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"})}),G=({rating:r})=>e("span",{className:"srv-stars","aria-hidden":!0,children:[1,2,3,4,5].map(a=>i("svg",{viewBox:"0 0 20 20",width:"15",height:"15",style:{animationDelay:`${.25+a*.07}s`},children:[e("defs",{children:e("clipPath",{id:`srv-star-${a}`,children:e("rect",{x:"0",y:"0",width:20*Math.max(0,Math.min(1,r-a+1)),height:"20"})})}),e("path",{d:k,fill:"#e3e3e3",transform:"translate(-0.5 -0.6) scale(1.1)"}),e("path",{d:k,fill:"#ffb21e",clipPath:`url(#srv-star-${a})`,transform:"translate(-0.5 -0.6) scale(1.1)"})]},a))}),y=["#7c5cff","#29b6f6","#f5a623","#22c55e","#ff5c8a","#ffd23f"],Z=()=>{const r=O(()=>Array.from({length:70},(a,s)=>({left:Math.random()*100,drift:(Math.random()-.5)*140,spin:(Math.random()-.5)*900,delay:Math.random()*.35,duration:1.6+Math.random()*1.1,colour:y[s%y.length],round:s%3===0})),[]);return e("div",{className:"srv-confetti","aria-hidden":!0,children:r.map((a,s)=>e("i",{className:a.round?"srv-confetti-dot":void 0,style:{left:`${a.left}%`,background:a.colour,animationDelay:`${a.delay}s`,animationDuration:`${a.duration}s`,"--drift":`${a.drift}px`,"--spin":`${a.spin}deg`}},s))})},ae=({message:r,shopOwnerName:a,listing:s,preview:c,onState:v,onAway:S})=>{const{t,i18n:L}=q("home"),o=r.review,l=r.agentName??"Stefan",[m,h]=d(o.state),[x,f]=d(!1),[M,R]=d(!1),[A,P]=d(!1),w=I(!1);b(()=>h(o.state),[o.state]),b(()=>{c||w.current||o.state!=="sent"||(w.current=!0,v?.("seen"))},[c,o.state,v]);const g=(n,p)=>{h(n),v?.(n,p)},_=async()=>{if(c)return;const n=await z(S);n!==null&&(n==="app-store"&&R(!0),P(!0),g("clicked",n))},D=async()=>{c||(await E(u),f(!0),window.setTimeout(()=>f(!1),2500))},N=a?.split(" ")[0],T=s?new Intl.NumberFormat(L.language,{minimumFractionDigits:1,maximumFractionDigits:1}).format(s.rating):null;return m==="clicked"?i("div",{className:"srv-card srv-card--thanks",role:"status",children:[A&&e(Z,{}),e("img",{className:"srv-thanks-logo",src:C().brand.logo,alt:"",width:52,height:52}),e("p",{className:"srv-thanks-title",children:N?t("supportChat.review.thanksNamed",{name:N}):t("supportChat.review.thanks")}),e("p",{className:"srv-thanks-copy",children:t("supportChat.review.thanksCopy",{agent:l})}),e("a",{className:"srv-link",href:u,target:"_blank",rel:"noopener noreferrer",children:t(M?"supportChat.review.openListing":"supportChat.review.openAgain")})]}):m==="issue"?e("div",{className:"srv-card srv-card--quiet",role:"status",children:e("p",{className:"srv-quiet",children:t("supportChat.review.issueAck",{agent:l})})}):m==="dismissed"?e("div",{className:"srv-card srv-card--quiet",children:i("p",{className:"srv-quiet",children:[t("supportChat.review.dismissedAck")," ",e("button",{type:"button",className:"srv-link",onClick:()=>g("seen"),children:t("supportChat.review.showAgain")})]})}):i("article",{className:`srv-card${c?" srv-card--preview":""}`,"aria-label":t("supportChat.review.label"),children:[i("div",{className:"srv-hero",children:[e("span",{className:"srv-blob srv-blob--a","aria-hidden":!0}),e("span",{className:"srv-blob srv-blob--b","aria-hidden":!0}),e("img",{className:"srv-logo",src:C().brand.logo,alt:"",width:56,height:56}),i("div",{className:"srv-app",children:[e("strong",{children:t("supportChat.review.appName",V())}),s?i("span",{className:"srv-rating",children:[e(G,{rating:s.rating}),e("b",{children:T}),e("span",{children:t("supportChat.review.reviewCount",{count:s.reviewCount})})]}):e("span",{className:"srv-rating",children:t("supportChat.review.onAppStore")})]})]}),i("div",{className:"srv-body",children:[o.fixed&&i("div",{className:"srv-fixed",children:[i("span",{className:"srv-agent-ring",children:[e(F,{name:l,size:36}),e("span",{className:"srv-check",children:e(H,{})})]}),i("div",{className:"srv-fixed-main",children:[e("span",{className:"srv-eyebrow",children:t("supportChat.review.fixedBy",{agent:l})}),e("p",{className:"srv-fixed-text",children:o.fixed})]})]}),o.beforeImageUrl&&o.afterImageUrl&&e("div",{className:"srv-ba",children:[[o.beforeImageUrl,t("supportChat.review.before")],[o.afterImageUrl,t("supportChat.review.after")]].map(([n,p],$)=>i("a",{className:`srv-shot${$?" srv-shot--after":""}`,href:n,target:"_blank",rel:"noopener noreferrer",children:[e("img",{src:n,alt:p,loading:"lazy"}),e("span",{children:p})]},p))}),e("h3",{className:"srv-title",children:o?.title||t("supportChat.review.title")}),e("p",{className:"srv-copy",children:o?.ask||t("supportChat.review.body")}),i("button",{type:"button",className:"srv-primary","data-card-action":"review_clicked",onClick:_,disabled:c,children:[e("span",{children:t("supportChat.review.cta")}),e("span",{className:"srv-primary-icon","aria-hidden":!0,children:e("svg",{viewBox:"0 0 20 20",width:"12",height:"12",children:e("path",{d:"M7 13l6-6M8 7h5v5",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e("p",{className:"srv-time",children:s?t("supportChat.review.joinOthers",{count:s.reviewCount}):t("supportChat.review.time")})]}),i("footer",{className:"srv-owner",children:[e("span",{children:t("supportChat.review.ownerOnly")}),e("button",{type:"button",className:"srv-link",onClick:D,children:t(x?"supportChat.review.copied":"supportChat.review.copyLink")})]})]})};export{ae as ReviewCard,j as requestReview,z as requestReviewTimed};
@@ -5,6 +5,7 @@ export type StoreLook = {
5
5
  reviewed?: boolean;
6
6
  rating?: number | null;
7
7
  locked?: boolean | null;
8
+ paying?: boolean;
8
9
  uninstalled?: boolean;
9
10
  collaborator?: boolean;
10
11
  };
@@ -15,6 +16,7 @@ export declare const lookFrom: (info: {
15
16
  rating: number | null;
16
17
  } | null;
17
18
  passwordProtected?: boolean | null;
19
+ paying?: boolean | null;
18
20
  logo?: string | null;
19
21
  installed?: boolean;
20
22
  } | null | undefined) => StoreLook | null;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as L}from"react/jsx-runtime";import{STORE_THREAD as m}from"@whoa-chat/core/conversation";import{useState as w}from"react";const y=n=>n?{uninstalled:n.installed===!1,favicon:n.logo??null,development:!!n.development,reviewed:!!n.reviewed,rating:n.reviewed?.rating??null,locked:n.passwordProtected??null}:null,c=["#ff6b2c","#f2506a","#e040c8","#a53af0","#4f7cff","#12a150","#f5a524","#0ea5a4"],b=n=>c[[...n].reduce((l,t)=>l*31+t.charCodeAt(0)>>>0,7)%c.length],S=n=>n.replace(/\.myshopify\.com(~[a-z0-9]+)?$/,"").split(/[\s._-]+/).filter(Boolean).slice(0,2).map(l=>l[0].toUpperCase()).join("")||"?",B=({dev:n})=>e("img",{className:"st-bag",src:n?"/support/shopify-dev.png":"/support/shopify.svg",alt:""}),N=({shop:n,name:l,look:t,size:i=40,flag:o=null,online:u=!1,status:r=null})=>{const[p,g]=w(!1),v=!!(n&&m.test(n)),a=!!t?.development,f=t?.favicon&&!p?e("img",{src:t.favicon,alt:"",onError:()=>g(!0)}):v?e(B,{dev:a}):e("span",{className:"st-initials",style:{background:b(l||n||"?"),fontSize:i*.38},children:S(l||n||"?")}),s=t?.reviewed?t.rating!==null&&t.rating!==void 0&&t.rating<=3?"low":"gold":null,h=[t?.uninstalled?"Uninstalled":null,t?.reviewed?`Reviewed${t.rating?` \u2605 ${t.rating}`:""}`:null,t?.collaborator?"Collaborator access":null,a?"Development store":t?.locked?"Password protected":null,r?.label??null].filter(Boolean),d=r&&!t?.uninstalled?{good:"done",partial:"half",none:"none"}[r.tone]:null;return L("span",{className:`st-avatar${t?.uninstalled?" st-avatar--gone":""}${a?" st-avatar--dev":""}${s?` st-avatar--ring-${s}`:""}`,style:{width:i,height:i},title:h.join(" \xB7 ")||void 0,children:[f,u&&e("i",{className:"st-online",title:"Online now","aria-label":"Online now"}),d&&e("i",{className:`st-setup st-setup--${d}`,"aria-hidden":!0,children:d==="done"&&e("svg",{viewBox:"0 0 16 16",width:"7",height:"7",children:e("path",{d:"M3.5 8.5 6.5 11.5 12.5 4.5",fill:"none",stroke:"#fff",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round"})})}),o&&e("i",{className:"st-flag",title:o.title,"aria-label":o.title,children:o.code?e("img",{src:`https://flagcdn.com/${o.code.toLowerCase()}.svg`,alt:""}):e("span",{children:o.emoji})}),s?e("i",{className:`st-star${s==="low"?" st-star--low":""}`,children:e("svg",{viewBox:"0 0 16 16","aria-hidden":!0,children:e("path",{d:"M8 1.5l1.9 4.1 4.5.5-3.3 3.1.9 4.4L8 11.4l-4 2.2.9-4.4-3.3-3.1 4.5-.5z",fill:"#fff"})})}):a?e("i",{className:"st-code",children:e("svg",{viewBox:"0 0 16 16",width:"7",height:"7","aria-hidden":!0,children:e("path",{d:"M5.5 4.5 2 8l3.5 3.5M10.5 4.5 14 8l-3.5 3.5",fill:"none",stroke:"#fff",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}):t?.locked?e("i",{className:"st-lock",children:e("svg",{viewBox:"0 0 16 16",width:"6.5",height:"6.5","aria-hidden":!0,children:e("path",{d:"M4.5 7V5.5a3.5 3.5 0 0 1 7 0V7M3.5 7h9v7h-9z",fill:"none",stroke:"#fff",strokeWidth:"1.8",strokeLinejoin:"round"})})}):null]})};export{N as StoreAvatar,y as lookFrom};
1
+ import{jsx as e,jsxs as S}from"react/jsx-runtime";import{STORE_THREAD as m}from"@whoa-chat/core/conversation";import{useState as w}from"react";const N=t=>t?{uninstalled:t.installed===!1,favicon:t.logo??null,development:!!t.development,reviewed:!!t.reviewed,rating:t.reviewed?.rating??null,locked:t.passwordProtected??null,paying:!!t.paying}:null,c=["#ff6b2c","#f2506a","#e040c8","#a53af0","#4f7cff","#12a150","#f5a524","#0ea5a4"],b=t=>c[[...t].reduce((l,n)=>l*31+n.charCodeAt(0)>>>0,7)%c.length],y=t=>t.replace(/\.myshopify\.com(~[a-z0-9]+)?$/,"").split(/[\s._-]+/).filter(Boolean).slice(0,2).map(l=>l[0].toUpperCase()).join("")||"?",B=({dev:t})=>e("img",{className:"st-bag",src:t?"/support/shopify-dev.png":"/support/shopify.svg",alt:""}),k=({shop:t,name:l,look:n,size:i=40,flag:a=null,online:u=!1,status:r=null})=>{const[p,g]=w(!1),v=!!(t&&m.test(t)),o=!!n?.development,f=n?.favicon&&!p?e("img",{src:n.favicon,alt:"",onError:()=>g(!0)}):v?e(B,{dev:o}):e("span",{className:"st-initials",style:{background:b(l||t||"?"),fontSize:i*.38},children:y(l||t||"?")}),s=n?.reviewed?n.rating!==null&&n.rating!==void 0&&n.rating<=3?"low":"gold":null,h=[n?.uninstalled?"Uninstalled":null,n?.paying?"Paying":null,n?.reviewed?`Reviewed${n.rating?` \u2605 ${n.rating}`:""}`:null,n?.collaborator?"Collaborator access":null,o?"Development store":n?.locked?"Password protected":null,r?.label??null].filter(Boolean),d=r&&!n?.uninstalled?{good:"done",partial:"half",none:"none"}[r.tone]:null;return S("span",{className:`st-avatar${n?.uninstalled?" st-avatar--gone":""}${o?" st-avatar--dev":""}${s?` st-avatar--ring-${s}`:""}`,style:{width:i,height:i},title:h.join(" \xB7 ")||void 0,children:[f,u&&e("i",{className:"st-online",title:"Online now","aria-label":"Online now"}),d&&e("i",{className:`st-setup st-setup--${d}`,"aria-hidden":!0,children:d==="done"&&e("svg",{viewBox:"0 0 16 16",width:"7",height:"7",children:e("path",{d:"M3.5 8.5 6.5 11.5 12.5 4.5",fill:"none",stroke:"#fff",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round"})})}),a&&e("i",{className:"st-flag",title:a.title,"aria-label":a.title,children:a.code?e("img",{src:`https://flagcdn.com/${a.code.toLowerCase()}.svg`,alt:""}):e("span",{children:a.emoji})}),n?.paying?e("i",{className:`st-cash${n.reviewed?" st-cash--gold":""}`,children:e("svg",{viewBox:"0 0 16 16","aria-hidden":!0,children:e("path",{d:"M10.5 5.2c-.5-.8-1.4-1.2-2.5-1.2-1.4 0-2.4.7-2.4 1.8 0 2.4 5 1.3 5 3.9 0 1.1-1 1.9-2.6 1.9-1.2 0-2.1-.5-2.6-1.3M8 2.5v11",fill:"none",stroke:"#fff",strokeWidth:"1.8",strokeLinecap:"round"})})}):s?e("i",{className:`st-star${s==="low"?" st-star--low":""}`,children:e("svg",{viewBox:"0 0 16 16","aria-hidden":!0,children:e("path",{d:"M8 1.5l1.9 4.1 4.5.5-3.3 3.1.9 4.4L8 11.4l-4 2.2.9-4.4-3.3-3.1 4.5-.5z",fill:"#fff"})})}):o?e("i",{className:"st-code",children:e("svg",{viewBox:"0 0 16 16",width:"7",height:"7","aria-hidden":!0,children:e("path",{d:"M5.5 4.5 2 8l3.5 3.5M10.5 4.5 14 8l-3.5 3.5",fill:"none",stroke:"#fff",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}):n?.locked?e("i",{className:"st-lock",children:e("svg",{viewBox:"0 0 16 16",width:"6.5",height:"6.5","aria-hidden":!0,children:e("path",{d:"M4.5 7V5.5a3.5 3.5 0 0 1 7 0V7M3.5 7h9v7h-9z",fill:"none",stroke:"#fff",strokeWidth:"1.8",strokeLinejoin:"round"})})}):null]})};export{k as StoreAvatar,N as lookFrom};
@@ -162,6 +162,9 @@ export declare const merchantChatApi: (base: string, token: () => Promise<string
162
162
  react: (id: string, emoji: string) => Promise<{
163
163
  ok: true;
164
164
  }>;
165
+ transcript: () => Promise<{
166
+ to: string;
167
+ }>;
165
168
  reviewState: (messageId: string, state: string, outcome?: string) => Promise<{
166
169
  ok: true;
167
170
  }>;
@@ -1 +1 @@
1
- import{chatHost as c,setChatHost as u}from"./host.js";const f=(e,{cards:a})=>{const t={id:e.id,from:e.from,body:e.body,agentName:e.bot?c().brand.bot:e.agentName??null,at:e.at,review:null,...e.files?.length?{files:e.files.map(i=>({id:i.key,name:i.name,type:i.type,size:i.size}))}:{},...e.clicks?.length?{clicks:e.clicks.map(i=>({action:i.action,at:i.at,detail:i.detail??null}))}:{},...e.email?{email:e.email}:{},...e.editedAt?{editedAt:e.editedAt}:{},...e.refs?.length?{refs:e.refs}:{},...e.ai?{ai:e.ai}:{},...e.bot?{bot:!0}:{},...e.translation?{translation:e.translation}:{},...e.translating?{translating:!0}:{},...e.original?{original:e.original}:{},...e.choices?.length?{choices:e.choices}:{},...e.bot&&e.progress?.length?{progress:e.progress}:{},...e.bot&&e.assigned?{assigned:e.assigned}:{},...e.deletedAt?{deletedAt:e.deletedAt,deletedBy:e.deletedBy}:{},...e.replyTo?{replyTo:e.replyTo}:{},...e.reactions?.length?{reactions:e.reactions}:{},...e.verified?{verified:e.verified}:{}};switch(e.kind){case"draft":return{...t,kind:"draft",draft:e.draft??{state:"open"}};case"event":return{...t,kind:"event",event:e.event??{type:"other",fields:[]}};case"note":return{...t,kind:"note",mentions:e.mentions??[],...e.reminder?{reminder:!0}:{}};case"review_request":return{...t,kind:"review_request",review:e.review?{fixed:e.review.fixed,title:e.review.title??null,ask:e.review.ask??null,beforeImageUrl:e.review.beforeImageUrl??null,afterImageUrl:e.review.afterImageUrl??null,state:e.review.state}:null};case"link":return{...t,kind:"link",link:e.link??null};case"pricing":return{...t,kind:"pricing",pricing:e.pricing??null};case"help_offer":return{...t,kind:"help_offer"};case"password_request":return{...t,kind:"password_request"};case"feature_request":return{...t,kind:"feature_request",feature:e.feature??{title:e.body}};case"ticket":return{...t,kind:"ticket",ticket:e.ticket??{title:e.body,state:"open"}};case"reference":return a?{...t,kind:"subscription",subscriptionId:e.ref??null}:{...t,kind:"text",body:`#${e.ref}`};case"custom":return e.card?{...t,kind:"custom",card:e.card}:{...t,kind:"text"};case"offer":return a?{...t,kind:"offer",offerId:e.ref??null}:{...t,kind:"text",body:`Offer ${e.ref}`};default:return{...t,kind:"text"}}},h=e=>{let a=null,t=null;return async()=>a&&a.exp-3e5>Date.now()?a.token:(t??=e().then(i=>{let r=Date.now()+6e5;try{r=JSON.parse(atob(i.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"))).exp*1e3}catch{}return a={token:i,exp:r},i}).finally(()=>t=null),t)},k=(e,a)=>{const t=async(r,n)=>{const s=await fetch(`${e}${r}`,{...n,headers:{"content-type":"application/json",authorization:`Bearer ${await a()}`,...n?.headers}}),o=await s.json().catch(()=>({}));if(!s.ok)throw new Error(o.error??`Request failed (${s.status})`);return o},i=(r,n)=>t(r,{method:"POST",body:JSON.stringify(n)});return{thread:async r=>{const n=await t(`/v1/merchant/thread${r?"?peek=1":""}`);return n.team&&Object.keys(n.team).length&&u({team:n.team}),n},appearance:()=>t("/v1/merchant/appearance"),send:(r,n,s,o,g,l)=>i("/v1/merchant/messages",{body:r,shopName:s,...o?{contact:o}:{},...n.length?{files:n.map(d=>({key:d}))}:{},...g?{workflow:g}:{},...l?{replyTo:l}:{}}),react:(r,n)=>i("/v1/merchant/react",{id:r,emoji:n}),reviewState:(r,n,s)=>i("/v1/merchant/review-state",{messageId:r,state:n,outcome:s}),track:(r,n,s)=>t("/v1/merchant/card-action",{method:"POST",body:JSON.stringify({messageId:r,action:n,detail:s}),keepalive:!0}),upload:async r=>{const{upload:n,file:s}=await i("/v1/merchant/uploads",{name:r.name||"screenshot.png",type:r.type,size:r.size}),o=new FormData;for(const[g,l]of Object.entries(n.fields))o.append(g,l);if(o.append("file",r),!(await fetch(n.url,{method:"POST",body:o})).ok)throw new Error("Upload failed");return{id:s.key,name:s.name,type:s.type,size:s.size}},fileUrl:r=>`${e}/v1/merchant/files?${new URLSearchParams({key:r})}`,fetchFile:async r=>fetch(r,{headers:{authorization:`Bearer ${await a()}`}})}};export{h as cachedMerchantToken,k as merchantChatApi,f as toView};
1
+ import{chatHost as c,setChatHost as p}from"./host.js";const f=(e,{cards:a})=>{const t={id:e.id,from:e.from,body:e.body,agentName:e.bot?c().brand.bot:e.agentName??null,at:e.at,review:null,...e.files?.length?{files:e.files.map(i=>({id:i.key,name:i.name,type:i.type,size:i.size}))}:{},...e.clicks?.length?{clicks:e.clicks.map(i=>({action:i.action,at:i.at,detail:i.detail??null}))}:{},...e.email?{email:e.email}:{},...e.editedAt?{editedAt:e.editedAt}:{},...e.refs?.length?{refs:e.refs}:{},...e.ai?{ai:e.ai}:{},...e.bot?{bot:!0}:{},...e.translation?{translation:e.translation}:{},...e.translating?{translating:!0}:{},...e.original?{original:e.original}:{},...e.choices?.length?{choices:e.choices}:{},...e.bot&&e.progress?.length?{progress:e.progress}:{},...e.bot&&e.assigned?{assigned:e.assigned}:{},...e.deletedAt?{deletedAt:e.deletedAt,deletedBy:e.deletedBy}:{},...e.replyTo?{replyTo:e.replyTo}:{},...e.reactions?.length?{reactions:e.reactions}:{},...e.verified?{verified:e.verified}:{}};switch(e.kind){case"draft":return{...t,kind:"draft",draft:e.draft??{state:"open"}};case"event":return{...t,kind:"event",event:e.event??{type:"other",fields:[]}};case"note":return{...t,kind:"note",mentions:e.mentions??[],...e.reminder?{reminder:!0}:{}};case"review_request":return{...t,kind:"review_request",review:e.review?{fixed:e.review.fixed,title:e.review.title??null,ask:e.review.ask??null,beforeImageUrl:e.review.beforeImageUrl??null,afterImageUrl:e.review.afterImageUrl??null,state:e.review.state}:null};case"link":return{...t,kind:"link",link:e.link??null};case"pricing":return{...t,kind:"pricing",pricing:e.pricing??null};case"help_offer":return{...t,kind:"help_offer"};case"password_request":return{...t,kind:"password_request"};case"feature_request":return{...t,kind:"feature_request",feature:e.feature??{title:e.body}};case"ticket":return{...t,kind:"ticket",ticket:e.ticket??{title:e.body,state:"open"}};case"reference":return a?{...t,kind:"subscription",subscriptionId:e.ref??null}:{...t,kind:"text",body:`#${e.ref}`};case"custom":return e.card?{...t,kind:"custom",card:e.card}:{...t,kind:"text"};case"offer":return a?{...t,kind:"offer",offerId:e.ref??null}:{...t,kind:"text",body:`Offer ${e.ref}`};default:return{...t,kind:"text"}}},h=e=>{let a=null,t=null;return async()=>a&&a.exp-3e5>Date.now()?a.token:(t??=e().then(i=>{let r=Date.now()+6e5;try{r=JSON.parse(atob(i.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"))).exp*1e3}catch{}return a={token:i,exp:r},i}).finally(()=>t=null),t)},k=(e,a)=>{const t=async(r,n)=>{const s=await fetch(`${e}${r}`,{...n,headers:{"content-type":"application/json",authorization:`Bearer ${await a()}`,...n?.headers}}),o=await s.json().catch(()=>({}));if(!s.ok)throw new Error(o.error??`Request failed (${s.status})`);return o},i=(r,n)=>t(r,{method:"POST",body:JSON.stringify(n)});return{thread:async r=>{const n=await t(`/v1/merchant/thread${r?"?peek=1":""}`);return n.team&&Object.keys(n.team).length&&p({team:n.team}),n},appearance:()=>t("/v1/merchant/appearance"),send:(r,n,s,o,g,l)=>i("/v1/merchant/messages",{body:r,shopName:s,...o?{contact:o}:{},...n.length?{files:n.map(d=>({key:d}))}:{},...g?{workflow:g}:{},...l?{replyTo:l}:{}}),react:(r,n)=>i("/v1/merchant/react",{id:r,emoji:n}),transcript:()=>i("/v1/merchant/transcript",{}),reviewState:(r,n,s)=>i("/v1/merchant/review-state",{messageId:r,state:n,outcome:s}),track:(r,n,s)=>t("/v1/merchant/card-action",{method:"POST",body:JSON.stringify({messageId:r,action:n,detail:s}),keepalive:!0}),upload:async r=>{const{upload:n,file:s}=await i("/v1/merchant/uploads",{name:r.name||"screenshot.png",type:r.type,size:r.size}),o=new FormData;for(const[g,l]of Object.entries(n.fields))o.append(g,l);if(o.append("file",r),!(await fetch(n.url,{method:"POST",body:o})).ok)throw new Error("Upload failed");return{id:s.key,name:s.name,type:s.type,size:s.size}},fileUrl:r=>`${e}/v1/merchant/files?${new URLSearchParams({key:r})}`,fetchFile:async r=>fetch(r,{headers:{authorization:`Bearer ${await a()}`}})}};export{h as cachedMerchantToken,k as merchantChatApi,f as toView};