@eusate/messenger-sdk 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MessengerUI.d.ts.map +1 -1
- package/dist/eusate-sdk.esm.js +1 -1
- package/dist/eusate-sdk.min.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessengerUI.d.ts","sourceRoot":"","sources":["../src/MessengerUI.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAOhB,MAAM,SAAS,CAAA;AAEhB,cAAM,eAAe;IACnB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA+B;IAEtD,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,UAAU,CAAmB;IACrC,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,GAAG,CAAmB;IAC9B,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,OAAO,CAAC,CAAY;IAC5B,OAAO,CAAC,OAAO,CAAC,CAAwB;IACxC,OAAO,CAAC,eAAe,CAAiB;IACxC,OAAO,CAAC,UAAU,CAAiB;IACnC,OAAO,CAAC,WAAW,CAAiB;IAEpC,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,cAAc,CAA6C;IACnE,OAAO,CAAC,WAAW,CAA8B;IAEjD,OAAO;IAeP,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,eAAe;IA2B7D,OAAO,CAAC,IAAI,CAmBX;IAED,OAAO,CAAC,cAAc,
|
|
1
|
+
{"version":3,"file":"MessengerUI.d.ts","sourceRoot":"","sources":["../src/MessengerUI.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAOhB,MAAM,SAAS,CAAA;AAEhB,cAAM,eAAe;IACnB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA+B;IAEtD,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,UAAU,CAAmB;IACrC,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,GAAG,CAAmB;IAC9B,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,OAAO,CAAC,CAAY;IAC5B,OAAO,CAAC,OAAO,CAAC,CAAwB;IACxC,OAAO,CAAC,eAAe,CAAiB;IACxC,OAAO,CAAC,UAAU,CAAiB;IACnC,OAAO,CAAC,WAAW,CAAiB;IAEpC,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,cAAc,CAA6C;IACnE,OAAO,CAAC,WAAW,CAA8B;IAEjD,OAAO;IAeP,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,eAAe;IA2B7D,OAAO,CAAC,IAAI,CAmBX;IAED,OAAO,CAAC,cAAc,CAYrB;IAED,OAAO,CAAC,cAAc,CAmBrB;IAED,OAAO,CAAC,iBAAiB,CAqBxB;IAED,OAAO,CAAC,eAAe,CAuEtB;IAED,OAAO,CAAC,oBAAoB,CAmB3B;IAED,OAAO,CAAC,iBAAiB,CAExB;IAED,OAAO,CAAC,oBAAoB,CAuB3B;IAED,OAAO,CAAC,WAAW,CAclB;IAED,OAAO,CAAC,WAAW,CASlB;IAED,OAAO,CAAC,OAAO,CAsEd;IAED,aAAa,gBAA6B;IAC1C,MAAM,gBAAwB;IAE9B,IAAI,QAAO,IAAI,CAuBd;IAED,KAAK,aAmBJ;IAED,MAAM,aAYL;IAED,OAAO,aAgDN;CACF;AAED,eAAe,eAAe,CAAA"}
|
package/dist/eusate-sdk.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t="https://cdn.jsdelivr.net/gh/eusate/eusate-messenger-sdk@latest/src/assets/icomoon/style.css",e="0.2.
|
|
1
|
+
const t="https://cdn.jsdelivr.net/gh/eusate/eusate-messenger-sdk@latest/src/assets/icomoon/style.css",e="0.2.2",i={local:"http://localhost:3000",development:"https://chat.dev.eusate.com",production:"https://chat.eusate.com"},n="EUSATE_INIT",a="EUSATE_READY",s="EUSATE_AUTH_ERROR",o="CLOSE_CHAT",r="OPEN_CHAT",h="EUSATE_DESTROY",d="[EUSATE SDK] API Key is required for initialization",c="[EUSATE SDK] Error:",l="[EUSATE SDK] Initialization timeout",m="[EUSATE SDK] Failed to load chat iframe",u="[EUSATE SDK] Not initialized yet. Call init() first.",f="[EUSATE SDK] Already destroyed",p="[Eusate SDK] Already initialized. Call destroy() first to reinitialize.";var b,w;!function(t){t.INIT="init",t.AUTH="auth"}(b||(b={})),function(t){t.PROD="production",t.DEV="development"}(w||(w={}));class y{constructor(e){this.chatInitialized=!1,this.isChatOpen=!1,this.isDestroyed=!1,this.fabClickHandler=null,this.messageHandler=null,this.initTimeout=null,this.init=()=>{try{this.setupContainer(),this.setupFabIframe(),this.setupChatIframe(),this.setupMessageHandlers(),document.body?document.body.appendChild(this.container):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(this.container)})}catch(t){this.handleError(new Error(`${c}, ${t.message}`))}},this.setupContainer=()=>{this.container.id="eusate-chat-widget-container",this.container.style.cssText="\n position: fixed;\n bottom: 0px;\n right: 0px;\n z-index: 10000;\n width: 0px;\n height: 0px;\n ",this.container.setAttribute("data-eusate-widget","true")},this.setupFabIframe=()=>{this.fabIframe.id="eusate-chat-widget-fab",this.fabIframe.style.cssText="\n position: relative;\n bottom: 100px;\n right: 100px;\n z-index: 1;\n height: 80px;\n width: 80px;\n border: none;\n background: transparent;\n ",this.fabIframe.setAttribute("title","Open chat support"),this.fabIframe.setAttribute("aria-label","Open chat support"),this.container.appendChild(this.fabIframe),this.fabIframe.onload=this.loadFabIframeHead},this.loadFabIframeHead=()=>{const e=this.fabIframe.contentDocument;if(!e)return void setTimeout(()=>this.loadFabIframeHead(),100);const i=e.head||e.createElement("head"),n=e.createElement("link");n.href=t,n.rel="stylesheet",i.appendChild(n),e.head||e.documentElement.appendChild(i)},this.setupChatIframe=()=>{this.chatIframe.id="eusate-chat-widget",this.chatIframe.src=this.chatUrl;let t=document.querySelector("#eusate-chat-widget");t||(t=document.createElement("style"),t.id="eusate-chat-widget",document.head.append(t)),t.textContent="\n #eusate-chat-widget-container #eusate-chat-widget {\n position: absolute;\n z-index: 1;\n bottom: 120px;\n right: 20px;\n width: 390px;\n max-width: calc(100dvw - 40px);\n max-height: calc(100dvh - 140px);\n outline: none;\n height: 576px;\n transform: scale(0);\n opacity: 0;\n transition-property: transform, translate, scale, rotate, opacity;\n transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n transition-duration: 500ms;\n border: none;\n transform-origin: bottom right;\n box-shadow: 0px 40px 72px -12px #10192824;\n transform: scale(0);\n opacity: 0;\n }\n #eusate-chat-widget-container #eusate-chat-widget.isOpen {\n transform: scale(1);\n opacity: 1;\n }\n @media only screen and (max-width: 640px) {\n #eusate-chat-widget-container #eusate-chat-widget {\n height: 100dvh;\n width: 100dvw;\n bottom: 0px;\n right:0px;\n max-height: 100dvh;\n max-width: 100dvw;\n }\n }\n @media only screen and (max-height: 500px) {\n #eusate-chat-widget-container #eusate-chat-widget {\n height: 100dvh;\n bottom: 0px;\n max-height: 100dvh;\n }\n }\n ",this.chatIframe.setAttribute("title","Eusate chat support"),this.chatIframe.setAttribute("aria-hidden","true"),this.chatIframe.setAttribute("sandbox","allow-scripts allow-forms allow-same-origin allow-popups"),this.chatIframe.onload=()=>this.handleChatIframeLoad(),this.chatIframe.onerror=()=>this.handleIframeError(),this.container.appendChild(this.chatIframe)},this.handleChatIframeLoad=()=>{setTimeout(()=>{var t;const e={type:n,data:{apiKey:this.apiKey},timestamp:Date.now()};null===(t=this.chatIframe.contentWindow)||void 0===t||t.postMessage(e,this.chatUrl)},1e3),this.initTimeout=setTimeout(()=>{this.isInitialized||this.handleError(new Error(l))},1e4)},this.handleIframeError=()=>{this.handleError(new Error(m))},this.setupMessageHandlers=()=>{this.messageHandler=t=>{if(t.origin===new URL(this.chatUrl).origin)switch(t.data.type){case a:this.handleReady();break;case s:this.chatInitialized=!1,this.handleError(new Error(t.data.message||"Authentication failed"));break;case o:this.close()}},window.addEventListener("message",this.messageHandler,!1)},this.handleReady=()=>{var t;this.chatInitialized=!0,this.initTimeout&&(clearTimeout(this.initTimeout),this.initTimeout=null),this.fab&&(this.fab.disabled=!1),null===(t=this.onReady)||void 0===t||t.call(this),this.loadFab()},this.handleError=t=>{var e;this.initTimeout&&(clearTimeout(this.initTimeout),this.initTimeout=null),this.destroy(),null===(e=this.onError)||void 0===e||e.call(this,t)},this.loadFab=()=>{const t=this.fabIframe.contentDocument;if(!t)return void setTimeout(()=>this.loadFab(),100);const e=t.body||t.createElement("body");e.style.cssText="\n margin: 0;\n padding: 0;\n display: flex;\n justify-content: center;\n align-items: center;\n width: 100%;\n height: 100%;\n overflow: hidden;\n border: none;\n outline: none;\n ",this.fab.id="eusate-messenger-fab-btn",this.fab.style.cssText="\n width: 80px;\n height: 80px;\n background-color: #0a0a0a;\n border-radius: 50%;\n cursor: pointer;\n color: white;\n display: flex;\n align-items: center;\n justify-content: center;\n transform: scale(0.95);\n transition: transform 0.2s ease;\n border: none;\n outline: none;\n ",this.fab.onmouseenter=()=>{this.fab.disabled||(this.fab.style.transform="scale(1)")},this.fab.onmouseleave=()=>{this.fab.disabled||(this.isChatOpen?this.fab.style.transform="scale(0.8)":this.fab.style.transform="scale(0.95)")},this.fab.onmousedown=()=>{this.fab.disabled||(this.fab.style.transform="scale(0.8)")},this.fabIcon.id="button-icon",this.fabIcon.className="icon-eusate",this.fabIcon.style.cssText="font-size: 36px;",this.fab.appendChild(this.fabIcon),e.appendChild(this.fab),t.body||t.documentElement.appendChild(e),this.fabClickHandler=()=>this.toggle(),this.fab.addEventListener("click",this.fabClickHandler,!1)},this.isInitialized=()=>this.chatInitialized,this.isOpen=()=>this.isChatOpen,this.open=()=>{var t;this.chatInitialized?this.isChatOpen||(this.isChatOpen=!0,this.chatIframe.classList.add("isOpen"),this.fabIcon.classList.add("icon-chevron-down"),this.fabIcon.classList.remove("icon-eusate"),this.fab.style.transform="scale(0.8)",null===(t=this.chatIframe.contentWindow)||void 0===t||t.postMessage({type:r,timestamp:Date.now()},this.chatUrl)):console.warn(u)},this.close=()=>{var t;this.isChatOpen&&(this.isChatOpen=!1,this.chatIframe.classList.remove("isOpen"),this.fabIcon.classList.add("icon-eusate"),this.fabIcon.classList.remove("icon-chevron-down"),this.fab.style.transform="scale(0.95)",null===(t=this.chatIframe.contentWindow)||void 0===t||t.postMessage({type:o,timestamp:Date.now()},this.chatUrl))},this.toggle=()=>{this.chatInitialized?this.isChatOpen?this.close():this.open():console.warn(u)},this.destroy=()=>{var t;this.isDestroyed?console.warn(f):(this.isChatOpen&&this.close(),this.initTimeout&&(clearTimeout(this.initTimeout),this.initTimeout=null),this.messageHandler&&(window.removeEventListener("message",this.messageHandler,!1),this.messageHandler=null),this.fab&&this.fabClickHandler&&(this.fab.removeEventListener("click",this.fabClickHandler,!1),this.fabClickHandler=null),this.chatIframe.contentWindow&&this.chatIframe.contentWindow.postMessage({type:h,timestamp:Date.now()},this.chatUrl),this.container.remove(),y.instance=null,this.isDestroyed=!0,null===(t=document.querySelector("#eusate-chat-widget"))||void 0===t||t.remove())},this.apiKey=null==e?void 0:e.apiKey.trim(),this.onReady=e.onReady,this.onError=e.onError,this.chatUrl=i[(null==e?void 0:e.environment)||w.PROD],this.container=document.createElement("div"),this.fabIframe=document.createElement("iframe"),this.chatIframe=document.createElement("iframe"),this.fabIcon=document.createElement("span"),this.fab=document.createElement("button"),this.init()}static getInstance(t){if("undefined"==typeof window)throw new Error("[Eusate] Cannot create instance on server-side");if(y.instance)return t&&console.warn(p),y.instance;if(!t)throw new Error(d);if(!t.apiKey||"string"!=typeof t.apiKey||""===t.apiKey.trim())throw new Error(d);return y.instance=new y(t),y.instance}}y.instance=null;const g={init:t=>{if("undefined"!=typeof window)try{const e="string"==typeof t?{apiKey:t}:t;y.getInstance(e)}catch(t){throw console.error(c,t),t}else console.warn("[Eusate] Cannot initialize on server-side. Will initialize when browser loads.")},open:()=>{if("undefined"!=typeof window)try{y.getInstance().open()}catch(t){console.error(c,t)}},close:()=>{if("undefined"!=typeof window)try{y.getInstance().close()}catch(t){console.error(c,t)}},destroy:()=>{if("undefined"!=typeof window)try{y.getInstance().destroy()}catch(t){console.error(c,t)}},isInitialized:()=>{if("undefined"==typeof window)return!1;try{return y.getInstance().isInitialized()}catch(t){return!1}},isOpen:()=>{if("undefined"==typeof window)return!1;try{return y.getInstance().isOpen()}catch(t){return!1}},version:e};"undefined"!=typeof window&&(window.Eusate=g);const I=w;export{I as EusateEnvironment,g as default};
|
package/dist/eusate-sdk.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
this.Eusate=function(){"use strict";const t="https://cdn.jsdelivr.net/gh/eusate/eusate-messenger-sdk@latest/src/assets/icomoon/style.css",e="0.2.1",i={local:"http://localhost:3000",development:"https://chat.dev.eusate.com",production:"https://chat.eusate.com"},n="EUSATE_INIT",s="EUSATE_READY",a="EUSATE_AUTH_ERROR",o="CLOSE_CHAT",r="OPEN_CHAT",h="EUSATE_DESTROY",c="[EUSATE SDK] API Key is required for initialization",d="[EUSATE SDK] Error:",l="[EUSATE SDK] Initialization timeout",m="[EUSATE SDK] Failed to load chat iframe",f="[EUSATE SDK] Not initialized yet. Call init() first.",u="[EUSATE SDK] Already destroyed",p="[Eusate SDK] Already initialized. Call destroy() first to reinitialize.";var b,y;!function(t){t.INIT="init",t.AUTH="auth"}(b||(b={})),function(t){t.PROD="production",t.DEV="development"}(y||(y={}));class w{constructor(e){this.chatInitialized=!1,this.isChatOpen=!1,this.isDestroyed=!1,this.fabClickHandler=null,this.messageHandler=null,this.initTimeout=null,this.init=()=>{try{this.setupContainer(),this.setupFabIframe(),this.setupChatIframe(),this.setupMessageHandlers(),document.body?document.body.appendChild(this.container):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(this.container)})}catch(t){this.handleError(new Error(`${d}, ${t.message}`))}},this.setupContainer=()=>{this.container.id="eusate-chat-widget-container",this.container.style.cssText="\n position: fixed;\n bottom: 0px;\n right: 0px;\n z-index: 10000;\n ",this.container.setAttribute("data-eusate-widget","true")},this.setupFabIframe=()=>{this.fabIframe.id="eusate-chat-widget-fab",this.fabIframe.style.cssText="\n position: relative;\n bottom: 20px;\n right: 20px;\n z-index: 1;\n height: 80px;\n width: 80px;\n border: none;\n background: transparent;\n ",this.fabIframe.setAttribute("title","Open chat support"),this.fabIframe.setAttribute("aria-label","Open chat support"),this.container.appendChild(this.fabIframe),this.fabIframe.onload=this.loadFabIframeHead},this.loadFabIframeHead=()=>{const e=this.fabIframe.contentDocument;if(!e)return void setTimeout(()=>this.loadFabIframeHead(),100);const i=e.head||e.createElement("head"),n=e.createElement("link");n.href=t,n.rel="stylesheet",i.appendChild(n),e.head||e.documentElement.appendChild(i)},this.setupChatIframe=()=>{this.chatIframe.id="eusate-chat-widget",this.chatIframe.src=this.chatUrl;const t=document.createElement("style");document.head.append(t),t.textContent="\n #eusate-chat-widget-container #eusate-chat-widget {\n position: absolute;\n z-index: 1;\n bottom: 120px;\n right: 20px;\n width: 390px;\n max-width: calc(100dvw - 40px);\n outline: none;\n height: 576px;\n transform: scale(0);\n opacity: 0;\n transition-property: transform, translate, scale, rotate, opacity;\n transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n transition-duration: 500ms;\n border: none;\n transform-origin: bottom right;\n box-shadow: 0px 40px 72px -12px #10192824;\n }\n @media only screen and (max-width: 640px) {\n #eusate-chat-widget-container #eusate-chat-widget {\n height: 100dvh;\n width: 100dvw;\n bottom: 0px;\n right:0px;\n max-width: 100dvw;\n }\n }\n ",this.chatIframe.setAttribute("title","Eusate chat support"),this.chatIframe.setAttribute("aria-hidden","true"),this.chatIframe.setAttribute("sandbox","allow-scripts allow-forms allow-same-origin allow-popups"),this.chatIframe.onload=()=>this.handleChatIframeLoad(),this.chatIframe.onerror=()=>this.handleIframeError(),this.container.appendChild(this.chatIframe)},this.handleChatIframeLoad=()=>{setTimeout(()=>{var t;const e={type:n,data:{apiKey:this.apiKey},timestamp:Date.now()};null===(t=this.chatIframe.contentWindow)||void 0===t||t.postMessage(e,this.chatUrl)},1e3),this.initTimeout=setTimeout(()=>{this.isInitialized||this.handleError(new Error(l))},1e4)},this.handleIframeError=()=>{this.handleError(new Error(m))},this.setupMessageHandlers=()=>{this.messageHandler=t=>{if(t.origin===new URL(this.chatUrl).origin)switch(t.data.type){case s:this.handleReady();break;case a:this.chatInitialized=!1,this.handleError(new Error(t.data.message||"Authentication failed"));break;case o:this.close()}},window.addEventListener("message",this.messageHandler,!1)},this.handleReady=()=>{var t;this.chatInitialized=!0,this.initTimeout&&(clearTimeout(this.initTimeout),this.initTimeout=null),this.fab&&(this.fab.disabled=!1),null===(t=this.onReady)||void 0===t||t.call(this),this.loadFab()},this.handleError=t=>{var e;this.initTimeout&&(clearTimeout(this.initTimeout),this.initTimeout=null),this.destroy(),null===(e=this.onError)||void 0===e||e.call(this,t)},this.loadFab=()=>{const t=this.fabIframe.contentDocument;if(!t)return void setTimeout(()=>this.loadFab(),100);const e=t.body||t.createElement("body");e.style.cssText="\n margin: 0;\n padding: 0;\n display: flex;\n justify-content: center;\n align-items: center;\n width: 100%;\n height: 100%;\n overflow: hidden;\n border: none;\n outline: none;\n ",this.fab.id="eusate-messenger-fab-btn",this.fab.style.cssText="\n width: 80px;\n height: 80px;\n background-color: #0a0a0a;\n border-radius: 50%;\n cursor: pointer;\n color: white;\n display: flex;\n align-items: center;\n justify-content: center;\n transform: scale(0.95);\n transition: transform 0.2s ease;\n border: none;\n outline: none;\n ",this.fab.onmouseenter=()=>{this.fab.disabled||(this.fab.style.transform="scale(1)")},this.fab.onmouseleave=()=>{this.fab.disabled||(this.isChatOpen?this.fab.style.transform="scale(0.8)":this.fab.style.transform="scale(0.95)")},this.fab.onmousedown=()=>{this.fab.disabled||(this.fab.style.transform="scale(0.8)")},this.fabIcon.id="button-icon",this.fabIcon.className="icon-eusate",this.fabIcon.style.cssText="font-size: 36px;",this.fab.appendChild(this.fabIcon),e.appendChild(this.fab),t.body||t.documentElement.appendChild(e),this.fabClickHandler=()=>this.toggle(),this.fab.addEventListener("click",this.fabClickHandler,!1)},this.isInitialized=()=>this.chatInitialized,this.isOpen=()=>this.isChatOpen,this.open=()=>{var t;this.chatInitialized?this.isChatOpen||(this.isChatOpen=!0,this.chatIframe.style.transform="scale(1)",this.chatIframe.style.opacity="1",this.fabIcon.classList.add("icon-chevron-down"),this.fabIcon.classList.remove("icon-eusate"),this.fab.style.transform="scale(0.8)",null===(t=this.chatIframe.contentWindow)||void 0===t||t.postMessage({type:r,timestamp:Date.now()},this.chatUrl)):console.warn(f)},this.close=()=>{var t;this.isChatOpen&&(this.isChatOpen=!1,this.chatIframe.style.transform="scale(0)",this.chatIframe.style.opacity="0",this.fabIcon.classList.add("icon-eusate"),this.fabIcon.classList.remove("icon-chevron-down"),this.fab.style.transform="scale(0.95)",null===(t=this.chatIframe.contentWindow)||void 0===t||t.postMessage({type:o,timestamp:Date.now()},this.chatUrl))},this.toggle=()=>{this.chatInitialized?"scale(1)"===this.chatIframe.style.transform?this.close():this.open():console.warn(f)},this.destroy=()=>{this.isDestroyed?console.warn(u):(this.isChatOpen&&this.close(),this.initTimeout&&(clearTimeout(this.initTimeout),this.initTimeout=null),this.messageHandler&&(window.removeEventListener("message",this.messageHandler,!1),this.messageHandler=null),this.fab&&this.fabClickHandler&&(this.fab.removeEventListener("click",this.fabClickHandler,!1),this.fabClickHandler=null),this.chatIframe.contentWindow&&this.chatIframe.contentWindow.postMessage({type:h,timestamp:Date.now()},this.chatUrl),this.container.remove(),w.instance=null,this.isDestroyed=!0,console.log("EusateMessenger instance destroyed successfully"))},this.apiKey=null==e?void 0:e.apiKey.trim(),this.onReady=e.onReady,this.onError=e.onError,this.chatUrl=i[(null==e?void 0:e.environment)||y.PROD],this.container=document.createElement("div"),this.fabIframe=document.createElement("iframe"),this.chatIframe=document.createElement("iframe"),this.fabIcon=document.createElement("span"),this.fab=document.createElement("button"),this.init()}static getInstance(t){if("undefined"==typeof window)throw new Error("[Eusate] Cannot create instance on server-side");if(w.instance)return t&&console.warn(p),w.instance;if(!t)throw new Error(c);if(!t.apiKey||"string"!=typeof t.apiKey||""===t.apiKey.trim())throw new Error(c);return w.instance=new w(t),w.instance}}w.instance=null;const I={init:t=>{if("undefined"!=typeof window)try{const e="string"==typeof t?{apiKey:t}:t;w.getInstance(e)}catch(t){throw console.error(d,t),t}else console.warn("[Eusate] Cannot initialize on server-side. Will initialize when browser loads.")},open:()=>{if("undefined"!=typeof window)try{w.getInstance().open()}catch(t){console.error(d,t)}},close:()=>{if("undefined"!=typeof window)try{w.getInstance().close()}catch(t){console.error(d,t)}},destroy:()=>{if("undefined"!=typeof window)try{w.getInstance().destroy()}catch(t){console.error(d,t)}},isInitialized:()=>{if("undefined"==typeof window)return!1;try{return w.getInstance().isInitialized()}catch(t){return!1}},isOpen:()=>{if("undefined"==typeof window)return!1;try{return w.getInstance().isOpen()}catch(t){return!1}},version:e};return"undefined"!=typeof window&&(window.Eusate=I),I}();
|
|
1
|
+
!function(t){"use strict";const e="https://cdn.jsdelivr.net/gh/eusate/eusate-messenger-sdk@latest/src/assets/icomoon/style.css",i="0.2.2",n={local:"http://localhost:3000",development:"https://chat.dev.eusate.com",production:"https://chat.eusate.com"},a="EUSATE_INIT",s="EUSATE_READY",o="EUSATE_AUTH_ERROR",r="CLOSE_CHAT",h="OPEN_CHAT",d="EUSATE_DESTROY",c="[EUSATE SDK] API Key is required for initialization",l="[EUSATE SDK] Error:",m="[EUSATE SDK] Initialization timeout",u="[EUSATE SDK] Failed to load chat iframe",f="[EUSATE SDK] Not initialized yet. Call init() first.",p="[EUSATE SDK] Already destroyed",b="[Eusate SDK] Already initialized. Call destroy() first to reinitialize.";var w,y;!function(t){t.INIT="init",t.AUTH="auth"}(w||(w={})),function(t){t.PROD="production",t.DEV="development"}(y||(y={}));class g{constructor(t){this.chatInitialized=!1,this.isChatOpen=!1,this.isDestroyed=!1,this.fabClickHandler=null,this.messageHandler=null,this.initTimeout=null,this.init=()=>{try{this.setupContainer(),this.setupFabIframe(),this.setupChatIframe(),this.setupMessageHandlers(),document.body?document.body.appendChild(this.container):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(this.container)})}catch(t){this.handleError(new Error(`${l}, ${t.message}`))}},this.setupContainer=()=>{this.container.id="eusate-chat-widget-container",this.container.style.cssText="\n position: fixed;\n bottom: 0px;\n right: 0px;\n z-index: 10000;\n width: 0px;\n height: 0px;\n ",this.container.setAttribute("data-eusate-widget","true")},this.setupFabIframe=()=>{this.fabIframe.id="eusate-chat-widget-fab",this.fabIframe.style.cssText="\n position: relative;\n bottom: 100px;\n right: 100px;\n z-index: 1;\n height: 80px;\n width: 80px;\n border: none;\n background: transparent;\n ",this.fabIframe.setAttribute("title","Open chat support"),this.fabIframe.setAttribute("aria-label","Open chat support"),this.container.appendChild(this.fabIframe),this.fabIframe.onload=this.loadFabIframeHead},this.loadFabIframeHead=()=>{const t=this.fabIframe.contentDocument;if(!t)return void setTimeout(()=>this.loadFabIframeHead(),100);const i=t.head||t.createElement("head"),n=t.createElement("link");n.href=e,n.rel="stylesheet",i.appendChild(n),t.head||t.documentElement.appendChild(i)},this.setupChatIframe=()=>{this.chatIframe.id="eusate-chat-widget",this.chatIframe.src=this.chatUrl;let t=document.querySelector("#eusate-chat-widget");t||(t=document.createElement("style"),t.id="eusate-chat-widget",document.head.append(t)),t.textContent="\n #eusate-chat-widget-container #eusate-chat-widget {\n position: absolute;\n z-index: 1;\n bottom: 120px;\n right: 20px;\n width: 390px;\n max-width: calc(100dvw - 40px);\n max-height: calc(100dvh - 140px);\n outline: none;\n height: 576px;\n transform: scale(0);\n opacity: 0;\n transition-property: transform, translate, scale, rotate, opacity;\n transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n transition-duration: 500ms;\n border: none;\n transform-origin: bottom right;\n box-shadow: 0px 40px 72px -12px #10192824;\n transform: scale(0);\n opacity: 0;\n }\n #eusate-chat-widget-container #eusate-chat-widget.isOpen {\n transform: scale(1);\n opacity: 1;\n }\n @media only screen and (max-width: 640px) {\n #eusate-chat-widget-container #eusate-chat-widget {\n height: 100dvh;\n width: 100dvw;\n bottom: 0px;\n right:0px;\n max-height: 100dvh;\n max-width: 100dvw;\n }\n }\n @media only screen and (max-height: 500px) {\n #eusate-chat-widget-container #eusate-chat-widget {\n height: 100dvh;\n bottom: 0px;\n max-height: 100dvh;\n }\n }\n ",this.chatIframe.setAttribute("title","Eusate chat support"),this.chatIframe.setAttribute("aria-hidden","true"),this.chatIframe.setAttribute("sandbox","allow-scripts allow-forms allow-same-origin allow-popups"),this.chatIframe.onload=()=>this.handleChatIframeLoad(),this.chatIframe.onerror=()=>this.handleIframeError(),this.container.appendChild(this.chatIframe)},this.handleChatIframeLoad=()=>{setTimeout(()=>{var t;const e={type:a,data:{apiKey:this.apiKey},timestamp:Date.now()};null===(t=this.chatIframe.contentWindow)||void 0===t||t.postMessage(e,this.chatUrl)},1e3),this.initTimeout=setTimeout(()=>{this.isInitialized||this.handleError(new Error(m))},1e4)},this.handleIframeError=()=>{this.handleError(new Error(u))},this.setupMessageHandlers=()=>{this.messageHandler=t=>{if(t.origin===new URL(this.chatUrl).origin)switch(t.data.type){case s:this.handleReady();break;case o:this.chatInitialized=!1,this.handleError(new Error(t.data.message||"Authentication failed"));break;case r:this.close()}},window.addEventListener("message",this.messageHandler,!1)},this.handleReady=()=>{var t;this.chatInitialized=!0,this.initTimeout&&(clearTimeout(this.initTimeout),this.initTimeout=null),this.fab&&(this.fab.disabled=!1),null===(t=this.onReady)||void 0===t||t.call(this),this.loadFab()},this.handleError=t=>{var e;this.initTimeout&&(clearTimeout(this.initTimeout),this.initTimeout=null),this.destroy(),null===(e=this.onError)||void 0===e||e.call(this,t)},this.loadFab=()=>{const t=this.fabIframe.contentDocument;if(!t)return void setTimeout(()=>this.loadFab(),100);const e=t.body||t.createElement("body");e.style.cssText="\n margin: 0;\n padding: 0;\n display: flex;\n justify-content: center;\n align-items: center;\n width: 100%;\n height: 100%;\n overflow: hidden;\n border: none;\n outline: none;\n ",this.fab.id="eusate-messenger-fab-btn",this.fab.style.cssText="\n width: 80px;\n height: 80px;\n background-color: #0a0a0a;\n border-radius: 50%;\n cursor: pointer;\n color: white;\n display: flex;\n align-items: center;\n justify-content: center;\n transform: scale(0.95);\n transition: transform 0.2s ease;\n border: none;\n outline: none;\n ",this.fab.onmouseenter=()=>{this.fab.disabled||(this.fab.style.transform="scale(1)")},this.fab.onmouseleave=()=>{this.fab.disabled||(this.isChatOpen?this.fab.style.transform="scale(0.8)":this.fab.style.transform="scale(0.95)")},this.fab.onmousedown=()=>{this.fab.disabled||(this.fab.style.transform="scale(0.8)")},this.fabIcon.id="button-icon",this.fabIcon.className="icon-eusate",this.fabIcon.style.cssText="font-size: 36px;",this.fab.appendChild(this.fabIcon),e.appendChild(this.fab),t.body||t.documentElement.appendChild(e),this.fabClickHandler=()=>this.toggle(),this.fab.addEventListener("click",this.fabClickHandler,!1)},this.isInitialized=()=>this.chatInitialized,this.isOpen=()=>this.isChatOpen,this.open=()=>{var t;this.chatInitialized?this.isChatOpen||(this.isChatOpen=!0,this.chatIframe.classList.add("isOpen"),this.fabIcon.classList.add("icon-chevron-down"),this.fabIcon.classList.remove("icon-eusate"),this.fab.style.transform="scale(0.8)",null===(t=this.chatIframe.contentWindow)||void 0===t||t.postMessage({type:h,timestamp:Date.now()},this.chatUrl)):console.warn(f)},this.close=()=>{var t;this.isChatOpen&&(this.isChatOpen=!1,this.chatIframe.classList.remove("isOpen"),this.fabIcon.classList.add("icon-eusate"),this.fabIcon.classList.remove("icon-chevron-down"),this.fab.style.transform="scale(0.95)",null===(t=this.chatIframe.contentWindow)||void 0===t||t.postMessage({type:r,timestamp:Date.now()},this.chatUrl))},this.toggle=()=>{this.chatInitialized?this.isChatOpen?this.close():this.open():console.warn(f)},this.destroy=()=>{var t;this.isDestroyed?console.warn(p):(this.isChatOpen&&this.close(),this.initTimeout&&(clearTimeout(this.initTimeout),this.initTimeout=null),this.messageHandler&&(window.removeEventListener("message",this.messageHandler,!1),this.messageHandler=null),this.fab&&this.fabClickHandler&&(this.fab.removeEventListener("click",this.fabClickHandler,!1),this.fabClickHandler=null),this.chatIframe.contentWindow&&this.chatIframe.contentWindow.postMessage({type:d,timestamp:Date.now()},this.chatUrl),this.container.remove(),g.instance=null,this.isDestroyed=!0,null===(t=document.querySelector("#eusate-chat-widget"))||void 0===t||t.remove())},this.apiKey=null==t?void 0:t.apiKey.trim(),this.onReady=t.onReady,this.onError=t.onError,this.chatUrl=n[(null==t?void 0:t.environment)||y.PROD],this.container=document.createElement("div"),this.fabIframe=document.createElement("iframe"),this.chatIframe=document.createElement("iframe"),this.fabIcon=document.createElement("span"),this.fab=document.createElement("button"),this.init()}static getInstance(t){if("undefined"==typeof window)throw new Error("[Eusate] Cannot create instance on server-side");if(g.instance)return t&&console.warn(b),g.instance;if(!t)throw new Error(c);if(!t.apiKey||"string"!=typeof t.apiKey||""===t.apiKey.trim())throw new Error(c);return g.instance=new g(t),g.instance}}g.instance=null;const E={init:t=>{if("undefined"!=typeof window)try{const e="string"==typeof t?{apiKey:t}:t;g.getInstance(e)}catch(t){throw console.error(l,t),t}else console.warn("[Eusate] Cannot initialize on server-side. Will initialize when browser loads.")},open:()=>{if("undefined"!=typeof window)try{g.getInstance().open()}catch(t){console.error(l,t)}},close:()=>{if("undefined"!=typeof window)try{g.getInstance().close()}catch(t){console.error(l,t)}},destroy:()=>{if("undefined"!=typeof window)try{g.getInstance().destroy()}catch(t){console.error(l,t)}},isInitialized:()=>{if("undefined"==typeof window)return!1;try{return g.getInstance().isInitialized()}catch(t){return!1}},isOpen:()=>{if("undefined"==typeof window)return!1;try{return g.getInstance().isOpen()}catch(t){return!1}},version:i};"undefined"!=typeof window&&(window.Eusate=E);const I=y;t.EusateEnvironment=I,t.default=E,Object.defineProperty(t,"__esModule",{value:!0})}(this.Eusate=this.Eusate||{});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { EusateMessengerSDK } from './utils';
|
|
1
|
+
import { Environment, EusateMessengerSDK } from './utils';
|
|
2
2
|
declare global {
|
|
3
3
|
interface Window {
|
|
4
4
|
Eusate: object;
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
declare const Eusate: EusateMessengerSDK;
|
|
8
|
+
export declare const EusateEnvironment: typeof Environment;
|
|
8
9
|
export default Eusate;
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EAEX,kBAAkB,EAGnB,MAAM,SAAS,CAAA;AAEhB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,EAAE,MAAM,CAAA;KACf;CACF;AAED,QAAA,MAAM,MAAM,EAAE,kBA2Db,CAAA;AAKD,eAAO,MAAM,iBAAiB,oBAAc,CAAA;AAC5C,eAAe,MAAM,CAAA"}
|