@eka-care/medassist-widget-embed 0.2.116-dev.1 → 0.2.117-dev.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.
@@ -18,7 +18,7 @@
18
18
  CORS mode — the browser would download it twice. -->
19
19
  <link
20
20
  rel="modulepreload"
21
- href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.138-dev.1/dist/medassist-widget.js"
21
+ href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.139-dev.0/dist/medassist-widget.js"
22
22
  fetchpriority="high"
23
23
  crossorigin
24
24
  />
@@ -27,14 +27,14 @@
27
27
  <link
28
28
  rel="preload"
29
29
  as="style"
30
- href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.138-dev.1/dist/medassist-widget.css"
30
+ href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.139-dev.0/dist/medassist-widget.css"
31
31
  onload="this.rel='stylesheet'"
32
32
  crossorigin
33
33
  />
34
34
  <noscript>
35
35
  <link
36
36
  rel="stylesheet"
37
- href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.138-dev.1/dist/medassist-widget.css"
37
+ href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.139-dev.0/dist/medassist-widget.css"
38
38
  />
39
39
  </noscript>
40
40
 
@@ -149,7 +149,7 @@
149
149
  window.renderMedAssist would never be set. -->
150
150
  <script
151
151
  type="module"
152
- src="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.138-dev.1/dist/medassist-widget.js"
152
+ src="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.139-dev.0/dist/medassist-widget.js"
153
153
  onload="init()"
154
154
  fetchpriority="high"
155
155
  crossorigin
