@product7/feedback-sdk 1.3.9 → 1.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@product7/feedback-sdk",
3
- "version": "1.3.9",
3
+ "version": "1.4.1",
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",
@@ -236,6 +236,10 @@ export class APIService extends BaseAPIService {
236
236
  return this.help.searchHelpArticles(query, options);
237
237
  }
238
238
 
239
+ async getChangelogs(options) {
240
+ return this.changelog.getChangelogs(options);
241
+ }
242
+
239
243
  _loadStoredSession() {
240
244
  if (typeof localStorage === 'undefined') return false;
241
245
 
@@ -124,6 +124,7 @@ export const feedbackStyles = `
124
124
  transform: translateX(calc(100% + 24px));
125
125
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
126
126
  font-family: inherit;
127
+ box-shadow: rgba(50, 50, 93, 0.25) 0px 2px 5px -1px, rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;
127
128
  }
128
129
 
129
130
  .feedback-panel.open {
@@ -136,7 +137,6 @@ export const feedbackStyles = `
136
137
  display: flex;
137
138
  flex-direction: column;
138
139
  border-radius: var(--radius-2xl);
139
- box-shadow: rgba(50, 50, 93, 0.25) 0px 2px 5px -1px, rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;
140
140
  }
141
141
 
142
142
  .feedback-panel-header {
@@ -0,0 +1,105 @@
1
+ export function applyMessengerCustomStyles(options = {}) {
2
+ const {
3
+ primaryColor = '#155EEF',
4
+ textColor = '#1d1d1f',
5
+ backgroundColor = '#ffffff',
6
+ theme = 'light',
7
+ } = options;
8
+
9
+ let styleElement = document.getElementById(
10
+ 'product7-messenger-custom-styles'
11
+ );
12
+
13
+ if (!styleElement) {
14
+ styleElement = document.createElement('style');
15
+ styleElement.id = 'product7-messenger-custom-styles';
16
+ document.head.appendChild(styleElement);
17
+ }
18
+
19
+ const adjustColor = (hex, percent, alpha = 1) => {
20
+ const num = parseInt(hex.replace('#', ''), 16);
21
+ const r = Math.max(0, Math.min(255, (num >> 16) + percent));
22
+ const g = Math.max(0, Math.min(255, ((num >> 8) & 0x00ff) + percent));
23
+ const b = Math.max(0, Math.min(255, (num & 0x0000ff) + percent));
24
+
25
+ if (alpha < 1) {
26
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
27
+ }
28
+
29
+ return '#' + ((r << 16) | (g << 8) | b).toString(16).padStart(6, '0');
30
+ };
31
+
32
+ styleElement.textContent = `
33
+ #product7-messenger-widget {
34
+ --color-primary: ${primaryColor} !important;
35
+ --color-primary-hover: ${adjustColor(primaryColor, -10)} !important;
36
+ }
37
+
38
+ .messenger-launcher-btn {
39
+ background: ${primaryColor} !important;
40
+ }
41
+
42
+ .messenger-launcher-btn:hover {
43
+ box-shadow: 0 8px 24px ${adjustColor(primaryColor, 0, 0.3)} !important;
44
+ }
45
+
46
+ .sdk-btn-primary {
47
+ background: ${primaryColor} !important;
48
+ border-color: ${primaryColor} !important;
49
+ }
50
+
51
+ .sdk-btn-primary:hover {
52
+ background: ${adjustColor(primaryColor, -10)} !important;
53
+ border-color: ${adjustColor(primaryColor, -10)} !important;
54
+ }
55
+
56
+ .messenger-compose-send {
57
+ background: ${primaryColor} !important;
58
+ }
59
+
60
+ .messenger-compose-send:hover:not(:disabled) {
61
+ background: ${adjustColor(primaryColor, -10)} !important;
62
+ }
63
+
64
+ .messenger-nav-tab.active .messenger-nav-icon,
65
+ .messenger-nav-tab.active .messenger-nav-label {
66
+ color: ${primaryColor} !important;
67
+ }
68
+
69
+ .messenger-home-view::before {
70
+ background: radial-gradient(circle, ${adjustColor(primaryColor, 0, 0.08)} 0%, transparent 70%) !important;
71
+ }
72
+
73
+ ${
74
+ backgroundColor !== '#ffffff'
75
+ ? `
76
+ .messenger-panel-content {
77
+ background: ${backgroundColor} !important;
78
+ }
79
+ `
80
+ : ''
81
+ }
82
+
83
+ ${
84
+ textColor !== '#1d1d1f'
85
+ ? `
86
+ .messenger-panel-content,
87
+ .messenger-view {
88
+ color: ${textColor} !important;
89
+ }
90
+ `
91
+ : ''
92
+ }
93
+ `;
94
+
95
+ console.log('✅ Custom messenger styles applied:', { primaryColor, theme });
96
+ }
97
+
98
+ export function removeMessengerCustomStyles() {
99
+ const styleElement = document.getElementById(
100
+ 'product7-messenger-custom-styles'
101
+ );
102
+ if (styleElement && styleElement.parentNode) {
103
+ styleElement.parentNode.removeChild(styleElement);
104
+ }
105
+ }
@@ -23,7 +23,7 @@ export const surveyStyles = `
23
23
  z-index: var(--z-modal);
24
24
  background: var(--color-white);
25
25
  border-radius: var(--radius-2xl);
26
- box-shadow: var(--shadow-2xl);
26
+ box-shadow: rgba(50, 50, 93, 0.25) 0px 2px 5px -1px, rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;
27
27
  padding: var(--spacing-6);
28
28
  min-width: 320px;
29
29
  max-width: 400px;
@@ -1,4 +1,8 @@
1
1
  import { WebSocketService } from '../core/WebSocketService.js';
2
+ import {
3
+ applyMessengerCustomStyles,
4
+ removeMessengerCustomStyles,
5
+ } from '../styles/messengerCustomStyles.js';
2
6
  import { BaseWidget } from './BaseWidget.js';
3
7
  import { MessengerState } from './messenger/MessengerState.js';
4
8
  import { MessengerLauncher } from './messenger/components/MessengerLauncher.js';
@@ -17,14 +21,16 @@ export class MessengerWidget extends BaseWidget {
17
21
  this.messengerOptions = {
18
22
  position: options.position || 'bottom-right',
19
23
  theme: options.theme || 'light',
24
+ primaryColor: options.primaryColor || '#155EEF',
25
+ textColor: options.textColor || '#1d1d1f',
26
+ backgroundColor: options.backgroundColor || '#ffffff',
27
+ logoUrl: options.logoUrl || 'https://product7.io/p7logo.svg',
20
28
  teamName: options.teamName || 'Support',
21
29
  teamAvatars: options.teamAvatars || [],
22
30
  welcomeMessage: options.welcomeMessage || 'How can we help?',
23
31
  enableHelp: options.enableHelp !== false,
24
32
  enableChangelog: options.enableChangelog !== false,
25
- logoUrl: options.logoUrl || 'https://product7.io/p7logo.svg',
26
33
  featuredContent: options.featuredContent || null,
27
- primaryColor: options.primaryColor || '#1c1c1e',
28
34
  onSendMessage: options.onSendMessage || null,
29
35
  onArticleClick: options.onArticleClick || null,
30
36
  onChangelogClick: options.onChangelogClick || null,
@@ -56,6 +62,13 @@ export class MessengerWidget extends BaseWidget {
56
62
  container.className = `messenger-widget theme-${this.messengerOptions.theme}`;
57
63
  container.style.zIndex = '999999';
58
64
 
65
+ applyMessengerCustomStyles({
66
+ primaryColor: this.messengerOptions.primaryColor,
67
+ textColor: this.messengerOptions.textColor,
68
+ backgroundColor: this.messengerOptions.backgroundColor,
69
+ theme: this.messengerOptions.theme,
70
+ });
71
+
59
72
  this.launcher = new MessengerLauncher(this.messengerState, {
60
73
  position: this.messengerOptions.position,
61
74
  primaryColor: this.messengerOptions.primaryColor,
@@ -529,15 +542,14 @@ export class MessengerWidget extends BaseWidget {
529
542
  async _fetchHelpArticles() {
530
543
  try {
531
544
  const response = await this.apiService.getHelpCollections();
532
- if (response.status && response.data) {
533
- return response.data.map((collection) => ({
545
+ if (response.success && response.data) {
546
+ const collections = response.data.collections || response.data;
547
+ return collections.map((collection) => ({
534
548
  id: collection.id,
535
- title: collection.title || collection.name,
549
+ title: collection.title,
536
550
  description: collection.description || '',
537
- articleCount:
538
- collection.article_count || collection.articleCount || 0,
539
- icon: collection.icon || 'ph-book-open',
540
- url: collection.url || `#/help/${collection.slug || collection.id}`,
551
+ articleCount: collection.article_count || 0,
552
+ url: collection.url_slug ? `/help/${collection.url_slug}` : null,
541
553
  }));
