@product7/feedback-sdk 1.6.4 → 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">
@@ -8087,12 +8094,15 @@
8087
8094
  }
8088
8095
 
8089
8096
  const widgetId = generateId('widget');
8097
+ const widgetConfig = this._getWidgetTypeConfig(type);
8098
+ const explicitOptions = this._omitUndefined(options);
8090
8099
  const widgetOptions = {
8091
8100
  id: widgetId,
8092
8101
  sdk: this,
8093
8102
  apiService: this.apiService,
8094
8103
  ...this.config,
8095
- ...options,
8104
+ ...widgetConfig,
8105
+ ...explicitOptions,
8096
8106
  };
8097
8107
 
8098
8108
  try {
@@ -8204,13 +8214,22 @@
8204
8214
  }
8205
8215
 
8206
8216
  const normalizedOptions = this._normalizeSurveyConfig(options);
8217
+ const surveyConfigDefaults = this._getWidgetTypeConfig('survey');
8207
8218
 
8208
8219
  const surveyWidget = this.createWidget('survey', {
8209
8220
  surveyId: normalizedOptions.surveyId,
8210
8221
  surveyType:
8211
8222
  normalizedOptions.surveyType || normalizedOptions.type || 'nps',
8212
- position: normalizedOptions.position || 'bottom-right',
8213
- 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',
8214
8233
  title: normalizedOptions.title,
8215
8234
  description: normalizedOptions.description,
8216
8235
  lowLabel: normalizedOptions.lowLabel,
@@ -8413,6 +8432,58 @@
8413
8432
  return null;
8414
8433
  }
8415
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
+
8416
8487
  showChangelog(options = {}) {
8417
8488
  if (!this.initialized) {
8418
8489
  throw new SDKError(
@@ -8420,16 +8491,22 @@
8420
8491
  );
8421
8492
  }
8422
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
+
8423
8506
  const changelogWidget = this.createWidget('changelog', {
8424
- position: options.position || 'bottom-right',
8425
- theme: options.theme || this.config.theme || 'light',
8426
- title: options.title || "What's New",
8427
- triggerText: options.triggerText || "What's New",
8428
- showBadge: options.showBadge !== false,
8429
- viewButtonText: options.viewButtonText || 'View Update',
8430
- changelogBaseUrl: options.changelogBaseUrl,
8431
- openInNewTab: options.openInNewTab,
8432
- onViewUpdate: options.onViewUpdate,
8507
+ ...defaults,
8508
+ ...configDefaults,
8509
+ ...explicitOptions,
8433
8510
  });
8434
8511
 
8435
8512
  changelogWidget.mount();