@eka-care/medassist-widget-embed 0.2.100 → 0.2.101-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.
- package/dist/eka-agents.html +4 -4
- package/dist/iframe.js +1 -1
- package/dist/index.d.ts +31 -3
- package/dist/index.js +9 -9
- 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.
|
|
21
|
+
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.123-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.
|
|
30
|
+
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.123-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.
|
|
37
|
+
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.123-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.
|
|
152
|
+
src="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.123-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
|
|
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.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.123-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 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",E=i.get("connectivity"),N=E==="http_stream"||E==="socket"?E:void 0,_=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 T={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:{},..._!=null?_:{}}};window.renderMedAssist(q,P,T)}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)}})();
|
package/dist/index.d.ts
CHANGED
|
@@ -85,8 +85,14 @@ type MedAssistInitConfig = {
|
|
|
85
85
|
declare function mapAgentConfigThemeToWidgetTheme(apiTheme: AgentConfig["theme"] | undefined): MedAssistInitConfig["theme"];
|
|
86
86
|
/** Preload an image by URL so it is cached and loads faster when the widget uses it. */
|
|
87
87
|
declare function preloadImage(url: string): void;
|
|
88
|
-
/**
|
|
89
|
-
|
|
88
|
+
/**
|
|
89
|
+
* How the widget is presented → the `x-channel` value sent on every API call:
|
|
90
|
+
* floating window → "widget", fullscreen → "web", docked panel → "side_panel".
|
|
91
|
+
* Mirrors `channelFromDisplayMode` in the widget package (the loader is built
|
|
92
|
+
* without a bundler, so it cannot import from @synapse/core).
|
|
93
|
+
*/
|
|
94
|
+
type SynapseChannel = "widget" | "web" | "side_panel";
|
|
95
|
+
declare function channelFromDisplayMode(displayMode: string | null | undefined): SynapseChannel;
|
|
90
96
|
type NudgeApiResponse = {
|
|
91
97
|
url_pattern?: {
|
|
92
98
|
domain?: string;
|
|
@@ -155,7 +161,7 @@ declare function getNudgeCookie(agentId: string): "open" | "closed" | null;
|
|
|
155
161
|
declare const WIDGET_STORE_KEY_PREFIX = "med-assist-store-";
|
|
156
162
|
/** Sess (access) token persisted by the widget store, if the widget already ran in this tab. */
|
|
157
163
|
declare function readPersistedSessToken(agentId: string): string | undefined;
|
|
158
|
-
declare function fetchNudgeData(agentId: string, baseUrl?: string, sessToken?: string): Promise<NudgeApiResponse | undefined>;
|
|
164
|
+
declare function fetchNudgeData(agentId: string, baseUrl?: string, sessToken?: string, channel?: SynapseChannel): Promise<NudgeApiResponse | undefined>;
|
|
159
165
|
type ReactRoot = {
|
|
160
166
|
unmount: () => void;
|
|
161
167
|
};
|
|
@@ -187,7 +193,15 @@ type WidgetModule = {
|
|
|
187
193
|
authToken?: string;
|
|
188
194
|
serverUrl?: string;
|
|
189
195
|
environment?: WidgetEnvironment;
|
|
196
|
+
channel?: SynapseChannel;
|
|
190
197
|
}) => Promise<PrefetchAuthResult>;
|
|
198
|
+
/** Agent-config fetch owned by the SDK (URL, headers and envelope live in @synapse/core). */
|
|
199
|
+
fetchAgentConfig?: (config: {
|
|
200
|
+
agentId: string;
|
|
201
|
+
serverUrl?: string;
|
|
202
|
+
environment?: WidgetEnvironment;
|
|
203
|
+
channel?: SynapseChannel;
|
|
204
|
+
}) => Promise<AgentConfig | undefined>;
|
|
191
205
|
};
|
|
192
206
|
declare let widgetModulePromise: Promise<WidgetModule> | null;
|
|
193
207
|
declare let widgetCssTextPromise: Promise<string> | null;
|
|
@@ -207,6 +221,20 @@ declare class MedAssistWidgetLoader extends HTMLElement {
|
|
|
207
221
|
* - "open" → hidden (widget is mounted)
|
|
208
222
|
*/
|
|
209
223
|
private setLauncherState;
|
|
224
|
+
/**
|
|
225
|
+
* `x-channel` for every request this loader makes, from how the widget is set
|
|
226
|
+
* to open. The attribute wins; `init({ displayMode })` covers calls made
|
|
227
|
+
* during idle pre-warm, before init() has stamped the attribute on.
|
|
228
|
+
*/
|
|
229
|
+
private getChannel;
|
|
230
|
+
/**
|
|
231
|
+
* Agent-config, fetched by the SDK — the endpoint path, headers and response
|
|
232
|
+
* envelope all live in @synapse/core, so nothing about the API is duplicated
|
|
233
|
+
* here. The loader is built without a bundler and cannot import core, so it
|
|
234
|
+
* reaches the SDK through the widget module it already loads; that module's
|
|
235
|
+
* download is started at idle pre-warm (and again at the top of
|
|
236
|
+
* loadAndRender), so it is normally in flight or cached by the time this runs.
|
|
237
|
+
*/
|
|
210
238
|
private getAgentConfig;
|
|
211
239
|
constructor();
|
|
212
240
|
static get observedAttributes(): string[];
|
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.122/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},...e.feature!==void 0&&{feature:e.feature}}}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 f=findFreshCachedNudge(r,c,w);if(!f){const y=(o==null?void 0:o.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",u=await this.resolveSessToken(r).catch(()=>{}),g=await fetchNudgeData(r,y,u).catch(()=>{});!((i=g==null?void 0:g.nudges)===null||i===void 0)&&i.length&&(storeNudgeResponse(r,g),f=findFreshCachedNudge(r,c,h))}if(f||(f=findFreshCachedNudge(r,c,v)),!f)return;const x=f.data.nudges[Math.floor(Math.random()*f.data.nudges.length)],b=(s=f.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,f=16,x=16;let b=window.innerWidth-h-w,y=76,u=h-f-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(f,Math.min(A-b-v,h-f-v*2))}const g=document.createElement("div");g.id="medassist-nudge-popup",g.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.123-dev.0/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},...e.feature!==void 0&&{feature:e.feature}}}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}}function channelFromDisplayMode(e){return e==="full"?"web":e==="side-panel"?"side_panel":"widget"}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 i=localStorage.getItem(AGENT_CONFIG_CACHE_KEY),n=i?JSON.parse(i):{};n[e]={...n[e]||{},...t},localStorage.setItem(AGENT_CONFIG_CACHE_KEY,JSON.stringify(n))}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),i=[];for(let n=t.length;n>=0;n--)i.push(n===0?"/":"/"+t.slice(0,n).join("/"));return i}function findCachedNudgeForCandidates(e,t,i){const s=getNudgeStore()[e];if(!s)return null;const o=t.host,d=s[o];if(!d)return null;for(const r of i){if(d[r]!==void 0)return{domain:o,path:r,data:d[r]};const a=r==="/"?"/*":r+"/*";if(d[a]!==void 0)return{domain:o,path:a,data:d[a]}}return null}function findFreshCachedNudge(e,t,i){const n=findCachedNudgeForCandidates(e,t,i);if(!n)return null;const s=Math.floor(Date.now()/1e3);return n.data.expiry<=s?(clearNudgeForPath(e,n.domain,n.path),null):n}function clearNudgeForPath(e,t,i){const n=getNudgeStore(),s=n[e];!s||!s[t]||(delete s[t][i],setNudgeStore(n))}function storeNudgeResponse(e,t){var i,n,s,o;const d=(i=t==null?void 0:t.url_pattern)===null||i===void 0?void 0:i.domain,r=(n=t==null?void 0:t.url_pattern)===null||n===void 0?void 0:n.path;if(!(!((s=t.nudges)===null||s===void 0)&&s.length)||!t.expiry||!d||!r)return;const a=getNudgeStore();a[e]||(a[e]={}),a[e][d]||(a[e][d]={}),a[e][d][r]={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 i=new Date(Date.now()+864e5).toUTCString();document.cookie=`${NUDGE_COOKIE_PREFIX}-${e}=${t}; expires=${i}; path=/; SameSite=Lax`}function getNudgeCookie(e){const t=document.cookie.split(";").map(n=>n.trim()).find(n=>n.startsWith(`${NUDGE_COOKIE_PREFIX}-${e}=`));if(!t)return null;const i=t.split("=")[1];return i==="open"||i==="closed"?i:null}const WIDGET_STORE_KEY_PREFIX="med-assist-store-";function readPersistedSessToken(e){var t,i;try{const n=sessionStorage.getItem(`${WIDGET_STORE_KEY_PREFIX}${e}`),s=n?(i=(t=JSON.parse(n))===null||t===void 0?void 0:t.state)===null||i===void 0?void 0:i.sessToken:void 0;return typeof s=="string"&&s?s:void 0}catch{return}}async function fetchNudgeData(e,t,i,n="widget"){const s=`${t}/med-assist/user-nudge`,o=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(d=>{var r,a,p;const h=(r=d.getAttribute("name"))!==null&&r!==void 0?r:void 0,u=(a=d.getAttribute("property"))!==null&&a!==void 0?a:void 0,m=(p=d.getAttribute("content"))!==null&&p!==void 0?p:void 0;(h||u)&&o.push({name:h,property:u,content:m})});try{const d=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","x-agent-id":e,"x-channel":n,referer:typeof window!="undefined"?window.location.href:"",...i&&{Authorization:`Bearer ${i}`}},body:JSON.stringify({meta_tags:o,url:typeof window!="undefined"?window.location.href:""})});return d.ok?await d.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 i,n,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),!((i=t.theme)===null||i===void 0)&&i.backgroundImage&&preloadImage(t.theme.backgroundImage),(s=(n=o).openFromBridge)===null||s===void 0||s.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 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 i;const n=(i=this.shadowRoot)===null||i===void 0?void 0:i.getElementById("medassist-open-btn");n&&(n.classList.toggle("loading",t==="loading"),n.classList.toggle("hidden",t==="open"),t==="loading"?n.setAttribute("aria-busy","true"):n.removeAttribute("aria-busy"))}getChannel(){const t=this.getAttribute("display-mode");if(t)return channelFromDisplayMode(t);const i=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0;return channelFromDisplayMode(i==null?void 0:i.displayMode)}getAgentConfig(){var t;if(!this.agentConfigPromise){const i=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},n=i.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",s=i.agentId||this.getAttribute("agent-id")||"";if(!s)return Promise.resolve(void 0);const o=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production";this.agentConfigPromise=this.loadWidgetModule().then(d=>{var r;return(r=d.fetchAgentConfig)===null||r===void 0?void 0:r.call(d,{agentId:s,serverUrl:n,environment:o,channel:this.getChannel()})}).catch(()=>{this.agentConfigPromise=null})}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 i=window.requestIdleCallback;typeof i=="function"?i(t,{timeout:3e3}):setTimeout(t,200)}attributeChangedCallback(t){if(t==="icon-url"&&this.displayMode==="widget"&&this.renderButton(),t==="display-mode"){const i=this.getAttribute("display-mode")==="full"?"full":"widget";i!==this.displayMode&&(this.displayMode=i,i==="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 i=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},n=i.agentId||this.getAttribute("agent-id")||"";if(!n)return Promise.resolve(void 0);const s=i.authToken||this.getAttribute("auth-token")||void 0,o=i.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",d=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production";return this.authPrefetchPromise=this.loadWidgetModule().then(r=>{var a;return(a=r.prefetchAuth)===null||a===void 0?void 0:a.call(r,{agentId:n,authToken:s,serverUrl:o,environment:d,channel:this.getChannel()})}).catch(()=>{this.authPrefetchPromise=null}),this.authPrefetchPromise}async resolveSessToken(t){const i=readPersistedSessToken(t);if(i)return i;const n=await this.prefetchAuthTokens();return(n==null?void 0:n.sess_token)||readPersistedSessToken(t)}preloadBackgroundImage(){var t;const i=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,n=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,s=(t=i==null?void 0:i.theme)===null||t===void 0?void 0:t.backgroundImage,o=n==null?void 0:n.backgroundImage;s&&preloadImage(s),o&&o!==s&&preloadImage(o),this.getAgentConfig().then(d=>{var r;const a=(r=d==null?void 0:d.theme)===null||r===void 0?void 0:r.background_img;a&&preloadImage(a)}).catch(()=>{})}setupAuthExpirationListener(){if(typeof window=="undefined")return;const t=i=>{var n;((n=i.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",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,i,n,s;const o=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,d=(o==null?void 0:o.agentId)||this.getAttribute("agent-id")||"";if(!d)return;const r=await this.getAgentConfig();if(!(r!=null&&r.nudge))return;const a=(i=(t=r==null?void 0:r.theme)===null||t===void 0?void 0:t.nudge_color)!==null&&i!==void 0?i:"#ffffff",p=typeof window!="undefined"?window.location.href:"";let h;try{h=new URL(p)}catch{return}const u=getNudgePathCandidates(h.pathname),m=u.slice(0,1),v=u.slice(1);let g=findFreshCachedNudge(d,h,m);if(!g){const y=(o==null?void 0:o.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",c=await this.resolveSessToken(d).catch(()=>{}),f=await fetchNudgeData(d,y,c,this.getChannel()).catch(()=>{});!((n=f==null?void 0:f.nudges)===null||n===void 0)&&n.length&&(storeNudgeResponse(d,f),g=findFreshCachedNudge(d,h,u))}if(g||(g=findFreshCachedNudge(d,h,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,i){var n,s;const o=this.shadowRoot;if(!o||!(!((n=o.getElementById("medassist-widget-root"))===null||n===void 0)&&n.classList.contains("hidden")))return;const r=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";if(r&&getNudgeCookie(r)!==null||o.getElementById("medassist-nudge-popup"))return;const p=o.getElementById("medassist-open-btn"),h=p==null?void 0:p.getBoundingClientRect(),u=272,m=12,v=8,g=16,x=16;let b=window.innerWidth-u-m,y=76,c=u-g-v*2;if(h&&h.width>0){const A=h.left+h.width/2,w=A-u/2,_=window.innerWidth-u-m;b=Math.max(m,Math.min(w,_)),y=window.innerHeight-h.top+x,c=Math.max(g,Math.min(A-b-v,u-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); }
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
position: fixed;
|
|
9
9
|
bottom: ${y}px;
|
|
10
10
|
left: ${b}px;
|
|
11
|
-
width: ${
|
|
12
|
-
background: ${
|
|
11
|
+
width: ${u}px;
|
|
12
|
+
background: ${i};
|
|
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);
|
|
15
15
|
padding: 16px 16px 14px 16px;
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
content: '';
|
|
27
27
|
position: absolute;
|
|
28
28
|
bottom: -8px;
|
|
29
|
-
left: ${
|
|
29
|
+
left: ${c}px;
|
|
30
30
|
width: 16px;
|
|
31
31
|
height: 10px;
|
|
32
|
-
background: ${
|
|
32
|
+
background: ${i};
|
|
33
33
|
clip-path: polygon(0 0, 100% 0, 50% 100%);
|
|
34
34
|
}
|
|
35
35
|
#medassist-nudge-popup {
|
|
@@ -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
|
-
`,(s=
|
|
82
|
+
`,(s=f.querySelector(".nudge-close"))===null||s===void 0||s.addEventListener("click",A=>{A.stopPropagation(),r&&setNudgeCookie(r,"closed"),this.dismissNudgePopup()}),f.addEventListener("click",()=>{r&&setNudgeCookie(r,"closed"),this.dismissNudgePopup(),this.loadAndRender()}),o.appendChild(f)}dismissNudgePopup(){var t;const i=(t=this.shadowRoot)===null||t===void 0?void 0:t.getElementById("medassist-nudge-popup");i==null||i.remove()}applyCustomLauncherStyles(){var t;const i=this.shadowRoot;if(!i||this.displayMode!=="widget")return;const n=i.querySelector('style[data-medassist-custom-launcher="true"]'),s=(t=this.getAttribute("custom-launcher-styles"))!==null&&t!==void 0?t:"";if(!s){n==null||n.remove();return}if(n){n.textContent=s;return}const o=document.createElement("style");o.setAttribute("data-medassist-custom-launcher","true"),o.textContent=s,i.appendChild(o)}renderButton(){var t;const i=this.getAttribute("icon-url")||this.defaultIconUrl,n=this.shadowRoot;if(!n){console.error("Shadow root was not created");return}if(!n.querySelector("button"))n.innerHTML=`
|
|
83
83
|
<style>
|
|
84
84
|
#medassist-open-btn {
|
|
85
85
|
width: 60px;
|
|
@@ -149,11 +149,11 @@
|
|
|
149
149
|
</style>
|
|
150
150
|
|
|
151
151
|
<button id="medassist-open-btn">
|
|
152
|
-
<img src="${
|
|
152
|
+
<img src="${i}" alt="MedAssist Icon">
|
|
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=
|
|
156
|
+
`,(t=n.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=n.querySelector("#medassist-open-btn img");s&&(s.src=i)}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,
|
|
173
|
+
`)}async loadAndRender(){var t,i;const n=this.shadowRoot;if(!n){console.error("Shadow root is not available");return}if(this.loading)return;this.prefetchAuthTokens(),this.style.display="";const s=n.getElementById("medassist-widget-root"),o=this.getAttribute("agent-id");let d=this.getAttribute("icon-url")||this.defaultIconUrl;const r=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production",a=this.getAttribute("connectivity"),p=a==="http_stream"||a==="socket"?a:void 0,h=this.getAttribute("force-start")==="true";let u=this.getAttribute("title")||"Medi Clinic";const m=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,c=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},f={...x||{},...c.context||{}},A=c.authToken||this.getAttribute("auth-token")||void 0,w=c.agentId||o,_=c.baseUrl||m,k=typeof window!="undefined"?(i=window.EkaMedAssist)===null||i===void 0?void 0:i.onClose:void 0,z=this.getAttribute("redirect-url")||void 0,C=c.redirectUrl||z,F=!!C||c.showCloseButton===!0;if(!w){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;u=l.name||u,d=((M=l.theme)===null||M===void 0?void 0:M.icon_img)||d,L=mapAgentConfigThemeToWidgetTheme(l.theme||void 0),P=l.allowed,U=l.connectivity,N=l.resize||(c==null?void 0:c.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},W=readAgentConfigCache(w);if(W)B(W),this.getAgentConfig().then(l=>{l&&writeAgentConfigCache(w,l)}).catch(()=>{});else try{const l=await this.getAgentConfig();l&&(writeAgentConfigCache(w,l),B(l))}catch{}const O=p||U||"socket",$={title:c.title||u,iconUrl:d||c.iconUrl,showCloseButton:F,allowed:P,environment:r,connectionType:O,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:h,initialMessage:R,hideWatermark:T,...(y||S)&&{feedback:y||S},theme:{...L||{},...b||{},...c.theme||{}}},D=window;if(this.widgetLoaded){this.reactRoot=D.renderMedAssist(s,w,$),this.setLauncherState("open"),this.loading=!1;return}try{const[,l]=await Promise.all([this.loadWidgetCss(),this.loadWidgetModule()]);this.reactRoot=l.renderMedAssist(s,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 i=await getWidgetCssTextPromise(),n=document.createElement("style");n.setAttribute("data-medassist-style","true"),n.textContent=i,t.appendChild(n)}loadWidgetModule(){return widgetModulePromise||(widgetModulePromise=import(WIDGET_JS_URL)),widgetModulePromise}}customElements.define("eka-medassist-widget",MedAssistWidgetLoader);
|