@product7/feedback-sdk 1.6.5 → 1.6.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@product7/feedback-sdk",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
4
4
  "description": "JavaScript SDK for integrating Product7 feedback widgets into any website",
5
5
  "main": "dist/feedback-sdk.js",
6
6
  "module": "src/index.js",
@@ -18,6 +18,11 @@ export class MessengerWidget extends BaseWidget {
18
18
  constructor(options) {
19
19
  super({ ...options, type: 'messenger' });
20
20
 
21
+ const resolvedEnableChangelog =
22
+ typeof options.enableChangelog === 'boolean'
23
+ ? options.enableChangelog
24
+ : options.enableNews !== false;
25
+
21
26
  this.messengerOptions = {
22
27
  position: options.position || 'bottom-right',
23
28
  theme: options.theme || 'light',
@@ -30,7 +35,10 @@ export class MessengerWidget extends BaseWidget {
30
35
  greetingMessage: options.greetingMessage || 'Hi there 👋',
31
36
  welcomeMessage: options.welcomeMessage || 'How can we help?',
32
37
  enableHelp: options.enableHelp !== false,
33
- enableChangelog: options.enableChangelog !== false,
38
+ enableChangelog: resolvedEnableChangelog,
39
+ autoLoadData: options.autoLoadData !== false,
40
+ initialView: options.initialView || 'home',
41
+ previewData: options.previewData || null,
34
42
  featuredContent: options.featuredContent || null,
35
43
  feedbackUrl: options.feedbackUrl || null,
36
44
  changelogUrl: options.changelogUrl || null,
@@ -498,6 +506,51 @@ export class MessengerWidget extends BaseWidget {
498
506
  };
499
507
  }
500
508
 
509
+ _applyPreviewData() {
510
+ const data = this.messengerOptions.previewData;
511
+ if (!data || typeof data !== 'object') {
512
+ return;
513
+ }
514
+
515
+ if (Array.isArray(data.conversations)) {
516
+ this.messengerState.setConversations(data.conversations);
517
+ }
518
+
519
+ if (Array.isArray(data.helpArticles)) {
520
+ this.messengerState.setHelpArticles(data.helpArticles);
521
+ }
522
+
523
+ if (Array.isArray(data.homeChangelogItems)) {
524
+ this.messengerState.setHomeChangelogItems(data.homeChangelogItems);
525
+ }
526
+
527
+ if (Array.isArray(data.changelogItems)) {
528
+ this.messengerState.setChangelogItems(data.changelogItems);
529
+ }
530
+
531
+ if (typeof data.unreadCount === 'number') {
532
+ this.setUnreadCount(data.unreadCount);
533
+ }
534
+
535
+ if (data.availability && typeof data.availability === 'object') {
536
+ const availability = data.availability;
537
+ this.messengerState.agentsOnline = Boolean(
538
+ availability.agentsOnline ?? availability.agents_online
539
+ );
540
+ this.messengerState.onlineCount =
541
+ availability.onlineCount ?? availability.online_count ?? 0;
542
+ this.messengerState.responseTime =
543
+ availability.responseTime ??
544
+ availability.response_time ??
545
+ this.messengerState.responseTime;
546
+ this.messengerState._notify('availabilityUpdate', availability);
547
+ }
548
+
549
+ if (typeof data.currentView === 'string') {
550
+ this.messengerState.setView(data.currentView);
551
+ }
552
+ }
553
+
501
554
  async loadInitialData() {
502
555
  try {
503
556
  const conversations = await this._fetchConversations();
@@ -824,17 +877,28 @@ export class MessengerWidget extends BaseWidget {
824
877
  }
825
878
 
826
879
  async onMount() {
827
- this.loadInitialData();
880
+ this._applyPreviewData();
828
881
 
829
- if (this.apiService?.sessionToken) {
830
- this._initWebSocket();
831
- }
882
+ if (this.messengerOptions.autoLoadData) {
883
+ this.loadInitialData();
832
884
 
833
- this.checkAgentAvailability();
885
+ if (this.apiService?.sessionToken) {
886
+ this._initWebSocket();
887
+ }
834
888
 
835
- this._availabilityInterval = setInterval(() => {
836
889
  this.checkAgentAvailability();
837
- }, 60000);
890
+
891
+ this._availabilityInterval = setInterval(() => {
892
+ this.checkAgentAvailability();
893
+ }, 60000);
894
+ }
895
+
896
+ if (
897
+ this.messengerOptions.initialView &&
898
+ this.messengerOptions.initialView !== this.messengerState.currentView
899
+ ) {
900
+ this.messengerState.setView(this.messengerOptions.initialView);
901
+ }
838
902
  }
839
903
 
840
904
  onDestroy() {
package/types/index.d.ts CHANGED
@@ -4,10 +4,14 @@ declare module '@product7/feedback-sdk' {
4
4
  userContext?: UserContext;
5
5
  debug?: boolean;
6
6
  boardId?: string;
7
+ siteId?: string;
8
+ sessionToken?: string;
7
9
  position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
8
10
  theme?: 'light' | 'dark';
9
11
  apiUrl?: string;
10
12
  autoShow?: boolean;
13
+ mock?: boolean;
14
+ env?: string;
11
15
  widgets?: WidgetConfigMap;
12
16
  }
13
17
 
@@ -258,6 +262,25 @@ declare module '@product7/feedback-sdk' {
258
262
  welcomeMessage?: string;
259
263
  enableHelp?: boolean;
260
264
  enableChangelog?: boolean;
265
+ enableNews?: boolean;
266
+ autoLoadData?: boolean;
267
+ initialView?: 'home' | 'messages' | 'chat' | 'prechat' | 'help' | 'changelog';
268
+ previewData?: {
269
+ conversations?: any[];
270
+ helpArticles?: any[];
271
+ homeChangelogItems?: any[];
272
+ changelogItems?: any[];
273
+ unreadCount?: number;
274
+ currentView?: string;
275
+ availability?: {
276
+ agentsOnline?: boolean;
277
+ agents_online?: boolean;
278
+ onlineCount?: number;
279
+ online_count?: number;
280
+ responseTime?: string;
281
+ response_time?: string;
282
+ };
283
+ };
261
284
  logoUrl?: string;
262
285
  primaryColor?: string;
263
286
  featuredContent?: {