@eka-care/medassist-widget-embed 0.2.106-1 → 0.2.106-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 +6 -22
- package/dist/index.js +10 -18
- 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.128-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.128-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.128-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.128-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.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.
|
|
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.128-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
|
@@ -30,6 +30,8 @@ type AgentConfig = {
|
|
|
30
30
|
tagline?: string;
|
|
31
31
|
hide_watermark?: boolean;
|
|
32
32
|
explicit_disclaimer?: boolean;
|
|
33
|
+
/** When true, the widget asks for upfront consent once before the chat is usable. */
|
|
34
|
+
upfront_consent?: boolean;
|
|
33
35
|
/** Feature flag — currently gates the chat-history UI (session drawer + fullscreen sidebar). */
|
|
34
36
|
feature?: boolean;
|
|
35
37
|
};
|
|
@@ -64,13 +66,7 @@ type MedAssistInitConfig = {
|
|
|
64
66
|
iconUrl?: string;
|
|
65
67
|
baseUrl?: string;
|
|
66
68
|
resize?: boolean;
|
|
67
|
-
displayMode?: "full" | "widget"
|
|
68
|
-
/** Only relevant when displayMode is "side_panel". Whether the host page's own content is shifted aside ("push", default) or the panel floats on top of it ("overlay"). */
|
|
69
|
-
sidePanelMode?: "push" | "overlay";
|
|
70
|
-
/** Only relevant when displayMode is "side_panel". Fixed panel width in px (default 400, clamped 320-560). */
|
|
71
|
-
sidePanelWidth?: number;
|
|
72
|
-
/** Only relevant when displayMode is "side_panel". Which viewport edge the panel docks to. Defaults to "right", or "left" when the document is RTL. */
|
|
73
|
-
side?: "left" | "right";
|
|
69
|
+
displayMode?: "full" | "widget";
|
|
74
70
|
customLauncherStyles?: string;
|
|
75
71
|
redirectUrl?: string;
|
|
76
72
|
showCloseButton?: boolean;
|
|
@@ -83,6 +79,7 @@ type MedAssistInitConfig = {
|
|
|
83
79
|
titleImg?: string;
|
|
84
80
|
tagline?: string;
|
|
85
81
|
explicitDisclaimer?: boolean;
|
|
82
|
+
upfrontConsent?: boolean;
|
|
86
83
|
feature?: boolean;
|
|
87
84
|
};
|
|
88
85
|
[key: string]: unknown;
|
|
@@ -99,8 +96,6 @@ declare function preloadImage(url: string): void;
|
|
|
99
96
|
*/
|
|
100
97
|
type SynapseChannel = "widget" | "web" | "side_panel";
|
|
101
98
|
declare function channelFromDisplayMode(displayMode: string | null | undefined): SynapseChannel;
|
|
102
|
-
/** Normalizes the `display-mode` attribute value to one of the three supported modes. */
|
|
103
|
-
declare function normalizeDisplayMode(value: string | null | undefined): "full" | "widget" | "side_panel";
|
|
104
99
|
type NudgeApiResponse = {
|
|
105
100
|
url_pattern?: {
|
|
106
101
|
domain?: string;
|
|
@@ -161,7 +156,7 @@ declare function findCachedNudgeForCandidates(agentId: string, url: URL, candida
|
|
|
161
156
|
*/
|
|
162
157
|
declare function findFreshCachedNudge(agentId: string, url: URL, candidates: string[]): NudgeCacheHit | null;
|
|
163
158
|
declare function clearNudgeForPath(agentId: string, domain: string, path: string): void;
|
|
164
|
-
declare function storeNudgeResponse(agentId: string, response: NudgeApiResponse): void;
|
|
159
|
+
declare function storeNudgeResponse(agentId: string, response: NudgeApiResponse, visitedPath?: string): void;
|
|
165
160
|
declare const NUDGE_COOKIE_PREFIX = "eka-nudge";
|
|
166
161
|
declare function setNudgeCookie(agentId: string, value: "open" | "closed"): void;
|
|
167
162
|
declare function getNudgeCookie(agentId: string): "open" | "closed" | null;
|
|
@@ -169,7 +164,7 @@ declare function getNudgeCookie(agentId: string): "open" | "closed" | null;
|
|
|
169
164
|
declare const WIDGET_STORE_KEY_PREFIX = "med-assist-store-";
|
|
170
165
|
/** Sess (access) token persisted by the widget store, if the widget already ran in this tab. */
|
|
171
166
|
declare function readPersistedSessToken(agentId: string): string | undefined;
|
|
172
|
-
declare function fetchNudgeData(agentId: string,
|
|
167
|
+
declare function fetchNudgeData(agentId: string, sessToken: string, baseUrl?: string, channel?: SynapseChannel): Promise<NudgeApiResponse | undefined>;
|
|
173
168
|
type ReactRoot = {
|
|
174
169
|
unmount: () => void;
|
|
175
170
|
};
|
|
@@ -219,7 +214,6 @@ declare class MedAssistWidgetLoader extends HTMLElement {
|
|
|
219
214
|
private defaultIconUrl;
|
|
220
215
|
private widgetLoaded;
|
|
221
216
|
private displayMode;
|
|
222
|
-
private hostPushStyleEl;
|
|
223
217
|
private reactRoot;
|
|
224
218
|
private agentConfigPromise;
|
|
225
219
|
private loading;
|
|
@@ -248,16 +242,6 @@ declare class MedAssistWidgetLoader extends HTMLElement {
|
|
|
248
242
|
constructor();
|
|
249
243
|
static get observedAttributes(): string[];
|
|
250
244
|
connectedCallback(): void;
|
|
251
|
-
disconnectedCallback(): void;
|
|
252
|
-
/**
|
|
253
|
-
* Side-panel "push" mode: shifts the host page's own <body> aside via a
|
|
254
|
-
* margin injected into the host's real document.head (NOT the shadow root —
|
|
255
|
-
* this must be visible to the host page's own layout). Owns a single style
|
|
256
|
-
* element, toggled via a class on <body> so open/close is just a class flip
|
|
257
|
-
* once the CSS is in place. Fully removes both on revert so closing the
|
|
258
|
-
* widget leaves the host page pixel-identical to before it opened.
|
|
259
|
-
*/
|
|
260
|
-
private applyHostPush;
|
|
261
245
|
/** Run work when the browser is idle, falling back to a short timeout. */
|
|
262
246
|
private scheduleIdle;
|
|
263
247
|
attributeChangedCallback(name: string): void;
|
package/dist/index.js
CHANGED
|
@@ -1,12 +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 t=Array.from(document.getElementsByTagName("script")),e=t.find(o=>o.hasAttribute("data-widget-assets"));if(e)return e;const n=t.filter(o=>/(^|\/)index\.js(\?.*)?$/.test(o.src));return n.length?n[n.length-1]:t.length?t[t.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.127-4/dist/"})();var FeedbackTypeEnum;(function(i){i.DEFAULT="default",i.NPS="nps"})(FeedbackTypeEnum||(FeedbackTypeEnum={}));function mapAgentConfigThemeToWidgetTheme(i){if(!i)return;const t=i.mode==="dark"?"white":i.mode==="light"?"black":void 0;return{...i.background_img&&{backgroundImage:i.background_img},...i.accent&&{primary:i.accent},...t&&{textColor:t},...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.feature!==void 0&&{feature:i.feature}}}function preloadImage(i){if(!(!i||typeof document=="undefined"))try{const t=document.createElement("link");t.rel="preload",t.as="image",t.href=i,document.head.appendChild(t)}catch{const t=new Image;t.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 t=localStorage.getItem(AGENT_CONFIG_CACHE_KEY);return(t?JSON.parse(t):{})[i]}catch{return}}function writeAgentConfigCache(i,t){try{const e=localStorage.getItem(AGENT_CONFIG_CACHE_KEY),n=e?JSON.parse(e):{};n[i]={...n[i]||{},...t},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 t=i.replace(/\/+$/,"");return t.startsWith("/")||(t="/"+t),t||"/"}function getNudgePathCandidates(i){const t=i.split("/").filter(Boolean),e=[];for(let n=t.length;n>=0;n--)e.push(n===0?"/":"/"+t.slice(0,n).join("/"));return e}function findCachedNudgeForCandidates(i,t,e){const o=getNudgeStore()[i];if(!o)return null;const s=t.host,r=o[s];if(!r)return null;for(const d of e){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,t,e){const n=findCachedNudgeForCandidates(i,t,e);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,t,e){const n=getNudgeStore(),o=n[i];!o||!o[t]||(delete o[t][e],setNudgeStore(n))}function storeNudgeResponse(i,t){var e,n,o,s;const r=(e=t==null?void 0:t.url_pattern)===null||e===void 0?void 0:e.domain,d=(n=t==null?void 0:t.url_pattern)===null||n===void 0?void 0:n.path;if(!(!((o=t.nudges)===null||o===void 0)&&o.length)||!t.expiry||!r||!d)return;const a=getNudgeStore();a[i]||(a[i]={}),a[i][r]||(a[i][r]={}),a[i][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(i,t){const e=new Date(Date.now()+864e5).toUTCString();document.cookie=`${NUDGE_COOKIE_PREFIX}-${i}=${t}; expires=${e}; path=/; SameSite=Lax`}function getNudgeCookie(i){const t=document.cookie.split(";").map(n=>n.trim()).find(n=>n.startsWith(`${NUDGE_COOKIE_PREFIX}-${i}=`));if(!t)return null;const e=t.split("=")[1];return e==="open"||e==="closed"?e:null}const WIDGET_STORE_KEY_PREFIX="med-assist-store-";function readPersistedSessToken(i){var t,e;try{const n=sessionStorage.getItem(`${WIDGET_STORE_KEY_PREFIX}${i}`),o=n?(e=(t=JSON.parse(n))===null||t===void 0?void 0:t.state)===null||e===void 0?void 0:e.sessToken:void 0;return typeof o=="string"&&o?o:void 0}catch{return}}async function fetchNudgeData(i,t,e,n="widget"){const o=`${t}/med-assist/user-nudge`,s=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(r=>{var d,a,g;const c=(d=r.getAttribute("name"))!==null&&d!==void 0?d:void 0,h=(a=r.getAttribute("property"))!==null&&a!==void 0?a:void 0,p=(g=r.getAttribute("content"))!==null&&g!==void 0?g:void 0;(c||h)&&s.push({name:c,property:h,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:"",...e&&{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 globalMedAssistConfig={},getWidgetElement=()=>typeof document=="undefined"?null:document.querySelector("eka-medassist-widget");if(typeof window!="undefined"){const i=window;i.__ekaMedAssistConfig__=globalMedAssistConfig,i.EkaMedAssist={init(t){var e,n,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"||t.displayMode==="side_panel")&&s.setAttribute("display-mode",t.displayMode),t.sidePanelMode&&s.setAttribute("side-panel-mode",t.sidePanelMode),t.sidePanelWidth!==void 0&&s.setAttribute("side-panel-width",String(t.sidePanelWidth)),t.side&&s.setAttribute("side",t.side),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),!((e=t.theme)===null||e===void 0)&&e.backgroundImage&&preloadImage(t.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(t){var e;const n=(e=this.shadowRoot)===null||e===void 0?void 0:e.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 e=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0;return channelFromDisplayMode(e==null?void 0:e.displayMode)}getAgentConfig(){var t;if(!this.agentConfigPromise){const e=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},n=e.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",o=e.agentId||this.getAttribute("agent-id")||"";if(!o)return Promise.resolve(void 0);const s=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"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.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=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(t=>{console.error("Failed to load MedAssist widget in full mode",t)})):(this.renderButton(),this.scheduleIdle(()=>{this.preloadWidgetAssets(),this.prefetchAuthTokens(),this.initNudge()}))}disconnectedCallback(){var t,e,n;(t=this.reactRoot)===null||t===void 0||t.unmount(),this.reactRoot=null,(e=document.body)===null||e===void 0||e.classList.remove("eka-medassist-pushed"),(n=this.hostPushStyleEl)===null||n===void 0||n.remove(),this.hostPushStyleEl=null}applyHostPush(t,e,n){if(typeof document=="undefined")return;this.hostPushStyleEl||(this.hostPushStyleEl=document.createElement("style"),this.hostPushStyleEl.setAttribute("data-medassist-side-panel-push","true"),document.head.appendChild(this.hostPushStyleEl));const o=n==="left"?"margin-left":"margin-right";this.hostPushStyleEl.textContent=`
|
|
2
|
-
body.eka-medassist-pushed {
|
|
3
|
-
${o}: ${e}px;
|
|
4
|
-
transition: margin 300ms ease;
|
|
5
|
-
}
|
|
6
|
-
@media (prefers-reduced-motion: reduce) {
|
|
7
|
-
body.eka-medassist-pushed { transition: none !important; }
|
|
8
|
-
}
|
|
9
|
-
`,document.body.classList.toggle("eka-medassist-pushed",t),t||(document.body.classList.remove("eka-medassist-pushed"),this.hostPushStyleEl.remove(),this.hostPushStyleEl=null)}scheduleIdle(t){if(typeof window=="undefined"){t();return}const e=window.requestIdleCallback;typeof e=="function"?e(t,{timeout:3e3}):setTimeout(t,200)}attributeChangedCallback(t){if(t==="icon-url"&&this.displayMode!=="full"&&this.renderButton(),t==="display-mode"){const e=normalizeDisplayMode(this.getAttribute("display-mode"));e!==this.displayMode&&(this.displayMode=e,e==="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 e=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},n=e.agentId||this.getAttribute("agent-id")||"";if(!n)return Promise.resolve(void 0);const o=e.authToken||this.getAttribute("auth-token")||void 0,s=e.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:n,authToken:o,serverUrl:s,environment:r,channel:this.getChannel()})}).catch(()=>{this.authPrefetchPromise=null}),this.authPrefetchPromise}async resolveSessToken(t){const e=readPersistedSessToken(t);if(e)return e;const n=await this.prefetchAuthTokens();return(n==null?void 0:n.sess_token)||readPersistedSessToken(t)}preloadBackgroundImage(){var t;const e=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,n=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,o=(t=e==null?void 0:e.theme)===null||t===void 0?void 0:t.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 t=e=>{var n;((n=e.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=normalizeDisplayMode(this.getAttribute("display-mode")),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,e,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=(e=(t=d==null?void 0:d.theme)===null||t===void 0?void 0:t.nudge_color)!==null&&e!==void 0?e:"#ffffff",g=typeof window!="undefined"?window.location.href:"";let c;try{c=new URL(g)}catch{return}const h=getNudgePathCandidates(c.pathname),p=h.slice(0,1),m=h.slice(1);let f=findFreshCachedNudge(r,c,p);if(!f){const v=(s==null?void 0:s.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",y=await this.resolveSessToken(r).catch(()=>{}),l=await fetchNudgeData(r,v,y,this.getChannel()).catch(()=>{});!((n=l==null?void 0:l.nudges)===null||n===void 0)&&n.length&&(storeNudgeResponse(r,l),f=findFreshCachedNudge(r,c,h))}if(f||(f=findFreshCachedNudge(r,c,m)),!f)return;const w=f.data.nudges[Math.floor(Math.random()*f.data.nudges.length)],b=(o=f.data.delay)!==null&&o!==void 0?o:5;setTimeout(()=>{this.showNudgePopup(w,a)},b*1e3)}showNudgePopup(t,e){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 g=s.getElementById("medassist-open-btn"),c=g==null?void 0:g.getBoundingClientRect(),h=272,p=12,m=8,f=16,w=16;let b=window.innerWidth-h-p,v=76,y=h-f-m*2;if(c&&c.width>0){const A=c.left+c.width/2,S=A-h/2,C=window.innerWidth-h-p;b=Math.max(p,Math.min(S,C)),v=window.innerHeight-c.top+w,y=Math.max(f,Math.min(A-b-m,h-f-m*2))}const l=document.createElement("div");l.id="medassist-nudge-popup",l.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.128-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.upfront_consent&&{upfrontConsent:e.upfront_consent},...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 o=getNudgeStore()[e];if(!o)return null;const s=t.host,r=o[s];if(!r)return null;for(const d of i){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,i){const n=findCachedNudgeForCandidates(e,t,i);if(!n)return null;const o=Math.floor(Date.now()/1e3);return n.data.expiry<=o?(clearNudgeForPath(e,n.domain,n.path),null):n}function clearNudgeForPath(e,t,i){const n=getNudgeStore(),o=n[e];!o||!o[t]||(delete o[t][i],setNudgeStore(n))}function storeNudgeResponse(e,t,i){var n,o,s,r;const d=(n=t==null?void 0:t.url_pattern)===null||n===void 0?void 0:n.domain,a=(o=t==null?void 0:t.url_pattern)===null||o===void 0?void 0:o.path;if(!(!((s=t.nudges)===null||s===void 0)&&s.length)||!t.expiry||!d||!a)return;const c=getNudgeStore();c[e]||(c[e]={}),c[e][d]||(c[e][d]={});const u={nudges:t.nudges,expiry:t.expiry,delay:(r=t.delay)!==null&&r!==void 0?r:5};c[e][d][a]=u,i&&i!==a&&(c[e][d][i]=u),setNudgeStore(c)}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}`),o=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 o=="string"&&o?o:void 0}catch{return}}async function fetchNudgeData(e,t,i,n="widget"){const o=`${i}/med-assist/user-nudge`,s=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(r=>{var d,a,c;const u=(d=r.getAttribute("name"))!==null&&d!==void 0?d:void 0,f=(a=r.getAttribute("property"))!==null&&a!==void 0?a:void 0,m=(c=r.getAttribute("content"))!==null&&c!==void 0?c:void 0;(u||f)&&s.push({name:u,property:f,content:m})});try{const r=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","x-agent-id":e,"x-channel":n,referer:typeof window!="undefined"?window.location.href:"",Authorization:`Bearer ${t}`},body:JSON.stringify({meta_tags:s,url:typeof window!="undefined"?window.location.href:""})});return r.ok?await r.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,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),!((i=t.theme)===null||i===void 0)&&i.backgroundImage&&preloadImage(t.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 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",o=i.agentId||this.getAttribute("agent-id")||"";if(!o)return Promise.resolve(void 0);const s=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"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.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 o=i.authToken||this.getAttribute("auth-token")||void 0,s=i.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:n,authToken:o,serverUrl:s,environment:r,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,o=(t=i==null?void 0:i.theme)===null||t===void 0?void 0:t.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 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,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=(i=(t=d==null?void 0:d.theme)===null||t===void 0?void 0:t.nudge_color)!==null&&i!==void 0?i:"#ffffff",c=typeof window!="undefined"?window.location.href:"";let u;try{u=new URL(c)}catch{return}const f=getNudgePathCandidates(u.pathname),m=f.slice(0,1),v=f.slice(1);let g=findFreshCachedNudge(r,u,m);if(!g){const y=(s==null?void 0:s.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",h=await this.resolveSessToken(r).catch(()=>{});if(h){const p=await fetchNudgeData(r,h,y,this.getChannel()).catch(()=>{});!((n=p==null?void 0:p.nudges)===null||n===void 0)&&n.length&&(storeNudgeResponse(r,p,normalizePath(u.pathname)),g=findFreshCachedNudge(r,u,f))}}if(g||(g=findFreshCachedNudge(r,u,v)),!g)return;const _=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(_,a)},b*1e3)}showNudgePopup(t,i){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 c=s.getElementById("medassist-open-btn"),u=c==null?void 0:c.getBoundingClientRect(),f=272,m=12,v=8,g=16,_=16;let b=window.innerWidth-f-m,y=76,h=f-g-v*2;if(u&&u.width>0){const A=u.left+u.width/2,w=A-f/2,x=window.innerWidth-f-m;b=Math.max(m,Math.min(w,x)),y=window.innerHeight-u.top+_,h=Math.max(g,Math.min(A-b-v,f-g-v*2))}const p=document.createElement("div");p.id="medassist-nudge-popup",p.innerHTML=`
|
|
10
2
|
<style>
|
|
11
3
|
@keyframes nudge-slide-up {
|
|
12
4
|
from { opacity: 0; transform: translateY(12px) scale(0.97); }
|
|
@@ -14,10 +6,10 @@
|
|
|
14
6
|
}
|
|
15
7
|
#medassist-nudge-popup {
|
|
16
8
|
position: fixed;
|
|
17
|
-
bottom: ${
|
|
9
|
+
bottom: ${y}px;
|
|
18
10
|
left: ${b}px;
|
|
19
|
-
width: ${
|
|
20
|
-
background: ${
|
|
11
|
+
width: ${f}px;
|
|
12
|
+
background: ${i};
|
|
21
13
|
border-radius: 16px;
|
|
22
14
|
box-shadow: 0 8px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.08);
|
|
23
15
|
padding: 16px 16px 14px 16px;
|
|
@@ -34,10 +26,10 @@
|
|
|
34
26
|
content: '';
|
|
35
27
|
position: absolute;
|
|
36
28
|
bottom: -8px;
|
|
37
|
-
left: ${
|
|
29
|
+
left: ${h}px;
|
|
38
30
|
width: 16px;
|
|
39
31
|
height: 10px;
|
|
40
|
-
background: ${
|
|
32
|
+
background: ${i};
|
|
41
33
|
clip-path: polygon(0 0, 100% 0, 50% 100%);
|
|
42
34
|
}
|
|
43
35
|
#medassist-nudge-popup {
|
|
@@ -87,7 +79,7 @@
|
|
|
87
79
|
<p class="nudge-text">${t.replace(/</g,"<").replace(/>/g,">")}</p>
|
|
88
80
|
<button class="nudge-close" aria-label="Dismiss">✕</button>
|
|
89
81
|
</div>
|
|
90
|
-
`,(o=
|
|
82
|
+
`,(o=p.querySelector(".nudge-close"))===null||o===void 0||o.addEventListener("click",A=>{A.stopPropagation(),d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup()}),p.addEventListener("click",()=>{d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup(),this.loadAndRender()}),s.appendChild(p)}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"]'),o=(t=this.getAttribute("custom-launcher-styles"))!==null&&t!==void 0?t:"";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,i.appendChild(s)}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=`
|
|
91
83
|
<style>
|
|
92
84
|
#medassist-open-btn {
|
|
93
85
|
width: 60px;
|
|
@@ -157,11 +149,11 @@
|
|
|
157
149
|
</style>
|
|
158
150
|
|
|
159
151
|
<button id="medassist-open-btn">
|
|
160
|
-
<img src="${
|
|
152
|
+
<img src="${i}" alt="MedAssist Icon">
|
|
161
153
|
<span id="medassist-loader" aria-hidden="true"></span>
|
|
162
154
|
</button>
|
|
163
155
|
<div id="medassist-widget-root" class="hidden"></div>
|
|
164
|
-
`,(t=n.getElementById("medassist-open-btn"))===null||t===void 0||t.addEventListener("click",()=>{const s=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";s&&setNudgeCookie(s,"closed"),this.dismissNudgePopup(),this.loadAndRender()});else{const o=n.querySelector("#medassist-open-btn img");o&&(o.src=
|
|
156
|
+
`,(t=n.getElementById("medassist-open-btn"))===null||t===void 0||t.addEventListener("click",()=>{const s=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";s&&setNudgeCookie(s,"closed"),this.dismissNudgePopup(),this.loadAndRender()});else{const o=n.querySelector("#medassist-open-btn img");o&&(o.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=`
|
|
165
157
|
<style>
|
|
166
158
|
:host {
|
|
167
159
|
display: block;
|
|
@@ -178,4 +170,4 @@
|
|
|
178
170
|
}
|
|
179
171
|
</style>
|
|
180
172
|
<div id="medassist-widget-root"></div>
|
|
181
|
-
`)}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 o=n.getElementById("medassist-widget-root"),s=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"),c=a==="http_stream"||a==="socket"?a:void 0,u=this.getAttribute("force-start")==="true";let f=this.getAttribute("title")||"Medi Clinic";const m=this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",g=this.getAttribute("display-mode")==="full"?"full":"widget",_=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,h=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},p={..._||{},...h.context||{}},A=h.authToken||this.getAttribute("auth-token")||void 0,w=h.agentId||s,x=h.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=h.redirectUrl||z,F=!!C||h.showCloseButton===!0;if(!w){console.error("Agent ID is required");return}if(!o){console.error("Widget root element is missing");return}this.loading=!0,this.setLauncherState("loading"),o.classList.remove("hidden");let L,U,P,N=!1,R,T=!1,S;const B=l=>{var M,E,I;f=l.name||f,r=((M=l.theme)===null||M===void 0?void 0:M.icon_img)||r,L=mapAgentConfigThemeToWidgetTheme(l.theme||void 0),U=l.allowed,P=l.connectivity,N=l.resize||(h==null?void 0:h.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=c||P||"socket",$={title:h.title||f,iconUrl:r||h.iconUrl,showCloseButton:F,allowed:U,environment:d,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"),o.classList.add("hidden"))},baseUrl:x,context:p,displayMode:g,resize:N||this.getAttribute("resize")==="true",authToken:A,force:u,initialMessage:R,hideWatermark:T,...(y||S)&&{feedback:y||S},theme:{...L||{},...b||{},...h.theme||{}}},D=window;if(this.widgetLoaded){this.reactRoot=D.renderMedAssist(o,w,$),this.setLauncherState("open"),this.loading=!1;return}try{const[,l]=await Promise.all([this.loadWidgetCss(),this.loadWidgetModule()]);this.reactRoot=l.renderMedAssist(o,w,$),this.widgetLoaded=!0,this.setLauncherState("open")}catch(l){console.error("Failed to load MedAssist widget",l),this.setLauncherState("idle"),o.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);
|