@eka-care/medassist-widget-embed 0.2.27 → 0.2.28
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/iframe.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/iframe.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(function(){const M=()=>{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},P=e=>{if(e==="production"||e==="development"||e==="staging")return e};function O(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.title_img&&{titleImg:e.title_img}}}function E(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 x(e,t){const o=`${e.replace(/\/$/,"")}/med-assist/agent-config/${t}`,n=new AbortController,i=setTimeout(()=>n.abort(),1e4);try{const c=await fetch(o,{signal:n.signal,headers:{"ngrok-skip-browser-warning":"69420"}});if(!c.ok)return;const s=await c.json();return s!=null&&s.success&&(s!=null&&s.data)?s.data:void 0}catch{return}finally{clearTimeout(i)}}const k="https://unpkg.com/@eka-care/medassist-widget@latest/dist/",a=M(),_=(()=>{if(!a)return"";try{return new URL(".",a.src||window.location.href).href}catch{return""}})(),m=(()=>{if(!a)return k;const e=a.dataset.widgetAssets;if(e==="local")return`${_}src/`;if(e&&e.length>0)try{return new URL(e,_).href}catch{return e.endsWith("/")?e:`${e}/`}return k})(),l=`${m}medassist-widget.js`,g=`${m}medassist-widget.css`;let f=null,p=null;const d=new URLSearchParams(typeof window!="undefined"?window.location.search:""),C=d.get("agentId"),w=d.get("baseUrl")||"https://matrix.eka.care/reloaded";if(typeof document!="undefined"&&document.head){try{const e=new URL(m).origin,t=new URL(w).origin,o=document.createElement("link");if(o.rel="preconnect",o.href=e,o.crossOrigin="anonymous",document.head.appendChild(o),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="preload",n.as="script",n.href=l,document.head.appendChild(n);const i=document.createElement("link");i.rel="preload",i.as="style",i.href=g,document.head.appendChild(i)}catch{}A(),I()}const S=C&&w?x(w,C):Promise.resolve(void 0);if(typeof document!="undefined"&&document.head){const e=d.get("theme");if(e)try{const t=JSON.parse(e);t.backgroundImage&&E(t.backgroundImage)}catch{}S.then(t=>{var o;const n=(o=t==null?void 0:t.theme)===null||o===void 0?void 0:o.background_img;n&&E(n)})}const b=async()=>{var e,t,o,n,i;const c=d.get("agentId");if(!c){console.error("Agent ID is required in URL parameters");return}let s=d.get("title")||"Medi Clinic",h=d.get("iconUrl")||void 0;const U=d.get("context"),$=d.get("baseUrl")||"https://matrix.eka.care/reloaded",F=(e=P(d.get("environment")))!==null&&e!==void 0?e:"production",y=d.get("
|
|
1
|
+
"use strict";(function(){const M=()=>{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},P=e=>{if(e==="production"||e==="development"||e==="staging")return e};function O(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.title_img&&{titleImg:e.title_img}}}function E(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 x(e,t){const o=`${e.replace(/\/$/,"")}/med-assist/agent-config/${t}`,n=new AbortController,i=setTimeout(()=>n.abort(),1e4);try{const c=await fetch(o,{signal:n.signal,headers:{"ngrok-skip-browser-warning":"69420"}});if(!c.ok)return;const s=await c.json();return s!=null&&s.success&&(s!=null&&s.data)?s.data:void 0}catch{return}finally{clearTimeout(i)}}const k="https://unpkg.com/@eka-care/medassist-widget@latest/dist/",a=M(),_=(()=>{if(!a)return"";try{return new URL(".",a.src||window.location.href).href}catch{return""}})(),m=(()=>{if(!a)return k;const e=a.dataset.widgetAssets;if(e==="local")return`${_}src/`;if(e&&e.length>0)try{return new URL(e,_).href}catch{return e.endsWith("/")?e:`${e}/`}return k})(),l=`${m}medassist-widget.js`,g=`${m}medassist-widget.css`;let f=null,p=null;const d=new URLSearchParams(typeof window!="undefined"?window.location.search:""),C=d.get("agentId"),w=d.get("baseUrl")||"https://matrix.eka.care/reloaded";if(typeof document!="undefined"&&document.head){try{const e=new URL(m).origin,t=new URL(w).origin,o=document.createElement("link");if(o.rel="preconnect",o.href=e,o.crossOrigin="anonymous",document.head.appendChild(o),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="preload",n.as="script",n.href=l,document.head.appendChild(n);const i=document.createElement("link");i.rel="preload",i.as="style",i.href=g,document.head.appendChild(i)}catch{}A(),I()}const S=C&&w?x(w,C):Promise.resolve(void 0);if(typeof document!="undefined"&&document.head){const e=d.get("theme");if(e)try{const t=JSON.parse(e);t.backgroundImage&&E(t.backgroundImage)}catch{}S.then(t=>{var o;const n=(o=t==null?void 0:t.theme)===null||o===void 0?void 0:o.background_img;n&&E(n)})}const b=async()=>{var e,t,o,n,i;const c=d.get("agentId");if(!c){console.error("Agent ID is required in URL parameters");return}let s=d.get("title")||"Medi Clinic",h=d.get("iconUrl")||void 0;const U=d.get("context"),$=d.get("baseUrl")||"https://matrix.eka.care/reloaded",F=(e=P(d.get("environment")))!==null&&e!==void 0?e:"production",y=d.get("connectivity"),R=y==="sse"||y==="socket"?y:void 0,v=d.get("theme")?(()=>{try{return JSON.parse(d.get("theme")||"{}")}catch{return}})():void 0,W=document.getElementById("root")||document.body;try{const[,,r]=await Promise.all([A(),I(),S]);if(!(window!=null&&window.renderMedAssist)||typeof(window==null?void 0:window.renderMedAssist)!="function")throw new Error("renderMedAssist is not available on window");let u,L,T;r&&(s=(t=r==null?void 0:r.name)!==null&&t!==void 0?t:s,h=(n=(o=r==null?void 0:r.theme)===null||o===void 0?void 0:o.icon_img)!==null&&n!==void 0?n:h,u=O((i=r==null?void 0:r.theme)!==null&&i!==void 0?i:void 0),L=r==null?void 0:r.allowed,T=r==null?void 0:r.connectivity);const B={title:s,iconUrl:h,environment:F,connectionType:T||R||"socket",onClose:()=>{window.parent!==window&&window.parent.postMessage({type:"WIDGET_CLOSE"},"*")},context:U?JSON.parse(U):void 0,baseUrl:$,displayMode:"full",allowed:L,showCloseButton:!1,theme:{...u!=null?u:{},...v!=null?v:{}}};window.renderMedAssist(W,c,B)}catch(r){throw console.error("Failed to initialize MedAssist widget",r),r}};async function A(){document.querySelector("link[data-medassist-style='true']")||(p||(p=new Promise((t,o)=>{const n=document.createElement("link");n.rel="stylesheet",n.href=g,n.setAttribute("data-medassist-style","true"),n.onload=()=>{t("")},n.onerror=()=>{o(new Error(`Failed to load ${g}`))},document.head.appendChild(n)})),await p)}function I(){return f||(f=new Promise((e,t)=>{const o=document.querySelector(`script[src="${l}"]`);if(o){if(o.dataset.loaded==="true"){e();return}o.addEventListener("load",()=>e()),o.addEventListener("error",i=>t(i.error||new Error("Unknown script loading error")));return}const n=document.createElement("script");n.src=l,n.async=!0,n.dataset.widget="medassist",n.onload=()=>{n.dataset.loaded="true",e()},n.onerror=i=>{if(i instanceof ErrorEvent&&i.error){t(i.error);return}t(new Error(`Failed to load ${l}`))},document.head.appendChild(n)})),f}if(typeof document!="undefined")if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",b);else try{b()}catch(e){console.error("Failed to initialize MedAssist widget",e)}})();
|
package/dist/index.js
CHANGED
|
@@ -136,4 +136,4 @@
|
|
|
136
136
|
}
|
|
137
137
|
</style>
|
|
138
138
|
<div id="medassist-widget-root"></div>
|
|
139
|
-
`)}async loadAndRender(){var t,o,i;const n=this.shadowRoot;if(!n){console.error("Shadow root is not available");return}this.style.display="";const d=n.getElementById("medassist-open-btn"),s=n.getElementById("medassist-widget-root"),r=this.getAttribute("agent-id");let u=this.getAttribute("icon-url")||this.defaultIconUrl;const a=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production",l=this.getAttribute("
|
|
139
|
+
`)}async loadAndRender(){var t,o,i;const n=this.shadowRoot;if(!n){console.error("Shadow root is not available");return}this.style.display="";const d=n.getElementById("medassist-open-btn"),s=n.getElementById("medassist-widget-root"),r=this.getAttribute("agent-id");let u=this.getAttribute("icon-url")||this.defaultIconUrl;const a=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production",l=this.getAttribute("connectivity"),m=l==="sse"||l==="socket"?l:void 0;let h=this.getAttribute("title")||"Medi Clinic";const g=this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",f=this.getAttribute("display-mode")==="full"?"full":"widget",C=this.getAttribute("context")?JSON.parse(this.getAttribute("context")||"{}"):void 0,E=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,p=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},S={...C||{},...p.context||{}},M=p.auth||void 0,w=p.agentId||r,I=p.baseUrl||g,b=typeof window!="undefined"?(o=window.EkaMedAssist)===null||o===void 0?void 0:o.onClose:void 0;if(!w){console.error("Agent ID is required");return}if(!s){console.error("Widget root element is missing");return}d&&d.classList.add("hidden"),s.classList.remove("hidden");let x,A,_;try{const c=await this.getAgentConfig();h=(c==null?void 0:c.name)||h,u=((i=c==null?void 0:c.theme)===null||i===void 0?void 0:i.icon_img)||u,x=mapAgentConfigThemeToWidgetTheme((c==null?void 0:c.theme)||void 0),A=c==null?void 0:c.allowed,_=c==null?void 0:c.connectivity}catch{}const U=_||m||"socket",k={title:p.title||h,iconUrl:p.iconUrl||u,allowed:A,environment:a,connectionType:U,onClose:()=>{var c;(c=this.reactRoot)===null||c===void 0||c.unmount(),this.reactRoot=null,b&&typeof b=="function"&&b(),f==="full"?this.style.display="none":(d&&d.classList.remove("hidden"),s.classList.add("hidden"))},baseUrl:I,context:S,displayMode:f,auth:M,theme:{...x||{},...E||{},...p.theme||{}}},v=window;if(this.widgetLoaded){this.reactRoot=v.renderMedAssist(s,w,k);return}try{if(await Promise.all([this.loadWidgetCss(),this.loadWidgetScript()]),typeof v.renderMedAssist!="function")throw new Error("renderMedAssist is not available on window");this.reactRoot=v.renderMedAssist(s,w,k),this.widgetLoaded=!0}catch(c){console.error("Failed to load MedAssist widget",c),d&&d.classList.remove("hidden"),s.classList.add("hidden")}}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 o=await getWidgetCssTextPromise(),i=document.createElement("style");i.setAttribute("data-medassist-style","true"),i.textContent=o,t.appendChild(i)}loadWidgetScript(){return widgetScriptPromise||(widgetScriptPromise=new Promise((t,o)=>{const i=document.querySelector(`script[src="${WIDGET_JS_URL}"]`);if(i){if(i.dataset.loaded==="true"){t();return}i.addEventListener("load",()=>t()),i.addEventListener("error",d=>o(d.error||new Error("Unknown script loading error")));return}const n=document.createElement("script");n.src=WIDGET_JS_URL,n.async=!0,n.dataset.widget="medassist",n.onload=()=>{n.dataset.loaded="true",t()},n.onerror=d=>{if(d instanceof ErrorEvent&&d.error){o(d.error);return}o(new Error(`Failed to load ${WIDGET_JS_URL}`))},document.head.appendChild(n)})),widgetScriptPromise}}customElements.define("eka-medassist-widget",MedAssistWidgetLoader);
|