@product7/feedback-sdk 1.0.1

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.
@@ -0,0 +1,686 @@
1
+ # API Reference
2
+
3
+ Complete reference for the Feedback Widget SDK API.
4
+
5
+ ## 🏗️ FeedbackSDK Class
6
+
7
+ The main SDK class that manages widgets and configuration.
8
+
9
+ ### Constructor
10
+
11
+ ```javascript
12
+ new FeedbackSDK(config);
13
+ ```
14
+
15
+ **Parameters:**
16
+
17
+ - `config` (Object) - SDK configuration object
18
+
19
+ **Example:**
20
+
21
+ ```javascript
22
+ const feedback = new FeedbackSDK({
23
+ workspace: 'my-workspace',
24
+ boardId: 'board-123',
25
+ theme: 'light',
26
+ });
27
+ ```
28
+
29
+ ### Methods
30
+
31
+ #### `init(): Promise<FeedbackSDK>`
32
+
33
+ Initialize the SDK and prepare it for use.
34
+
35
+ **Returns:** Promise that resolves to the SDK instance
36
+
37
+ **Example:**
38
+
39
+ ```javascript
40
+ await feedback.init();
41
+ // or
42
+ feedback.init().then(() => {
43
+ console.log('SDK ready');
44
+ });
45
+ ```
46
+
47
+ #### `createWidget(type, options?): Widget`
48
+
49
+ Create a new widget instance.
50
+
51
+ **Parameters:**
52
+
53
+ - `type` (String) - Widget type: `'button'`, `'tab'`, or `'inline'`
54
+ - `options` (Object) - Widget-specific options
55
+
56
+ **Returns:** Widget instance
57
+
58
+ **Example:**
59
+
60
+ ```javascript
61
+ const widget = feedback.createWidget('button', {
62
+ position: 'bottom-right',
63
+ theme: 'dark',
64
+ });
65
+ ```
66
+
67
+ #### `getWidget(id): Widget | undefined`
68
+
69
+ Get a widget by its ID.
70
+
71
+ **Parameters:**
72
+
73
+ - `id` (String) - Widget ID
74
+
75
+ **Returns:** Widget instance or undefined
76
+
77
+ **Example:**
78
+
79
+ ```javascript
80
+ const widget = feedback.getWidget('widget_123');
81
+ if (widget) {
82
+ widget.show();
83
+ }
84
+ ```
85
+
86
+ #### `destroyWidget(id): void`
87
+
88
+ Destroy a specific widget.
89
+
90
+ **Parameters:**
91
+
92
+ - `id` (String) - Widget ID
93
+
94
+ **Example:**
95
+
96
+ ```javascript
97
+ feedback.destroyWidget('widget_123');
98
+ ```
99
+
100
+ #### `updateConfig(newConfig): void`
101
+
102
+ Update SDK configuration.
103
+
104
+ **Parameters:**
105
+
106
+ - `newConfig` (Object) - Configuration updates
107
+
108
+ **Example:**
109
+
110
+ ```javascript
111
+ feedback.updateConfig({
112
+ theme: 'dark',
113
+ position: 'top-left',
114
+ });
115
+ ```
116
+
117
+ #### `destroy(): void`
118
+
119
+ Destroy the SDK and all widgets.
120
+
121
+ **Example:**
122
+
123
+ ```javascript
124
+ feedback.destroy();
125
+ ```
126
+
127
+ ### Properties
128
+
129
+ #### `config: Object`
130
+
131
+ Current SDK configuration (read-only)
132
+
133
+ #### `widgets: Map<String, Widget>`
134
+
135
+ Map of all created widgets (read-only)
136
+
137
+ #### `eventBus: EventBus`
138
+
139
+ Event bus for SDK communication
140
+
141
+ #### `initialized: Boolean`
142
+
143
+ Whether the SDK is initialized (read-only)
144
+
145
+ ---
146
+
147
+ ## 🎛️ Widget Classes
148
+
149
+ ### BaseWidget
150
+
151
+ Base class for all widgets. Not used directly.
152
+
153
+ #### Methods
154
+
155
+ ##### `mount(container?): Widget`
156
+
157
+ Mount the widget to the DOM.
158
+
159
+ **Parameters:**
160
+
161
+ - `container` (String | Element) - CSS selector or DOM element. Defaults to `document.body`
162
+
163
+ **Returns:** Widget instance for chaining
164
+
165
+ **Example:**
166
+
167
+ ```javascript
168
+ widget.mount('#my-container');
169
+ // or
170
+ widget.mount(document.getElementById('container'));
171
+ ```
172
+
173
+ ##### `show(): Widget`
174
+
175
+ Show the widget.
176
+
177
+ **Example:**
178
+
179
+ ```javascript
180
+ widget.show();
181
+ ```
182
+
183
+ ##### `hide(): Widget`
184
+
185
+ Hide the widget.
186
+
187
+ **Example:**
188
+
189
+ ```javascript
190
+ widget.hide();
191
+ ```
192
+
193
+ ##### `openModal(): void`
194
+
195
+ Open the feedback modal (button and tab widgets only).
196
+
197
+ **Example:**
198
+
199
+ ```javascript
200
+ widget.openModal();
201
+ ```
202
+
203
+ ##### `closeModal(): void`
204
+
205
+ Close the feedback modal.
206
+
207
+ **Example:**
208
+
209
+ ```javascript
210
+ widget.closeModal();
211
+ ```
212
+
213
+ ##### `destroy(): void`
214
+
215
+ Destroy the widget and clean up.
216
+
217
+ **Example:**
218
+
219
+ ```javascript
220
+ widget.destroy();
221
+ ```
222
+
223
+ #### Properties
224
+
225
+ ##### `id: String`
226
+
227
+ Unique widget ID (read-only)
228
+
229
+ ##### `type: String`
230
+
231
+ Widget type (read-only)
232
+
233
+ ##### `mounted: Boolean`
234
+
235
+ Whether widget is mounted (read-only)
236
+
237
+ ##### `destroyed: Boolean`
238
+
239
+ Whether widget is destroyed (read-only)
240
+
241
+ ##### `state: Object`
242
+
243
+ Widget state object
244
+
245
+ ### ButtonWidget
246
+
247
+ Floating button widget.
248
+
249
+ #### Additional Methods
250
+
251
+ ##### `updateText(text): void`
252
+
253
+ Update button text.
254
+
255
+ **Example:**
256
+
257
+ ```javascript
258
+ buttonWidget.updateText('Send Feedback');
259
+ ```
260
+
261
+ ##### `updatePosition(position): void`
262
+
263
+ Update button position.
264
+
265
+ **Parameters:**
266
+
267
+ - `position` (String) - Position: `'bottom-right'`, `'bottom-left'`, `'top-right'`, `'top-left'`
268
+
269
+ **Example:**
270
+
271
+ ```javascript
272
+ buttonWidget.updatePosition('top-left');
273
+ ```
274
+
275
+ ### TabWidget
276
+
277
+ Side tab widget.
278
+
279
+ #### Additional Methods
280
+
281
+ ##### `updateText(text): void`
282
+
283
+ Update tab text.
284
+
285
+ **Example:**
286
+
287
+ ```javascript
288
+ tabWidget.updateText('Feedback');
289
+ ```
290
+
291
+ ##### `updatePosition(position): void`
292
+
293
+ Update tab position.
294
+
295
+ **Example:**
296
+
297
+ ```javascript
298
+ tabWidget.updatePosition('bottom-left');
299
+ ```
300
+
301
+ ### InlineWidget
302
+
303
+ Inline form widget.
304
+
305
+ #### Additional Methods
306
+
307
+ ##### `updateTitle(title): void`
308
+
309
+ Update form title.
310
+
311
+ **Example:**
312
+
313
+ ```javascript
314
+ inlineWidget.updateTitle('Share your thoughts');
315
+ ```
316
+
317
+ ##### `setPlaceholder(field, placeholder): void`
318
+
319
+ Set placeholder text for form fields.
320
+
321
+ **Parameters:**
322
+
323
+ - `field` (String) - Field name: `'title'`, `'content'`, `'email'`
324
+ - `placeholder` (String) - Placeholder text
325
+
326
+ **Example:**
327
+
328
+ ```javascript
329
+ inlineWidget.setPlaceholder('content', 'Tell us what you think...');
330
+ ```
331
+
332
+ ---
333
+
334
+ ## 📡 EventBus
335
+
336
+ Event system for SDK communication.
337
+
338
+ ### Methods
339
+
340
+ #### `on(event, callback): Function`
341
+
342
+ Subscribe to an event.
343
+
344
+ **Parameters:**
345
+
346
+ - `event` (String) - Event name
347
+ - `callback` (Function) - Event handler
348
+
349
+ **Returns:** Unsubscribe function
350
+
351
+ **Example:**
352
+
353
+ ```javascript
354
+ const unsubscribe = feedback.eventBus.on('feedback:submitted', (data) => {
355
+ console.log('Feedback submitted:', data);
356
+ });
357
+
358
+ // Later, unsubscribe
359
+ unsubscribe();
360
+ ```
361
+
362
+ #### `off(event, callback): void`
363
+
364
+ Unsubscribe from an event.
365
+
366
+ **Example:**
367
+
368
+ ```javascript
369
+ const handler = (data) => console.log(data);
370
+ feedback.eventBus.on('feedback:submitted', handler);
371
+ feedback.eventBus.off('feedback:submitted', handler);
372
+ ```
373
+
374
+ #### `emit(event, data): void`
375
+
376
+ Emit an event.
377
+
378
+ **Example:**
379
+
380
+ ```javascript
381
+ feedback.eventBus.emit('custom:event', { message: 'Hello' });
382
+ ```
383
+
384
+ #### `once(event, callback): Function`
385
+
386
+ Subscribe to an event once.
387
+
388
+ **Example:**
389
+
390
+ ```javascript
391
+ feedback.eventBus.once('sdk:ready', () => {
392
+ console.log('SDK is ready!');
393
+ });
394
+ ```
395
+
396
+ ### Events
397
+
398
+ #### SDK Events
399
+
400
+ ##### `sdk:ready`
401
+
402
+ Fired when SDK initialization completes.
403
+
404
+ **Data:**
405
+
406
+ ```javascript
407
+ {
408
+ config: Object; // SDK configuration
409
+ }
410
+ ```
411
+
412
+ ##### `sdk:destroyed`
413
+
414
+ Fired when SDK is destroyed.
415
+
416
+ ##### `config:updated`
417
+
418
+ Fired when SDK configuration is updated.
419
+
420
+ **Data:**
421
+
422
+ ```javascript
423
+ {
424
+ // Updated configuration object
425
+ }
426
+ ```
427
+
428
+ #### Widget Events
429
+
430
+ ##### `widget:mounted`
431
+
432
+ Fired when a widget is mounted.
433
+
434
+ **Data:**
435
+
436
+ ```javascript
437
+ {
438
+ widget: Widget; // Widget instance
439
+ }
440
+ ```
441
+
442
+ ##### `widget:destroyed`
443
+
444
+ Fired when a widget is destroyed.
445
+
446
+ **Data:**
447
+
448
+ ```javascript
449
+ {
450
+ widget: Widget; // Widget instance
451
+ }
452
+ ```
453
+
454
+ #### Feedback Events
455
+
456
+ ##### `feedback:submitted`
457
+
458
+ Fired when feedback is successfully submitted.
459
+
460
+ **Data:**
461
+
462
+ ```javascript
463
+ {
464
+ widget: Widget, // Widget that submitted
465
+ feedback: Object // Server response
466
+ }
467
+ ```
468
+
469
+ ##### `feedback:error`
470
+
471
+ Fired when feedback submission fails.
472
+
473
+ **Data:**
474
+
475
+ ```javascript
476
+ {
477
+ widget: Widget, // Widget that failed
478
+ error: Error // Error object
479
+ }
480
+ ```
481
+
482
+ ---
483
+
484
+ ## 🏭 WidgetFactory
485
+
486
+ Factory for creating widgets.
487
+
488
+ ### Static Methods
489
+
490
+ #### `register(type, WidgetClass): void`
491
+
492
+ Register a custom widget type.
493
+
494
+ **Parameters:**
495
+
496
+ - `type` (String) - Widget type name
497
+ - `WidgetClass` (Class) - Widget class constructor
498
+
499
+ **Example:**
500
+
501
+ ```javascript
502
+ class CustomWidget extends BaseWidget {
503
+ // Custom implementation
504
+ }
505
+
506
+ WidgetFactory.register('custom', CustomWidget);
507
+ ```
508
+
509
+ #### `create(type, options): Widget`
510
+
511
+ Create a widget instance.
512
+
513
+ **Parameters:**
514
+
515
+ - `type` (String) - Widget type
516
+ - `options` (Object) - Widget options
517
+
518
+ **Returns:** Widget instance
519
+
520
+ #### `getAvailableTypes(): Array<String>`
521
+
522
+ Get all registered widget types.
523
+
524
+ **Returns:** Array of type names
525
+
526
+ **Example:**
527
+
528
+ ```javascript
529
+ const types = WidgetFactory.getAvailableTypes();
530
+ console.log(types); // ['button', 'tab', 'inline']
531
+ ```
532
+
533
+ #### `isTypeRegistered(type): Boolean`
534
+
535
+ Check if a widget type is registered.
536
+
537
+ **Example:**
538
+
539
+ ```javascript
540
+ if (WidgetFactory.isTypeRegistered('custom')) {
541
+ // Type is available
542
+ }
543
+ ```
544
+
545
+ ---
546
+
547
+ ## 🌐 APIService
548
+
549
+ Service for API communication.
550
+
551
+ ### Methods
552
+
553
+ #### `submitFeedback(payload): Promise<Object>`
554
+
555
+ Submit feedback to the API.
556
+
557
+ **Parameters:**
558
+
559
+ - `payload` (Object) - Feedback data
560
+
561
+ **Example:**
562
+
563
+ ```javascript
564
+ const response = await feedback.apiService.submitFeedback({
565
+ title: 'Bug Report',
566
+ content: 'Found a bug...',
567
+ email: 'user@example.com',
568
+ });
569
+ ```
570
+
571
+ #### `uploadFile(file): Promise<Object>`
572
+
573
+ Upload a file attachment.
574
+
575
+ **Parameters:**
576
+
577
+ - `file` (File) - File object
578
+
579
+ **Returns:** Object with file URL
580
+
581
+ ---
582
+
583
+ ## 🚨 Error Classes
584
+
585
+ ### SDKError
586
+
587
+ General SDK errors.
588
+
589
+ **Properties:**
590
+
591
+ - `name` (String) - 'SDKError'
592
+ - `message` (String) - Error message
593
+ - `cause` (Error) - Original error (if any)
594
+
595
+ ### APIError
596
+
597
+ API-related errors.
598
+
599
+ **Properties:**
600
+
601
+ - `name` (String) - 'APIError'
602
+ - `message` (String) - Error message
603
+ - `status` (Number) - HTTP status code
604
+ - `response` (Object) - Server response
605
+
606
+ **Methods:**
607
+
608
+ - `isNetworkError()` - Returns true if network error
609
+ - `isClientError()` - Returns true if 4xx error
610
+ - `isServerError()` - Returns true if 5xx error
611
+
612
+ ### WidgetError
613
+
614
+ Widget-related errors.
615
+
616
+ **Properties:**
617
+
618
+ - `name` (String) - 'WidgetError'
619
+ - `widgetType` (String) - Widget type
620
+ - `widgetId` (String) - Widget ID
621
+
622
+ ---
623
+
624
+ ## 🛠️ Utility Helpers
625
+
626
+ Utility functions available at `feedback.helpers` or by importing directly.
627
+
628
+ ### `generateId(prefix?): String`
629
+
630
+ Generate a unique ID.
631
+
632
+ **Example:**
633
+
634
+ ```javascript
635
+ const id = generateId('widget'); // 'widget_1234567890_abc123'
636
+ ```
637
+
638
+ ### `isValidEmail(email): Boolean`
639
+
640
+ Validate email address.
641
+
642
+ **Example:**
643
+
644
+ ```javascript
645
+ const valid = isValidEmail('user@example.com'); // true
646
+ ```
647
+
648
+ ### `debounce(func, wait): Function`
649
+
650
+ Debounce a function.
651
+
652
+ **Example:**
653
+
654
+ ```javascript
655
+ const debouncedSearch = debounce(searchFunction, 300);
656
+ ```
657
+
658
+ ### `isMobile(): Boolean`
659
+
660
+ Check if running on mobile device.
661
+
662
+ **Example:**
663
+
664
+ ```javascript
665
+ if (isMobile()) {
666
+ // Mobile-specific behavior
667
+ }
668
+ ```
669
+
670
+ ---
671
+
672
+ ## 📚 TypeScript Definitions
673
+
674
+ The SDK includes full TypeScript definitions:
675
+
676
+ ```typescript
677
+ import { FeedbackSDK, ButtonWidget, SDKConfig } from '@product7/feedback-sdk';
678
+
679
+ const config: SDKConfig = {
680
+ workspace: 'my-workspace',
681
+ boardId: 'board-123',
682
+ };
683
+
684
+ const sdk = new FeedbackSDK(config);
685
+ const widget: ButtonWidget = sdk.createWidget('button');
686
+ ```