542
554
  }
543
555
  return [];
@@ -681,8 +693,7 @@ export class MessengerWidget extends BaseWidget {
681
693
  'Connect with more tools you love and streamline your workflow.',
682
694
  tags: ['Integration'],
683
695
  coverImage:
684
- 'https://images.unsplash.com/photo-1674027444485-cec3da58eef4?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8M3x8YWl8ZW58MHx8MHx8fDA%3D',
685
- coverText: null,
696
+ 'https://images.unsplash.com/photo-1674027444485-cec3da58eef4?w=500&auto=format&fit=crop&q=60',
686
697
  publishedAt: new Date(
687
698
  Date.now() - 14 * 24 * 60 * 60 * 1000
688
699
  ).toISOString(),
@@ -695,8 +706,7 @@ export class MessengerWidget extends BaseWidget {
695
706
  'We announced Fin Insights, a groundbreaking, AI-powered product that gives you complete visibility into every customer conversation.',
696
707
  tags: ['New feature', 'AI'],
697
708
  coverImage:
698
- 'https://images.unsplash.com/photo-1666875753105-c63a6f3bdc86?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTJ8fGluc2lnaHRzfGVufDB8fDB8fHww',
699
- coverText: 'Watch our major product launch on-demand',
709
+ 'https://images.unsplash.com/photo-1666875753105-c63a6f3bdc86?w=500&auto=format&fit=crop&q=60',
700
710
  publishedAt: new Date(
701
711
  Date.now() - 5 * 24 * 60 * 60 * 1000
702
712
  ).toISOString(),
@@ -709,8 +719,7 @@ export class MessengerWidget extends BaseWidget {
709
719
  'Learn how AI has transformed customer service from the ground up—rewriting its economics and reshaping expectations.',
710
720
  tags: ['Report'],
711
721
  coverImage:
712
- 'https://images.unsplash.com/photo-1762330467475-a565d04e1808?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8N3x8YWklMjBjdXN0b21lciUyMHNlcnZpY2V8ZW58MHx8MHx8fDA%3D',
713
- coverText: 'Customer service trends as we know them are dead.',
722
+ 'https://images.unsplash.com/photo-1762330467475-a565d04e1808?w=500&auto=format&fit=crop&q=60',
714
723
  publishedAt: new Date(
715
724
  Date.now() - 2 * 24 * 60 * 60 * 1000
716
725
  ).toISOString(),
@@ -725,8 +734,7 @@ export class MessengerWidget extends BaseWidget {
725
734
  'Get deeper insights into your customer conversations with our new analytics dashboard.',
726
735
  tags: ['Analytics'],
727
736
  coverImage:
728
- 'https://images.unsplash.com/photo-1523961131990-5ea7c61b2107?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTJ8fGFuYWx5dGljc3xlbnwwfHwwfHx8MA%3D%3D',
729
- coverText: null,
737
+ 'https://images.unsplash.com/photo-1523961131990-5ea7c61b2107?w=500&auto=format&fit=crop&q=60',
730
738
  publishedAt: new Date(
731
739
  Date.now() - 10 * 24 * 60 * 60 * 1000
732
740
  ).toISOString(),
@@ -739,8 +747,7 @@ export class MessengerWidget extends BaseWidget {
739
747
  'New AI-powered escalation guidance helps your team handle complex customer issues more effectively.',
740
748
  tags: ['New feature', 'AI'],
741
749
  coverImage:
742
- 'https://images.unsplash.com/photo-1764773516703-b246ac2ad5ef?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8M3x8Y29tcGxleCUyMGlzc3Vlc3xlbnwwfHwwfHx8MA%3D%3D',
743
- coverText: null,
750
+ 'https://images.unsplash.com/photo-1764773516703-b246ac2ad5ef?w=500&auto=format&fit=crop&q=60',
744
751
  publishedAt: new Date(
745
752
  Date.now() - 7 * 24 * 60 * 60 * 1000
746
753
  ).toISOString(),
@@ -750,24 +757,33 @@ export class MessengerWidget extends BaseWidget {
750
757
  };
751
758
  }
752
759
 
753
- const response = await this.apiService.getChangelogs({ limit: 20 });
754
- const changelogs = response.data || [];
760
+ try {
761
+ const response = await this.apiService.getChangelogs({ limit: 20 });
762
+
763
+ if (response.success && response.data) {
764
+ const changelogs = Array.isArray(response.data) ? response.data : [];
765
+
766
+ const mappedItems = changelogs.map((item) => ({
767
+ id: item.id,
768
+ title: item.title,
769
+ description: item.excerpt || item.description || '',
770
+ tags: item.labels ? item.labels.map((label) => label.name) : [],
771
+ coverImage: item.cover_image || null,
772
+ publishedAt: item.published_at,
773
+ url: item.slug ? `/changelog/${item.slug}` : null,
774
+ }));
755
775
 
756
- const mappedItems = changelogs.map((item) => ({
757
- id: item.id,
758
- title: item.title,
759
- description: item.excerpt || item.description || '',
760
- tags: item.labels ? item.labels.map((label) => label.name) : [],
761
- coverImage: item.cover_image || null,
762
- coverText: null,
763
- publishedAt: item.published_at,
764
- url: item.slug ? `/changelog/${item.slug}` : '#',
765
- }));
776
+ return {
777
+ homeItems: mappedItems.slice(0, 3),
778
+ changelogItems: mappedItems,
779
+ };
780
+ }
766
781
 
767
- return {
768
- homeItems: mappedItems.slice(0, 3),
769
- changelogItems: mappedItems,
770
- };
782
+ return { homeItems: [], changelogItems: [] };
783
+ } catch (error) {
784
+ console.error('[MessengerWidget] Failed to fetch changelog:', error);
785
+ return { homeItems: [], changelogItems: [] };
786
+ }
771
787
  }
772
788
 
773
789
  async onMount() {
@@ -802,6 +818,8 @@ export class MessengerWidget extends BaseWidget {
802
818
  }
803
819
 
804
820
  destroy() {
821
+ removeMessengerCustomStyles();
822
+
805
823
  if (this.launcher) {
806
824
  this.launcher.destroy();
807
825
  }