@product7/feedback-sdk 1.4.0 → 1.4.2

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.4.0",
3
+ "version": "1.4.2",
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",
@@ -237,7 +237,7 @@ export class APIService extends BaseAPIService {
237
237
  }
238
238
 
239
239
  async getChangelogs(options) {
240
- return this.changelog.getChangelogs(options);
240
+ return this.changelog.getChangelogs(options);
241
241
  }
242
242
 
243
243
  _loadStoredSession() {
@@ -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
+ }
@@ -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,
@@ -526,25 +539,25 @@ export class MessengerWidget extends BaseWidget {
526
539
  }
527
540
  }
528
541
 
529
- async _fetchHelpArticles() {
530
- try {
531
- const response = await this.apiService.getHelpCollections();
532
- if (response.success && response.data) {
533
- const collections = response.data.collections || response.data;
534
- return collections.map((collection) => ({
535
- id: collection.id,
536
- title: collection.title,
537
- description: collection.description || '',
538
- articleCount: collection.article_count || 0,
539
- url: collection.url_slug ? `/help/${collection.url_slug}` : null,
540
- }));
541
- }
542
- return [];
543
- } catch (error) {
544
- console.error('[MessengerWidget] Failed to fetch help articles:', error);
545
- return [];
546
- }
547
- }
542
+ async _fetchHelpArticles() {
543
+ try {
544
+ const response = await this.apiService.getHelpCollections();
545
+ if (response.success && response.data) {
546
+ const collections = response.data.collections || response.data;
547
+ return collections.map((collection) => ({
548
+ id: collection.id,
549
+ title: collection.title,
550
+ description: collection.description || '',
551
+ articleCount: collection.article_count || 0,
552
+ url: collection.url_slug ? `/help-docs/${collection.url_slug}` : null,
553
+ }));
554
+ }
555
+ return [];
556
+ } catch (error) {
557
+ console.error('[MessengerWidget] Failed to fetch help articles:', error);
558
+ return [];
559
+ }
560
+ }
548
561
 
