@wabbit-dashboard/embed 1.0.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/README.md ADDED
@@ -0,0 +1,383 @@
1
+ # @wabbit-dashboard/embed
2
+
3
+ Wabbit Embed SDK - Unified widget library for embedding chat, forms, and email capture functionality into customer websites.
4
+
5
+ ## Installation
6
+
7
+ ### CDN (Recommended for Production)
8
+
9
+ ```html
10
+ <script src="https://unpkg.com/@wabbit-dashboard/embed@1/dist/wabbit-embed.umd.min.js"></script>
11
+ ```
12
+
13
+ For local development:
14
+ ```html
15
+ <script src="http://localhost:3000/sdk/wabbit-embed.umd.js"></script>
16
+ ```
17
+
18
+ > **Note**: For local development, run `make dev` from the project root. The SDK will be automatically built and served at `/sdk/wabbit-embed.umd.js`.
19
+
20
+ ### NPM
21
+
22
+ ```bash
23
+ npm install @wabbit-dashboard/embed
24
+ ```
25
+
26
+ ```javascript
27
+ import { Wabbit } from '@wabbit-dashboard/embed';
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ > 📖 **New to Wabbit?** Check out the [Getting Started Guide](./docs/getting-started.md) to integrate in 5 minutes.
33
+
34
+ ### Using CDN
35
+
36
+ **Production:**
37
+ ```html
38
+ <script src="https://unpkg.com/@wabbit-dashboard/embed@1/dist/wabbit-embed.umd.min.js"></script>
39
+ <script>
40
+ Wabbit.init({
41
+ apiKey: 'pk_live_xxx',
42
+ chat: {
43
+ enabled: true,
44
+ collectionId: 'abc123',
45
+ position: 'bottom-right'
46
+ }
47
+ });
48
+ </script>
49
+ ```
50
+
51
+ **Local Development:**
52
+ ```html
53
+ <script src="http://localhost:3000/sdk/wabbit-embed.umd.js"></script>
54
+ <script>
55
+ Wabbit.init({
56
+ apiKey: 'pk_live_xxx',
57
+ apiUrl: 'http://localhost:3000',
58
+ chat: {
59
+ enabled: true,
60
+ collectionId: 'abc123',
61
+ position: 'bottom-right'
62
+ }
63
+ });
64
+ </script>
65
+ ```
66
+
67
+ ## Configuration
68
+
69
+ ### Chat Widget
70
+
71
+ ```javascript
72
+ Wabbit.init({
73
+ apiKey: 'pk_live_xxx',
74
+ chat: {
75
+ enabled: true,
76
+ collectionId: 'abc123',
77
+ position: 'bottom-right', // 'bottom-right' | 'bottom-left'
78
+ triggerType: 'button', // 'button' | 'auto' | 'scroll'
79
+ triggerDelay: 5000, // ms before auto-open
80
+ theme: 'auto', // 'auto' | 'light' | 'dark'
81
+ primaryColor: '#6366f1',
82
+ welcomeMessage: 'Hi! How can I help?',
83
+ placeholder: 'Type your message...'
84
+ }
85
+ });
86
+ ```
87
+
88
+ ### Form Widget
89
+
90
+ ```javascript
91
+ Wabbit.init({
92
+ apiKey: 'pk_live_xxx',
93
+ forms: {
94
+ enabled: true,
95
+ containerId: 'feedback-form', // DOM element ID
96
+ formId: 'form_xxx',
97
+ theme: 'auto',
98
+ onSubmit: (data) => {
99
+ console.log('Form submitted:', data);
100
+ },
101
+ onError: (error) => {
102
+ console.error('Form error:', error);
103
+ }
104
+ }
105
+ });
106
+ ```
107
+
108
+ ### Email Capture
109
+
110
+ ```javascript
111
+ Wabbit.init({
112
+ apiKey: 'pk_live_xxx',
113
+ emailCapture: {
114
+ enabled: true,
115
+ triggerAfterMessages: 3,
116
+ title: 'Stay in touch',
117
+ description: 'Get notified about updates',
118
+ fields: ['email'], // 'email' | 'name' | 'company'
119
+ onCapture: (data) => {
120
+ console.log('Email captured:', data);
121
+ }
122
+ }
123
+ });
124
+ ```
125
+
126
+ ## Testing
127
+
128
+ ### Option 1: Copy Embed Code from Dashboard (Recommended)
129
+
130
+ 1. **Start all services**:
131
+ ```bash
132
+ make dev
133
+ ```
134
+
135
+ 2. **Build the SDK** (required for local development):
136
+ ```bash
137
+ cd packages/embed
138
+ bun run build
139
+ ```
140
+
141
+ 3. **Get embed code from Dashboard**:
142
+ - Open Dashboard: `http://localhost:3000`
143
+ - Navigate to **Collections** → Select a collection → Click **"Embed Chat"** button
144
+ - Or navigate to **Forms** → Select a form → Click **"Embed"** button
145
+ - Copy the embed code from the modal
146
+
147
+ 4. **Paste into your HTML**:
148
+ - Create a test HTML file
149
+ - Paste the copied embed code
150
+ - Replace `YOUR_API_KEY` with your actual API key
151
+ - Open the HTML file in a browser
152
+
153
+ ### Option 2: Use Example Files
154
+
155
+ 1. **Configure settings**:
156
+ Edit `examples/config.js`:
157
+ ```javascript
158
+ window.WABBIT_CONFIG = {
159
+ "apiKey": "pk_live_your_actual_api_key",
160
+ "apiUrl": "http://localhost:3000",
161
+ "collectionId": "your-collection-id",
162
+ "formId": "your-form-id"
163
+ };
164
+ ```
165
+
166
+ 2. **Build the SDK**:
167
+ ```bash
168
+ cd packages/embed
169
+ bun run build
170
+ ```
171
+
172
+ 3. **Start a local server**:
173
+ ```bash
174
+ cd packages/embed
175
+ python3 -m http.server 8080
176
+ # or
177
+ npx http-server -p 8080
178
+ ```
179
+
180
+ 4. **Open example files**:
181
+ - **Complete example** (recommended): `http://localhost:8080/examples/test-complete.html`
182
+ - Chat only: `http://localhost:8080/examples/test-chat.html`
183
+ - Form only: `http://localhost:8080/examples/test-form.html`
184
+ - Email capture: `http://localhost:8080/examples/test-email-capture.html`
185
+
186
+ See `examples/README.md` for more details.
187
+
188
+ ## Project Structure
189
+
190
+ ```
191
+ packages/embed/
192
+ ├── src/ # Source code
193
+ │ ├── index.ts # Main entry point
194
+ │ ├── core/ # Core SDK functionality
195
+ │ │ ├── wabbit.ts # Main Wabbit class
196
+ │ │ ├── config.ts # Configuration management
197
+ │ │ ├── api.ts # API client
198
+ │ │ ├── types.ts # TypeScript type definitions
199
+ │ │ └── events.ts # Event emitter
200
+ │ ├── chat/ # Chat widget
201
+ │ │ ├── ChatWidget.ts # Main chat widget class
202
+ │ │ ├── ChatBubble.ts # Floating chat bubble
203
+ │ │ ├── ChatPanel.ts # Chat panel UI
204
+ │ │ ├── WebSocketClient.ts # WebSocket connection
205
+ │ │ └── styles.ts # Chat styles
206
+ │ ├── forms/ # Form widget
207
+ │ │ ├── FormWidget.ts # Main form widget class
208
+ │ │ ├── FormRenderer.ts # Form HTML renderer
209
+ │ │ └── FormStyles.ts # Form styles
210
+ │ ├── email-capture/ # Email capture widget
211
+ │ │ ├── EmailCaptureWidget.ts # Main email capture class
212
+ │ │ ├── EmailCaptureModal.ts # Email capture modal UI
213
+ │ │ └── EmailCaptureStyles.ts # Email capture styles
214
+ │ └── utils/ # Utility functions
215
+ │ ├── dom.ts # DOM utilities
216
+ │ ├── storage.ts # localStorage wrapper
217
+ │ └── theme.ts # Theme detection
218
+ ├── dist/ # Build output (generated)
219
+ │ ├── wabbit-embed.umd.js # UMD bundle (for CDN)
220
+ │ ├── wabbit-embed.esm.js # ES module bundle
221
+ │ ├── wabbit-embed.cjs.js # CommonJS bundle
222
+ │ └── wabbit-embed.d.ts # TypeScript definitions
223
+ ├── examples/ # Example implementations
224
+ │ ├── test-complete.html # Complete integration example
225
+ │ ├── test-chat.html # Chat widget example
226
+ │ ├── test-form.html # Form widget example
227
+ │ ├── test-email-capture.html # Email capture example
228
+ │ ├── config.js # Example configuration
229
+ │ └── README.md # Examples documentation
230
+ ├── tests/ # Test files
231
+ ├── package.json # Package configuration
232
+ ├── tsconfig.json # TypeScript configuration
233
+ ├── rollup.config.js # Rollup build configuration
234
+ └── README.md # This file
235
+ ```
236
+
237
+ ## Development
238
+
239
+ ```bash
240
+ # Install dependencies
241
+ bun install
242
+
243
+ # Build SDK (required before testing)
244
+ bun run build
245
+
246
+ # Development mode (watch)
247
+ bun run dev
248
+
249
+ # Production build
250
+ bun run build:prod
251
+
252
+ # Lint
253
+ bun run lint
254
+ ```
255
+
256
+ ## API Reference
257
+
258
+ ### `Wabbit.init(config)`
259
+
260
+ Initialize the Wabbit SDK.
261
+
262
+ **Parameters:**
263
+ - `config.apiKey` (string, required): Your Wabbit API key
264
+ - `config.apiUrl` (string, optional): API base URL (default: auto-detected)
265
+ - `config.chat` (ChatConfig, optional): Chat widget configuration
266
+ - `config.forms` (FormConfig, optional): Form widget configuration
267
+ - `config.emailCapture` (EmailCaptureConfig, optional): Email capture configuration
268
+
269
+ **Example:**
270
+ ```javascript
271
+ Wabbit.init({
272
+ apiKey: 'pk_live_xxx',
273
+ chat: { enabled: true, collectionId: 'abc123' }
274
+ });
275
+ ```
276
+
277
+ ### `Wabbit.getInstance()`
278
+
279
+ Get the current Wabbit instance.
280
+
281
+ **Returns:** Wabbit instance or `null` if not initialized
282
+
283
+ ### `Wabbit.destroy()`
284
+
285
+ Destroy the SDK instance and cleanup all widgets.
286
+
287
+ ### Configuration Types
288
+
289
+ #### ChatConfig
290
+ ```typescript
291
+ {
292
+ enabled: boolean; // Required
293
+ collectionId: string; // Required
294
+ position?: 'bottom-right' | 'bottom-left';
295
+ triggerType?: 'button' | 'auto' | 'scroll';
296
+ triggerDelay?: number;
297
+ theme?: 'auto' | 'light' | 'dark';
298
+ primaryColor?: string;
299
+ welcomeMessage?: string;
300
+ placeholder?: string;
301
+ }
302
+ ```
303
+
304
+ #### FormConfig
305
+ ```typescript
306
+ {
307
+ enabled: boolean; // Required
308
+ formId: string; // Required
309
+ containerId?: string;
310
+ theme?: 'auto' | 'light' | 'dark';
311
+ primaryColor?: string;
312
+ onSubmit?: (data, submissionId?) => void;
313
+ onError?: (error) => void;
314
+ onLoad?: () => void;
315
+ }
316
+ ```
317
+
318
+ #### EmailCaptureConfig
319
+ ```typescript
320
+ {
321
+ enabled: boolean; // Required
322
+ triggerAfterMessages?: number; // Default: 3
323
+ title?: string;
324
+ description?: string;
325
+ fields?: ('email' | 'name' | 'company')[];
326
+ onCapture?: (data) => void;
327
+ }
328
+ ```
329
+
330
+ ## Programmatic Control
331
+
332
+ ```javascript
333
+ const wabbit = Wabbit.getInstance();
334
+
335
+ // Chat controls
336
+ wabbit.chat.open();
337
+ wabbit.chat.close();
338
+ wabbit.chat.sendMessage('Hello');
339
+ ```
340
+
341
+ ## Troubleshooting
342
+
343
+ ### Chat widget not appearing
344
+ - Check browser console for errors
345
+ - Verify `chat.enabled` is `true`
346
+ - Verify API key and collection ID are correct
347
+ - Ensure WebSocket URL is accessible
348
+
349
+ ### Form not loading
350
+ - Check API URL is correct (should be dashboard service URL, e.g., `http://localhost:3000`)
351
+ - Verify form ID exists
352
+ - Check browser console for errors
353
+ - Verify CORS is configured correctly
354
+
355
+ ### Email capture not triggering
356
+ - Ensure `emailCapture.enabled` is `true`
357
+ - Check that chat widget is enabled (email capture requires chat)
358
+ - Verify `triggerAfterMessages` value
359
+ - Check localStorage for `wabbit_email_captured` or `wabbit_email_capture_dismissed` flags
360
+
361
+ ### Local development issues
362
+ - **SDK not loading**: Make sure you've run `bun run build` in `packages/embed` directory
363
+ - **File not found**: Ensure `dist/wabbit-embed.umd.js` exists after building
364
+ - **CORS errors**: Check that all services are running (`make dev`)
365
+
366
+ ## Browser Support
367
+
368
+ - Chrome (latest)
369
+ - Firefox (latest)
370
+ - Safari (latest)
371
+ - Edge (latest)
372
+
373
+ ## Documentation
374
+
375
+ - 📖 [Getting Started Guide](./docs/getting-started.md) - Integrate in 5 minutes
376
+ - 🌐 [Example Code](./examples/) - Integration examples (React, Vue, Vanilla JS)
377
+ - 📚 API Reference - Coming soon
378
+ - 🔧 Troubleshooting Guide - Coming soon
379
+
380
+ ## Related Resources
381
+
382
+ - [Browser Compatibility](./BROWSER_COMPATIBILITY.md) - Browser compatibility test results
383
+ - [Testing Guide](./TESTING.md) - Testing guide