package/dist/iframe.js CHANGED
@@ -1 +1 @@
1
- "use strict";(function(){const $=()=>{if(typeof document=="undefined")return null;const{currentScript:e}=document;if(e instanceof HTMLScriptElement)return e;const t=document.getElementsByTagName("script");return t.length?t[t.length-1]:null},C=e=>{if(e==="production"||e==="development"||e==="staging")return e};function z(e){if(!e)return;const t=e.mode==="dark"?"white":e.mode==="light"?"black":void 0;return{...e.background&&{background:e.background},...e.background_img&&{backgroundImage:e.background_img},...e.accent&&{primary:e.accent},...t&&{textColor:t},...e.mode&&{mode:e.mode},...e.header_tinted!==void 0&&{headerTinted:e.header_tinted},...e.title_img&&{titleImg:e.title_img},...e.tagline&&{tagline:e.tagline},...e.consent_content&&{consentContent:e.consent_content},...e.feature!==void 0&&{feature:e.feature}}}function S(e){if(!(!e||typeof document=="undefined"))try{const t=document.createElement("link");t.rel="preload",t.as="image",t.href=e,document.head.appendChild(t)}catch{const t=new Image;t.src=e}}async function F(e,t,r){var n;try{return await h(),await((n=window.fetchAgentConfig)===null||n===void 0?void 0:n.call(window,{agentId:t,serverUrl:e,environment:r,channel:"web"}))}catch{return}}const U="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.138-dev.1/dist/",s=$(),b=(()=>{if(!s)return"";try{return new URL(".",s.src||window.location.href).href}catch{return""}})(),u=(()=>{if(!s)return U;const e=s.dataset.widgetAssets;if(e==="local")return`${b}src/`;if(e&&e.length>0)try{return new URL(e,b).href}catch{return e.endsWith("/")?e:`${e}/`}return U})(),a=`${u}medassist-widget.js`,g=`${u}medassist-widget.css`;let m=null,f=null;const i=new URLSearchParams(typeof window!="undefined"?window.location.search:""),A=i.get("agentId"),w=i.get("baseUrl")||"https://matrix.eka.care/reloaded";if(typeof document!="undefined"&&document.head){try{const e=new URL(u).origin,t=new URL(w).origin,r=document.createElement("link");if(r.rel="preconnect",r.href=e,r.crossOrigin="anonymous",document.head.appendChild(r),e!==t){const c=document.createElement("link");c.rel="preconnect",c.href=t,c.crossOrigin="anonymous",document.head.appendChild(c)}const n=document.createElement("link");n.rel="modulepreload",n.href=a,document.head.appendChild(n);const d=document.createElement("link");d.rel="preload",d.as="style",d.href=g,document.head.appendChild(d)}catch{}M(),h()}const L=A&&w?F(w,A,C(i.get("environment"))):Promise.resolve(void 0);if(typeof document!="undefined"&&document.head){const e=i.get("theme");if(e)try{const t=JSON.parse(e);t.backgroundImage&&S(t.backgroundImage)}catch{}L.then(t=>{var r;const n=(r=t==null?void 0:t.theme)===null||r===void 0?void 0:r.background_img;n&&S(n)})}const I=async()=>{var e,t,r,n,d,c,p;const P=i.get("agentId");if(!P){console.error("Agent ID is required in URL parameters");return}let v=i.get("title")||"Medi Clinic",y=i.get("iconUrl")||void 0;const x=i.get("context"),G=i.get("baseUrl")||"https://matrix.eka.care/reloaded",O=i.get("auth-token")||void 0;let k=i.get("resize")==="true"?!0:void 0;const J=(e=C(i.get("environment")))!==null&&e!==void 0?e:"production",_=i.get("connectivity"),N=_==="http_stream"||_==="socket"?_:void 0,E=i.get("theme")?(()=>{try{return JSON.parse(i.get("theme")||"{}")}catch{return}})():void 0,q=document.getElementById("root")||document.body;try{const[,,o]=await Promise.all([M(),h(),L]);if(!(window!=null&&window.renderMedAssist)||typeof(window==null?void 0:window.renderMedAssist)!="function")throw new Error("renderMedAssist is not available on window");let l,W,R,B,D=!1;o&&(v=(t=o==null?void 0:o.name)!==null&&t!==void 0?t:v,y=(n=(r=o==null?void 0:o.theme)===null||r===void 0?void 0:r.icon_img)!==null&&n!==void 0?n:y,l=z((d=o==null?void 0:o.theme)!==null&&d!==void 0?d:void 0),W=o==null?void 0:o.allowed,R=o==null?void 0:o.connectivity,B=o==null?void 0:o.initial_message,D=(p=(c=o==null?void 0:o.theme)===null||c===void 0?void 0:c.hide_watermark)!==null&&p!==void 0?p:!1,k=k||(o==null?void 0:o.resize)||void 0);const H={title:v,iconUrl:y,environment:J,connectionType:R||N||"socket",onClose:()=>{window.parent!==window&&window.parent.postMessage({type:"WIDGET_CLOSE"},"*")},context:x?JSON.parse(x):void 0,baseUrl:G,displayMode:"full",allowed:W,showCloseButton:!1,resize:k,initialMessage:B,hideWatermark:D,...O&&{authToken:O},theme:{...l!=null?l:{},...E!=null?E:{}}};window.renderMedAssist(q,P,H)}catch(o){throw console.error("Failed to initialize MedAssist widget",o),o}};async function M(){document.querySelector("link[data-medassist-style='true']")||(f||(f=new Promise((t,r)=>{const n=document.createElement("link");n.rel="stylesheet",n.href=g,n.setAttribute("data-medassist-style","true"),n.onload=()=>{t("")},n.onerror=()=>{r(new Error(`Failed to load ${g}`))},document.head.appendChild(n)})),await f)}function h(){return m||(m=new Promise((e,t)=>{const r=document.querySelector(`script[src="${a}"]`);if(r){if(r.dataset.loaded==="true"){e();return}r.addEventListener("load",()=>e()),r.addEventListener("error",d=>t(d.error||new Error("Unknown script loading error")));return}const n=document.createElement("script");n.src=a,n.type="module",n.async=!0,n.dataset.widget="medassist",n.onload=()=>{n.dataset.loaded="true",e()},n.onerror=d=>{if(d instanceof ErrorEvent&&d.error){t(d.error);return}t(new Error(`Failed to load ${a}`))},document.head.appendChild(n)})),m}if(typeof document!="undefined")if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",I);else try{I()}catch(e){console.error("Failed to initialize MedAssist widget",e)}})();
1
+ "use strict";(function(){const $=()=>{if(typeof document=="undefined")return null;const{currentScript:e}=document;if(e instanceof HTMLScriptElement)return e;const t=document.getElementsByTagName("script");return t.length?t[t.length-1]:null},C=e=>{if(e==="production"||e==="development"||e==="staging")return e};function z(e){var t;if(!e)return;const r=e.mode==="dark"?"white":e.mode==="light"?"black":void 0;return{...e.background&&{background:e.background},...e.background_img&&{backgroundImage:e.background_img},...e.accent&&{primary:e.accent},...r&&{textColor:r},...e.mode&&{mode:e.mode},...e.header_tinted!==void 0&&{headerTinted:e.header_tinted},...e.title_img&&{titleImg:e.title_img},...e.tagline&&{tagline:e.tagline},...e.consent_content&&{consentContent:e.consent_content},...((t=e.tips)===null||t===void 0?void 0:t.length)&&{tips:e.tips},...e.feature!==void 0&&{feature:e.feature}}}function S(e){if(!(!e||typeof document=="undefined"))try{const t=document.createElement("link");t.rel="preload",t.as="image",t.href=e,document.head.appendChild(t)}catch{const t=new Image;t.src=e}}async function F(e,t,r){var n;try{return await h(),await((n=window.fetchAgentConfig)===null||n===void 0?void 0:n.call(window,{agentId:t,serverUrl:e,environment:r,channel:"web"}))}catch{return}}const U="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.139-dev.0/dist/",s=$(),b=(()=>{if(!s)return"";try{return new URL(".",s.src||window.location.href).href}catch{return""}})(),u=(()=>{if(!s)return U;const e=s.dataset.widgetAssets;if(e==="local")return`${b}src/`;if(e&&e.length>0)try{return new URL(e,b).href}catch{return e.endsWith("/")?e:`${e}/`}return U})(),a=`${u}medassist-widget.js`,g=`${u}medassist-widget.css`;let f=null,m=null;const i=new URLSearchParams(typeof window!="undefined"?window.location.search:""),A=i.get("agentId"),w=i.get("baseUrl")||"https://matrix.eka.care/reloaded";if(typeof document!="undefined"&&document.head){try{const e=new URL(u).origin,t=new URL(w).origin,r=document.createElement("link");if(r.rel="preconnect",r.href=e,r.crossOrigin="anonymous",document.head.appendChild(r),e!==t){const c=document.createElement("link");c.rel="preconnect",c.href=t,c.crossOrigin="anonymous",document.head.appendChild(c)}const n=document.createElement("link");n.rel="modulepreload",n.href=a,document.head.appendChild(n);const d=document.createElement("link");d.rel="preload",d.as="style",d.href=g,document.head.appendChild(d)}catch{}M(),h()}const L=A&&w?F(w,A,C(i.get("environment"))):Promise.resolve(void 0);if(typeof document!="undefined"&&document.head){const e=i.get("theme");if(e)try{const t=JSON.parse(e);t.backgroundImage&&S(t.backgroundImage)}catch{}L.then(t=>{var r;const n=(r=t==null?void 0:t.theme)===null||r===void 0?void 0:r.background_img;n&&S(n)})}const I=async()=>{var e,t,r,n,d,c,p;const P=i.get("agentId");if(!P){console.error("Agent ID is required in URL parameters");return}let v=i.get("title")||"Medi Clinic",y=i.get("iconUrl")||void 0;const x=i.get("context"),G=i.get("baseUrl")||"https://matrix.eka.care/reloaded",O=i.get("auth-token")||void 0;let k=i.get("resize")==="true"?!0:void 0;const J=(e=C(i.get("environment")))!==null&&e!==void 0?e:"production",_=i.get("connectivity"),N=_==="http_stream"||_==="socket"?_:void 0,E=i.get("theme")?(()=>{try{return JSON.parse(i.get("theme")||"{}")}catch{return}})():void 0,q=document.getElementById("root")||document.body;try{const[,,o]=await Promise.all([M(),h(),L]);if(!(window!=null&&window.renderMedAssist)||typeof(window==null?void 0:window.renderMedAssist)!="function")throw new Error("renderMedAssist is not available on window");let l,W,R,B,D=!1;o&&(v=(t=o==null?void 0:o.name)!==null&&t!==void 0?t:v,y=(n=(r=o==null?void 0:o.theme)===null||r===void 0?void 0:r.icon_img)!==null&&n!==void 0?n:y,l=z((d=o==null?void 0:o.theme)!==null&&d!==void 0?d:void 0),W=o==null?void 0:o.allowed,R=o==null?void 0:o.connectivity,B=o==null?void 0:o.initial_message,D=(p=(c=o==null?void 0:o.theme)===null||c===void 0?void 0:c.hide_watermark)!==null&&p!==void 0?p:!1,k=k||(o==null?void 0:o.resize)||void 0);const H={title:v,iconUrl:y,environment:J,connectionType:R||N||"socket",onClose:()=>{window.parent!==window&&window.parent.postMessage({type:"WIDGET_CLOSE"},"*")},context:x?JSON.parse(x):void 0,baseUrl:G,displayMode:"full",allowed:W,showCloseButton:!1,resize:k,initialMessage:B,hideWatermark:D,...O&&{authToken:O},theme:{...l!=null?l:{},...E!=null?E:{}}};window.renderMedAssist(q,P,H)}catch(o){throw console.error("Failed to initialize MedAssist widget",o),o}};async function M(){document.querySelector("link[data-medassist-style='true']")||(m||(m=new Promise((t,r)=>{const n=document.createElement("link");n.rel="stylesheet",n.href=g,n.setAttribute("data-medassist-style","true"),n.onload=()=>{t("")},n.onerror=()=>{r(new Error(`Failed to load ${g}`))},document.head.appendChild(n)})),await m)}function h(){return f||(f=new Promise((e,t)=>{const r=document.querySelector(`script[src="${a}"]`);if(r){if(r.dataset.loaded==="true"){e();return}r.addEventListener("load",()=>e()),r.addEventListener("error",d=>t(d.error||new Error("Unknown script loading error")));return}const n=document.createElement("script");n.src=a,n.type="module",n.async=!0,n.dataset.widget="medassist",n.onload=()=>{n.dataset.loaded="true",e()},n.onerror=d=>{if(d instanceof ErrorEvent&&d.error){t(d.error);return}t(new Error(`Failed to load ${a}`))},document.head.appendChild(n)})),f}if(typeof document!="undefined")if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",I);else try{I()}catch(e){console.error("Failed to initialize MedAssist widget",e)}})();
package/dist/index.d.ts CHANGED
@@ -34,6 +34,8 @@ type AgentConfig = {
34
34
  consent_content?: string | string[];
35
35
  /** When true, the widget asks for upfront consent once before the chat is usable. */
36
36
  upfront_consent?: boolean;
37
+ /** Tips shown while the bot works on a reply. Absent or empty -> the widget's built-in tips. */
38
+ tips?: string[];
37
39
  /** Feature flag — currently gates the chat-history UI (session drawer + fullscreen sidebar). */
38
40
  feature?: boolean;
39
41
  };
@@ -89,6 +91,7 @@ type MedAssistInitConfig = {
89
91
  explicitDisclaimer?: boolean;
90
92
  consentContent?: string | string[];
91
93
  upfrontConsent?: boolean;
94
+ tips?: string[];
92
95
  feature?: boolean;
93
96
  };
94
97
  [key: string]: unknown;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";const getCurrentScript=()=>{if(typeof document=="undefined")return console.error("document is not defined"),null;const{currentScript:i}=document;if(i instanceof HTMLScriptElement)return i;const e=Array.from(document.getElementsByTagName("script")),t=e.find(o=>o.hasAttribute("data-widget-assets"));if(t)return t;const n=e.filter(o=>/(^|\/)index\.js(\?.*)?$/.test(o.src));return n.length?n[n.length-1]:e.length?e[e.length-1]:null},getEnvironment=i=>{if(i==="production"||i==="development"||i==="staging")return i},scriptEl=getCurrentScript(),DEFAULT_WIDGET_ASSET_BASE=(()=>{var i;return!((i=scriptEl==null?void 0:scriptEl.src)===null||i===void 0)&&i.includes("@dev"),"https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.138-dev.1/dist/"})();var FeedbackTypeEnum;(function(i){i.DEFAULT="default",i.NPS="nps"})(FeedbackTypeEnum||(FeedbackTypeEnum={}));function mapAgentConfigThemeToWidgetTheme(i){if(!i)return;const e=i.mode==="dark"?"white":i.mode==="light"?"black":void 0;return{...i.background_img&&{backgroundImage:i.background_img},...i.accent&&{primary:i.accent},...e&&{textColor:e},...i.mode&&{mode:i.mode},...i.header_tinted!==void 0&&{headerTinted:i.header_tinted},...i.title_img&&{titleImg:i.title_img},...i.tagline&&{tagline:i.tagline},...i.hide_watermark&&{hideWatermark:i.hide_watermark},...i.explicit_disclaimer&&{explicitDisclaimer:i.explicit_disclaimer},...i.consent_content&&{consentContent:i.consent_content},...i.upfront_consent&&{upfrontConsent:i.upfront_consent},...i.feature!==void 0&&{feature:i.feature}}}function preloadImage(i){if(!(!i||typeof document=="undefined"))try{const e=document.createElement("link");e.rel="preload",e.as="image",e.href=i,document.head.appendChild(e)}catch{const e=new Image;e.src=i}}function channelFromDisplayMode(i){return i==="full"?"web":i==="side_panel"?"side_panel":"widget"}function normalizeDisplayMode(i){return i==="full"?"full":i==="side_panel"?"side_panel":"widget"}const NUDGE_STORAGE_KEY="eka-medassist-nudges",AGENT_CONFIG_CACHE_KEY="eka-medassist-agent-config";function readAgentConfigCache(i){try{const e=localStorage.getItem(AGENT_CONFIG_CACHE_KEY);return(e?JSON.parse(e):{})[i]}catch{return}}function writeAgentConfigCache(i,e){try{const t=localStorage.getItem(AGENT_CONFIG_CACHE_KEY),n=t?JSON.parse(t):{};n[i]={...n[i]||{},...e},localStorage.setItem(AGENT_CONFIG_CACHE_KEY,JSON.stringify(n))}catch{}}function getNudgeStore(){try{const i=localStorage.getItem(NUDGE_STORAGE_KEY);return i?JSON.parse(i):{}}catch{return{}}}function setNudgeStore(i){try{localStorage.setItem(NUDGE_STORAGE_KEY,JSON.stringify(i))}catch{}}function normalizePath(i){let e=i.replace(/\/+$/,"");return e.startsWith("/")||(e="/"+e),e||"/"}function getNudgePathCandidates(i){const e=i.split("/").filter(Boolean),t=[];for(let n=e.length;n>=0;n--)t.push(n===0?"/":"/"+e.slice(0,n).join("/"));return t}function findCachedNudgeForCandidates(i,e,t){const o=getNudgeStore()[i];if(!o)return null;const s=e.host,r=o[s];if(!r)return null;for(const d of t){if(r[d]!==void 0)return{domain:s,path:d,data:r[d]};const a=d==="/"?"/*":d+"/*";if(r[a]!==void 0)return{domain:s,path:a,data:r[a]}}return null}function findFreshCachedNudge(i,e,t){const n=findCachedNudgeForCandidates(i,e,t);if(!n)return null;const o=Math.floor(Date.now()/1e3);return n.data.expiry<=o?(clearNudgeForPath(i,n.domain,n.path),null):n}function clearNudgeForPath(i,e,t){const n=getNudgeStore(),o=n[i];!o||!o[e]||(delete o[e][t],setNudgeStore(n))}function storeNudgeResponse(i,e,t){var n,o,s,r;const d=(n=e==null?void 0:e.url_pattern)===null||n===void 0?void 0:n.domain,a=(o=e==null?void 0:e.url_pattern)===null||o===void 0?void 0:o.path;if(!(!((s=e.nudges)===null||s===void 0)&&s.length)||!e.expiry||!d||!a)return;const l=getNudgeStore();l[i]||(l[i]={}),l[i][d]||(l[i][d]={});const h={nudges:e.nudges,expiry:e.expiry,delay:(r=e.delay)!==null&&r!==void 0?r:5};l[i][d][a]=h,t&&t!==a&&(l[i][d][t]=h),setNudgeStore(l)}const NUDGE_COOKIE_PREFIX="eka-nudge";function setNudgeCookie(i,e){const t=new Date(Date.now()+864e5).toUTCString();document.cookie=`${NUDGE_COOKIE_PREFIX}-${i}=${e}; expires=${t}; path=/; SameSite=Lax`}function getNudgeCookie(i){const e=document.cookie.split(";").map(n=>n.trim()).find(n=>n.startsWith(`${NUDGE_COOKIE_PREFIX}-${i}=`));if(!e)return null;const t=e.split("=")[1];return t==="open"||t==="closed"?t:null}const WIDGET_STORE_KEY_PREFIX="med-assist-store-";function readPersistedSessToken(i){var e,t;try{const n=sessionStorage.getItem(`${WIDGET_STORE_KEY_PREFIX}${i}`),o=n?(t=(e=JSON.parse(n))===null||e===void 0?void 0:e.state)===null||t===void 0?void 0:t.sessToken:void 0;return typeof o=="string"&&o?o:void 0}catch{return}}async function fetchNudgeData(i,e,t,n="widget"){const o=`${t}/med-assist/user-nudge`,s=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(r=>{var d,a,l;const h=(d=r.getAttribute("name"))!==null&&d!==void 0?d:void 0,f=(a=r.getAttribute("property"))!==null&&a!==void 0?a:void 0,p=(l=r.getAttribute("content"))!==null&&l!==void 0?l:void 0;(h||f)&&s.push({name:h,property:f,content:p})});try{const r=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","x-agent-id":i,"x-channel":n,referer:typeof window!="undefined"?window.location.href:"",Authorization:`Bearer ${e}`},body:JSON.stringify({meta_tags:s,url:typeof window!="undefined"?window.location.href:""})});return r.ok?await r.json():void 0}catch{return}}const SIDE_PANEL_PUSH_EVENT="eka-medassist:side-panel-push",globalMedAssistConfig={},getWidgetElement=()=>typeof document=="undefined"?null:document.querySelector("eka-medassist-widget");if(typeof window!="undefined"){const i=window;i.__ekaMedAssistConfig__=globalMedAssistConfig,i.EkaMedAssist={init(e){var t,n,o;Object.assign(globalMedAssistConfig,e);const s=getWidgetElement();if(s){if(e.agentId&&s.setAttribute("agent-id",e.agentId),e.authToken&&s.setAttribute("auth-token",e.authToken),e.title&&s.setAttribute("title",e.title),e.iconUrl&&s.setAttribute("icon-url",e.iconUrl),e.baseUrl&&s.setAttribute("base-url",e.baseUrl),e.resize!==void 0&&s.setAttribute("resize",String(e.resize)),(e.displayMode==="full"||e.displayMode==="widget"||e.displayMode==="side_panel")&&s.setAttribute("display-mode",e.displayMode),e.sidePanelMode&&s.setAttribute("side-panel-mode",e.sidePanelMode),e.sidePanelWidth!==void 0&&s.setAttribute("side-panel-width",String(e.sidePanelWidth)),e.side&&s.setAttribute("side",e.side),e.context)try{s.setAttribute("context",JSON.stringify(e.context))}catch{console.warn("Failed to stringify context passed to init")}typeof e.customLauncherStyles=="string"&&s.setAttribute("custom-launcher-styles",e.customLauncherStyles),e.redirectUrl&&s.setAttribute("redirect-url",e.redirectUrl),!((t=e.theme)===null||t===void 0)&&t.backgroundImage&&preloadImage(e.theme.backgroundImage),(o=(n=s).openFromBridge)===null||o===void 0||o.call(n)}}}}const scriptBaseUrl=(()=>{if(!scriptEl)return"";try{return new URL(".",scriptEl.src||window.location.href).href}catch{return""}})(),widgetAssetBaseUrl=(()=>{if(!scriptEl)return DEFAULT_WIDGET_ASSET_BASE;const i=scriptEl.dataset.widgetAssets;if(i==="local")return`${scriptBaseUrl}src/`;if(i&&i.length>0)try{return new URL(i,scriptBaseUrl).href}catch{return i.endsWith("/")?i:`${i}/`}return DEFAULT_WIDGET_ASSET_BASE})(),WIDGET_JS_URL=`${widgetAssetBaseUrl}medassist-widget.js`,WIDGET_CSS_URL=`${widgetAssetBaseUrl}medassist-widget.css`;let widgetModulePromise=null,widgetCssTextPromise=null;function getWidgetCssTextPromise(){return widgetCssTextPromise||(widgetCssTextPromise=fetch(WIDGET_CSS_URL).then(i=>{if(!i.ok)throw new Error(`Unable to fetch widget styles from ${WIDGET_CSS_URL}`);return i.text()})),widgetCssTextPromise}class MedAssistWidgetLoader extends HTMLElement{setLauncherState(e){var t;const n=(t=this.shadowRoot)===null||t===void 0?void 0:t.getElementById("medassist-open-btn");n&&(n.classList.toggle("loading",e==="loading"),n.classList.toggle("hidden",e==="open"),e==="loading"?n.setAttribute("aria-busy","true"):n.removeAttribute("aria-busy"))}getChannel(){const e=this.getAttribute("display-mode");if(e)return channelFromDisplayMode(e);const t=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0;return channelFromDisplayMode(t==null?void 0:t.displayMode)}getAgentConfig(){var e;if(!this.agentConfigPromise){const t=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},n=t.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",o=t.agentId||this.getAttribute("agent-id")||"";if(!o)return Promise.resolve(void 0);const s=(e=getEnvironment(this.getAttribute("environment")))!==null&&e!==void 0?e:"production";this.agentConfigPromise=this.loadWidgetModule().then(r=>{var d;return(d=r.fetchAgentConfig)===null||d===void 0?void 0:d.call(r,{agentId:o,serverUrl:n,environment:s,channel:this.getChannel()})}).catch(()=>{this.agentConfigPromise=null})}return this.agentConfigPromise}constructor(){super(),this.hostPushStyleEl=null,this.hostPushState=null,this.reactRoot=null,this.agentConfigPromise=null,this.loading=!1,this.authPrefetchPromise=null,this.launcherRenderSeq=0,this.attachShadow({mode:"open"}),this.widgetLoaded=!1,this.displayMode=normalizeDisplayMode(this.getAttribute("display-mode")),this.setupAuthExpirationListener()}static get observedAttributes(){return["icon-url","display-mode","custom-launcher-styles","redirect-url","side-panel-mode","side-panel-width","side"]}connectedCallback(){this.displayMode==="full"?(this.initializeFullMode(),this.loadAndRender().catch(e=>{console.error("Failed to load MedAssist widget in full mode",e)})):(this.renderLauncher(),this.scheduleIdle(()=>{this.preloadWidgetAssets(),this.prefetchAuthTokens(),this.initNudge()}))}disconnectedCallback(){var e,t,n,o,s;(e=this.reactRoot)===null||e===void 0||e.unmount(),this.reactRoot=null,(t=document.body)===null||t===void 0||t.classList.remove("eka-medassist-pushed"),(n=document.documentElement)===null||n===void 0||n.style.removeProperty("--eka-medassist-panel-width"),(o=document.documentElement)===null||o===void 0||o.style.removeProperty("--eka-medassist-panel-side"),(s=this.hostPushStyleEl)===null||s===void 0||s.remove(),this.hostPushStyleEl=null,this.hostPushState=null}applyHostPush(e,t,n){var o;if(typeof document=="undefined")return;const s=e?{width:t,side:n}:null,r=this.hostPushState;if(r===s||r&&s&&r.width===s.width&&r.side===s.side)return;this.hostPushState=s,this.hostPushStyleEl||(this.hostPushStyleEl=document.createElement("style"),this.hostPushStyleEl.setAttribute("data-medassist-side-panel-push","true"),document.head.appendChild(this.hostPushStyleEl));const d=n==="left"?"margin-left":"margin-right";this.hostPushStyleEl.textContent=`
1
+ "use strict";const getCurrentScript=()=>{if(typeof document=="undefined")return console.error("document is not defined"),null;const{currentScript:n}=document;if(n instanceof HTMLScriptElement)return n;const e=Array.from(document.getElementsByTagName("script")),t=e.find(o=>o.hasAttribute("data-widget-assets"));if(t)return t;const i=e.filter(o=>/(^|\/)index\.js(\?.*)?$/.test(o.src));return i.length?i[i.length-1]:e.length?e[e.length-1]:null},getEnvironment=n=>{if(n==="production"||n==="development"||n==="staging")return n},scriptEl=getCurrentScript(),DEFAULT_WIDGET_ASSET_BASE=(()=>{var n;return!((n=scriptEl==null?void 0:scriptEl.src)===null||n===void 0)&&n.includes("@dev"),"https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.139-dev.0/dist/"})();var FeedbackTypeEnum;(function(n){n.DEFAULT="default",n.NPS="nps"})(FeedbackTypeEnum||(FeedbackTypeEnum={}));function mapAgentConfigThemeToWidgetTheme(n){var e;if(!n)return;const t=n.mode==="dark"?"white":n.mode==="light"?"black":void 0;return{...n.background_img&&{backgroundImage:n.background_img},...n.accent&&{primary:n.accent},...t&&{textColor:t},...n.mode&&{mode:n.mode},...n.header_tinted!==void 0&&{headerTinted:n.header_tinted},...n.title_img&&{titleImg:n.title_img},...n.tagline&&{tagline:n.tagline},...n.hide_watermark&&{hideWatermark:n.hide_watermark},...n.explicit_disclaimer&&{explicitDisclaimer:n.explicit_disclaimer},...n.consent_content&&{consentContent:n.consent_content},...n.upfront_consent&&{upfrontConsent:n.upfront_consent},...((e=n.tips)===null||e===void 0?void 0:e.length)&&{tips:n.tips},...n.feature!==void 0&&{feature:n.feature}}}function preloadImage(n){if(!(!n||typeof document=="undefined"))try{const e=document.createElement("link");e.rel="preload",e.as="image",e.href=n,document.head.appendChild(e)}catch{const e=new Image;e.src=n}}function channelFromDisplayMode(n){return n==="full"?"web":n==="side_panel"?"side_panel":"widget"}function normalizeDisplayMode(n){return n==="full"?"full":n==="side_panel"?"side_panel":"widget"}const NUDGE_STORAGE_KEY="eka-medassist-nudges",AGENT_CONFIG_CACHE_KEY="eka-medassist-agent-config";function readAgentConfigCache(n){try{const e=localStorage.getItem(AGENT_CONFIG_CACHE_KEY);return(e?JSON.parse(e):{})[n]}catch{return}}function writeAgentConfigCache(n,e){try{const t=localStorage.getItem(AGENT_CONFIG_CACHE_KEY),i=t?JSON.parse(t):{};i[n]={...i[n]||{},...e},localStorage.setItem(AGENT_CONFIG_CACHE_KEY,JSON.stringify(i))}catch{}}function getNudgeStore(){try{const n=localStorage.getItem(NUDGE_STORAGE_KEY);return n?JSON.parse(n):{}}catch{return{}}}function setNudgeStore(n){try{localStorage.setItem(NUDGE_STORAGE_KEY,JSON.stringify(n))}catch{}}function normalizePath(n){let e=n.replace(/\/+$/,"");return e.startsWith("/")||(e="/"+e),e||"/"}function getNudgePathCandidates(n){const e=n.split("/").filter(Boolean),t=[];for(let i=e.length;i>=0;i--)t.push(i===0?"/":"/"+e.slice(0,i).join("/"));return t}function findCachedNudgeForCandidates(n,e,t){const o=getNudgeStore()[n];if(!o)return null;const s=e.host,r=o[s];if(!r)return null;for(const d of t){if(r[d]!==void 0)return{domain:s,path:d,data:r[d]};const a=d==="/"?"/*":d+"/*";if(r[a]!==void 0)return{domain:s,path:a,data:r[a]}}return null}function findFreshCachedNudge(n,e,t){const i=findCachedNudgeForCandidates(n,e,t);if(!i)return null;const o=Math.floor(Date.now()/1e3);return i.data.expiry<=o?(clearNudgeForPath(n,i.domain,i.path),null):i}function clearNudgeForPath(n,e,t){const i=getNudgeStore(),o=i[n];!o||!o[e]||(delete o[e][t],setNudgeStore(i))}function storeNudgeResponse(n,e,t){var i,o,s,r;const d=(i=e==null?void 0:e.url_pattern)===null||i===void 0?void 0:i.domain,a=(o=e==null?void 0:e.url_pattern)===null||o===void 0?void 0:o.path;if(!(!((s=e.nudges)===null||s===void 0)&&s.length)||!e.expiry||!d||!a)return;const l=getNudgeStore();l[n]||(l[n]={}),l[n][d]||(l[n][d]={});const h={nudges:e.nudges,expiry:e.expiry,delay:(r=e.delay)!==null&&r!==void 0?r:5};l[n][d][a]=h,t&&t!==a&&(l[n][d][t]=h),setNudgeStore(l)}const NUDGE_COOKIE_PREFIX="eka-nudge";function setNudgeCookie(n,e){const t=new Date(Date.now()+864e5).toUTCString();document.cookie=`${NUDGE_COOKIE_PREFIX}-${n}=${e}; expires=${t}; path=/; SameSite=Lax`}function getNudgeCookie(n){const e=document.cookie.split(";").map(i=>i.trim()).find(i=>i.startsWith(`${NUDGE_COOKIE_PREFIX}-${n}=`));if(!e)return null;const t=e.split("=")[1];return t==="open"||t==="closed"?t:null}const WIDGET_STORE_KEY_PREFIX="med-assist-store-";function readPersistedSessToken(n){var e,t;try{const i=sessionStorage.getItem(`${WIDGET_STORE_KEY_PREFIX}${n}`),o=i?(t=(e=JSON.parse(i))===null||e===void 0?void 0:e.state)===null||t===void 0?void 0:t.sessToken:void 0;return typeof o=="string"&&o?o:void 0}catch{return}}async function fetchNudgeData(n,e,t,i="widget"){const o=`${t}/med-assist/user-nudge`,s=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(r=>{var d,a,l;const h=(d=r.getAttribute("name"))!==null&&d!==void 0?d:void 0,f=(a=r.getAttribute("property"))!==null&&a!==void 0?a:void 0,p=(l=r.getAttribute("content"))!==null&&l!==void 0?l:void 0;(h||f)&&s.push({name:h,property:f,content:p})});try{const r=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","x-agent-id":n,"x-channel":i,referer:typeof window!="undefined"?window.location.href:"",Authorization:`Bearer ${e}`},body:JSON.stringify({meta_tags:s,url:typeof window!="undefined"?window.location.href:""})});return r.ok?await r.json():void 0}catch{return}}const SIDE_PANEL_PUSH_EVENT="eka-medassist:side-panel-push",globalMedAssistConfig={},getWidgetElement=()=>typeof document=="undefined"?null:document.querySelector("eka-medassist-widget");if(typeof window!="undefined"){const n=window;n.__ekaMedAssistConfig__=globalMedAssistConfig,n.EkaMedAssist={init(e){var t,i,o;Object.assign(globalMedAssistConfig,e);const s=getWidgetElement();if(s){if(e.agentId&&s.setAttribute("agent-id",e.agentId),e.authToken&&s.setAttribute("auth-token",e.authToken),e.title&&s.setAttribute("title",e.title),e.iconUrl&&s.setAttribute("icon-url",e.iconUrl),e.baseUrl&&s.setAttribute("base-url",e.baseUrl),e.resize!==void 0&&s.setAttribute("resize",String(e.resize)),(e.displayMode==="full"||e.displayMode==="widget"||e.displayMode==="side_panel")&&s.setAttribute("display-mode",e.displayMode),e.sidePanelMode&&s.setAttribute("side-panel-mode",e.sidePanelMode),e.sidePanelWidth!==void 0&&s.setAttribute("side-panel-width",String(e.sidePanelWidth)),e.side&&s.setAttribute("side",e.side),e.context)try{s.setAttribute("context",JSON.stringify(e.context))}catch{console.warn("Failed to stringify context passed to init")}typeof e.customLauncherStyles=="string"&&s.setAttribute("custom-launcher-styles",e.customLauncherStyles),e.redirectUrl&&s.setAttribute("redirect-url",e.redirectUrl),!((t=e.theme)===null||t===void 0)&&t.backgroundImage&&preloadImage(e.theme.backgroundImage),(o=(i=s).openFromBridge)===null||o===void 0||o.call(i)}}}}const scriptBaseUrl=(()=>{if(!scriptEl)return"";try{return new URL(".",scriptEl.src||window.location.href).href}catch{return""}})(),widgetAssetBaseUrl=(()=>{if(!scriptEl)return DEFAULT_WIDGET_ASSET_BASE;const n=scriptEl.dataset.widgetAssets;if(n==="local")return`${scriptBaseUrl}src/`;if(n&&n.length>0)try{return new URL(n,scriptBaseUrl).href}catch{return n.endsWith("/")?n:`${n}/`}return DEFAULT_WIDGET_ASSET_BASE})(),WIDGET_JS_URL=`${widgetAssetBaseUrl}medassist-widget.js`,WIDGET_CSS_URL=`${widgetAssetBaseUrl}medassist-widget.css`;let widgetModulePromise=null,widgetCssTextPromise=null;function getWidgetCssTextPromise(){return widgetCssTextPromise||(widgetCssTextPromise=fetch(WIDGET_CSS_URL).then(n=>{if(!n.ok)throw new Error(`Unable to fetch widget styles from ${WIDGET_CSS_URL}`);return n.text()})),widgetCssTextPromise}class MedAssistWidgetLoader extends HTMLElement{setLauncherState(e){var t;const i=(t=this.shadowRoot)===null||t===void 0?void 0:t.getElementById("medassist-open-btn");i&&(i.classList.toggle("loading",e==="loading"),i.classList.toggle("hidden",e==="open"),e==="loading"?i.setAttribute("aria-busy","true"):i.removeAttribute("aria-busy"))}getChannel(){const e=this.getAttribute("display-mode");if(e)return channelFromDisplayMode(e);const t=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0;return channelFromDisplayMode(t==null?void 0:t.displayMode)}getAgentConfig(){var e;if(!this.agentConfigPromise){const t=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},i=t.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",o=t.agentId||this.getAttribute("agent-id")||"";if(!o)return Promise.resolve(void 0);const s=(e=getEnvironment(this.getAttribute("environment")))!==null&&e!==void 0?e:"production";this.agentConfigPromise=this.loadWidgetModule().then(r=>{var d;return(d=r.fetchAgentConfig)===null||d===void 0?void 0:d.call(r,{agentId:o,serverUrl:i,environment:s,channel:this.getChannel()})}).catch(()=>{this.agentConfigPromise=null})}return this.agentConfigPromise}constructor(){super(),this.hostPushStyleEl=null,this.hostPushState=null,this.reactRoot=null,this.agentConfigPromise=null,this.loading=!1,this.authPrefetchPromise=null,this.launcherRenderSeq=0,this.attachShadow({mode:"open"}),this.widgetLoaded=!1,this.displayMode=normalizeDisplayMode(this.getAttribute("display-mode")),this.setupAuthExpirationListener()}static get observedAttributes(){return["icon-url","display-mode","custom-launcher-styles","redirect-url","side-panel-mode","side-panel-width","side"]}connectedCallback(){this.displayMode==="full"?(this.initializeFullMode(),this.loadAndRender().catch(e=>{console.error("Failed to load MedAssist widget in full mode",e)})):(this.renderLauncher(),this.scheduleIdle(()=>{this.preloadWidgetAssets(),this.prefetchAuthTokens(),this.initNudge()}))}disconnectedCallback(){var e,t,i,o,s;(e=this.reactRoot)===null||e===void 0||e.unmount(),this.reactRoot=null,(t=document.body)===null||t===void 0||t.classList.remove("eka-medassist-pushed"),(i=document.documentElement)===null||i===void 0||i.style.removeProperty("--eka-medassist-panel-width"),(o=document.documentElement)===null||o===void 0||o.style.removeProperty("--eka-medassist-panel-side"),(s=this.hostPushStyleEl)===null||s===void 0||s.remove(),this.hostPushStyleEl=null,this.hostPushState=null}applyHostPush(e,t,i){var o;if(typeof document=="undefined")return;const s=e?{width:t,side:i}:null,r=this.hostPushState;if(r===s||r&&s&&r.width===s.width&&r.side===s.side)return;this.hostPushState=s,this.hostPushStyleEl||(this.hostPushStyleEl=document.createElement("style"),this.hostPushStyleEl.setAttribute("data-medassist-side-panel-push","true"),document.head.appendChild(this.hostPushStyleEl));const d=i==="left"?"margin-left":"margin-right";this.hostPushStyleEl.textContent=`
2
2
  body.eka-medassist-pushed {
3
3
  ${d}: ${t}px;
4
4
  transition: margin 300ms ease;
@@ -9,7 +9,7 @@
9
9
  @media (prefers-reduced-motion: reduce) {
10
10
  body.eka-medassist-pushed { transition: none !important; }
11
11
  }
12
- `;const a=document.documentElement.style;e?(a.setProperty("--eka-medassist-panel-width",`${t}px`),a.setProperty("--eka-medassist-panel-side",n),document.body.classList.add("eka-medassist-pushed")):(document.body.classList.remove("eka-medassist-pushed"),a.removeProperty("--eka-medassist-panel-width"),a.removeProperty("--eka-medassist-panel-side"),this.hostPushStyleEl.remove(),this.hostPushStyleEl=null);const l={pushed:e,width:t,side:n};if(typeof window!="undefined"){try{window.dispatchEvent(new CustomEvent(SIDE_PANEL_PUSH_EVENT,{detail:l}))}catch{}const h=(o=window.EkaMedAssist)===null||o===void 0?void 0:o.onSidePanelPushChange;if(typeof h=="function")try{h(e,t,n)}catch(f){console.error("EkaMedAssist.onSidePanelPushChange threw",f)}}}scheduleIdle(e){if(typeof window=="undefined"){e();return}const t=window.requestIdleCallback;typeof t=="function"?t(e,{timeout:3e3}):setTimeout(e,200)}attributeChangedCallback(e){if(e==="icon-url"&&this.displayMode!=="full"&&this.renderLauncher(),e==="display-mode"){const t=normalizeDisplayMode(this.getAttribute("display-mode"));t!==this.displayMode&&(this.displayMode=t,t==="full"?this.initializeFullMode():this.renderLauncher())}e==="custom-launcher-styles"&&this.applyCustomLauncherStyles()}preloadWidgetAssets(){getWidgetCssTextPromise(),this.loadWidgetModule(),this.preloadBackgroundImage()}prefetchAuthTokens(){var e;if(this.authPrefetchPromise)return this.authPrefetchPromise;const t=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},n=t.agentId||this.getAttribute("agent-id")||"";if(!n)return Promise.resolve(void 0);const o=t.authToken||this.getAttribute("auth-token")||void 0,s=t.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",r=(e=getEnvironment(this.getAttribute("environment")))!==null&&e!==void 0?e:"production";return this.authPrefetchPromise=this.loadWidgetModule().then(d=>{var a;return(a=d.prefetchAuth)===null||a===void 0?void 0:a.call(d,{agentId:n,authToken:o,serverUrl:s,environment:r,channel:this.getChannel()})}).catch(()=>{this.authPrefetchPromise=null}),this.authPrefetchPromise}async resolveSessToken(e){const t=readPersistedSessToken(e);if(t)return t;const n=await this.prefetchAuthTokens();return(n==null?void 0:n.sess_token)||readPersistedSessToken(e)}preloadBackgroundImage(){var e;const t=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,n=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,o=(e=t==null?void 0:t.theme)===null||e===void 0?void 0:e.backgroundImage,s=n==null?void 0:n.backgroundImage;o&&preloadImage(o),s&&s!==o&&preloadImage(s),this.getAgentConfig().then(r=>{var d;const a=(d=r==null?void 0:r.theme)===null||d===void 0?void 0:d.background_img;a&&preloadImage(a)}).catch(()=>{})}setupAuthExpirationListener(){if(typeof window=="undefined")return;const e=t=>{var n;((n=t.data)===null||n===void 0?void 0:n.type)==="AUTH_EXPIRED"&&window.parent!==window&&window.parent.postMessage({type:"AUTH_EXPIRED",message:"Authentication expired"},"*")};window.addEventListener("message",e)}openFromBridge(){this.displayMode=normalizeDisplayMode(this.getAttribute("display-mode")),this.displayMode==="full"?this.initializeFullMode():this.renderLauncher(),this.loadAndRender().catch(e=>{console.error("Failed to open MedAssist widget from bridge",e)})}async initNudge(){var e,t,n,o;const s=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,r=(s==null?void 0:s.agentId)||this.getAttribute("agent-id")||"";if(!r)return;const d=await this.getAgentConfig();if(!(d!=null&&d.nudge))return;const a=(t=(e=d==null?void 0:d.theme)===null||e===void 0?void 0:e.nudge_color)!==null&&t!==void 0?t:"#ffffff",l=typeof window!="undefined"?window.location.href:"";let h;try{h=new URL(l)}catch{return}const f=getNudgePathCandidates(h.pathname),p=f.slice(0,1),y=f.slice(1);let g=findFreshCachedNudge(r,h,p);if(!g){const w=(s==null?void 0:s.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",m=await this.resolveSessToken(r).catch(()=>{});if(m){const u=await fetchNudgeData(r,m,w,this.getChannel()).catch(()=>{});!((n=u==null?void 0:u.nudges)===null||n===void 0)&&n.length&&(storeNudgeResponse(r,u,normalizePath(h.pathname)),g=findFreshCachedNudge(r,h,f))}}if(g||(g=findFreshCachedNudge(r,h,y)),!g)return;const v=g.data.nudges[Math.floor(Math.random()*g.data.nudges.length)],b=(o=g.data.delay)!==null&&o!==void 0?o:5;setTimeout(()=>{this.showNudgePopup(v,a)},b*1e3)}showNudgePopup(e,t){var n,o;const s=this.shadowRoot;if(!s||!(!((n=s.getElementById("medassist-widget-root"))===null||n===void 0)&&n.classList.contains("hidden")))return;const d=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";if(d&&getNudgeCookie(d)!==null||s.getElementById("medassist-nudge-popup"))return;const l=s.getElementById("medassist-open-btn"),h=l==null?void 0:l.getBoundingClientRect(),f=272,p=12,y=8,g=16,v=16;let b=window.innerWidth-f-p,w=76,m=f-g-y*2;if(h&&h.width>0){const A=h.left+h.width/2,S=A-f/2,C=window.innerWidth-f-p;b=Math.max(p,Math.min(S,C)),w=window.innerHeight-h.top+v,m=Math.max(g,Math.min(A-b-y,f-g-y*2))}const u=document.createElement("div");u.id="medassist-nudge-popup",u.innerHTML=`
12
+ `;const a=document.documentElement.style;e?(a.setProperty("--eka-medassist-panel-width",`${t}px`),a.setProperty("--eka-medassist-panel-side",i),document.body.classList.add("eka-medassist-pushed")):(document.body.classList.remove("eka-medassist-pushed"),a.removeProperty("--eka-medassist-panel-width"),a.removeProperty("--eka-medassist-panel-side"),this.hostPushStyleEl.remove(),this.hostPushStyleEl=null);const l={pushed:e,width:t,side:i};if(typeof window!="undefined"){try{window.dispatchEvent(new CustomEvent(SIDE_PANEL_PUSH_EVENT,{detail:l}))}catch{}const h=(o=window.EkaMedAssist)===null||o===void 0?void 0:o.onSidePanelPushChange;if(typeof h=="function")try{h(e,t,i)}catch(f){console.error("EkaMedAssist.onSidePanelPushChange threw",f)}}}scheduleIdle(e){if(typeof window=="undefined"){e();return}const t=window.requestIdleCallback;typeof t=="function"?t(e,{timeout:3e3}):setTimeout(e,200)}attributeChangedCallback(e){if(e==="icon-url"&&this.displayMode!=="full"&&this.renderLauncher(),e==="display-mode"){const t=normalizeDisplayMode(this.getAttribute("display-mode"));t!==this.displayMode&&(this.displayMode=t,t==="full"?this.initializeFullMode():this.renderLauncher())}e==="custom-launcher-styles"&&this.applyCustomLauncherStyles()}preloadWidgetAssets(){getWidgetCssTextPromise(),this.loadWidgetModule(),this.preloadBackgroundImage()}prefetchAuthTokens(){var e;if(this.authPrefetchPromise)return this.authPrefetchPromise;const t=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},i=t.agentId||this.getAttribute("agent-id")||"";if(!i)return Promise.resolve(void 0);const o=t.authToken||this.getAttribute("auth-token")||void 0,s=t.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",r=(e=getEnvironment(this.getAttribute("environment")))!==null&&e!==void 0?e:"production";return this.authPrefetchPromise=this.loadWidgetModule().then(d=>{var a;return(a=d.prefetchAuth)===null||a===void 0?void 0:a.call(d,{agentId:i,authToken:o,serverUrl:s,environment:r,channel:this.getChannel()})}).catch(()=>{this.authPrefetchPromise=null}),this.authPrefetchPromise}async resolveSessToken(e){const t=readPersistedSessToken(e);if(t)return t;const i=await this.prefetchAuthTokens();return(i==null?void 0:i.sess_token)||readPersistedSessToken(e)}preloadBackgroundImage(){var e;const t=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,i=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,o=(e=t==null?void 0:t.theme)===null||e===void 0?void 0:e.backgroundImage,s=i==null?void 0:i.backgroundImage;o&&preloadImage(o),s&&s!==o&&preloadImage(s),this.getAgentConfig().then(r=>{var d;const a=(d=r==null?void 0:r.theme)===null||d===void 0?void 0:d.background_img;a&&preloadImage(a)}).catch(()=>{})}setupAuthExpirationListener(){if(typeof window=="undefined")return;const e=t=>{var i;((i=t.data)===null||i===void 0?void 0:i.type)==="AUTH_EXPIRED"&&window.parent!==window&&window.parent.postMessage({type:"AUTH_EXPIRED",message:"Authentication expired"},"*")};window.addEventListener("message",e)}openFromBridge(){this.displayMode=normalizeDisplayMode(this.getAttribute("display-mode")),this.displayMode==="full"?this.initializeFullMode():this.renderLauncher(),this.loadAndRender().catch(e=>{console.error("Failed to open MedAssist widget from bridge",e)})}async initNudge(){var e,t,i,o;const s=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,r=(s==null?void 0:s.agentId)||this.getAttribute("agent-id")||"";if(!r)return;const d=await this.getAgentConfig();if(!(d!=null&&d.nudge))return;const a=(t=(e=d==null?void 0:d.theme)===null||e===void 0?void 0:e.nudge_color)!==null&&t!==void 0?t:"#ffffff",l=typeof window!="undefined"?window.location.href:"";let h;try{h=new URL(l)}catch{return}const f=getNudgePathCandidates(h.pathname),p=f.slice(0,1),y=f.slice(1);let g=findFreshCachedNudge(r,h,p);if(!g){const w=(s==null?void 0:s.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",m=await this.resolveSessToken(r).catch(()=>{});if(m){const u=await fetchNudgeData(r,m,w,this.getChannel()).catch(()=>{});!((i=u==null?void 0:u.nudges)===null||i===void 0)&&i.length&&(storeNudgeResponse(r,u,normalizePath(h.pathname)),g=findFreshCachedNudge(r,h,f))}}if(g||(g=findFreshCachedNudge(r,h,y)),!g)return;const b=g.data.nudges[Math.floor(Math.random()*g.data.nudges.length)],v=(o=g.data.delay)!==null&&o!==void 0?o:5;setTimeout(()=>{this.showNudgePopup(b,a)},v*1e3)}showNudgePopup(e,t){var i,o;const s=this.shadowRoot;if(!s||!(!((i=s.getElementById("medassist-widget-root"))===null||i===void 0)&&i.classList.contains("hidden")))return;const d=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";if(d&&getNudgeCookie(d)!==null||s.getElementById("medassist-nudge-popup"))return;const l=s.getElementById("medassist-open-btn"),h=l==null?void 0:l.getBoundingClientRect(),f=272,p=12,y=8,g=16,b=16;let v=window.innerWidth-f-p,w=76,m=f-g-y*2;if(h&&h.width>0){const A=h.left+h.width/2,S=A-f/2,C=window.innerWidth-f-p;v=Math.max(p,Math.min(S,C)),w=window.innerHeight-h.top+b,m=Math.max(g,Math.min(A-v-y,f-g-y*2))}const u=document.createElement("div");u.id="medassist-nudge-popup",u.innerHTML=`
13
13
  <style>
14
14
  @keyframes nudge-slide-up {
15
15
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
@@ -18,7 +18,7 @@
18
18
  #medassist-nudge-popup {
19
19
  position: fixed;
20
20
  bottom: ${w}px;
21
- left: ${b}px;
21
+ left: ${v}px;
22
22
  width: ${f}px;
23
23
  background: ${t};
24
24
  border-radius: 16px;
@@ -90,7 +90,7 @@
90
90
  <p class="nudge-text">${e.replace(/</g,"&lt;").replace(/>/g,"&gt;")}</p>
91
91
  <button class="nudge-close" aria-label="Dismiss">&#x2715;</button>
92
92
  </div>
93
- `,(o=u.querySelector(".nudge-close"))===null||o===void 0||o.addEventListener("click",A=>{A.stopPropagation(),d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup()}),u.addEventListener("click",()=>{d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup(),this.loadAndRender()}),s.appendChild(u)}dismissNudgePopup(){var e;const t=(e=this.shadowRoot)===null||e===void 0?void 0:e.getElementById("medassist-nudge-popup");t==null||t.remove()}applyCustomLauncherStyles(){var e;const t=this.shadowRoot;if(!t||this.displayMode==="full")return;const n=t.querySelector('style[data-medassist-custom-launcher="true"]'),o=(e=this.getAttribute("custom-launcher-styles"))!==null&&e!==void 0?e:"";if(!o){n==null||n.remove();return}if(n){n.textContent=o;return}const s=document.createElement("style");s.setAttribute("data-medassist-custom-launcher","true"),s.textContent=o,t.appendChild(s)}getAgentId(){return((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||""}async renderLauncher(){var e,t;if(this.displayMode==="full")return;const n=++this.launcherRenderSeq;this.renderButton();const o=this.getAttribute("icon-url");if(o){this.setLauncherIcon(o);return}const s=this.getAgentId();if(!s)return;const r=(t=(e=readAgentConfigCache(s))===null||e===void 0?void 0:e.theme)===null||t===void 0?void 0:t.icon_img;r&&this.setLauncherIcon(r);const d=async()=>{var a;const l=await this.getAgentConfig().catch(()=>{});n===this.launcherRenderSeq&&(l&&writeAgentConfigCache(s,l),this.setLauncherIcon(((a=l==null?void 0:l.theme)===null||a===void 0?void 0:a.icon_img)||r))};r?this.scheduleIdle(()=>{d()}):await d()}setLauncherIcon(e){var t;const n=this.shadowRoot;if(!n)return;const o=n.querySelector("#medassist-open-btn img");o&&(e?o.src=e:o.removeAttribute("src")),(t=n.getElementById("medassist-open-btn"))===null||t===void 0||t.classList.remove("pending")}renderButton(){var e;const t=this.shadowRoot;if(!t){console.error("Shadow root was not created");return}t.querySelector("button")||(t.innerHTML=`
93
+ `,(o=u.querySelector(".nudge-close"))===null||o===void 0||o.addEventListener("click",A=>{A.stopPropagation(),d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup()}),u.addEventListener("click",()=>{d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup(),this.loadAndRender()}),s.appendChild(u)}dismissNudgePopup(){var e;const t=(e=this.shadowRoot)===null||e===void 0?void 0:e.getElementById("medassist-nudge-popup");t==null||t.remove()}applyCustomLauncherStyles(){var e;const t=this.shadowRoot;if(!t||this.displayMode==="full")return;const i=t.querySelector('style[data-medassist-custom-launcher="true"]'),o=(e=this.getAttribute("custom-launcher-styles"))!==null&&e!==void 0?e:"";if(!o){i==null||i.remove();return}if(i){i.textContent=o;return}const s=document.createElement("style");s.setAttribute("data-medassist-custom-launcher","true"),s.textContent=o,t.appendChild(s)}getAgentId(){return((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||""}async renderLauncher(){var e,t;if(this.displayMode==="full")return;const i=++this.launcherRenderSeq;this.renderButton();const o=this.getAttribute("icon-url");if(o){this.setLauncherIcon(o);return}const s=this.getAgentId();if(!s)return;const r=(t=(e=readAgentConfigCache(s))===null||e===void 0?void 0:e.theme)===null||t===void 0?void 0:t.icon_img;r&&this.setLauncherIcon(r);const d=async()=>{var a;const l=await this.getAgentConfig().catch(()=>{});i===this.launcherRenderSeq&&(l&&writeAgentConfigCache(s,l),this.setLauncherIcon(((a=l==null?void 0:l.theme)===null||a===void 0?void 0:a.icon_img)||r))};r?this.scheduleIdle(()=>{d()}):await d()}setLauncherIcon(e){var t;const i=this.shadowRoot;if(!i)return;const o=i.querySelector("#medassist-open-btn img");o&&(e?o.src=e:o.removeAttribute("src")),(t=i.getElementById("medassist-open-btn"))===null||t===void 0||t.classList.remove("pending")}renderButton(){var e;const t=this.shadowRoot;if(!t){console.error("Shadow root was not created");return}t.querySelector("button")||(t.innerHTML=`
94
94
  <style>
95
95
  #medassist-open-btn {
96
96
  width: 60px;
@@ -174,7 +174,7 @@
174
174
  <span id="medassist-loader" aria-hidden="true"></span>
175
175
  </button>
176
176
  <div id="medassist-widget-root" class="hidden"></div>
177
- `,(e=t.getElementById("medassist-open-btn"))===null||e===void 0||e.addEventListener("click",()=>{const n=this.getAgentId();n&&setNudgeCookie(n,"closed"),this.dismissNudgePopup(),this.loadAndRender()})),this.applyCustomLauncherStyles()}initializeFullMode(){const e=this.shadowRoot;if(!e){console.error("Shadow root is not available");return}e.getElementById("medassist-widget-root")||(e.innerHTML=`
177
+ `,(e=t.getElementById("medassist-open-btn"))===null||e===void 0||e.addEventListener("click",()=>{const i=this.getAgentId();i&&setNudgeCookie(i,"closed"),this.dismissNudgePopup(),this.loadAndRender()})),this.applyCustomLauncherStyles()}initializeFullMode(){const e=this.shadowRoot;if(!e){console.error("Shadow root is not available");return}e.getElementById("medassist-widget-root")||(e.innerHTML=`
178
178
  <style>
179
179
  :host {
180
180
  display: block;
@@ -191,4 +191,4 @@
191
191
  }
192
192
  </style>
193
193
  <div id="medassist-widget-root"></div>
194
- `)}async loadAndRender(){var e,t,n;const o=this.shadowRoot;if(!o){console.error("Shadow root is not available");return}if(this.loading)return;this.prefetchAuthTokens(),this.style.display="";const s=o.getElementById("medassist-widget-root"),r=this.getAttribute("agent-id");let d=this.getAttribute("icon-url")||void 0;const a=(e=getEnvironment(this.getAttribute("environment")))!==null&&e!==void 0?e:"production",l=this.getAttribute("connectivity"),h=l==="http_stream"||l==="socket"?l:void 0,f=this.getAttribute("force-start")==="true";let p=this.getAttribute("title")||"Medi Clinic";const y=this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",g=this.getAttribute("display-mode"),v=normalizeDisplayMode(g),b=this.getAttribute("context")?JSON.parse(this.getAttribute("context")||"{}"):void 0,w=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,m=this.getAttribute("feedback")?(()=>{try{return JSON.parse(this.getAttribute("feedback")||"{}")}catch{return}})():void 0,u=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},A=this.getAttribute("side-panel-mode"),S=u.sidePanelMode||(A==="overlay"?"overlay":"push"),C=this.getAttribute("side-panel-width"),F=(t=u.sidePanelWidth)!==null&&t!==void 0?t:C?Number(C):void 0,O=u.side||this.getAttribute("side")||(typeof document!="undefined"&&document.dir==="rtl"?"left":"right"),D={...b||{},...u.context||{}},H=u.authToken||this.getAttribute("auth-token")||void 0,_=u.agentId||r,q=u.baseUrl||y,E=typeof window!="undefined"?(n=window.EkaMedAssist)===null||n===void 0?void 0:n.onClose:void 0,J=this.getAttribute("redirect-url")||void 0,P=u.redirectUrl||J,j=!!P||u.showCloseButton===!0;if(!_){console.error("Agent ID is required");return}if(!s){console.error("Widget root element is missing");return}this.loading=!0,this.setLauncherState("loading"),s.classList.remove("hidden");let L,R,N,U=!1,T,W=!1,M;const B=c=>{var x,k,I;p=c.name||p,d=((x=c.theme)===null||x===void 0?void 0:x.icon_img)||d,L=mapAgentConfigThemeToWidgetTheme(c.theme||void 0),R=c.allowed,N=c.connectivity,U=c.resize||(u==null?void 0:u.resize)||!1,T=c.initial_message,W=(I=(k=c.theme)===null||k===void 0?void 0:k.hide_watermark)!==null&&I!==void 0?I:!1,M=c.feedback},$=readAgentConfigCache(_);if($)B($),this.getAgentConfig().then(c=>{c&&writeAgentConfigCache(_,c)}).catch(()=>{});else try{const c=await this.getAgentConfig();c&&(writeAgentConfigCache(_,c),B(c))}catch{}const G=h||N||"socket",z={title:u.title||p,iconUrl:d||u.iconUrl,showCloseButton:j,allowed:R,environment:a,connectionType:G,onClose:()=>{var c;if((c=this.reactRoot)===null||c===void 0||c.unmount(),this.reactRoot=null,E&&typeof E=="function"&&E(),P){window.location.href=P;return}v==="full"?this.style.display="none":(this.setLauncherState("idle"),s.classList.add("hidden"))},baseUrl:q,context:D,displayMode:v,sidePanelMode:S,sidePanelWidth:F,side:O,onSidePanelPushChange:(c,x,k)=>this.applyHostPush(c,x,k),resize:U||this.getAttribute("resize")==="true",authToken:H,force:f,initialMessage:T,hideWatermark:W,...(m||M)&&{feedback:m||M},theme:{...L||{},...w||{},...u.theme||{}}},X=window;if(this.widgetLoaded){this.reactRoot=X.renderMedAssist(s,_,z),this.setLauncherState("open"),this.loading=!1;return}try{const[,c]=await Promise.all([this.loadWidgetCss(),this.loadWidgetModule()]);this.reactRoot=c.renderMedAssist(s,_,z),this.widgetLoaded=!0,this.setLauncherState("open")}catch(c){console.error("Failed to load MedAssist widget",c),this.setLauncherState("idle"),s.classList.add("hidden")}finally{this.loading=!1}}async loadWidgetCss(){const e=this.shadowRoot;if(!e)throw new Error("Shadow root is not available");if(e.querySelector("[data-medassist-style='true']"))return;const t=await getWidgetCssTextPromise(),n=document.createElement("style");n.setAttribute("data-medassist-style","true"),n.textContent=t,e.appendChild(n)}loadWidgetModule(){return widgetModulePromise||(widgetModulePromise=import(WIDGET_JS_URL)),widgetModulePromise}}customElements.define("eka-medassist-widget",MedAssistWidgetLoader);
194
+ `)}async loadAndRender(){var e,t,i;const o=this.shadowRoot;if(!o){console.error("Shadow root is not available");return}if(this.loading)return;this.prefetchAuthTokens(),this.style.display="";const s=o.getElementById("medassist-widget-root"),r=this.getAttribute("agent-id");let d=this.getAttribute("icon-url")||void 0;const a=(e=getEnvironment(this.getAttribute("environment")))!==null&&e!==void 0?e:"production",l=this.getAttribute("connectivity"),h=l==="http_stream"||l==="socket"?l:void 0,f=this.getAttribute("force-start")==="true";let p=this.getAttribute("title")||"Medi Clinic";const y=this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",g=this.getAttribute("display-mode"),b=normalizeDisplayMode(g),v=this.getAttribute("context")?JSON.parse(this.getAttribute("context")||"{}"):void 0,w=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,m=this.getAttribute("feedback")?(()=>{try{return JSON.parse(this.getAttribute("feedback")||"{}")}catch{return}})():void 0,u=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},A=this.getAttribute("side-panel-mode"),S=u.sidePanelMode||(A==="overlay"?"overlay":"push"),C=this.getAttribute("side-panel-width"),F=(t=u.sidePanelWidth)!==null&&t!==void 0?t:C?Number(C):void 0,O=u.side||this.getAttribute("side")||(typeof document!="undefined"&&document.dir==="rtl"?"left":"right"),D={...v||{},...u.context||{}},H=u.authToken||this.getAttribute("auth-token")||void 0,_=u.agentId||r,q=u.baseUrl||y,E=typeof window!="undefined"?(i=window.EkaMedAssist)===null||i===void 0?void 0:i.onClose:void 0,J=this.getAttribute("redirect-url")||void 0,P=u.redirectUrl||J,j=!!P||u.showCloseButton===!0;if(!_){console.error("Agent ID is required");return}if(!s){console.error("Widget root element is missing");return}this.loading=!0,this.setLauncherState("loading"),s.classList.remove("hidden");let L,R,N,U=!1,W,T=!1,M;const B=c=>{var x,k,I;p=c.name||p,d=((x=c.theme)===null||x===void 0?void 0:x.icon_img)||d,L=mapAgentConfigThemeToWidgetTheme(c.theme||void 0),R=c.allowed,N=c.connectivity,U=c.resize||(u==null?void 0:u.resize)||!1,W=c.initial_message,T=(I=(k=c.theme)===null||k===void 0?void 0:k.hide_watermark)!==null&&I!==void 0?I:!1,M=c.feedback},$=readAgentConfigCache(_);if($)B($),this.getAgentConfig().then(c=>{c&&writeAgentConfigCache(_,c)}).catch(()=>{});else try{const c=await this.getAgentConfig();c&&(writeAgentConfigCache(_,c),B(c))}catch{}const G=h||N||"socket",z={title:u.title||p,iconUrl:d||u.iconUrl,showCloseButton:j,allowed:R,environment:a,connectionType:G,onClose:()=>{var c;if((c=this.reactRoot)===null||c===void 0||c.unmount(),this.reactRoot=null,E&&typeof E=="function"&&E(),P){window.location.href=P;return}b==="full"?this.style.display="none":(this.setLauncherState("idle"),s.classList.add("hidden"))},baseUrl:q,context:D,displayMode:b,sidePanelMode:S,sidePanelWidth:F,side:O,onSidePanelPushChange:(c,x,k)=>this.applyHostPush(c,x,k),resize:U||this.getAttribute("resize")==="true",authToken:H,force:f,initialMessage:W,hideWatermark:T,...(m||M)&&{feedback:m||M},theme:{...L||{},...w||{},...u.theme||{}}},X=window;if(this.widgetLoaded){this.reactRoot=X.renderMedAssist(s,_,z),this.setLauncherState("open"),this.loading=!1;return}try{const[,c]=await Promise.all([this.loadWidgetCss(),this.loadWidgetModule()]);this.reactRoot=c.renderMedAssist(s,_,z),this.widgetLoaded=!0,this.setLauncherState("open")}catch(c){console.error("Failed to load MedAssist widget",c),this.setLauncherState("idle"),s.classList.add("hidden")}finally{this.loading=!1}}async loadWidgetCss(){const e=this.shadowRoot;if(!e)throw new Error("Shadow root is not available");if(e.querySelector("[data-medassist-style='true']"))return;const t=await getWidgetCssTextPromise(),i=document.createElement("style");i.setAttribute("data-medassist-style","true"),i.textContent=t,e.appendChild(i)}loadWidgetModule(){return widgetModulePromise||(widgetModulePromise=import(WIDGET_JS_URL)),widgetModulePromise}}customElements.define("eka-medassist-widget",MedAssistWidgetLoader);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eka-care/medassist-widget-embed",
3
- "version": "0.2.116-dev.1",
3
+ "version": "0.2.117-dev.0",
4
4
  "description": "Embeddable MedAssist widget loader built with Web Components.",
5
5
  "author": "Geethanjali S",
6
6
  "license": "MIT",