549
562
  async fetchMessages(conversationId) {
550
563
  try {
@@ -669,89 +682,109 @@ async _fetchHelpArticles() {
669
682
  }
670
683
  }
671
684
 
672
- async _fetchChangelog() {
673
- if (this.apiService?.mock) {
674
- return {
675
- homeItems: [
676
- {
677
- id: 'changelog_5',
678
- title: 'New integrations available',
679
- description: 'Connect with more tools you love and streamline your workflow.',
680
- tags: ['Integration'],
681
- coverImage: 'https://images.unsplash.com/photo-1674027444485-cec3da58eef4?w=500&auto=format&fit=crop&q=60',
682
- publishedAt: new Date(Date.now() - 14 * 24 * 60 * 60 * 1000).toISOString(),
683
- url: '#',
684
- },
685
- {
686
- id: 'changelog_2',
687
- title: 'A new era of Insights has arrived',
688
- description: 'We announced Fin Insights, a groundbreaking, AI-powered product that gives you complete visibility into every customer conversation.',
689
- tags: ['New feature', 'AI'],
690
- coverImage: 'https://images.unsplash.com/photo-1666875753105-c63a6f3bdc86?w=500&auto=format&fit=crop&q=60',
691
- publishedAt: new Date(Date.now() - 5 * 24 * 60 * 60 * 1000).toISOString(),
692
- url: '#',
693
- },
694
- {
695
- id: 'changelog_1',
696
- title: 'The 2025 Customer Service Transformation Report',
697
- description: 'Learn how AI has transformed customer service from the ground up—rewriting its economics and reshaping expectations.',
698
- tags: ['Report'],
699
- coverImage: 'https://images.unsplash.com/photo-1762330467475-a565d04e1808?w=500&auto=format&fit=crop&q=60',
700
- publishedAt: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString(),
701
- url: '#',
702
- },
703
- ],
704
- changelogItems: [
705
- {
706
- id: 'changelog_4',
707
- title: 'Enhanced conversation analytics',
708
- description: 'Get deeper insights into your customer conversations with our new analytics dashboard.',
709
- tags: ['Analytics'],
710
- coverImage: 'https://images.unsplash.com/photo-1523961131990-5ea7c61b2107?w=500&auto=format&fit=crop&q=60',
711
- publishedAt: new Date(Date.now() - 10 * 24 * 60 * 60 * 1000).toISOString(),
712
- url: '#',
713
- },
714
- {
715
- id: 'changelog_3',
716
- title: 'Escalation guidance for complex issues',
717
- description: 'New AI-powered escalation guidance helps your team handle complex customer issues more effectively.',
718
- tags: ['New feature', 'AI'],
719
- coverImage: 'https://images.unsplash.com/photo-1764773516703-b246ac2ad5ef?w=500&auto=format&fit=crop&q=60',
720
- publishedAt: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(),
721
- url: '#',
722
- },
723
- ],
724
- };
725
- }
726
-
727
- try {
728
- const response = await this.apiService.getChangelogs({ limit: 20 });
729
-
730
- if (response.success && response.data) {
731
- const changelogs = Array.isArray(response.data) ? response.data : [];
732
-
733
- const mappedItems = changelogs.map((item) => ({
734
- id: item.id,
735
- title: item.title,
736
- description: item.excerpt || item.description || '',
737
- tags: item.labels ? item.labels.map((label) => label.name) : [],
738
- coverImage: item.cover_image || null,
739
- publishedAt: item.published_at,
740
- url: item.slug ? `/changelog/${item.slug}` : null,
741
- }));
742
-
743
- return {
744
- homeItems: mappedItems.slice(0, 3),
745
- changelogItems: mappedItems,
746
- };
747
- }
748
-
749
- return { homeItems: [], changelogItems: [] };
750
- } catch (error) {
751
- console.error('[MessengerWidget] Failed to fetch changelog:', error);
752
- return { homeItems: [], changelogItems: [] };
753
- }
754
- }
685
+ async _fetchChangelog() {
686
+ if (this.apiService?.mock) {
687
+ return {
688
+ homeItems: [
689
+ {
690
+ id: 'changelog_5',
691
+ title: 'New integrations available',
692
+ description:
693
+ 'Connect with more tools you love and streamline your workflow.',
694
+ tags: ['Integration'],
695
+ coverImage:
696
+ 'https://images.unsplash.com/photo-1674027444485-cec3da58eef4?w=500&auto=format&fit=crop&q=60',
697
+ publishedAt: new Date(
698
+ Date.now() - 14 * 24 * 60 * 60 * 1000
699
+ ).toISOString(),
700
+ url: '#',
701
+ },
702
+ {
703
+ id: 'changelog_2',
704
+ title: 'A new era of Insights has arrived',
705
+ description:
706
+ 'We announced Fin Insights, a groundbreaking, AI-powered product that gives you complete visibility into every customer conversation.',
707
+ tags: ['New feature', 'AI'],
708
+ coverImage:
709
+ 'https://images.unsplash.com/photo-1666875753105-c63a6f3bdc86?w=500&auto=format&fit=crop&q=60',
710
+ publishedAt: new Date(
711
+ Date.now() - 5 * 24 * 60 * 60 * 1000
712
+ ).toISOString(),
713
+ url: '#',
714
+ },
715
+ {
716
+ id: 'changelog_1',
717
+ title: 'The 2025 Customer Service Transformation Report',
718
+ description:
719
+ 'Learn how AI has transformed customer service from the ground up—rewriting its economics and reshaping expectations.',
720
+ tags: ['Report'],
721
+ coverImage:
722
+ 'https://images.unsplash.com/photo-1762330467475-a565d04e1808?w=500&auto=format&fit=crop&q=60',
723
+ publishedAt: new Date(
724
+ Date.now() - 2 * 24 * 60 * 60 * 1000
725
+ ).toISOString(),
726
+ url: '#',
727
+ },
728
+ ],
729
+ changelogItems: [
730
+ {
731
+ id: 'changelog_4',
732
+ title: 'Enhanced conversation analytics',
733
+ description:
734
+ 'Get deeper insights into your customer conversations with our new analytics dashboard.',
735
+ tags: ['Analytics'],
736
+ coverImage:
737
+ 'https://images.unsplash.com/photo-1523961131990-5ea7c61b2107?w=500&auto=format&fit=crop&q=60',
738
+ publishedAt: new Date(
739
+ Date.now() - 10 * 24 * 60 * 60 * 1000
740
+ ).toISOString(),
741
+ url: '#',
742
+ },
743
+ {
744
+ id: 'changelog_3',
745
+ title: 'Escalation guidance for complex issues',
746
+ description:
747
+ 'New AI-powered escalation guidance helps your team handle complex customer issues more effectively.',
748
+ tags: ['New feature', 'AI'],
749
+ coverImage:
750
+ 'https://images.unsplash.com/photo-1764773516703-b246ac2ad5ef?w=500&auto=format&fit=crop&q=60',
751
+ publishedAt: new Date(
752
+ Date.now() - 7 * 24 * 60 * 60 * 1000
753
+ ).toISOString(),
754
+ url: '#',
755
+ },
756
+ ],
757
+ };
758
+ }
759
+
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
+ }));
775
+
776
+ return {
777
+ homeItems: mappedItems.slice(0, 3),
778
+ changelogItems: mappedItems,
779
+ };
780
+ }
781
+
782
+ return { homeItems: [], changelogItems: [] };
783
+ } catch (error) {
784
+ console.error('[MessengerWidget] Failed to fetch changelog:', error);
785
+ return { homeItems: [], changelogItems: [] };
786
+ }
787
+ }
755
788
 
756
789
  async onMount() {
757
790
  this.loadInitialData();
@@ -785,6 +818,8 @@ async _fetchChangelog() {
785
818
  }
786
819
 
787
820
  destroy() {
821
+ removeMessengerCustomStyles();
822
+
788
823
  if (this.launcher) {
789
824
  this.launcher.destroy();
790
825
  }