@eka-care/medassist-widget-embed 0.2.97-dev.0 → 0.2.97-dev.2
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.
- package/dist/eka-agents.html +4 -4
- package/dist/iframe.js +1 -1
- package/dist/index.d.ts +27 -5
- package/dist/index.js +7 -7
- package/package.json +1 -1
package/dist/eka-agents.html
CHANGED
|
@@ -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.119-dev.
|
|
21
|
+
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.119-dev.3/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.119-dev.
|
|
30
|
+
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.119-dev.3/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.119-dev.
|
|
37
|
+
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.119-dev.3/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.119-dev.
|
|
152
|
+
src="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.119-dev.3/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 F=()=>{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},R=e=>{if(e==="production"||e==="development"||e==="staging")return e};function B(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}}}function _(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 D(e,t){const r=`${e.replace(/\/$/,"")}/med-assist/agent-config/${t}`,n=new AbortController,i=setTimeout(()=>n.abort(),1e4);try{const s=await fetch(r,{signal:n.signal,headers:{"ngrok-skip-browser-warning":"69420"}});if(!s.ok)return;const c=await s.json();return c!=null&&c.success&&(c!=null&&c.data)?c.data:void 0}catch{return}finally{clearTimeout(i)}}const C="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.119-dev.
|
|
1
|
+
"use strict";(function(){const F=()=>{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},R=e=>{if(e==="production"||e==="development"||e==="staging")return e};function B(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}}}function _(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 D(e,t){const r=`${e.replace(/\/$/,"")}/med-assist/agent-config/${t}`,n=new AbortController,i=setTimeout(()=>n.abort(),1e4);try{const s=await fetch(r,{signal:n.signal,headers:{"ngrok-skip-browser-warning":"69420"}});if(!s.ok)return;const c=await s.json();return c!=null&&c.success&&(c!=null&&c.data)?c.data:void 0}catch{return}finally{clearTimeout(i)}}const C="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.119-dev.3/dist/",a=F(),S=(()=>{if(!a)return"";try{return new URL(".",a.src||window.location.href).href}catch{return""}})(),m=(()=>{if(!a)return C;const e=a.dataset.widgetAssets;if(e==="local")return`${S}src/`;if(e&&e.length>0)try{return new URL(e,S).href}catch{return e.endsWith("/")?e:`${e}/`}return C})(),l=`${m}medassist-widget.js`,g=`${m}medassist-widget.css`;let f=null,w=null;const d=new URLSearchParams(typeof window!="undefined"?window.location.search:""),b=d.get("agentId"),h=d.get("baseUrl")||"https://matrix.eka.care/reloaded";if(typeof document!="undefined"&&document.head){try{const e=new URL(m).origin,t=new URL(h).origin,r=document.createElement("link");if(r.rel="preconnect",r.href=e,r.crossOrigin="anonymous",document.head.appendChild(r),e!==t){const s=document.createElement("link");s.rel="preconnect",s.href=t,s.crossOrigin="anonymous",document.head.appendChild(s)}const n=document.createElement("link");n.rel="modulepreload",n.href=l,document.head.appendChild(n);const i=document.createElement("link");i.rel="preload",i.as="style",i.href=g,document.head.appendChild(i)}catch{}U(),L()}const A=b&&h?D(h,b):Promise.resolve(void 0);if(typeof document!="undefined"&&document.head){const e=d.get("theme");if(e)try{const t=JSON.parse(e);t.backgroundImage&&_(t.backgroundImage)}catch{}A.then(t=>{var r;const n=(r=t==null?void 0:t.theme)===null||r===void 0?void 0:r.background_img;n&&_(n)})}const I=async()=>{var e,t,r,n,i,s,c;const M=d.get("agentId");if(!M){console.error("Agent ID is required in URL parameters");return}let p=d.get("title")||"Medi Clinic",v=d.get("iconUrl")||void 0;const P=d.get("context"),z=d.get("baseUrl")||"https://matrix.eka.care/reloaded",T=d.get("auth-token")||void 0;let y=d.get("resize")==="true"?!0:void 0;const G=(e=R(d.get("environment")))!==null&&e!==void 0?e:"production",k=d.get("connectivity"),J=k==="http_stream"||k==="socket"?k:void 0,E=d.get("theme")?(()=>{try{return JSON.parse(d.get("theme")||"{}")}catch{return}})():void 0,N=document.getElementById("root")||document.body;try{const[,,o]=await Promise.all([U(),L(),A]);if(!(window!=null&&window.renderMedAssist)||typeof(window==null?void 0:window.renderMedAssist)!="function")throw new Error("renderMedAssist is not available on window");let u,O,x,$,W=!1;o&&(p=(t=o==null?void 0:o.name)!==null&&t!==void 0?t:p,v=(n=(r=o==null?void 0:o.theme)===null||r===void 0?void 0:r.icon_img)!==null&&n!==void 0?n:v,u=B((i=o==null?void 0:o.theme)!==null&&i!==void 0?i:void 0),O=o==null?void 0:o.allowed,x=o==null?void 0:o.connectivity,$=o==null?void 0:o.initial_message,W=(c=(s=o==null?void 0:o.theme)===null||s===void 0?void 0:s.hide_watermark)!==null&&c!==void 0?c:!1,y=y||(o==null?void 0:o.resize)||void 0);const q={title:p,iconUrl:v,environment:G,connectionType:x||J||"socket",onClose:()=>{window.parent!==window&&window.parent.postMessage({type:"WIDGET_CLOSE"},"*")},context:P?JSON.parse(P):void 0,baseUrl:z,displayMode:"full",allowed:O,showCloseButton:!1,resize:y,initialMessage:$,hideWatermark:W,...T&&{authToken:T},theme:{...u!=null?u:{},...E!=null?E:{}}};window.renderMedAssist(N,M,q)}catch(o){throw console.error("Failed to initialize MedAssist widget",o),o}};async function U(){document.querySelector("link[data-medassist-style='true']")||(w||(w=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 w)}function L(){return f||(f=new Promise((e,t)=>{const r=document.querySelector(`script[src="${l}"]`);if(r){if(r.dataset.loaded==="true"){e();return}r.addEventListener("load",()=>e()),r.addEventListener("error",i=>t(i.error||new Error("Unknown script loading error")));return}const n=document.createElement("script");n.src=l,n.type="module",n.async=!0,n.dataset.widget="medassist",n.onload=()=>{n.dataset.loaded="true",e()},n.onerror=i=>{if(i instanceof ErrorEvent&&i.error){t(i.error);return}t(new Error(`Failed to load ${l}`))},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
|
@@ -148,7 +148,11 @@ declare function storeNudgeResponse(agentId: string, response: NudgeApiResponse)
|
|
|
148
148
|
declare const NUDGE_COOKIE_PREFIX = "eka-nudge";
|
|
149
149
|
declare function setNudgeCookie(agentId: string, value: "open" | "closed"): void;
|
|
150
150
|
declare function getNudgeCookie(agentId: string): "open" | "closed" | null;
|
|
151
|
-
|
|
151
|
+
/** Widget store key (sessionStorage, agent-scoped) — mirrors `buildStoreKey` in the widget package. */
|
|
152
|
+
declare const WIDGET_STORE_KEY_PREFIX = "med-assist-store-";
|
|
153
|
+
/** Sess (access) token persisted by the widget store, if the widget already ran in this tab. */
|
|
154
|
+
declare function readPersistedSessToken(agentId: string): string | undefined;
|
|
155
|
+
declare function fetchNudgeData(agentId: string, baseUrl?: string, sessToken?: string): Promise<NudgeApiResponse | undefined>;
|
|
152
156
|
type ReactRoot = {
|
|
153
157
|
unmount: () => void;
|
|
154
158
|
};
|
|
@@ -166,6 +170,13 @@ declare const scriptBaseUrl: string;
|
|
|
166
170
|
declare const widgetAssetBaseUrl: string;
|
|
167
171
|
declare const WIDGET_JS_URL: string;
|
|
168
172
|
declare const WIDGET_CSS_URL: string;
|
|
173
|
+
/**
|
|
174
|
+
* Token-exchange result. `null` when the widget short-circuited the prefetch
|
|
175
|
+
* because a complete sess+refresh pair was already persisted.
|
|
176
|
+
*/
|
|
177
|
+
type PrefetchAuthResult = {
|
|
178
|
+
sess_token?: string;
|
|
179
|
+
} | null | undefined;
|
|
169
180
|
type WidgetModule = {
|
|
170
181
|
renderMedAssist: (container: HTMLElement, agentId: string, config: MedAssistInitConfig) => ReactRoot;
|
|
171
182
|
prefetchAuth?: (config: {
|
|
@@ -173,7 +184,7 @@ type WidgetModule = {
|
|
|
173
184
|
authToken?: string;
|
|
174
185
|
serverUrl?: string;
|
|
175
186
|
environment?: WidgetEnvironment;
|
|
176
|
-
}) => Promise<
|
|
187
|
+
}) => Promise<PrefetchAuthResult>;
|
|
177
188
|
};
|
|
178
189
|
declare let widgetModulePromise: Promise<WidgetModule> | null;
|
|
179
190
|
declare let widgetCssTextPromise: Promise<string> | null;
|
|
@@ -202,17 +213,28 @@ declare class MedAssistWidgetLoader extends HTMLElement {
|
|
|
202
213
|
attributeChangedCallback(name: string): void;
|
|
203
214
|
/** When in widget mode, start loading JS and CSS on page load so first open is faster. */
|
|
204
215
|
private preloadWidgetAssets;
|
|
205
|
-
private
|
|
216
|
+
private authPrefetchPromise;
|
|
206
217
|
/**
|
|
207
218
|
* Kick off the token exchange as soon as the widget module is available so
|
|
208
219
|
* tokens are ready before (or while) the widget opens. Runs in parallel with
|
|
209
|
-
* the agent-config fetch. Safe to call repeatedly —
|
|
210
|
-
* core-side prefetch cache both dedupe it; the SDK adopts the in-flight
|
|
220
|
+
* the agent-config fetch. Safe to call repeatedly — the memoized promise and
|
|
221
|
+
* the core-side prefetch cache both dedupe it; the SDK adopts the in-flight
|
|
211
222
|
* exchange when the widget mounts. The widget-side prefetchAuth skips
|
|
212
223
|
* brand-new anonymous visitors (no partner authToken, no persisted refresh
|
|
213
224
|
* token) so idle pre-warm never mints throwaway guest identities.
|
|
225
|
+
*
|
|
226
|
+
* Returns the exchange result so callers that need the freshly minted sess
|
|
227
|
+
* token (e.g. the nudge request) can read it without the widget ever having
|
|
228
|
+
* been opened — nothing is persisted to the widget store until it mounts.
|
|
214
229
|
*/
|
|
215
230
|
private prefetchAuthTokens;
|
|
231
|
+
/**
|
|
232
|
+
* Sess (access) token for host-side API calls made before the widget mounts.
|
|
233
|
+
* Prefers the widget store (set once the widget has run in this tab), else
|
|
234
|
+
* the token minted by the idle-time prefetch exchange — which lives only in
|
|
235
|
+
* the in-flight promise until the widget mounts and persists it.
|
|
236
|
+
*/
|
|
237
|
+
private resolveSessToken;
|
|
216
238
|
/** Preload theme background image from init config, theme attribute, or agent-config API. */
|
|
217
239
|
private preloadBackgroundImage;
|
|
218
240
|
private setupAuthExpirationListener;
|
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:e}=document;if(e instanceof HTMLScriptElement)return e;const t=document.getElementsByTagName("script");return t.length?t[t.length-1]:null},getEnvironment=e=>{if(e==="production"||e==="development"||e==="staging")return e},scriptEl=getCurrentScript(),DEFAULT_WIDGET_ASSET_BASE=(()=>{var e;return!((e=scriptEl==null?void 0:scriptEl.src)===null||e===void 0)&&e.includes("@dev"),"https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.119-dev.1/dist/"})();var FeedbackTypeEnum;(function(e){e.DEFAULT="default",e.NPS="nps"})(FeedbackTypeEnum||(FeedbackTypeEnum={}));function mapAgentConfigThemeToWidgetTheme(e){if(!e)return;const t=e.mode==="dark"?"white":e.mode==="light"?"black":void 0;return{...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.hide_watermark&&{hideWatermark:e.hide_watermark},...e.explicit_disclaimer&&{explicitDisclaimer:e.explicit_disclaimer}}}function preloadImage(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 fetchAgentConfig(e,t){const n=`${e.replace(/\/$/,"")}/med-assist/agent-config/${t}`,i=await fetch(n,{headers:{"ngrok-skip-browser-warning":"69420"}});if(!i.ok)return;const o=await i.json();if(o!=null&&o.success&&(o!=null&&o.data))return o.data}const NUDGE_STORAGE_KEY="eka-medassist-nudges",AGENT_CONFIG_CACHE_KEY="eka-medassist-agent-config";function readAgentConfigCache(e){try{const t=localStorage.getItem(AGENT_CONFIG_CACHE_KEY);return(t?JSON.parse(t):{})[e]}catch{return}}function writeAgentConfigCache(e,t){try{const n=localStorage.getItem(AGENT_CONFIG_CACHE_KEY),i=n?JSON.parse(n):{};i[e]={...i[e]||{},...t},localStorage.setItem(AGENT_CONFIG_CACHE_KEY,JSON.stringify(i))}catch{}}function getNudgeStore(){try{const e=localStorage.getItem(NUDGE_STORAGE_KEY);return e?JSON.parse(e):{}}catch{return{}}}function setNudgeStore(e){try{localStorage.setItem(NUDGE_STORAGE_KEY,JSON.stringify(e))}catch{}}function normalizePath(e){let t=e.replace(/\/+$/,"");return t.startsWith("/")||(t="/"+t),t||"/"}function getNudgePathCandidates(e){const t=e.split("/").filter(Boolean),n=[];for(let i=t.length;i>=0;i--)n.push(i===0?"/":"/"+t.slice(0,i).join("/"));return n}function findCachedNudgeForCandidates(e,t,n){const o=getNudgeStore()[e];if(!o)return null;const s=t.host,r=o[s];if(!r)return null;for(const d of n){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(e,t,n){const i=findCachedNudgeForCandidates(e,t,n);if(!i)return null;const o=Math.floor(Date.now()/1e3);return i.data.expiry<=o?(clearNudgeForPath(e,i.domain,i.path),null):i}function clearNudgeForPath(e,t,n){const i=getNudgeStore(),o=i[e];!o||!o[t]||(delete o[t][n],setNudgeStore(i))}function storeNudgeResponse(e,t){var n,i,o,s;const r=(n=t==null?void 0:t.url_pattern)===null||n===void 0?void 0:n.domain,d=(i=t==null?void 0:t.url_pattern)===null||i===void 0?void 0:i.path;if(!(!((o=t.nudges)===null||o===void 0)&&o.length)||!t.expiry||!r||!d)return;const a=getNudgeStore();a[e]||(a[e]={}),a[e][r]||(a[e][r]={}),a[e][r][d]={nudges:t.nudges,expiry:t.expiry,delay:(s=t.delay)!==null&&s!==void 0?s:5},setNudgeStore(a)}const NUDGE_COOKIE_PREFIX="eka-nudge";function setNudgeCookie(e,t){const n=new Date(Date.now()+864e5).toUTCString();document.cookie=`${NUDGE_COOKIE_PREFIX}-${e}=${t}; expires=${n}; path=/; SameSite=Lax`}function getNudgeCookie(e){const t=document.cookie.split(";").map(i=>i.trim()).find(i=>i.startsWith(`${NUDGE_COOKIE_PREFIX}-${e}=`));if(!t)return null;const n=t.split("=")[1];return n==="open"||n==="closed"?n:null}async function fetchNudgeData(e,t){const n=`${t}/med-assist/user-nudge`,i=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(o=>{var s,r,d;const a=(s=o.getAttribute("name"))!==null&&s!==void 0?s:void 0,f=(r=o.getAttribute("property"))!==null&&r!==void 0?r:void 0,c=(d=o.getAttribute("content"))!==null&&d!==void 0?d:void 0;(a||f)&&i.push({name:a,property:f,content:c})});try{const o=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json","x-agent-id":e,referer:typeof window!="undefined"?window.location.href:""},body:JSON.stringify({meta_tags:i,url:typeof window!="undefined"?window.location.href:""})});return o.ok?await o.json():void 0}catch{return}}const globalMedAssistConfig={},getWidgetElement=()=>typeof document=="undefined"?null:document.querySelector("eka-medassist-widget");if(typeof window!="undefined"){const e=window;e.__ekaMedAssistConfig__=globalMedAssistConfig,e.EkaMedAssist={init(t){var n,i,o;Object.assign(globalMedAssistConfig,t);const s=getWidgetElement();if(s){if(t.agentId&&s.setAttribute("agent-id",t.agentId),t.authToken&&s.setAttribute("auth-token",t.authToken),t.title&&s.setAttribute("title",t.title),t.iconUrl&&s.setAttribute("icon-url",t.iconUrl),t.baseUrl&&s.setAttribute("base-url",t.baseUrl),t.resize!==void 0&&s.setAttribute("resize",String(t.resize)),(t.displayMode==="full"||t.displayMode==="widget")&&s.setAttribute("display-mode",t.displayMode),t.context)try{s.setAttribute("context",JSON.stringify(t.context))}catch{console.warn("Failed to stringify context passed to init")}typeof t.customLauncherStyles=="string"&&s.setAttribute("custom-launcher-styles",t.customLauncherStyles),t.redirectUrl&&s.setAttribute("redirect-url",t.redirectUrl),!((n=t.theme)===null||n===void 0)&&n.backgroundImage&&preloadImage(t.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 e=scriptEl.dataset.widgetAssets;if(e==="local")return`${scriptBaseUrl}src/`;if(e&&e.length>0)try{return new URL(e,scriptBaseUrl).href}catch{return e.endsWith("/")?e:`${e}/`}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(e=>{if(!e.ok)throw new Error(`Unable to fetch widget styles from ${WIDGET_CSS_URL}`);return e.text()})),widgetCssTextPromise}class MedAssistWidgetLoader extends HTMLElement{setLauncherState(t){var n;const i=(n=this.shadowRoot)===null||n===void 0?void 0:n.getElementById("medassist-open-btn");i&&(i.classList.toggle("loading",t==="loading"),i.classList.toggle("hidden",t==="open"),t==="loading"?i.setAttribute("aria-busy","true"):i.removeAttribute("aria-busy"))}getAgentConfig(){if(!this.agentConfigPromise){const t=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},n=t.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",i=t.agentId||this.getAttribute("agent-id")||"";if(!i)return Promise.resolve(void 0);this.agentConfigPromise=fetchAgentConfig(n,i).catch(()=>{})}return this.agentConfigPromise}constructor(){super(),this.reactRoot=null,this.agentConfigPromise=null,this.loading=!1,this.authPrefetchStarted=!1,this.attachShadow({mode:"open"}),this.defaultIconUrl="https://cdn.eka.care/bot-icon.svg",this.widgetLoaded=!1,this.displayMode=this.getAttribute("display-mode")==="full"?"full":"widget",this.setupAuthExpirationListener()}static get observedAttributes(){return["icon-url","display-mode","custom-launcher-styles","redirect-url"]}connectedCallback(){this.displayMode==="full"?(this.initializeFullMode(),this.loadAndRender().catch(t=>{console.error("Failed to load MedAssist widget in full mode",t)})):(this.renderButton(),this.scheduleIdle(()=>{this.preloadWidgetAssets(),this.prefetchAuthTokens(),this.initNudge()}))}scheduleIdle(t){if(typeof window=="undefined"){t();return}const n=window.requestIdleCallback;typeof n=="function"?n(t,{timeout:3e3}):setTimeout(t,200)}attributeChangedCallback(t){if(t==="icon-url"&&this.displayMode==="widget"&&this.renderButton(),t==="display-mode"){const n=this.getAttribute("display-mode")==="full"?"full":"widget";n!==this.displayMode&&(this.displayMode=n,n==="full"?this.initializeFullMode():this.renderButton())}t==="custom-launcher-styles"&&this.applyCustomLauncherStyles()}preloadWidgetAssets(){getWidgetCssTextPromise(),this.loadWidgetModule(),this.preloadBackgroundImage()}prefetchAuthTokens(){var t;if(this.authPrefetchStarted)return;const n=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},i=n.agentId||this.getAttribute("agent-id")||"";if(!i)return;this.authPrefetchStarted=!0;const o=n.authToken||this.getAttribute("auth-token")||void 0,s=n.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",r=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production";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})}).catch(()=>{this.authPrefetchStarted=!1})}preloadBackgroundImage(){var t;const n=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,i=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,o=(t=n==null?void 0:n.theme)===null||t===void 0?void 0:t.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 t=n=>{var i;((i=n.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",t)}openFromBridge(){this.displayMode=this.getAttribute("display-mode")==="full"?"full":"widget",this.displayMode==="full"?this.initializeFullMode():this.renderButton(),this.loadAndRender().catch(t=>{console.error("Failed to open MedAssist widget from bridge",t)})}async initNudge(){var t,n,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=(n=(t=d==null?void 0:d.theme)===null||t===void 0?void 0:t.nudge_color)!==null&&n!==void 0?n:"#ffffff",f=typeof window!="undefined"?window.location.href:"";let c;try{c=new URL(f)}catch{return}const g=getNudgePathCandidates(c.pathname),m=g.slice(0,1),v=g.slice(1);let h=findFreshCachedNudge(r,c,m);if(!h){const b=(s==null?void 0:s.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",u=await fetchNudgeData(r,b).catch(()=>{});!((i=u==null?void 0:u.nudges)===null||i===void 0)&&i.length&&(storeNudgeResponse(r,u),h=findFreshCachedNudge(r,c,g))}if(h||(h=findFreshCachedNudge(r,c,v)),!h)return;const x=h.data.nudges[Math.floor(Math.random()*h.data.nudges.length)],w=(o=h.data.delay)!==null&&o!==void 0?o:5;setTimeout(()=>{this.showNudgePopup(x,a)},w*1e3)}showNudgePopup(t,n){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 f=s.getElementById("medassist-open-btn"),c=f==null?void 0:f.getBoundingClientRect(),g=272,m=12,v=8,h=16,x=16;let w=window.innerWidth-g-m,b=76,u=g-h-v*2;if(c&&c.width>0){const A=c.left+c.width/2,p=A-g/2,_=window.innerWidth-g-m;w=Math.max(m,Math.min(p,_)),b=window.innerHeight-c.top+x,u=Math.max(h,Math.min(A-w-v,g-h-v*2))}const y=document.createElement("div");y.id="medassist-nudge-popup",y.innerHTML=`
|
|
1
|
+
"use strict";const getCurrentScript=()=>{if(typeof document=="undefined")return console.error("document is not defined"),null;const{currentScript:e}=document;if(e instanceof HTMLScriptElement)return e;const t=document.getElementsByTagName("script");return t.length?t[t.length-1]:null},getEnvironment=e=>{if(e==="production"||e==="development"||e==="staging")return e},scriptEl=getCurrentScript(),DEFAULT_WIDGET_ASSET_BASE=(()=>{var e;return!((e=scriptEl==null?void 0:scriptEl.src)===null||e===void 0)&&e.includes("@dev"),"https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.119-dev.3/dist/"})();var FeedbackTypeEnum;(function(e){e.DEFAULT="default",e.NPS="nps"})(FeedbackTypeEnum||(FeedbackTypeEnum={}));function mapAgentConfigThemeToWidgetTheme(e){if(!e)return;const t=e.mode==="dark"?"white":e.mode==="light"?"black":void 0;return{...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.hide_watermark&&{hideWatermark:e.hide_watermark},...e.explicit_disclaimer&&{explicitDisclaimer:e.explicit_disclaimer}}}function preloadImage(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 fetchAgentConfig(e,t){const n=`${e.replace(/\/$/,"")}/med-assist/agent-config/${t}`,i=await fetch(n,{headers:{"ngrok-skip-browser-warning":"69420"}});if(!i.ok)return;const s=await i.json();if(s!=null&&s.success&&(s!=null&&s.data))return s.data}const NUDGE_STORAGE_KEY="eka-medassist-nudges",AGENT_CONFIG_CACHE_KEY="eka-medassist-agent-config";function readAgentConfigCache(e){try{const t=localStorage.getItem(AGENT_CONFIG_CACHE_KEY);return(t?JSON.parse(t):{})[e]}catch{return}}function writeAgentConfigCache(e,t){try{const n=localStorage.getItem(AGENT_CONFIG_CACHE_KEY),i=n?JSON.parse(n):{};i[e]={...i[e]||{},...t},localStorage.setItem(AGENT_CONFIG_CACHE_KEY,JSON.stringify(i))}catch{}}function getNudgeStore(){try{const e=localStorage.getItem(NUDGE_STORAGE_KEY);return e?JSON.parse(e):{}}catch{return{}}}function setNudgeStore(e){try{localStorage.setItem(NUDGE_STORAGE_KEY,JSON.stringify(e))}catch{}}function normalizePath(e){let t=e.replace(/\/+$/,"");return t.startsWith("/")||(t="/"+t),t||"/"}function getNudgePathCandidates(e){const t=e.split("/").filter(Boolean),n=[];for(let i=t.length;i>=0;i--)n.push(i===0?"/":"/"+t.slice(0,i).join("/"));return n}function findCachedNudgeForCandidates(e,t,n){const s=getNudgeStore()[e];if(!s)return null;const o=t.host,r=s[o];if(!r)return null;for(const d of n){if(r[d]!==void 0)return{domain:o,path:d,data:r[d]};const a=d==="/"?"/*":d+"/*";if(r[a]!==void 0)return{domain:o,path:a,data:r[a]}}return null}function findFreshCachedNudge(e,t,n){const i=findCachedNudgeForCandidates(e,t,n);if(!i)return null;const s=Math.floor(Date.now()/1e3);return i.data.expiry<=s?(clearNudgeForPath(e,i.domain,i.path),null):i}function clearNudgeForPath(e,t,n){const i=getNudgeStore(),s=i[e];!s||!s[t]||(delete s[t][n],setNudgeStore(i))}function storeNudgeResponse(e,t){var n,i,s,o;const r=(n=t==null?void 0:t.url_pattern)===null||n===void 0?void 0:n.domain,d=(i=t==null?void 0:t.url_pattern)===null||i===void 0?void 0:i.path;if(!(!((s=t.nudges)===null||s===void 0)&&s.length)||!t.expiry||!r||!d)return;const a=getNudgeStore();a[e]||(a[e]={}),a[e][r]||(a[e][r]={}),a[e][r][d]={nudges:t.nudges,expiry:t.expiry,delay:(o=t.delay)!==null&&o!==void 0?o:5},setNudgeStore(a)}const NUDGE_COOKIE_PREFIX="eka-nudge";function setNudgeCookie(e,t){const n=new Date(Date.now()+864e5).toUTCString();document.cookie=`${NUDGE_COOKIE_PREFIX}-${e}=${t}; expires=${n}; path=/; SameSite=Lax`}function getNudgeCookie(e){const t=document.cookie.split(";").map(i=>i.trim()).find(i=>i.startsWith(`${NUDGE_COOKIE_PREFIX}-${e}=`));if(!t)return null;const n=t.split("=")[1];return n==="open"||n==="closed"?n:null}const WIDGET_STORE_KEY_PREFIX="med-assist-store-";function readPersistedSessToken(e){var t,n;try{const i=sessionStorage.getItem(`${WIDGET_STORE_KEY_PREFIX}${e}`),s=i?(n=(t=JSON.parse(i))===null||t===void 0?void 0:t.state)===null||n===void 0?void 0:n.sessToken:void 0;return typeof s=="string"&&s?s:void 0}catch{return}}async function fetchNudgeData(e,t,n){const i=`${t}/med-assist/user-nudge`,s=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(o=>{var r,d,a;const p=(r=o.getAttribute("name"))!==null&&r!==void 0?r:void 0,c=(d=o.getAttribute("property"))!==null&&d!==void 0?d:void 0,h=(a=o.getAttribute("content"))!==null&&a!==void 0?a:void 0;(p||c)&&s.push({name:p,property:c,content:h})});try{const o=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json","x-agent-id":e,referer:typeof window!="undefined"?window.location.href:"",...n&&{Authorization:`Bearer ${n}`}},body:JSON.stringify({meta_tags:s,url:typeof window!="undefined"?window.location.href:""})});return o.ok?await o.json():void 0}catch{return}}const globalMedAssistConfig={},getWidgetElement=()=>typeof document=="undefined"?null:document.querySelector("eka-medassist-widget");if(typeof window!="undefined"){const e=window;e.__ekaMedAssistConfig__=globalMedAssistConfig,e.EkaMedAssist={init(t){var n,i,s;Object.assign(globalMedAssistConfig,t);const o=getWidgetElement();if(o){if(t.agentId&&o.setAttribute("agent-id",t.agentId),t.authToken&&o.setAttribute("auth-token",t.authToken),t.title&&o.setAttribute("title",t.title),t.iconUrl&&o.setAttribute("icon-url",t.iconUrl),t.baseUrl&&o.setAttribute("base-url",t.baseUrl),t.resize!==void 0&&o.setAttribute("resize",String(t.resize)),(t.displayMode==="full"||t.displayMode==="widget")&&o.setAttribute("display-mode",t.displayMode),t.context)try{o.setAttribute("context",JSON.stringify(t.context))}catch{console.warn("Failed to stringify context passed to init")}typeof t.customLauncherStyles=="string"&&o.setAttribute("custom-launcher-styles",t.customLauncherStyles),t.redirectUrl&&o.setAttribute("redirect-url",t.redirectUrl),!((n=t.theme)===null||n===void 0)&&n.backgroundImage&&preloadImage(t.theme.backgroundImage),(s=(i=o).openFromBridge)===null||s===void 0||s.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 e=scriptEl.dataset.widgetAssets;if(e==="local")return`${scriptBaseUrl}src/`;if(e&&e.length>0)try{return new URL(e,scriptBaseUrl).href}catch{return e.endsWith("/")?e:`${e}/`}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(e=>{if(!e.ok)throw new Error(`Unable to fetch widget styles from ${WIDGET_CSS_URL}`);return e.text()})),widgetCssTextPromise}class MedAssistWidgetLoader extends HTMLElement{setLauncherState(t){var n;const i=(n=this.shadowRoot)===null||n===void 0?void 0:n.getElementById("medassist-open-btn");i&&(i.classList.toggle("loading",t==="loading"),i.classList.toggle("hidden",t==="open"),t==="loading"?i.setAttribute("aria-busy","true"):i.removeAttribute("aria-busy"))}getAgentConfig(){if(!this.agentConfigPromise){const t=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},n=t.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",i=t.agentId||this.getAttribute("agent-id")||"";if(!i)return Promise.resolve(void 0);this.agentConfigPromise=fetchAgentConfig(n,i).catch(()=>{})}return this.agentConfigPromise}constructor(){super(),this.reactRoot=null,this.agentConfigPromise=null,this.loading=!1,this.authPrefetchPromise=null,this.attachShadow({mode:"open"}),this.defaultIconUrl="https://cdn.eka.care/bot-icon.svg",this.widgetLoaded=!1,this.displayMode=this.getAttribute("display-mode")==="full"?"full":"widget",this.setupAuthExpirationListener()}static get observedAttributes(){return["icon-url","display-mode","custom-launcher-styles","redirect-url"]}connectedCallback(){this.displayMode==="full"?(this.initializeFullMode(),this.loadAndRender().catch(t=>{console.error("Failed to load MedAssist widget in full mode",t)})):(this.renderButton(),this.scheduleIdle(()=>{this.preloadWidgetAssets(),this.prefetchAuthTokens(),this.initNudge()}))}scheduleIdle(t){if(typeof window=="undefined"){t();return}const n=window.requestIdleCallback;typeof n=="function"?n(t,{timeout:3e3}):setTimeout(t,200)}attributeChangedCallback(t){if(t==="icon-url"&&this.displayMode==="widget"&&this.renderButton(),t==="display-mode"){const n=this.getAttribute("display-mode")==="full"?"full":"widget";n!==this.displayMode&&(this.displayMode=n,n==="full"?this.initializeFullMode():this.renderButton())}t==="custom-launcher-styles"&&this.applyCustomLauncherStyles()}preloadWidgetAssets(){getWidgetCssTextPromise(),this.loadWidgetModule(),this.preloadBackgroundImage()}prefetchAuthTokens(){var t;if(this.authPrefetchPromise)return this.authPrefetchPromise;const n=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},i=n.agentId||this.getAttribute("agent-id")||"";if(!i)return Promise.resolve(void 0);const s=n.authToken||this.getAttribute("auth-token")||void 0,o=n.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",r=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"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:s,serverUrl:o,environment:r})}).catch(()=>{this.authPrefetchPromise=null}),this.authPrefetchPromise}async resolveSessToken(t){const n=readPersistedSessToken(t);if(n)return n;const i=await this.prefetchAuthTokens();return(i==null?void 0:i.sess_token)||readPersistedSessToken(t)}preloadBackgroundImage(){var t;const n=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,i=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,s=(t=n==null?void 0:n.theme)===null||t===void 0?void 0:t.backgroundImage,o=i==null?void 0:i.backgroundImage;s&&preloadImage(s),o&&o!==s&&preloadImage(o),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 t=n=>{var i;((i=n.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",t)}openFromBridge(){this.displayMode=this.getAttribute("display-mode")==="full"?"full":"widget",this.displayMode==="full"?this.initializeFullMode():this.renderButton(),this.loadAndRender().catch(t=>{console.error("Failed to open MedAssist widget from bridge",t)})}async initNudge(){var t,n,i,s;const o=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,r=(o==null?void 0:o.agentId)||this.getAttribute("agent-id")||"";if(!r)return;const d=await this.getAgentConfig();if(!(d!=null&&d.nudge))return;const a=(n=(t=d==null?void 0:d.theme)===null||t===void 0?void 0:t.nudge_color)!==null&&n!==void 0?n:"#ffffff",p=typeof window!="undefined"?window.location.href:"";let c;try{c=new URL(p)}catch{return}const h=getNudgePathCandidates(c.pathname),w=h.slice(0,1),v=h.slice(1);let g=findFreshCachedNudge(r,c,w);if(!g){const y=(o==null?void 0:o.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",u=await this.resolveSessToken(r).catch(()=>{}),f=await fetchNudgeData(r,y,u).catch(()=>{});!((i=f==null?void 0:f.nudges)===null||i===void 0)&&i.length&&(storeNudgeResponse(r,f),g=findFreshCachedNudge(r,c,h))}if(g||(g=findFreshCachedNudge(r,c,v)),!g)return;const x=g.data.nudges[Math.floor(Math.random()*g.data.nudges.length)],b=(s=g.data.delay)!==null&&s!==void 0?s:5;setTimeout(()=>{this.showNudgePopup(x,a)},b*1e3)}showNudgePopup(t,n){var i,s;const o=this.shadowRoot;if(!o||!(!((i=o.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||o.getElementById("medassist-nudge-popup"))return;const p=o.getElementById("medassist-open-btn"),c=p==null?void 0:p.getBoundingClientRect(),h=272,w=12,v=8,g=16,x=16;let b=window.innerWidth-h-w,y=76,u=h-g-v*2;if(c&&c.width>0){const A=c.left+c.width/2,m=A-h/2,_=window.innerWidth-h-w;b=Math.max(w,Math.min(m,_)),y=window.innerHeight-c.top+x,u=Math.max(g,Math.min(A-b-v,h-g-v*2))}const f=document.createElement("div");f.id="medassist-nudge-popup",f.innerHTML=`
|
|
2
2
|
<style>
|
|
3
3
|
@keyframes nudge-slide-up {
|
|
4
4
|
from { opacity: 0; transform: translateY(12px) scale(0.97); }
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
}
|
|
7
7
|
#medassist-nudge-popup {
|
|
8
8
|
position: fixed;
|
|
9
|
-
bottom: ${
|
|
10
|
-
left: ${
|
|
11
|
-
width: ${
|
|
9
|
+
bottom: ${y}px;
|
|
10
|
+
left: ${b}px;
|
|
11
|
+
width: ${h}px;
|
|
12
12
|
background: ${n};
|
|
13
13
|
border-radius: 16px;
|
|
14
14
|
box-shadow: 0 8px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.08);
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
<p class="nudge-text">${t.replace(/</g,"<").replace(/>/g,">")}</p>
|
|
80
80
|
<button class="nudge-close" aria-label="Dismiss">✕</button>
|
|
81
81
|
</div>
|
|
82
|
-
`,(
|
|
82
|
+
`,(s=f.querySelector(".nudge-close"))===null||s===void 0||s.addEventListener("click",A=>{A.stopPropagation(),d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup()}),f.addEventListener("click",()=>{d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup(),this.loadAndRender()}),o.appendChild(f)}dismissNudgePopup(){var t;const n=(t=this.shadowRoot)===null||t===void 0?void 0:t.getElementById("medassist-nudge-popup");n==null||n.remove()}applyCustomLauncherStyles(){var t;const n=this.shadowRoot;if(!n||this.displayMode!=="widget")return;const i=n.querySelector('style[data-medassist-custom-launcher="true"]'),s=(t=this.getAttribute("custom-launcher-styles"))!==null&&t!==void 0?t:"";if(!s){i==null||i.remove();return}if(i){i.textContent=s;return}const o=document.createElement("style");o.setAttribute("data-medassist-custom-launcher","true"),o.textContent=s,n.appendChild(o)}renderButton(){var t;const n=this.getAttribute("icon-url")||this.defaultIconUrl,i=this.shadowRoot;if(!i){console.error("Shadow root was not created");return}if(!i.querySelector("button"))i.innerHTML=`
|
|
83
83
|
<style>
|
|
84
84
|
#medassist-open-btn {
|
|
85
85
|
width: 60px;
|
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
<span id="medassist-loader" aria-hidden="true"></span>
|
|
154
154
|
</button>
|
|
155
155
|
<div id="medassist-widget-root" class="hidden"></div>
|
|
156
|
-
`,(t=i.getElementById("medassist-open-btn"))===null||t===void 0||t.addEventListener("click",()=>{const
|
|
156
|
+
`,(t=i.getElementById("medassist-open-btn"))===null||t===void 0||t.addEventListener("click",()=>{const o=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";o&&setNudgeCookie(o,"closed"),this.dismissNudgePopup(),this.loadAndRender()});else{const s=i.querySelector("#medassist-open-btn img");s&&(s.src=n)}this.applyCustomLauncherStyles()}initializeFullMode(){const t=this.shadowRoot;if(!t){console.error("Shadow root is not available");return}t.getElementById("medassist-widget-root")||(t.innerHTML=`
|
|
157
157
|
<style>
|
|
158
158
|
:host {
|
|
159
159
|
display: block;
|
|
@@ -170,4 +170,4 @@
|
|
|
170
170
|
}
|
|
171
171
|
</style>
|
|
172
172
|
<div id="medassist-widget-root"></div>
|
|
173
|
-
`)}async loadAndRender(){var t,n;const i=this.shadowRoot;if(!i){console.error("Shadow root is not available");return}if(this.loading)return;this.prefetchAuthTokens(),this.style.display="";const
|
|
173
|
+
`)}async loadAndRender(){var t,n;const i=this.shadowRoot;if(!i){console.error("Shadow root is not available");return}if(this.loading)return;this.prefetchAuthTokens(),this.style.display="";const s=i.getElementById("medassist-widget-root"),o=this.getAttribute("agent-id");let r=this.getAttribute("icon-url")||this.defaultIconUrl;const d=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production",a=this.getAttribute("connectivity"),p=a==="http_stream"||a==="socket"?a:void 0,c=this.getAttribute("force-start")==="true";let h=this.getAttribute("title")||"Medi Clinic";const w=this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",g=this.getAttribute("display-mode")==="full"?"full":"widget",x=this.getAttribute("context")?JSON.parse(this.getAttribute("context")||"{}"):void 0,b=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,y=this.getAttribute("feedback")?(()=>{try{return JSON.parse(this.getAttribute("feedback")||"{}")}catch{return}})():void 0,u=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},f={...x||{},...u.context||{}},A=u.authToken||this.getAttribute("auth-token")||void 0,m=u.agentId||o,_=u.baseUrl||w,k=typeof window!="undefined"?(n=window.EkaMedAssist)===null||n===void 0?void 0:n.onClose:void 0,z=this.getAttribute("redirect-url")||void 0,C=u.redirectUrl||z,O=!!C||u.showCloseButton===!0;if(!m){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,P,U,N=!1,R,T=!1,S;const B=l=>{var M,E,I;h=l.name||h,r=((M=l.theme)===null||M===void 0?void 0:M.icon_img)||r,L=mapAgentConfigThemeToWidgetTheme(l.theme||void 0),P=l.allowed,U=l.connectivity,N=l.resize||(u==null?void 0:u.resize)||!1,R=l.initial_message,T=(I=(E=l.theme)===null||E===void 0?void 0:E.hide_watermark)!==null&&I!==void 0?I:!1,S=l.feedback},$=readAgentConfigCache(m);if($)B($),this.getAgentConfig().then(l=>{l&&writeAgentConfigCache(m,l)}).catch(()=>{});else try{const l=await this.getAgentConfig();l&&(writeAgentConfigCache(m,l),B(l))}catch{}const F=p||U||"socket",W={title:u.title||h,iconUrl:r||u.iconUrl,showCloseButton:O,allowed:P,environment:d,connectionType:F,onClose:()=>{var l;if((l=this.reactRoot)===null||l===void 0||l.unmount(),this.reactRoot=null,k&&typeof k=="function"&&k(),C){window.location.href=C;return}g==="full"?this.style.display="none":(this.setLauncherState("idle"),s.classList.add("hidden"))},baseUrl:_,context:f,displayMode:g,resize:N||this.getAttribute("resize")==="true",authToken:A,force:c,initialMessage:R,hideWatermark:T,...(y||S)&&{feedback:y||S},theme:{...L||{},...b||{},...u.theme||{}}},D=window;if(this.widgetLoaded){this.reactRoot=D.renderMedAssist(s,m,W),this.setLauncherState("open"),this.loading=!1;return}try{const[,l]=await Promise.all([this.loadWidgetCss(),this.loadWidgetModule()]);this.reactRoot=l.renderMedAssist(s,m,W),this.widgetLoaded=!0,this.setLauncherState("open")}catch(l){console.error("Failed to load MedAssist widget",l),this.setLauncherState("idle"),s.classList.add("hidden")}finally{this.loading=!1}}async loadWidgetCss(){const t=this.shadowRoot;if(!t)throw new Error("Shadow root is not available");if(t.querySelector("[data-medassist-style='true']"))return;const n=await getWidgetCssTextPromise(),i=document.createElement("style");i.setAttribute("data-medassist-style","true"),i.textContent=n,t.appendChild(i)}loadWidgetModule(){return widgetModulePromise||(widgetModulePromise=import(WIDGET_JS_URL)),widgetModulePromise}}customElements.define("eka-medassist-widget",MedAssistWidgetLoader);
|