@product7/product7-js 0.3.1 → 0.3.4

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
@@ -8,40 +8,95 @@
8
8
  new Product7(config);
9
9
  ```
10
10
 
11
- **Config Options:**
12
-
13
- | Option | Type | Required | Default | Description |
14
- | -------------- | ------- | -------- | ---------------- | --------------------- |
15
- | `workspace` | String | Yes | - | Workspace identifier |
16
- | `metadata` | Object | Yes | - | User identification |
17
- | `apiUrl` | String | No | Auto | Custom API endpoint |
18
- | `boardName` | 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 |
11
+ ### Config Options
23
12
 
24
- ### Methods
13
+ | Option | Type | Required | Default | Description |
14
+ | ----------- | --------- | -------- | ----------- | ------------------------------ |
15
+ | `workspace` | `string` | Yes | - | Workspace identifier |
16
+ | `boardName` | `string` | No | `'general'` | Default feedback board |
17
+ | `apiUrl` | `string` | No | Auto | Custom API endpoint |
18
+ | `theme` | `string` | No | `'light'` | Default widget theme |
19
+ | `position` | `string` | No | `'right'` | Default widget position |
20
+ | `debug` | `boolean` | No | `false` | Enable debug logging |
21
+ | `mock` | `boolean` | No | `false` | Use mock responses |
22
+ | `metadata` | `object` | No | `null` | Optional legacy identify input |
23
+
24
+ ### Lifecycle
25
25
 
26
26
  #### `async init(): Promise<Object>`
27
27
 
28
- Initialize SDK and create session.
28
+ Initializes the SDK session for the configured workspace.
29
+
30
+ ```javascript
31
+ await sdk.init();
32
+ ```
33
+
34
+ #### `async identify(metadata): Promise<Object>`
35
+
36
+ Associates the current session with a user after `init()`.
37
+
38
+ ```javascript
39
+ await sdk.identify({
40
+ user_id: 'user_123',
41
+ email: 'user@example.com',
42
+ name: 'Jane Doe',
43
+ });
44
+ ```
45
+
46
+ #### `destroy(): void`
47
+
48
+ Destroys widgets, clears the session, and tears down event listeners.
49
+
50
+ ### Widget Factory Methods
51
+
52
+ #### `createFeedbackWidget(options?): FeedbackWidget`
53
+
54
+ Creates the feedback widget.
55
+
56
+ ```javascript
57
+ const widget = sdk.createFeedbackWidget({
58
+ position: 'bottom-right',
59
+ headless: true,
60
+ });
61
+ ```
62
+
63
+ #### `createMessengerWidget(options?): MessengerWidget`
64
+
65
+ Creates the messenger widget.
66
+
67
+ #### `createChangelogWidget(options?): ChangelogWidget`
68
+
69
+ Creates the changelog widget.
70
+
71
+ #### `createSurveyWidget(options?): SurveyWidget`
72
+
73
+ Creates the survey widget.
29
74
 
30
75
  #### `createWidget(type, options?): Widget`
31
76
 
32
- Create widget. Type: `'button'`.
77
+ Low-level factory for advanced usage. Supported types include:
78
+
79
+ - `'feedback'`
80
+ - `'button'` (legacy alias for feedback)
81
+ - `'messenger'`
82
+ - `'survey'`
83
+ - `'changelog'`
84
+ - `'inline'`
85
+ - `'tab'`
86
+
87
+ ### Other Instance Methods
33
88
 
34
89
  #### `getWidget(id): Widget | undefined`
35
90
 
36
- Get widget by ID.
91
+ Get a widget by ID.
37
92
 
38
- #### `getAllWidgets(): Array<Widget>`
93
+ #### `getAllWidgets(): Widget[]`
39
94
 
40
- Get all widgets.
95
+ Get all widgets created by this SDK instance.
41
96
 
42
- #### `destroyWidget(id): Boolean`
97
+ #### `destroyWidget(id): boolean`
43
98
 
44
- Destroy widget by ID.
99
+ Destroy a single widget by ID.
45
100
 
46
101
  #### `destroyAllWidgets(): void`
47
102
 
@@ -49,96 +104,174 @@ Destroy all widgets.
49
104
 
50
105
  #### `updateConfig(config): void`
51
106
 
52
- Update configuration.
107
+ Update SDK config and propagate the change to mounted widgets.
53
108
 
54
109
  #### `setMetadata(metadata): void`
55
110
 
56
- Update user context.
111
+ Update stored metadata locally. This does not replace `identify()`.
57
112
 
58
113
  #### `getMetadata(): Object | null`
59
114
 
60
- Get current user context.
115
+ Get the currently stored metadata.
61
116
 
62
117
  #### `async reinitialize(metadata?): Promise<Object>`
63
118
 
64
- Reinitialize with new user.
65
-
66
- #### `on(event, callback): Product7`
119
+ Clear the current session and initialize again. If metadata is passed, it will be stored and automatically identified after the new session is created.
67
120
 
68
- Subscribe to event.
121
+ #### `async getActiveSurveys(context?): Promise<Array>`
69
122
 
70
- #### `off(event, callback): Product7`
123
+ Fetch active surveys for the current session.
71
124
 
72
- Unsubscribe from event.
125
+ #### `async showSurveyById(surveyId, options?): Promise<SurveyWidget | null>`
73
126
 
74
- #### `once(event, callback): Product7`
127
+ Find and display a survey by ID.
75
128
 
76
- Subscribe once.
129
+ #### `showSurvey(options?): SurveyWidget | null`
77
130
 
78
- #### `destroy(): void`
131
+ Render a survey directly from options.
79
132
 
80
- Destroy SDK.
133
+ #### `showChangelog(options?): ChangelogWidget | null`
81
134
 
82
- ### Static Methods
135
+ Create, mount, and show a changelog widget.
83
136
 
84
- #### `Product7.create(config): Product7`
137
+ #### `async getChangelogs(options?): Promise<Array>`
85
138
 
86
- Create SDK instance.
139
+ Fetch changelog items.
87
140
 
88
- #### `async Product7.createAndInit(config): Promise<Product7>`
141
+ #### `on(event, callback): Product7`
89
142
 
90
- Create and initialize.
143
+ Subscribe to an SDK event.
91
144
 
92
- #### `Product7.extractMetadataFromAuth(authData): Object`
145
+ #### `off(event, callback): Product7`
93
146
 
94
- Extract user context from auth.
147
+ Unsubscribe from an SDK event.
95
148
 
96
- ---
149
+ #### `once(event, callback): Product7`
97
150
 
98
- ## Widget
151
+ Subscribe to an event once.
99
152
 
100
- ### ButtonWidget
153
+ ---
101
154
 
102
- #### Methods
155
+ ## FeedbackWidget
103
156
 
104
- ##### `mount(container?): Widget`
157
+ Created by `sdk.createFeedbackWidget()` or `sdk.createWidget('feedback', ...)`.
105
158
 
106
- Mount to DOM.
159
+ ### Methods
107
160
 
108
- ##### `show(): Widget`
161
+ - `mount(container?): this`
162
+ - `destroy(): void`
163
+ - `show(): this`
164
+ - `hide(): this`
165
+ - `open(): this`
166
+ - `close(): this`
167
+ - `toggle(): this`
168
+ - `openPanel(): void`
169
+ - `closePanel(): void`
170
+ - `openModal(): void`
171
+ - `closeModal(): void`
172
+ - `updateText(text): void`
173
+ - `updatePosition(position): void`
174
+
175
+ ### Common Options
176
+
177
+ - `boardName`
178
+ - `position`
179
+ - `theme`
180
+ - `displayMode`
181
+ - `headless`
182
+ - `trigger`
183
+ - `primaryColor`
184
+ - `backgroundColor`
185
+ - `textColor`
109
186
 
110
- Show widget.
187
+ ---
111
188
 
112
- ##### `hide(): Widget`
189
+ ## MessengerWidget
113
190
 
114
- Hide widget.
191
+ Created by `sdk.createMessengerWidget()`.
115
192
 
116
- ##### `openPanel(): void`
193
+ ### Methods
117
194
 
118
- Open feedback panel.
195
+ - `mount(container?): this`
196
+ - `destroy(): void`
197
+ - `open(): void`
198
+ - `close(): void`
199
+ - `toggle(): void`
200
+ - `navigateTo(view): void`
201
+ - `setConversations(conversations): void`
202
+ - `setHelpArticles(articles): void`
203
+ - `setChangelogItems(items): void`
204
+ - `setHomeChangelogItems(items): void`
205
+ - `setUnreadCount(count): void`
206
+ - `loadInitialData(): Promise<void>`
207
+ - `checkAgentAvailability(): Promise<any>`
208
+ - `getState(): Object`
209
+
210
+ ### Common Options
211
+
212
+ - `position`
213
+ - `theme`
214
+ - `headless`
215
+ - `teamName`
216
+ - `teamAvatars`
217
+ - `welcomeMessage`
218
+ - `enableHelp`
219
+ - `enableChangelog`
220
+ - `primaryColor`
119
221
 
120
- ##### `closePanel(): void`
222
+ ---
121
223
 
122
- Close panel.
224
+ ## SurveyWidget
123
225
 
124
- ##### `updateText(text): void`
226
+ Created by `sdk.createSurveyWidget()`.
125
227
 
126
- Update button text.
228
+ ### Methods
127
229
 
128
- ##### `updatePosition(position): void`
230
+ - `mount(container?): this`
231
+ - `show(): this`
232
+ - `hide(): this`
233
+ - `open(): this`
234
+ - `close(): this`
235
+ - `toggle(): this`
236
+ - `destroy(): void`
237
+
238
+ ### Common Options
239
+
240
+ - `surveyId`
241
+ - `surveyType`
242
+ - `position`
243
+ - `theme`
244
+ - `title`
245
+ - `description`
246
+ - `ratingScale`
247
+ - `showFeedbackInput`
248
+ - `showSubmitButton`
249
+ - `autoSubmitOnSelect`
250
+ - `onSubmit`
251
+ - `onDismiss`
129
252
 
130
- Update position.
253
+ ---
131
254
 
132
- ##### `destroy(): void`
255
+ ## ChangelogWidget
133
256
 
134
- Destroy widget.
257
+ Created by `sdk.createChangelogWidget()`.
135
258
 
136
- #### Properties
259
+ ### Methods
137
260
 
138
- - `id: String` - Widget ID
139
- - `type: String` - Widget type
140
- - `mounted: Boolean` - Mount status
141
- - `state: Object` - Widget state
261
+ - `mount(container?): this`
262
+ - `destroy(): void`
263
+ - `open(): this`
264
+ - `close(): this`
265
+ - `toggle(): this`
266
+ - `openModal(): void`
267
+ - `closeModal(): void`
268
+ - `openSidebar(): void`
269
+ - `closeSidebar(): void`
270
+ - `hideBadge(): void`
271
+ - `showBadge(): void`
272
+ - `nextChangelog(): void`
273
+ - `prevChangelog(): void`
274
+ - `refresh(): Promise<void>`
142
275
 
143
276
  ---
144
277
 
@@ -146,23 +279,40 @@ Destroy widget.
146
279
 
147
280
  ### SDK Events
148
281
 
149
- - `sdk:initialized` - SDK ready
150
- - `sdk:error` - Error occurred
151
- - `sdk:destroyed` - SDK destroyed
152
- - `config:updated` - Config changed
153
- - `user:updated` - User changed
282
+ - `sdk:initialized`
283
+ - `sdk:identified`
284
+ - `sdk:error`
285
+ - `sdk:destroyed`
286
+ - `config:updated`
287
+ - `metadata:updated`
154
288
 
155
289
  ### Widget Events
156
290
 
157
- - `widget:created` - Widget created
158
- - `widget:mounted` - Widget mounted
159
- - `widget:destroyed` - Widget destroyed
160
- - `widgets:cleared` - All cleared
291
+ - `widget:created`
292
+ - `widget:mounted`
293
+ - `widget:destroyed`
294
+ - `widget:suppressed`
295
+ - `widgets:cleared`
161
296
 
162
297
  ### Feedback Events
163
298
 
164
- - `feedback:submitted` - Feedback sent
165
- - `feedback:error` - Submission failed
299
+ - `feedback:submitted`
300
+ - `feedback:error`
301
+
302
+ ### Messenger Events
303
+
304
+ - `messenger:opened`
305
+ - `messenger:closed`
306
+ - `messenger:messageSent`
307
+
308
+ ### Survey Events
309
+
310
+ - `survey:shown`
311
+ - `survey:submitted`
312
+ - `survey:dismissed`
313
+ - `survey:closed`
314
+ - `survey:questionAnswered`
315
+ - `survey:suppressed`
166
316
 
167
317
  ---
168
318
 
@@ -172,50 +322,64 @@ Access via `sdk.apiService`.
172
322
 
173
323
  ### Methods
174
324
 
175
- #### `async init(metadata?): Promise<Object>`
325
+ #### `async init(): Promise<Object>`
326
+
327
+ Initialize a workspace session.
328
+
329
+ #### `async identify(metadata): Promise<Object>`
176
330
 
177
- Initialize session.
331
+ Identify the current user for the active session.
178
332
 
179
333
  #### `async submitFeedback(data): Promise<Object>`
180
334
 
181
335
  Submit feedback.
182
336
 
183
- #### `isSessionValid(): Boolean`
337
+ #### `async getActiveSurveys(context?): Promise<Object>`
338
+
339
+ Fetch surveys.
340
+
341
+ #### `async submitSurveyResponse(surveyId, response): Promise<Object>`
184
342
 
185
- Check session validity.
343
+ Submit a survey response.
344
+
345
+ #### `isSessionValid(): boolean`
346
+
347
+ Check whether the current session token is still valid.
186
348
 
187
349
  #### `clearSession(): void`
188
350
 
189
- Clear session.
351
+ Clear the stored session and metadata.
190
352
 
191
353
  ---
192
354
 
193
355
  ## Error Classes
194
356
 
195
- ### SDKError
357
+ ### `SDKError`
196
358
 
197
- General SDK errors.
359
+ General SDK-level errors.
198
360
 
199
- ### APIError
361
+ ### `APIError`
200
362
 
201
- API errors with methods:
363
+ API errors. Helpful methods include:
202
364
 
203
365
  - `isNetworkError()`
204
366
  - `isClientError()`
205
367
  - `isServerError()`
206
368
 
207
- ### ConfigError
369
+ ### `ConfigError`
208
370
 
209
- Configuration errors.
371
+ Configuration and metadata validation errors.
210
372
 
211
- ### WidgetError
373
+ ### `WidgetError`
212
374
 
213
- Widget errors.
375
+ Widget-specific runtime errors.
214
376
 
215
377
  ---
216
378
 
217
379
  ## Utilities
218
380
 
381
+ Available helpers include:
382
+
219
383
  - `generateId(prefix?)`
220
384
  - `deepMerge(target, source)`
221
385
  - `debounce(func, wait)`