@aslaluroba/help-center-react 3.0.20 → 3.2.0

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/dist/services.js CHANGED
@@ -3686,7 +3686,6 @@ class ApiService {
3686
3686
  _this2.tokenExpiryTime = currentTime + response.expiresIn;
3687
3687
  return _this2.currentToken;
3688
3688
  } catch (error) {
3689
- console.error('Error getting token:', error);
3690
3689
  throw error;
3691
3690
  }
3692
3691
  }
@@ -3745,7 +3744,6 @@ class ApiService {
3745
3744
  if (this.config.onError) {
3746
3745
  this.config.onError(error instanceof Error ? error : new Error('Unknown error occurred'));
3747
3746
  }
3748
- console.error('API Error:', error);
3749
3747
  }
3750
3748
  }
3751
3749
 
@@ -13562,15 +13560,15 @@ class ClientAblyService {
13562
13560
  _this2.channel = _this2.client.channels.get(roomName);
13563
13561
  // Subscribe to assistant/system responses
13564
13562
  _this2.channel.subscribe('ReceiveMessage', message => {
13565
- var _a, _b, _c, _d;
13563
+ var _a, _b, _c, _d, _e;
13566
13564
  try {
13567
13565
  var messageContent = typeof message.data === 'string' ? message.data : ((_a = message.data) === null || _a === void 0 ? void 0 : _a.content) || ((_b = message.data) === null || _b === void 0 ? void 0 : _b.message);
13568
13566
  var senderType = ((_c = message.data) === null || _c === void 0 ? void 0 : _c.senderType) || 3; // Assistant
13569
13567
  var needsAgent = ((_d = message.data) === null || _d === void 0 ? void 0 : _d.needsAgent) || false;
13570
- onMessageReceived(messageContent, senderType, needsAgent);
13568
+ var attachments = ((_e = message.data) === null || _e === void 0 ? void 0 : _e.attachments) || [];
13569
+ onMessageReceived(messageContent, senderType, needsAgent, attachments);
13571
13570
  } catch (error) {
13572
13571
  // Handle error silently
13573
- console.error('[AblyService] Error processing ReceiveMessage:', error);
13574
13572
  }
13575
13573
  });
13576
13574
  yield _this2.channel.attach();
@@ -13710,7 +13708,6 @@ function _getValidToken() {
13710
13708
  localStorage.setItem('chatbot-token', storedToken);
13711
13709
  localStorage.setItem('chatbot-token-expiry', storedExpiry);
13712
13710
  } catch (error) {
13713
- console.error('Failed to refresh token:', error);
13714
13711
  throw error;
13715
13712
  }
13716
13713
  }
@@ -13746,7 +13743,6 @@ function _fetchWithAuth() {
13746
13743
  clearTimeout(timeoutId);
13747
13744
  // Handle 401/403 with token refresh
13748
13745
  if ((response.status === 401 || response.status === 403) && retry) {
13749
- console.warn('Token expired, refreshing...');
13750
13746
  var newToken = yield getValidToken(true);
13751
13747
  headers.set('Authorization', "Bearer ".concat(newToken));
13752
13748
  options.headers = headers;
@@ -13762,7 +13758,6 @@ function _fetchWithAuth() {
13762
13758
  throw error;
13763
13759
  }
13764
13760
  } catch (error) {
13765
- console.error('Fetch error:', error);
13766
13761
  throw error;
13767
13762
  }
13768
13763
  });
@@ -13804,7 +13799,7 @@ function _apiRequest() {
13804
13799
  _apiRequest = _asyncToGenerator(function* (endpoint) {
13805
13800
  var method = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GET';
13806
13801
  var body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
13807
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
13802
+ var options = arguments.length > 3 ? arguments[3] : undefined;
13808
13803
  if (!baseUrl) throw new Error('API not initialized');
13809
13804
  var url = "".concat(baseUrl, "/").concat(endpoint);
13810
13805
  var requestKey = "".concat(method, ":").concat(endpoint, ":").concat(JSON.stringify(body));
@@ -13824,7 +13819,8 @@ function _apiRequest() {
13824
13819
  method,
13825
13820
  headers: {
13826
13821
  'Content-Type': 'application/json',
13827
- 'Cache-Control': method === 'GET' ? 'max-age=30' : 'no-cache'
13822
+ 'Cache-Control': method === 'GET' ? 'max-age=30' : 'no-cache',
13823
+ 'Accept-Language': options.language
13828
13824
  },
13829
13825
  body: body ? JSON.stringify(body) : null
13830
13826
  };
@@ -13834,24 +13830,35 @@ function _apiRequest() {
13834
13830
  if (!response.ok) {
13835
13831
  var errorMessage = 'API request failed';
13836
13832
  try {
13837
- var errorData = yield response.json();
13838
- errorMessage = errorData.message || errorMessage;
13839
- } catch (_a) {
13840
- errorMessage = "HTTP ".concat(response.status, ": ").concat(response.statusText);
13833
+ // Clone response before reading to avoid consuming the body
13834
+ var errorResponse = response.clone();
13835
+ var errorData = yield errorResponse.json();
13836
+ errorMessage = errorData.message || errorData.error || errorMessage;
13837
+ } catch (parseError) {
13838
+ // If JSON parsing fails, try to get text
13839
+ try {
13840
+ var _errorResponse = response.clone();
13841
+ var errorText = yield _errorResponse.text();
13842
+ errorMessage = errorText || "HTTP ".concat(response.status, ": ").concat(response.statusText);
13843
+ } catch (_a) {
13844
+ errorMessage = "HTTP ".concat(response.status, ": ").concat(response.statusText);
13845
+ }
13841
13846
  }
13842
13847
  throw new Error(errorMessage);
13843
13848
  }
13844
13849
  // Cache successful GET responses
13850
+ // Note: We clone before caching to avoid consuming the original response body
13845
13851
  if (method === 'GET' && options.cache !== false) {
13846
- var responseData = yield response.clone();
13852
+ var responseData = response.clone();
13847
13853
  var data = yield responseData.json();
13848
13854
  setCachedResponse(requestKey, {
13849
13855
  json: () => Promise.resolve(data)
13850
13856
  });
13851
13857
  }
13858
+ // Return the original response - it's body hasn't been consumed yet
13859
+ // (we only cloned for caching, and the clone was consumed)
13852
13860
  return response;
13853
13861
  } catch (error) {
13854
- console.error("API request failed for ".concat(endpoint, ":"), error);
13855
13862
  throw error;
13856
13863
  }
13857
13864
  })();