@product7/feedback-sdk 1.0.6 → 1.0.8

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/src/docs/api.md CHANGED
@@ -1,686 +1,192 @@
1
1
  # API Reference
2
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.
3
+ ## FeedbackSDK
8
4
 
9
5
  ### Constructor
10
6
 
11
7
  ```javascript
12
- new FeedbackSDK(config);
8
+ new FeedbackSDK(config)
13
9
  ```
14
10
 
15
- **Parameters:**
16
-
17
- - `config` (Object) - SDK configuration object
11
+ **Config Options:**
18
12
 
19
- **Example:**
20
-
21
- ```javascript
22
- const feedback = new FeedbackSDK({
23
- workspace: 'my-workspace',
24
- boardId: 'board-123',
25
- theme: 'light',
26
- });
27
- ```
13
+ | Option | Type | Required | Default | Description |
14
+ |--------|------|----------|---------|-------------|
15
+ | `workspace` | String | Yes | - | Workspace identifier |
16
+ | `userContext` | Object | Yes | - | User identification |
17
+ | `apiUrl` | String | No | Auto | Custom API endpoint |
18
+ | `boardId` | String | No | `'general'` | Default board |
19
+ | `theme` | String | No | `'light'` | `'light'` or `'dark'` |
20
+ | `position` | String | No | `'bottom-right'` | Widget position |
21
+ | `showBackdrop` | Boolean | No | `true` | Show panel backdrop |
22
+ | `debug` | Boolean | No | `false` | Debug logging |
28
23
 
29
24
  ### Methods
30
25
 
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
- ```
26
+ #### `async init(): Promise<Object>`
27
+ Initialize SDK and create session.
46
28
 
47
29
  #### `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
- ```
30
+ Create widget. Type: `'button'`.
66
31
 
67
32
  #### `getWidget(id): Widget | undefined`
33
+ Get widget by ID.
68
34
 
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`
35
+ #### `getAllWidgets(): Array<Widget>`
36
+ Get all widgets.
87
37
 
88
- Destroy a specific widget.
38
+ #### `destroyWidget(id): Boolean`
39
+ Destroy widget by ID.
89
40
 
90
- **Parameters:**
41
+ #### `destroyAllWidgets(): void`
42
+ Destroy all widgets.
91
43
 
92
- - `id` (String) - Widget ID
44
+ #### `updateConfig(config): void`
45
+ Update configuration.
93
46
 
94
- **Example:**
47
+ #### `setUserContext(userContext): void`
48
+ Update user context.
95
49
 
96
- ```javascript
97
- feedback.destroyWidget('widget_123');
98
- ```
99
-
100
- #### `updateConfig(newConfig): void`
50
+ #### `getUserContext(): Object | null`
51
+ Get current user context.
101
52
 
102
- Update SDK configuration.
53
+ #### `async reinitialize(userContext?): Promise<Object>`
54
+ Reinitialize with new user.
103
55
 
104
- **Parameters:**
56
+ #### `on(event, callback): FeedbackSDK`
57
+ Subscribe to event.
105
58
 
106
- - `newConfig` (Object) - Configuration updates
59
+ #### `off(event, callback): FeedbackSDK`
60
+ Unsubscribe from event.
107
61
 
108
- **Example:**
109
-
110
- ```javascript
111
- feedback.updateConfig({
112
- theme: 'dark',
113
- position: 'top-left',
114
- });
115
- ```
62
+ #### `once(event, callback): FeedbackSDK`
63
+ Subscribe once.
116
64
 
117
65
  #### `destroy(): void`
66
+ Destroy SDK.
118
67
 
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`
68
+ ### Static Methods
138
69
 
139
- Event bus for SDK communication
70
+ #### `FeedbackSDK.create(config): FeedbackSDK`
71
+ Create SDK instance.
140
72
 
141
- #### `initialized: Boolean`
73
+ #### `async FeedbackSDK.createAndInit(config): Promise<FeedbackSDK>`
74
+ Create and initialize.
142
75
 
143
- Whether the SDK is initialized (read-only)
76
+ #### `FeedbackSDK.extractUserContextFromAuth(authData): Object`
77
+ Extract user context from auth.
144
78
 
145
79
  ---
146
80
 
147
- ## 🎛️ Widget Classes
81
+ ## Widget
148
82
 
149
- ### BaseWidget
150
-
151
- Base class for all widgets. Not used directly.
83
+ ### ButtonWidget
152
84
 
153
85
  #### Methods
154
86
 
155
87
  ##### `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
