releasebird-javascript-sdk 1.0.45 → 1.0.47

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.
@@ -1,7 +1,7 @@
1
- import RbirdUtils from './RbirdUtils';
2
1
  import RbirdSessionManager from './RbirdSessionManager';
3
2
 
4
- const API = RbirdUtils.API;
3
+ // API is defined globally via webpack.DefinePlugin
4
+ /* global API */
5
5
 
6
6
  export class RbirdBannerManager {
7
7
  static instance;
@@ -51,8 +51,10 @@ export class RbirdBannerManager {
51
51
  self.banners = response;
52
52
  self.renderBanners();
53
53
  } catch (exp) {
54
- console.error('Error parsing banners response:', exp);
54
+ console.error('[RbirdBannerManager] Error parsing banners response:', exp);
55
55
  }
56
+ } else {
57
+ console.error('[RbirdBannerManager] Failed to fetch banners. Status:', http.status, 'Response:', http.responseText);
56
58
  }
57
59
  }
58
60
  };
@@ -60,7 +62,9 @@ export class RbirdBannerManager {
60
62
  }
61
63
 
62
64
  renderBanners() {
63
- if (!this.banners || this.banners.length === 0) return;
65
+ if (!this.banners || this.banners.length === 0) {
66
+ return;
67
+ }
64
68
 
65
69
  this.banners.forEach(banner => {
66
70
  if (banner.type === 'INLINE') {
@@ -96,14 +100,13 @@ export class RbirdBannerManager {
96
100
  container.id = `rbird-banner-${banner.id}`;
97
101
  container.setAttribute('data-banner-id', banner.id);
98
102
 
99
- // Get user language
100
- const userLang = navigator.language?.split('-')[0] || 'de';
101
- const title = banner.title?.[userLang] || banner.title?.['de'] || '';
102
- const message = banner.message?.[userLang] || banner.message?.['de'] || '';
103
- const buttonText = banner.buttonText?.[userLang] || banner.buttonText?.['de'] || '';
103
+ // Get user language with proper fallback chain
104
+ const title = banner.title;
105
+ const message = banner.message;
106
+ const buttonText = banner.buttonText;
104
107
 
105
108
  // Create banner HTML structure
106
- const bannerHTML = `
109
+ container.innerHTML = `
107
110
  <div class="rbird-banner-content" style="${this.getBannerStyles(banner, isFloating)}">
108
111
  <button class="rbird-banner-close" data-banner-id="${banner.id}" style="${this.getCloseButtonStyles()}">
109
112
  ×
@@ -120,8 +123,6 @@ export class RbirdBannerManager {
120
123
  </div>
121
124
  `;
122
125
 
123
- container.innerHTML = bannerHTML;
124
-
125
126
  // Add position styles for floating banners
126
127
  if (isFloating) {
127
128
  this.applyFloatingPosition(container, banner.position);
@@ -325,7 +326,61 @@ export class RbirdBannerManager {
325
326
  http.send(JSON.stringify(requestData));
326
327
  }
327
328
 
329
+ getUserLanguage(banner) {
330
+ // 1. Try to get language from session manager (user preference)
331
+ const sessionManager = RbirdSessionManager.getInstance();
332
+ const state = sessionManager.getState();
333
+ if (state?.identify?.language) {
334
+ return state.identify.language;
335
+ }
336
+
337
+ // 2. Try browser language
338
+ const browserLang = navigator.language?.split('-')[0];
339
+ if (browserLang) {
340
+ return browserLang;
341
+ }
342
+
343
+ // 3. Fallback to banner's default language
344
+ if (banner.defaultLanguage) {
345
+ return banner.defaultLanguage;
346
+ }
347
+
348
+ // 4. Final fallback to 'en'
349
+ return 'en';
350
+ }
351
+
352
+ getLocalizedField(field, userLang, defaultLang) {
353
+ if (!field || typeof field !== 'object') {
354
+ return '';
355
+ }
356
+
357
+ // 1. Try user's language
358
+ if (field[userLang]) {
359
+ return field[userLang];
360
+ }
361
+
362
+ // 2. Try default language
363
+ if (defaultLang && field[defaultLang]) {
364
+ return field[defaultLang];
365
+ }
366
+
367
+ // 3. Try English as universal fallback
368
+ if (field['en']) {
369
+ return field['en'];
370
+ }
371
+
372
+ // 4. Try German as common fallback
373
+ if (field['de']) {
374
+ return field['de'];
375
+ }
376
+
377
+ // 5. Return first available value
378
+ const values = Object.values(field);
379
+ return values.length > 0 ? values[0] : '';
380
+ }
381
+
328
382
  escapeHtml(text) {
383
+ if (!text) return '';
329
384
  const div = document.createElement('div');
330
385
  div.textContent = text;
331
386
  return div.innerHTML;