@eusate/messenger-sdk 0.1.0 → 0.1.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/README.md +12 -2
- package/dist/eusate-sdk.esm.js +1 -1
- package/dist/eusate-sdk.min.js +1 -1
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/helpers.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,11 +16,11 @@ Eusate Messenger SDK lets you add intelligent customer support to your website i
|
|
|
16
16
|
- 🎯 **Framework Agnostic** - Works with Next.js, React, Vue, Angular, and plain HTML
|
|
17
17
|
- 🔒 **Secure** - API key authentication with strict origin validation
|
|
18
18
|
- 📱 **Responsive** - Mobile-first design that works everywhere
|
|
19
|
-
- 🎨 **Customizable** - Match your brand with custom styling (coming soon)
|
|
20
19
|
- ⚡ **SSR Safe** - Full Next.js App Router support out of the box
|
|
21
20
|
- 🔧 **TypeScript** - Complete type definitions included
|
|
22
21
|
- 🌐 **CDN Ready** - Use via npm or direct script tag
|
|
23
22
|
- ♿ **Accessible** - WCAG compliant with keyboard navigation
|
|
23
|
+
- 🎨 **Customizable** - Match your brand with custom styling (coming soon)
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
@@ -40,8 +40,18 @@ yarn add @eusate/messenger-sdk
|
|
|
40
40
|
|
|
41
41
|
### Via CDN
|
|
42
42
|
|
|
43
|
+
#### Auto-updating (Recommended)
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<!-- Automatically gets bug fixes and new features within v0.x.x -->
|
|
47
|
+
<script src="https://cdn.eusate.com/messenger/v0/eusate-sdk.min.js"></script>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Pinned Version (Maximum Stability)
|
|
51
|
+
|
|
43
52
|
```html
|
|
44
|
-
|
|
53
|
+
<!-- Never changes - you control when to update -->
|
|
54
|
+
<script src="https://cdn.eusate.com/messenger/v0.1.0/eusate-sdk.min.js"></script>
|
|
45
55
|
```
|
|
46
56
|
|
|
47
57
|
---
|
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="https://chat.
|
|
1
|
+
const t="https://cdn.jsdelivr.net/gh/eusate/eusate-messenger-sdk@latest/src/assets/icomoon/style.css",e="https://chat.eusate.com",i="0.1.2",n="EUSATE_INIT",s="EUSATE_READY",a="EUSATE_AUTH_ERROR",o="CLOSE_CHAT",r="OPEN_CHAT",h="EUSATE_DESTROY",l="[EUSATE SDK] API Key is required for initialization",d="[EUSATE SDK] Error:",c="[EUSATE SDK] Initialization timeout",f="[EUSATE SDK] Failed to load chat iframe",m="[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;!function(t){t.INIT="init",t.AUTH="auth"}(b||(b={}));class y{constructor(i){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)}),this.loadFabButton()}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: 20px;\n right: 20px;\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 z-index: 1;\n height: 80px;\n width: 80px;\n border: none;\n background: transparent;\n box-shadow: 0px 40px 72px -12px #10192824;\n ",this.fabIframe.setAttribute("title","Open chat support"),this.fabIframe.setAttribute("aria-label","Open chat support"),this.container.appendChild(this.fabIframe)},this.setupChatIframe=()=>{this.chatIframe.id="eusate-chat-widget",this.chatIframe.src=e,this.chatIframe.style.cssText="\n position: absolute;\n bottom: 100px;\n right: 0px;\n width: 390px;\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 ",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 i={type:n,data:{apiKey:this.apiKey},timestamp:Date.now()};null===(t=this.chatIframe.contentWindow)||void 0===t||t.postMessage(i,e)},1e3),this.initTimeout=setTimeout(()=>{this.isInitialized||this.handleError(new Error(c))},1e4)},this.handleIframeError=()=>{this.handleError(new Error(f))},this.setupMessageHandlers=()=>{this.messageHandler=t=>{if(t.origin===new URL(e).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.handleError=t=>{var e;console.error(t.message),this.initTimeout&&(clearTimeout(this.initTimeout),this.initTimeout=null),this.destroy(),null===(e=this.onError)||void 0===e||e.call(this,t)},this.loadFabButton=()=>{const e=this.fabIframe.contentDocument;if(!e)return void setTimeout(()=>this.loadFabButton(),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);const s=e.body||e.createElement("body");s.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.disabled=!0,this.fab.onmouseenter=()=>{this.fab.disabled||(this.fab.style.transform="scale(1)")},this.fab.onmouseleave=()=>{this.fab.disabled||(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="\n font-size: 36px;\n ",this.fab.appendChild(this.fabIcon),s.appendChild(this.fab),e.body||e.documentElement.appendChild(s),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()},e)):console.warn(m)},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()},e))},this.toggle=()=>{this.chatInitialized?"scale(1)"===this.chatIframe.style.transform?this.close():this.open():console.warn(m)},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()},e),this.container.remove(),y.instance=null,this.isDestroyed=!0,console.log("EusateMessenger instance destroyed successfully"))},this.apiKey=null==i?void 0:i.apiKey.trim(),this.onReady=i.onReady,this.onError=i.onError,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(l);if(!t.apiKey||"string"!=typeof t.apiKey||""===t.apiKey.trim())throw new Error(l);return y.instance=new y(t),y.instance}}y.instance=null;const w={init:t=>{if("undefined"!=typeof window)try{const e="string"==typeof t?{apiKey:t}:t;y.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{y.getInstance().open()}catch(t){console.error(d,t)}},close:()=>{if("undefined"!=typeof window)try{y.getInstance().close()}catch(t){console.error(d,t)}},destroy:()=>{if("undefined"!=typeof window)try{y.getInstance().destroy()}catch(t){console.error(d,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:i};"undefined"!=typeof window&&(console.log("window",window),window.Eusate=w);export{w 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="https://chat.
|
|
1
|
+
this.Eusate=function(){"use strict";const t="https://cdn.jsdelivr.net/gh/eusate/eusate-messenger-sdk@latest/src/assets/icomoon/style.css",e="https://chat.eusate.com",i="0.1.2",n="EUSATE_INIT",s="EUSATE_READY",a="EUSATE_AUTH_ERROR",o="CLOSE_CHAT",r="OPEN_CHAT",h="EUSATE_DESTROY",l="[EUSATE SDK] API Key is required for initialization",c="[EUSATE SDK] Error:",d="[EUSATE SDK] Initialization timeout",f="[EUSATE SDK] Failed to load chat iframe",m="[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;!function(t){t.INIT="init",t.AUTH="auth"}(b||(b={}));class y{constructor(i){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)}),this.loadFabButton()}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: 20px;\n right: 20px;\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 z-index: 1;\n height: 80px;\n width: 80px;\n border: none;\n background: transparent;\n box-shadow: 0px 40px 72px -12px #10192824;\n ",this.fabIframe.setAttribute("title","Open chat support"),this.fabIframe.setAttribute("aria-label","Open chat support"),this.container.appendChild(this.fabIframe)},this.setupChatIframe=()=>{this.chatIframe.id="eusate-chat-widget",this.chatIframe.src=e,this.chatIframe.style.cssText="\n position: absolute;\n bottom: 100px;\n right: 0px;\n width: 390px;\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 ",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 i={type:n,data:{apiKey:this.apiKey},timestamp:Date.now()};null===(t=this.chatIframe.contentWindow)||void 0===t||t.postMessage(i,e)},1e3),this.initTimeout=setTimeout(()=>{this.isInitialized||this.handleError(new Error(d))},1e4)},this.handleIframeError=()=>{this.handleError(new Error(f))},this.setupMessageHandlers=()=>{this.messageHandler=t=>{if(t.origin===new URL(e).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.handleError=t=>{var e;console.error(t.message),this.initTimeout&&(clearTimeout(this.initTimeout),this.initTimeout=null),this.destroy(),null===(e=this.onError)||void 0===e||e.call(this,t)},this.loadFabButton=()=>{const e=this.fabIframe.contentDocument;if(!e)return void setTimeout(()=>this.loadFabButton(),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);const s=e.body||e.createElement("body");s.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.disabled=!0,this.fab.onmouseenter=()=>{this.fab.disabled||(this.fab.style.transform="scale(1)")},this.fab.onmouseleave=()=>{this.fab.disabled||(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="\n font-size: 36px;\n ",this.fab.appendChild(this.fabIcon),s.appendChild(this.fab),e.body||e.documentElement.appendChild(s),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()},e)):console.warn(m)},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()},e))},this.toggle=()=>{this.chatInitialized?"scale(1)"===this.chatIframe.style.transform?this.close():this.open():console.warn(m)},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()},e),this.container.remove(),y.instance=null,this.isDestroyed=!0,console.log("EusateMessenger instance destroyed successfully"))},this.apiKey=null==i?void 0:i.apiKey.trim(),this.onReady=i.onReady,this.onError=i.onError,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(l);if(!t.apiKey||"string"!=typeof t.apiKey||""===t.apiKey.trim())throw new Error(l);return y.instance=new y(t),y.instance}}y.instance=null;const w={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:i};return"undefined"!=typeof window&&(console.log("window",window),window.Eusate=w),w}();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const PROD_CONFIG: {
|
|
2
2
|
readonly ICOMOON_URL: "https://cdn.jsdelivr.net/gh/eusate/eusate-messenger-sdk@latest/src/assets/icomoon/style.css";
|
|
3
|
-
readonly CHAT_URL: "https://chat.
|
|
3
|
+
readonly CHAT_URL: "https://chat.eusate.com";
|
|
4
4
|
readonly VERSION: string;
|
|
5
5
|
readonly ENV: string | undefined;
|
|
6
6
|
readonly DEBUG: boolean;
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export declare const debug: (...args: unknown[]) => void;
|
|
|
2
2
|
export declare const getSDKInfo: () => {
|
|
3
3
|
version: string;
|
|
4
4
|
environment: string | undefined;
|
|
5
|
-
chatUrl: "https://chat.
|
|
5
|
+
chatUrl: "https://chat.eusate.com";
|
|
6
6
|
};
|
|
7
7
|
//# sourceMappingURL=helpers.d.ts.map
|