@product7/feedback-sdk 1.6.3 → 1.6.5

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.
@@ -2203,6 +2203,13 @@
2203
2203
  }
2204
2204
 
2205
2205
  _render() {
2206
+ const buttonText =
2207
+ this.options.buttonText ||
2208
+ this.options.triggerText ||
2209
+ this.options.label ||
2210
+ this.options.text ||
2211
+ 'Feedback';
2212
+
2206
2213
  const button = document.createElement('div');
2207
2214
  button.className = `feedback-widget-button position-${this.options.position}`;
2208
2215
  button.innerHTML = `
@@ -2210,7 +2217,7 @@
2210
2217
  <svg class="feedback-icon" width="20" height="20" viewBox="0 0 256 256" fill="currentColor">
2211
2218
  <path d="M216,80H184V48a16,16,0,0,0-16-16H40A16,16,0,0,0,24,48V176a8,8,0,0,0,13,6.22L72,154V184a16,16,0,0,0,16,16h93.59L219,230.22a8,8,0,0,0,5,1.78,8,8,0,0,0,8-8V96A16,16,0,0,0,216,80ZM66.55,137.78,40,159.25V48H168v88H71.58A8,8,0,0,0,66.55,137.78ZM216,207.25l-26.55-21.47a8,8,0,0,0-5-1.78H88V152h80a16,16,0,0,0,16-16V96h32Z"/>
2212
2219
  </svg>
2213
- <span class="feedback-text">Feedback</span>
2220
+ <span class="feedback-text">${buttonText}</span>
2214
2221
 
2215
2222
  <div class="feedback-minimize-icon">
2216
2223
  <svg viewBox="0 0 256 256">
@@ -3455,6 +3462,7 @@
3455
3462
 
3456
3463
  this.teamName = options.teamName || 'Support';
3457
3464
  this.teamAvatars = options.teamAvatars || [];
3465
+ this.greetingMessage = options.greetingMessage || 'Hi there 👋';
3458
3466
  this.welcomeMessage = options.welcomeMessage || 'How can we help?';
3459
3467
 
3460
3468
  this.userContext = options.userContext || null;
@@ -5392,7 +5400,7 @@
5392
5400
  </button>
5393
5401
  </div>
5394
5402
  <div class="messenger-home-welcome">
5395
- <span class="messenger-home-greeting">Hi there 👋</span>
5403
+ <span class="messenger-home-greeting">${this.state.greetingMessage}</span>
5396
5404
  <span class="messenger-home-question">${this.state.welcomeMessage}</span>
5397
5405
  </div>
5398
5406
  </div>
@@ -5903,6 +5911,7 @@
5903
5911
  logoUrl: options.logoUrl || 'https://product7.io/p7logo.svg',
5904
5912
  teamName: options.teamName || 'Support',
5905
5913
  teamAvatars: options.teamAvatars || [],
5914
+ greetingMessage: options.greetingMessage || 'Hi there 👋',
5906
5915
  welcomeMessage: options.welcomeMessage || 'How can we help?',
5907
5916
  enableHelp: options.enableHelp !== false,
5908
5917
  enableChangelog: options.enableChangelog !== false,
@@ -5920,6 +5929,7 @@
5920
5929
  this.messengerState = new MessengerState({
5921
5930
  teamName: this.messengerOptions.teamName,
5922
5931
  teamAvatars: this.messengerOptions.teamAvatars,
5932
+ greetingMessage: this.messengerOptions.greetingMessage,
5923
5933
  welcomeMessage: this.messengerOptions.welcomeMessage,
5924
5934
  enableHelp: this.messengerOptions.enableHelp,
5925
5935
  enableChangelog: this.messengerOptions.enableChangelog,
@@ -8084,12 +8094,15 @@
8084
8094
  }
8085
8095
 
8086
8096
  const widgetId = generateId('widget');
8097
+ const widgetConfig = this._getWidgetTypeConfig(type);
8098
+ const explicitOptions = this._omitUndefined(options);
8087
8099
  const widgetOptions = {
8088
8100
  id: widgetId,
8089
8101
  sdk: this,
8090
8102
  apiService: this.apiService,
8091
8103
  ...this.config,
8092
- ...options,
8104
+ ...widgetConfig,
8105
+ ...explicitOptions,
8093
8106
  };
8094
8107
 
8095
8108
  try {
@@ -8201,13 +8214,22 @@
8201
8214
  }
8202
8215
 
8203
8216
  const normalizedOptions = this._normalizeSurveyConfig(options);
8217
+ const surveyConfigDefaults = this._getWidgetTypeConfig('survey');
8204
8218
 
8205
8219
  const surveyWidget = this.createWidget('survey', {
8206
8220
  surveyId: normalizedOptions.surveyId,
8207
8221
  surveyType:
8208
8222
  normalizedOptions.surveyType || normalizedOptions.type || 'nps',
8209
- position: normalizedOptions.position || 'bottom-right',
8210
- theme: normalizedOptions.theme || this.config.theme || 'light',
8223
+ position:
8224
+ normalizedOptions.position ??
8225
+ surveyConfigDefaults.position ??
8226
+ this.config.position ??
8227
+ 'bottom-right',
8228
+ theme:
8229
+ normalizedOptions.theme ??
8230
+ surveyConfigDefaults.theme ??
8231
+ this.config.theme ??
8232
+ 'light',
8211
8233
  title: normalizedOptions.title,
8212
8234
  description: normalizedOptions.description,
8213
8235
  lowLabel: normalizedOptions.lowLabel,
@@ -8410,6 +8432,58 @@
8410
8432
  return null;
8411
8433
  }
8412
8434
 
8435
+ _getWidgetTypeConfig(type) {
8436
+ const widgetsConfig = this._isPlainObject(this.config?.widgets)
8437
+ ? this.config.widgets
8438
+ : {};
8439
+
8440
+ const legacyTypeConfig = this._isPlainObject(this.config?.[type])
8441
+ ? this.config[type]
8442
+ : {};
8443
+
8444
+ const namespacedTypeConfig = this._isPlainObject(widgetsConfig?.[type])
8445
+ ? widgetsConfig[type]
8446
+ : {};
8447
+
8448
+ const mergedTypeConfig = deepMerge(legacyTypeConfig, namespacedTypeConfig);
8449
+ return this._toCamelCaseObject(mergedTypeConfig);
8450
+ }
8451
+
8452
+ _isPlainObject(value) {
8453
+ return Object.prototype.toString.call(value) === '[object Object]';
8454
+ }
8455
+
8456
+ _toCamelCaseKey(key) {
8457
+ return key.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
8458
+ }
8459
+
8460
+ _toCamelCaseObject(value) {
8461
+ if (Array.isArray(value)) {
8462
+ return value.map((item) => this._toCamelCaseObject(item));
8463
+ }
8464
+
8465
+ if (!this._isPlainObject(value)) {
8466
+ return value;
8467
+ }
8468
+
8469
+ const normalized = {};
8470
+ for (const [key, nestedValue] of Object.entries(value)) {
8471
+ normalized[this._toCamelCaseKey(key)] =
8472
+ this._toCamelCaseObject(nestedValue);
8473
+ }
8474
+ return normalized;
8475
+ }
8476
+
8477
+ _omitUndefined(value) {
8478
+ if (!this._isPlainObject(value)) {
8479
+ return value;
8480
+ }
8481
+
8482
+ return Object.fromEntries(
8483
+ Object.entries(value).filter(([, nestedValue]) => nestedValue !== undefined)
8484
+ );
8485
+ }
8486
+
8413
8487
  showChangelog(options = {}) {
8414
8488
  if (!this.initialized) {
8415
8489
  throw new SDKError(
@@ -8417,16 +8491,22 @@
8417
8491
  );
8418
8492
  }
8419
8493
 
8494
+ const defaults = {
8495
+ position: this.config.position || 'bottom-right',
8496
+ theme: this.config.theme || 'light',
8497
+ title: "What's New",
8498
+ triggerText: "What's New",
8499
+ showBadge: true,
8500
+ viewButtonText: 'View Update',
8501
+ };
8502
+
8503
+ const configDefaults = this._getWidgetTypeConfig('changelog');
8504
+ const explicitOptions = this._omitUndefined(options);
8505
+
8420
8506
  const changelogWidget = this.createWidget('changelog', {
8421
- position: options.position || 'bottom-right',
8422
- theme: options.theme || this.config.theme || 'light',
8423
- title: options.title || "What's New",
8424
- triggerText: options.triggerText || "What's New",
8425
- showBadge: options.showBadge !== false,
8426
- viewButtonText: options.viewButtonText || 'View Update',
8427
- changelogBaseUrl: options.changelogBaseUrl,
8428
- openInNewTab: options.openInNewTab,
8429
- onViewUpdate: options.onViewUpdate,
8507
+ ...defaults,
8508
+ ...configDefaults,
8509
+ ...explicitOptions,
8430
8510
  });
8431
8511
 
8432
8512
  changelogWidget.mount();