efficient-storefront-blocks 0.126.3 → 0.126.4

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,4 +1,5 @@
1
1
  export declare const ACCESS_TOKEN_SUBPROTOCOL = "efficient-access-token";
2
+ export declare const GUEST_TOKEN_SUBPROTOCOL = "efficient-chat-guest";
2
3
  export interface ChatSocketCredential {
3
4
  access?: string | null;
4
5
  guest?: string | null;
@@ -1 +1 @@
1
- import{API_URL as m}from"./api/index.js";function l(){return(m||(typeof window<"u"?window.location.origin:"")).replace(/^http/,"ws")}const S="efficient-access-token";function h(o,e){const n=`${l()}/ws/chat/?conversation=${encodeURIComponent(o)}`;return e.access?{url:n,protocols:[S,e.access]}:e.guest?{url:`${n}&token=${encodeURIComponent(e.guest)}`,protocols:[]}:{url:n,protocols:[]}}function _(o,e){return`${l()}/ws/chat/?conversation=${o}&token=${encodeURIComponent(e)}`}const k=new Set(["employee","system"]);function g(o){if(typeof o!="string")return!1;try{const e=JSON.parse(o);return e.type==="chat_event"&&e.event==="message"&&typeof e.payload?.sender_role=="string"&&k.has(e.payload.sender_role)}catch{return!1}}function d({conversationId:o,credential:e,token:n,onFrame:u}){let s=!1,t=null,c,r=3e3;const a=()=>{if(s)return;const{url:f,protocols:p}=e?h(o,e()):{url:_(o,n?.()??""),protocols:[]};t=new WebSocket(f,p),t.onopen=()=>{r=3e3},t.onmessage=i=>u(i.data),t.onclose=()=>{s||(c=setTimeout(a,r),r=Math.min(r*2,3e4))},t.onerror=()=>t?.close()};return a(),()=>{s=!0,c&&clearTimeout(c),t?.close()}}export{S as ACCESS_TOKEN_SUBPROTOCOL,h as chatSocketTarget,_ as chatSocketUrl,g as isOffStreamMessage,d as openChatSocket};
1
+ import{API_URL as S}from"./api/index.js";function f(){return(S||(typeof window<"u"?window.location.origin:"")).replace(/^http/,"ws")}const m="efficient-access-token",_="efficient-chat-guest";function h(t,e){const n=`${f()}/ws/chat/?conversation=${encodeURIComponent(t)}`;return e.access?{url:n,protocols:[m,e.access]}:e.guest?{url:n,protocols:[_,e.guest]}:{url:n,protocols:[]}}function O(t,e){return`${f()}/ws/chat/?conversation=${t}&token=${encodeURIComponent(e)}`}const g=new Set(["employee","system"]);function k(t){if(typeof t!="string")return!1;try{const e=JSON.parse(t);return e.type==="chat_event"&&e.event==="message"&&typeof e.payload?.sender_role=="string"&&g.has(e.payload.sender_role)}catch{return!1}}function T({conversationId:t,credential:e,token:n,onFrame:u}){let s=!1,o=null,c,r=3e3;const a=()=>{if(s)return;const{url:l,protocols:p}=e?h(t,e()):{url:O(t,n?.()??""),protocols:[]};o=new WebSocket(l,p),o.onopen=()=>{r=3e3},o.onmessage=i=>u(i.data),o.onclose=()=>{s||(c=setTimeout(a,r),r=Math.min(r*2,3e4))},o.onerror=()=>o?.close()};return a(),()=>{s=!0,c&&clearTimeout(c),o?.close()}}export{m as ACCESS_TOKEN_SUBPROTOCOL,_ as GUEST_TOKEN_SUBPROTOCOL,h as chatSocketTarget,O as chatSocketUrl,k as isOffStreamMessage,T as openChatSocket};