@eusate/messenger-sdk 0.1.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/LICENSE +12 -0
- package/README.md +629 -0
- package/dist/MessengerUI.d.ts +38 -0
- package/dist/MessengerUI.d.ts.map +1 -0
- package/dist/eusate-sdk.esm.js +1 -0
- package/dist/eusate-sdk.min.js +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +25 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/helpers.d.ts +7 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/types.d.ts +26 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/package.json +81 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
Copyright (c) 2025 EUSATE
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
4
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
5
|
+
copyright notice and this permission notice appear in all copies.
|
|
6
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
7
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
8
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
9
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
10
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
11
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
12
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
# Eusate Messenger SDK
|
|
2
|
+
|
|
3
|
+
> Embeddable AI-powered customer support chat widget for your website
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@eusate/messenger-sdk)
|
|
6
|
+
[](https://opensource.org/licenses/ISC)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
Eusate Messenger SDK lets you add intelligent customer support to your website in minutes. Built with TypeScript, it works seamlessly across all modern frameworks including Next.js, React, Vue, and vanilla JavaScript.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## ✨ Features
|
|
14
|
+
|
|
15
|
+
- 🚀 **Easy Integration** - Add to any website with one line of code
|
|
16
|
+
- 🎯 **Framework Agnostic** - Works with Next.js, React, Vue, Angular, and plain HTML
|
|
17
|
+
- 🔒 **Secure** - API key authentication with strict origin validation
|
|
18
|
+
- 📱 **Responsive** - Mobile-first design that works everywhere
|
|
19
|
+
- 🎨 **Customizable** - Match your brand with custom styling (coming soon)
|
|
20
|
+
- ⚡ **SSR Safe** - Full Next.js App Router support out of the box
|
|
21
|
+
- 🔧 **TypeScript** - Complete type definitions included
|
|
22
|
+
- 🌐 **CDN Ready** - Use via npm or direct script tag
|
|
23
|
+
- ♿ **Accessible** - WCAG compliant with keyboard navigation
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 📦 Installation
|
|
28
|
+
|
|
29
|
+
### Via NPM (Recommended)
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @eusate/messenger-sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Via Yarn
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
yarn add @eusate/messenger-sdk
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Via CDN
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<script src="https://cdn.eusate.com/messenger/v1/eusate-sdk.min.js"></script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 🚀 Quick Start
|
|
50
|
+
|
|
51
|
+
### Vanilla JavaScript / HTML
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<!DOCTYPE html>
|
|
55
|
+
<html lang="en">
|
|
56
|
+
<head>
|
|
57
|
+
<meta charset="UTF-8" />
|
|
58
|
+
<title>My Website</title>
|
|
59
|
+
</head>
|
|
60
|
+
<body>
|
|
61
|
+
<h1>Welcome to My Website</h1>
|
|
62
|
+
|
|
63
|
+
<!-- Load SDK -->
|
|
64
|
+
<script src="https://cdn.eusate.com/messenger/v1/eusate-sdk.min.js"></script>
|
|
65
|
+
|
|
66
|
+
<!-- Initialize -->
|
|
67
|
+
<script>
|
|
68
|
+
Eusate.init({
|
|
69
|
+
apiKey: 'your-api-key-here',
|
|
70
|
+
})
|
|
71
|
+
</script>
|
|
72
|
+
</body>
|
|
73
|
+
</html>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Next.js (App Router)
|
|
77
|
+
|
|
78
|
+
**Option 1: Client Component**
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
// app/components/ChatWidget.tsx
|
|
82
|
+
'use client'
|
|
83
|
+
|
|
84
|
+
import { useEffect } from 'react'
|
|
85
|
+
import Eusate from '@eusate/messenger-sdk'
|
|
86
|
+
|
|
87
|
+
export default function ChatWidget() {
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
Eusate.init({
|
|
90
|
+
apiKey: process.env.NEXT_PUBLIC_EUSATE_API_KEY!,
|
|
91
|
+
onReady: () => console.log('Chat is ready!'),
|
|
92
|
+
onError: (error) => console.error('Chat error:', error),
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
return () => {
|
|
96
|
+
Eusate.destroy()
|
|
97
|
+
}
|
|
98
|
+
}, [])
|
|
99
|
+
|
|
100
|
+
return null
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
// app/layout.tsx
|
|
106
|
+
import ChatWidget from './components/ChatWidget'
|
|
107
|
+
|
|
108
|
+
export default function RootLayout({ children }) {
|
|
109
|
+
return (
|
|
110
|
+
<html lang="en">
|
|
111
|
+
<body>
|
|
112
|
+
{children}
|
|
113
|
+
<ChatWidget />
|
|
114
|
+
</body>
|
|
115
|
+
</html>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Option 2: Dynamic Import (Code Splitting)**
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
// app/layout.tsx
|
|
124
|
+
import dynamic from 'next/dynamic'
|
|
125
|
+
|
|
126
|
+
const ChatWidget = dynamic(() => import('./components/ChatWidget'), {
|
|
127
|
+
ssr: false,
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
export default function RootLayout({ children }) {
|
|
131
|
+
return (
|
|
132
|
+
<html lang="en">
|
|
133
|
+
<body>
|
|
134
|
+
{children}
|
|
135
|
+
<ChatWidget />
|
|
136
|
+
</body>
|
|
137
|
+
</html>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### React
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
import { useEffect } from 'react'
|
|
146
|
+
import Eusate from '@eusate/messenger-sdk'
|
|
147
|
+
|
|
148
|
+
function App() {
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
Eusate.init({
|
|
151
|
+
apiKey: process.env.REACT_APP_EUSATE_API_KEY!,
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
return () => {
|
|
155
|
+
Eusate.destroy()
|
|
156
|
+
}
|
|
157
|
+
}, [])
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<div className="App">
|
|
161
|
+
<h1>My App</h1>
|
|
162
|
+
{/* Your content */}
|
|
163
|
+
</div>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export default App
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Vue 3
|
|
171
|
+
|
|
172
|
+
```vue
|
|
173
|
+
<!-- App.vue -->
|
|
174
|
+
<template>
|
|
175
|
+
<div id="app">
|
|
176
|
+
<h1>My App</h1>
|
|
177
|
+
<!-- Your content -->
|
|
178
|
+
</div>
|
|
179
|
+
</template>
|
|
180
|
+
|
|
181
|
+
<script setup>
|
|
182
|
+
import { onMounted, onUnmounted } from 'vue'
|
|
183
|
+
import Eusate from '@eusate/messenger-sdk'
|
|
184
|
+
|
|
185
|
+
onMounted(() => {
|
|
186
|
+
Eusate.init({
|
|
187
|
+
apiKey: import.meta.env.VITE_EUSATE_API_KEY,
|
|
188
|
+
})
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
onUnmounted(() => {
|
|
192
|
+
Eusate.destroy()
|
|
193
|
+
})
|
|
194
|
+
</script>
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## 📖 API Reference
|
|
200
|
+
|
|
201
|
+
### `Eusate.init(config)`
|
|
202
|
+
|
|
203
|
+
Initialize the chat widget.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
Eusate.init({
|
|
207
|
+
apiKey: string, // Required: Your Eusate API key
|
|
208
|
+
onReady?: () => void, // Optional: Called when SDK is ready
|
|
209
|
+
onError?: (error: Error) => void // Optional: Called on errors
|
|
210
|
+
})
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**Example:**
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
Eusate.init({
|
|
217
|
+
apiKey: 'esk_live_abc123...',
|
|
218
|
+
onReady: () => {
|
|
219
|
+
console.log('Eusate is ready!')
|
|
220
|
+
},
|
|
221
|
+
onError: (error) => {
|
|
222
|
+
console.error('Failed to load chat:', error)
|
|
223
|
+
},
|
|
224
|
+
})
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
### `Eusate.open()`
|
|
230
|
+
|
|
231
|
+
Programmatically open the chat window.
|
|
232
|
+
|
|
233
|
+
```javascript
|
|
234
|
+
Eusate.open()
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**Example Use Case:**
|
|
238
|
+
|
|
239
|
+
```html
|
|
240
|
+
<button onclick="Eusate.open()">Need Help? Chat with us!</button>
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
### `Eusate.close()`
|
|
246
|
+
|
|
247
|
+
Programmatically close the chat window.
|
|
248
|
+
|
|
249
|
+
```javascript
|
|
250
|
+
Eusate.close()
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
### `Eusate.destroy()`
|
|
256
|
+
|
|
257
|
+
Remove the chat widget completely from the page. Useful for cleanup in single-page applications.
|
|
258
|
+
|
|
259
|
+
```javascript
|
|
260
|
+
Eusate.destroy()
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**Important:** After calling `destroy()`, you need to call `init()` again to re-initialize.
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
### `Eusate.isInitialized()`
|
|
268
|
+
|
|
269
|
+
Check if the SDK is initialized.
|
|
270
|
+
|
|
271
|
+
```javascript
|
|
272
|
+
if (Eusate.isInitialized()) {
|
|
273
|
+
console.log('SDK is ready to use')
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**Returns:** `boolean`
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
### `Eusate.isOpen()`
|
|
282
|
+
|
|
283
|
+
Check if the chat window is currently open.
|
|
284
|
+
|
|
285
|
+
```javascript
|
|
286
|
+
if (Eusate.isOpen()) {
|
|
287
|
+
console.log('Chat is open')
|
|
288
|
+
} else {
|
|
289
|
+
console.log('Chat is closed')
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
**Returns:** `boolean`
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
### `Eusate.version`
|
|
298
|
+
|
|
299
|
+
Get the current SDK version.
|
|
300
|
+
|
|
301
|
+
```javascript
|
|
302
|
+
console.log('SDK Version:', Eusate.version)
|
|
303
|
+
// Output: "0.1.0"
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
**Returns:** `string`
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## 🔧 Configuration
|
|
311
|
+
|
|
312
|
+
### Environment Variables
|
|
313
|
+
|
|
314
|
+
#### Next.js
|
|
315
|
+
|
|
316
|
+
```env
|
|
317
|
+
# .env.local
|
|
318
|
+
NEXT_PUBLIC_EUSATE_API_KEY=your-api-key-here
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
**Note:** The `NEXT_PUBLIC_` prefix is required for client-side access.
|
|
322
|
+
|
|
323
|
+
#### React (Create React App)
|
|
324
|
+
|
|
325
|
+
```env
|
|
326
|
+
# .env
|
|
327
|
+
REACT_APP_EUSATE_API_KEY=your-api-key-here
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
#### Vue (Vite)
|
|
331
|
+
|
|
332
|
+
```env
|
|
333
|
+
# .env
|
|
334
|
+
VITE_EUSATE_API_KEY=your-api-key-here
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## 🎨 Advanced Usage
|
|
340
|
+
|
|
341
|
+
### Controlling Chat Visibility
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
// Open chat after 5 seconds
|
|
345
|
+
setTimeout(() => {
|
|
346
|
+
Eusate.open()
|
|
347
|
+
}, 5000)
|
|
348
|
+
|
|
349
|
+
// Close chat on route change
|
|
350
|
+
router.events.on('routeChangeStart', () => {
|
|
351
|
+
Eusate.close()
|
|
352
|
+
})
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### Custom Trigger Button
|
|
356
|
+
|
|
357
|
+
```html
|
|
358
|
+
<!-- Hide default button and use your own -->
|
|
359
|
+
<button id="custom-chat-btn">💬 Chat with Support</button>
|
|
360
|
+
|
|
361
|
+
<script>
|
|
362
|
+
Eusate.init({ apiKey: 'your-key' })
|
|
363
|
+
|
|
364
|
+
document.getElementById('custom-chat-btn').onclick = () => {
|
|
365
|
+
Eusate.open()
|
|
366
|
+
}
|
|
367
|
+
</script>
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Error Handling
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
Eusate.init({
|
|
374
|
+
apiKey: process.env.NEXT_PUBLIC_EUSATE_API_KEY!,
|
|
375
|
+
onError: (error) => {
|
|
376
|
+
// Log to error tracking service
|
|
377
|
+
console.error('Eusate SDK Error:', error)
|
|
378
|
+
|
|
379
|
+
// Show fallback to user
|
|
380
|
+
alert('Chat is temporarily unavailable. Please email support@example.com')
|
|
381
|
+
},
|
|
382
|
+
})
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Conditional Loading
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
// Only load for logged-in users
|
|
389
|
+
if (user.isAuthenticated) {
|
|
390
|
+
Eusate.init({
|
|
391
|
+
apiKey: process.env.NEXT_PUBLIC_EUSATE_API_KEY!,
|
|
392
|
+
})
|
|
393
|
+
}
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
## 🌍 Framework-Specific Guides
|
|
399
|
+
|
|
400
|
+
### Next.js (Pages Router)
|
|
401
|
+
|
|
402
|
+
```tsx
|
|
403
|
+
// pages/_app.tsx
|
|
404
|
+
import { useEffect } from 'react'
|
|
405
|
+
import type { AppProps } from 'next/app'
|
|
406
|
+
import Eusate from '@eusate/messenger-sdk'
|
|
407
|
+
|
|
408
|
+
export default function App({ Component, pageProps }: AppProps) {
|
|
409
|
+
useEffect(() => {
|
|
410
|
+
Eusate.init({
|
|
411
|
+
apiKey: process.env.NEXT_PUBLIC_EUSATE_API_KEY!,
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
return () => {
|
|
415
|
+
Eusate.destroy()
|
|
416
|
+
}
|
|
417
|
+
}, [])
|
|
418
|
+
|
|
419
|
+
return <Component {...pageProps} />
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Angular
|
|
424
|
+
|
|
425
|
+
```typescript
|
|
426
|
+
// app.component.ts
|
|
427
|
+
import { Component, OnInit, OnDestroy } from '@angular/core'
|
|
428
|
+
import Eusate from '@eusate/messenger-sdk'
|
|
429
|
+
|
|
430
|
+
@Component({
|
|
431
|
+
selector: 'app-root',
|
|
432
|
+
templateUrl: './app.component.html',
|
|
433
|
+
})
|
|
434
|
+
export class AppComponent implements OnInit, OnDestroy {
|
|
435
|
+
ngOnInit() {
|
|
436
|
+
Eusate.init({
|
|
437
|
+
apiKey: environment.eusateApiKey,
|
|
438
|
+
})
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
ngOnDestroy() {
|
|
442
|
+
Eusate.destroy()
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Svelte
|
|
448
|
+
|
|
449
|
+
```svelte
|
|
450
|
+
<!-- App.svelte -->
|
|
451
|
+
<script>
|
|
452
|
+
import { onMount, onDestroy } from 'svelte'
|
|
453
|
+
import Eusate from '@eusate/messenger-sdk'
|
|
454
|
+
|
|
455
|
+
onMount(() => {
|
|
456
|
+
Eusate.init({
|
|
457
|
+
apiKey: import.meta.env.VITE_EUSATE_API_KEY
|
|
458
|
+
})
|
|
459
|
+
})
|
|
460
|
+
|
|
461
|
+
onDestroy(() => {
|
|
462
|
+
Eusate.destroy()
|
|
463
|
+
})
|
|
464
|
+
</script>
|
|
465
|
+
|
|
466
|
+
<main>
|
|
467
|
+
<h1>My App</h1>
|
|
468
|
+
</main>
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
---
|
|
472
|
+
|
|
473
|
+
## 🔒 Security
|
|
474
|
+
|
|
475
|
+
### API Key Management
|
|
476
|
+
|
|
477
|
+
**✅ Do:**
|
|
478
|
+
|
|
479
|
+
- Store API keys in environment variables
|
|
480
|
+
- Use different API keys for development and production
|
|
481
|
+
- Rotate API keys periodically
|
|
482
|
+
|
|
483
|
+
**❌ Don't:**
|
|
484
|
+
|
|
485
|
+
- Commit API keys to version control
|
|
486
|
+
- Expose API keys in client-side code comments
|
|
487
|
+
- Share API keys publicly
|
|
488
|
+
|
|
489
|
+
### Content Security Policy (CSP)
|
|
490
|
+
|
|
491
|
+
If your site uses CSP, add these directives:
|
|
492
|
+
|
|
493
|
+
```
|
|
494
|
+
Content-Security-Policy:
|
|
495
|
+
frame-src https://chat.eusate.com;
|
|
496
|
+
script-src https://cdn.eusate.com;
|
|
497
|
+
connect-src https://api.eusate.com;
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
---
|
|
501
|
+
|
|
502
|
+
## 🐛 Troubleshooting
|
|
503
|
+
|
|
504
|
+
### Chat Widget Not Appearing
|
|
505
|
+
|
|
506
|
+
**Check:**
|
|
507
|
+
|
|
508
|
+
1. API key is correct and active
|
|
509
|
+
2. No console errors in browser DevTools
|
|
510
|
+
3. JavaScript is enabled in browser
|
|
511
|
+
4. No ad blockers interfering
|
|
512
|
+
|
|
513
|
+
```javascript
|
|
514
|
+
// Debug initialization
|
|
515
|
+
Eusate.init({
|
|
516
|
+
apiKey: 'your-key',
|
|
517
|
+
onReady: () => console.log('✅ SDK Ready'),
|
|
518
|
+
onError: (error) => console.error('❌ SDK Error:', error),
|
|
519
|
+
})
|
|
520
|
+
|
|
521
|
+
// Check status
|
|
522
|
+
console.log('Initialized?', Eusate.isInitialized())
|
|
523
|
+
console.log('SDK Version:', Eusate.version)
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
### Next.js: "window is not defined"
|
|
527
|
+
|
|
528
|
+
**Solution:** Make sure you're using `'use client'` directive:
|
|
529
|
+
|
|
530
|
+
```tsx
|
|
531
|
+
'use client' // ← Add this at the top
|
|
532
|
+
|
|
533
|
+
import Eusate from '@eusate/messenger-sdk'
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
Or use dynamic import with `ssr: false`.
|
|
537
|
+
|
|
538
|
+
### TypeScript Errors
|
|
539
|
+
|
|
540
|
+
**Solution:** Install types (they're included automatically):
|
|
541
|
+
|
|
542
|
+
```bash
|
|
543
|
+
npm install @eusate/messenger-sdk
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
If types aren't working, add to `tsconfig.json`:
|
|
547
|
+
|
|
548
|
+
```json
|
|
549
|
+
{
|
|
550
|
+
"compilerOptions": {
|
|
551
|
+
"moduleResolution": "node",
|
|
552
|
+
"esModuleInterop": true
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### Chat Appears Multiple Times
|
|
558
|
+
|
|
559
|
+
**Solution:** Make sure you're not calling `init()` multiple times. Use the singleton pattern:
|
|
560
|
+
|
|
561
|
+
```typescript
|
|
562
|
+
// ✅ Good
|
|
563
|
+
useEffect(() => {
|
|
564
|
+
Eusate.init({ apiKey: 'key' })
|
|
565
|
+
return () => Eusate.destroy()
|
|
566
|
+
}, []) // Empty dependency array
|
|
567
|
+
|
|
568
|
+
// ❌ Bad
|
|
569
|
+
useEffect(() => {
|
|
570
|
+
Eusate.init({ apiKey: 'key' })
|
|
571
|
+
}, [someValue]) // Reinitializes on every change
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
<!-- ## 📊 Browser Support
|
|
577
|
+
|
|
578
|
+
- Chrome (latest)
|
|
579
|
+
- Firefox (latest)
|
|
580
|
+
- Safari (latest)
|
|
581
|
+
- Edge (latest)
|
|
582
|
+
- Mobile browsers (iOS Safari, Chrome Mobile)
|
|
583
|
+
|
|
584
|
+
**Note:** Internet Explorer is not supported. -->
|
|
585
|
+
|
|
586
|
+
---
|
|
587
|
+
|
|
588
|
+
## 📄 License
|
|
589
|
+
|
|
590
|
+
ISC License - see [LICENSE](LICENSE) file for details.
|
|
591
|
+
|
|
592
|
+
---
|
|
593
|
+
|
|
594
|
+
## 📚 Documentation
|
|
595
|
+
|
|
596
|
+
- [API Reference](docs/API.md)
|
|
597
|
+
- [Version Management](docs/VERSIONING.md)
|
|
598
|
+
- [Release Process](docs/RELEASING.md)
|
|
599
|
+
|
|
600
|
+
---
|
|
601
|
+
|
|
602
|
+
## 💬 Support
|
|
603
|
+
|
|
604
|
+
- **Documentation:** [https://docs.eusate.com](https://docs.eusate.com)
|
|
605
|
+
- **Email:** dev@eusate.com
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
## 🔗 Links
|
|
610
|
+
|
|
611
|
+
- [NPM Package](https://www.npmjs.com/package/@eusate/messenger-sdk)
|
|
612
|
+
- [GitHub Repository](https://github.com/EUSATE/eusate-messenger-sdk)
|
|
613
|
+
- [Changelog](CHANGELOG.md)
|
|
614
|
+
|
|
615
|
+
---
|
|
616
|
+
|
|
617
|
+
## ⚡ Quick Reference
|
|
618
|
+
|
|
619
|
+
| Task | Command |
|
|
620
|
+
| ---------- | ------------------------------------- |
|
|
621
|
+
| Install | `npm install @eusate/messenger-sdk` |
|
|
622
|
+
| Initialize | `Eusate.init({ apiKey: 'your-key' })` |
|
|
623
|
+
| Open Chat | `Eusate.open()` |
|
|
624
|
+
| Close Chat | `Eusate.close()` |
|
|
625
|
+
| Cleanup | `Eusate.destroy()` |
|
|
626
|
+
|
|
627
|
+
---
|
|
628
|
+
|
|
629
|
+
Made with ❤️ by [Eusate](https://eusate.com)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { MessengerConfig } from './utils';
|
|
2
|
+
declare class EusateMessenger {
|
|
3
|
+
private static instance;
|
|
4
|
+
private container;
|
|
5
|
+
private fabIframe;
|
|
6
|
+
private chatIframe;
|
|
7
|
+
private fabIcon;
|
|
8
|
+
private fab;
|
|
9
|
+
private apiKey;
|
|
10
|
+
private onReady?;
|
|
11
|
+
private onError?;
|
|
12
|
+
private chatInitialized;
|
|
13
|
+
private isChatOpen;
|
|
14
|
+
private isDestroyed;
|
|
15
|
+
private fabClickHandler;
|
|
16
|
+
private messageHandler;
|
|
17
|
+
private initTimeout;
|
|
18
|
+
private constructor();
|
|
19
|
+
static getInstance(config?: MessengerConfig): EusateMessenger;
|
|
20
|
+
private init;
|
|
21
|
+
private setupContainer;
|
|
22
|
+
private setupFabIframe;
|
|
23
|
+
private setupChatIframe;
|
|
24
|
+
private handleChatIframeLoad;
|
|
25
|
+
private handleIframeError;
|
|
26
|
+
private setupMessageHandlers;
|
|
27
|
+
private handleReady;
|
|
28
|
+
private handleError;
|
|
29
|
+
private loadFabButton;
|
|
30
|
+
isInitialized: () => boolean;
|
|
31
|
+
isOpen: () => boolean;
|
|
32
|
+
open: () => void;
|
|
33
|
+
close: () => void;
|
|
34
|
+
toggle: () => void;
|
|
35
|
+
destroy: () => void;
|
|
36
|
+
}
|
|
37
|
+
export default EusateMessenger;
|
|
38
|
+
//# sourceMappingURL=MessengerUI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessengerUI.d.ts","sourceRoot":"","sources":["../src/MessengerUI.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAKhB,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,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;IAcP,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,eAAe;IA2B7D,OAAO,CAAC,IAAI,CAqBX;IAED,OAAO,CAAC,cAAc,CAUrB;IAED,OAAO,CAAC,cAAc,CAgBrB;IAED,OAAO,CAAC,eAAe,CAiCtB;IAED,OAAO,CAAC,oBAAoB,CAmB3B;IAED,OAAO,CAAC,iBAAiB,CAExB;IAED,OAAO,CAAC,oBAAoB,CAuB3B;IAED,OAAO,CAAC,WAAW,CAalB;IAED,OAAO,CAAC,WAAW,CAkBlB;IAED,OAAO,CAAC,aAAa,CAuFpB;IAED,aAAa,gBAA6B;IAC1C,MAAM,gBAAwB;IAE9B,IAAI,QAAO,IAAI,CAwBd;IAED,KAAK,aAoBJ;IAED,MAAM,aAYL;IAED,OAAO,aA+CN;CACF;AAED,eAAe,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t="https://cdn.jsdelivr.net/gh/eusate/eusate-messenger-sdk@latest/src/assets/icomoon/style.css",e="https://chat.dev.eusate.com",i="0.1.0",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};
|
|
@@ -0,0 +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.dev.eusate.com",i="0.1.0",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}();
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,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;AAOD,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const PROD_CONFIG: {
|
|
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.dev.eusate.com";
|
|
4
|
+
readonly VERSION: string;
|
|
5
|
+
readonly ENV: string | undefined;
|
|
6
|
+
readonly DEBUG: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const POST_MESSAGE_TYPES: {
|
|
9
|
+
readonly INIT: "EUSATE_INIT";
|
|
10
|
+
readonly READY: "EUSATE_READY";
|
|
11
|
+
readonly AUTH_ERROR: "EUSATE_AUTH_ERROR";
|
|
12
|
+
readonly CLOSE_CHAT: "CLOSE_CHAT";
|
|
13
|
+
readonly OPEN_CHAT: "OPEN_CHAT";
|
|
14
|
+
readonly DESTROY: "EUSATE_DESTROY";
|
|
15
|
+
};
|
|
16
|
+
export declare const ERROR_MESSAGES: {
|
|
17
|
+
readonly NO_API_KEY: "[EUSATE SDK] API Key is required for initialization";
|
|
18
|
+
readonly ERROR: "[EUSATE SDK] Error:";
|
|
19
|
+
readonly INIT_TIMEOUT: "[EUSATE SDK] Initialization timeout";
|
|
20
|
+
readonly IFRAME_LOAD: "[EUSATE SDK] Failed to load chat iframe";
|
|
21
|
+
readonly NOT_INIT_YET: "[EUSATE SDK] Not initialized yet. Call init() first.";
|
|
22
|
+
readonly DESTROYED_ALREADY: "[EUSATE SDK] Already destroyed";
|
|
23
|
+
readonly ALREADY_INIT: "[Eusate SDK] Already initialized. Call destroy() first to reinitialize.";
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW;;;;;;CAQd,CAAA;AAEV,eAAO,MAAM,kBAAkB;;;;;;;CAOrB,CAAA;AAEV,eAAO,MAAM,cAAc;;;;;;;;CASjB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,KAAK,GAAI,GAAG,MAAM,OAAO,EAAE,SAIvC,CAAA;AAED,eAAO,MAAM,UAAU;;;;CAIrB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { POST_MESSAGE_TYPES } from './constants';
|
|
2
|
+
export type ValueOf<K> = K[keyof K];
|
|
3
|
+
export declare enum ErrorType {
|
|
4
|
+
INIT = "init",
|
|
5
|
+
AUTH = "auth"
|
|
6
|
+
}
|
|
7
|
+
export type MessengerConfig = {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
onReady?: () => void;
|
|
10
|
+
onError?: (error: Error) => void;
|
|
11
|
+
};
|
|
12
|
+
export type MessageObjectType<T = unknown> = {
|
|
13
|
+
type: ValueOf<typeof POST_MESSAGE_TYPES>;
|
|
14
|
+
data?: T;
|
|
15
|
+
timestamp: number;
|
|
16
|
+
};
|
|
17
|
+
export interface EusateMessengerSDK {
|
|
18
|
+
init: (config: string | MessengerConfig) => void;
|
|
19
|
+
open: () => void;
|
|
20
|
+
close: () => void;
|
|
21
|
+
destroy: () => void;
|
|
22
|
+
isInitialized: () => boolean;
|
|
23
|
+
isOpen: () => boolean;
|
|
24
|
+
version: string;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;AAEnC,oBAAY,SAAS;IACnB,IAAI,SAAS;IACb,IAAI,SAAS;CACd;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,GAAG,OAAO,IAAI;IAC3C,IAAI,EAAE,OAAO,CAAC,OAAO,kBAAkB,CAAC,CAAA;IACxC,IAAI,CAAC,EAAE,CAAC,CAAA;IACR,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,KAAK,IAAI,CAAA;IAChD,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,aAAa,EAAE,MAAM,OAAO,CAAA;IAC5B,MAAM,EAAE,MAAM,OAAO,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;CAChB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eusate/messenger-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Eusate Messenger SDK - Embeddable AI-powered customer support",
|
|
5
|
+
"main": "dist/eusate-sdk.esm.js",
|
|
6
|
+
"module": "dist/eusate-sdk.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/eusate-sdk.esm.js",
|
|
17
|
+
"require": "./dist/eusate-sdk.esm.js",
|
|
18
|
+
"default": "./dist/eusate-sdk.esm.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "rm -rf dist",
|
|
23
|
+
"build": "npm run clean && rollup -c --environment NODE_ENV:production",
|
|
24
|
+
"build:dev": "npm run clean && rollup -c --environment NODE_ENV:development",
|
|
25
|
+
"dev": "rollup -c --watch --environment NODE_ENV:development",
|
|
26
|
+
"lint": "eslint 'src/**/*.{js,ts}'",
|
|
27
|
+
"lint:fix": "npm run lint -- --fix",
|
|
28
|
+
"type-check": "tsc --noEmit",
|
|
29
|
+
"test": "echo \"Error: no test specified\" ",
|
|
30
|
+
"prerelease": "node scripts/pre-release.js",
|
|
31
|
+
"release:patch": "npm version patch",
|
|
32
|
+
"release:minor": "npm version minor",
|
|
33
|
+
"release:major": "npm version major",
|
|
34
|
+
"version": "npm run build && git add -A dist",
|
|
35
|
+
"postversion": "git push && git push --tags",
|
|
36
|
+
"prepublishOnly": "npm run lint && npm run type-check && npm run build",
|
|
37
|
+
"prepare": "husky",
|
|
38
|
+
"size": "ls -lah dist/"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/EUSATE/eusate-messenger-sdk"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"messenger",
|
|
46
|
+
"sdk",
|
|
47
|
+
"customer-support",
|
|
48
|
+
"chat",
|
|
49
|
+
"chatbot",
|
|
50
|
+
"widget",
|
|
51
|
+
"support",
|
|
52
|
+
"ai",
|
|
53
|
+
"typescript"
|
|
54
|
+
],
|
|
55
|
+
"author": "EUSATE <dev@eusate.com> (https://eusate.com)",
|
|
56
|
+
"license": "ISC",
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/EUSATE/eusate-messenger-sdk/issues"
|
|
59
|
+
},
|
|
60
|
+
"homepage": "https://docs.eusate.com/modules/helpdesk/sdk",
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@eslint/js": "^9.36.0",
|
|
63
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
64
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
65
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
66
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
67
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
68
|
+
"@types/node": "^24.6.1",
|
|
69
|
+
"eslint": "^9.36.0",
|
|
70
|
+
"eslint-config-prettier": "^10.0.2",
|
|
71
|
+
"eslint-plugin-prettier": "^5.2.3",
|
|
72
|
+
"globals": "^16.4.0",
|
|
73
|
+
"husky": "^9.1.7",
|
|
74
|
+
"jiti": "^2.6.0",
|
|
75
|
+
"lint-staged": "^15.4.3",
|
|
76
|
+
"prettier": "^3.5.3",
|
|
77
|
+
"rollup": "^4.34.9",
|
|
78
|
+
"typescript": "^5.8.2",
|
|
79
|
+
"typescript-eslint": "^8.45.0"
|
|
80
|
+
}
|
|
81
|
+
}
|