- ```
88
+ Mount to DOM.
172
89
 
173
90
  ##### `show(): Widget`
174
-
175
- Show the widget.
176
-
177
- **Example:**
178
-
179
- ```javascript
180
- widget.show();
181
- ```
91
+ Show widget.
182
92
 
183
93
  ##### `hide(): Widget`
94
+ Hide widget.
184
95
 
185
- Hide the widget.
186
-
187
- **Example:**
188
-
189
- ```javascript
190
- widget.hide();
191
- ```
192
-
193
- ##### `openModal(): void`
96
+ ##### `openPanel(): void`
97
+ Open feedback panel.
194
98
 
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
99
+ ##### `closePanel(): void`
100
+ Close panel.
250
101
 
251
102
  ##### `updateText(text): void`
252
-
253
103
  Update button text.
254
104
 
255
- **Example:**
256
-
257
- ```javascript
258
- buttonWidget.updateText('Send Feedback');
259
- ```
260
-
261
105
  ##### `updatePosition(position): void`
106
+ Update position.
262
107
 
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`
108
+ ##### `destroy(): void`
109
+ Destroy widget.
470
110
 
471
- Fired when feedback submission fails.
111
+ #### Properties
472
112
 
473
- **Data:**
474
-
475
- ```javascript
476
- {
477
- widget: Widget, // Widget that failed
478
- error: Error // Error object
479
- }
480
- ```
113
+ - `id: String` - Widget ID
114
+ - `type: String` - Widget type
115
+ - `mounted: Boolean` - Mount status
116
+ - `state: Object` - Widget state
481
117
 
482
118
  ---
483
119
 
484
- ## 🏭 WidgetFactory
120
+ ## Events
485
121
 
486
- Factory for creating widgets.
487
-
488
- ### Static Methods
122
+ ### SDK Events
489
123
 
490
- #### `register(type, WidgetClass): void`
124
+ - `sdk:initialized` - SDK ready
125
+ - `sdk:error` - Error occurred
126
+ - `sdk:destroyed` - SDK destroyed
127
+ - `config:updated` - Config changed
128
+ - `user:updated` - User changed
491
129
 
492
- Register a custom widget type.
130
+ ### Widget Events
493
131
 
494
- **Parameters:**
132
+ - `widget:created` - Widget created
133
+ - `widget:mounted` - Widget mounted
134
+ - `widget:destroyed` - Widget destroyed
135
+ - `widgets:cleared` - All cleared
495
136
 
496
- - `type` (String) - Widget type name
497
- - `WidgetClass` (Class) - Widget class constructor
137
+ ### Feedback Events
498
138
 
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
- ```
139
+ - `feedback:submitted` - Feedback sent
140
+ - `feedback:error` - Submission failed
544
141
 
545
142
  ---
546
143
 
547
- ## 🌐 APIService
144
+ ## APIService
548
145
 
549
- Service for API communication.
146
+ Access via `sdk.apiService`.
550
147
 
551
148
  ### Methods
552
149
 
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.
150
+ #### `async init(userContext?): Promise<Object>`
151
+ Initialize session.
574
152
 
575
- **Parameters:**
153
+ #### `async submitFeedback(data): Promise<Object>`
154
+ Submit feedback.
576
155
 
577
- - `file` (File) - File object
156
+ #### `isSessionValid(): Boolean`
157
+ Check session validity.
578
158
 
579
- **Returns:** Object with file URL
159
+ #### `clearSession(): void`
160
+ Clear session.
580
161
 
581
162
  ---
582
163
 
583
- ## 🚨 Error Classes
164
+ ## Error Classes
584
165
 
585
166
  ### SDKError
586
-
587
167
  General SDK errors.
588
168
 
589
- **Properties:**
590
-
591
- - `name` (String) - 'SDKError'
592
- - `message` (String) - Error message
593
- - `cause` (Error) - Original error (if any)
594
-
595
169
  ### APIError
170
+ API errors with methods:
171
+ - `isNetworkError()`
172
+ - `isClientError()`
173
+ - `isServerError()`
596
174
 
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
175
+ ### ConfigError
176
+ Configuration errors.
611
177
 
612
178
  ### 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
- ```
179
+ Widget errors.
669
180
 
670
181
  ---
671
182
 
672
- ## 📚 TypeScript Definitions
183
+ ## Utilities
673
184
 
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
- ```
185
+ - `generateId(prefix?)`
186
+ - `deepMerge(target, source)`
187
+ - `debounce(func, wait)`
188
+ - `throttle(func, limit)`
189
+ - `isValidEmail(email)`
190
+ - `isMobile()`
191
+ - `formatFileSize(bytes)`
192
+ - `delay(ms)`