@aslaluroba/help-center-react 3.0.21 → 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/components/ui/image-attachment.d.ts +9 -0
- package/dist/components/ui/image-preview-dialog.d.ts +10 -0
- package/dist/components/ui/index.d.ts +4 -0
- package/dist/core/api.d.ts +3 -1
- package/dist/index.css +1 -1
- package/dist/index.esm.js +4964 -600
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +4964 -600
- package/dist/index.js.map +1 -1
- package/dist/lib/types.d.ts +23 -0
- package/dist/services.esm.js +41 -35
- package/dist/services.esm.js.map +1 -1
- package/dist/services.js +41 -35
- package/dist/services.js.map +1 -1
- package/dist/ui/chatbot-popup/chat-window-screen/footer.d.ts +3 -2
- package/dist/ui/chatbot-popup/chat-window-screen/index.d.ts +3 -2
- package/dist/ui/help-center.d.ts +1 -1
- package/dist/ui/help-popup.d.ts +3 -2
- package/package.json +1 -1
- package/src/.DS_Store +0 -0
- package/src/assets/icons/paperclip.svg +3 -0
- package/src/assets/icons/x.svg +4 -0
- package/src/components/ui/image-attachment.tsx +107 -0
- package/src/components/ui/image-preview-dialog.tsx +354 -0
- package/src/components/ui/index.ts +4 -0
- package/src/core/AblyService.ts +2 -2
- package/src/core/ApiService.ts +0 -2
- package/src/core/api.ts +106 -58
- package/src/lib/types.ts +110 -84
- package/src/ui/chatbot-popup/chat-window-screen/footer.tsx +259 -22
- package/src/ui/chatbot-popup/chat-window-screen/index.tsx +206 -101
- package/src/ui/help-center.tsx +88 -92
- package/src/ui/help-popup.tsx +11 -9
- package/src/ui/powered-by.tsx +10 -9
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
|
-
|
|
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();
|
|
@@ -13694,10 +13692,10 @@ function _getValidToken() {
|
|
|
13694
13692
|
var forceRefresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
13695
13693
|
var _a;
|
|
13696
13694
|
if (!getTokenFunction) {
|
|
13697
|
-
throw new Error(
|
|
13695
|
+
throw new Error('API module not initialized. Call initializeAPI(getToken) first.');
|
|
13698
13696
|
}
|
|
13699
|
-
var storedToken = localStorage.getItem(
|
|
13700
|
-
var storedExpiry = localStorage.getItem(
|
|
13697
|
+
var storedToken = localStorage.getItem('chatbot-token');
|
|
13698
|
+
var storedExpiry = localStorage.getItem('chatbot-token-expiry');
|
|
13701
13699
|
var currentTime = Math.floor(Date.now() / 1000);
|
|
13702
13700
|
// Add buffer time to prevent token expiry during request
|
|
13703
13701
|
var bufferTime = 60; // 1 minute buffer
|
|
@@ -13707,10 +13705,9 @@ function _getValidToken() {
|
|
|
13707
13705
|
var tokenResponse = yield getTokenFunction();
|
|
13708
13706
|
storedToken = tokenResponse.token;
|
|
13709
13707
|
storedExpiry = String(currentTime + ((_a = tokenResponse.expiresIn) !== null && _a !== void 0 ? _a : 900));
|
|
13710
|
-
localStorage.setItem(
|
|
13711
|
-
localStorage.setItem(
|
|
13708
|
+
localStorage.setItem('chatbot-token', storedToken);
|
|
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
|
}
|
|
@@ -13727,11 +13724,11 @@ function _fetchWithAuth() {
|
|
|
13727
13724
|
var headers = new Headers(options.headers);
|
|
13728
13725
|
try {
|
|
13729
13726
|
var token = yield getValidToken();
|
|
13730
|
-
headers.set(
|
|
13727
|
+
headers.set('Authorization', "Bearer ".concat(token));
|
|
13731
13728
|
// Add performance optimizations
|
|
13732
|
-
headers.set(
|
|
13733
|
-
headers.set(
|
|
13734
|
-
headers.set(
|
|
13729
|
+
headers.set('Accept', 'application/json');
|
|
13730
|
+
headers.set('Accept-Encoding', 'gzip, deflate, br');
|
|
13731
|
+
headers.set('Connection', 'keep-alive');
|
|
13735
13732
|
options.headers = headers;
|
|
13736
13733
|
// Add timeout to prevent hanging requests
|
|
13737
13734
|
var controller = new AbortController();
|
|
@@ -13740,15 +13737,14 @@ function _fetchWithAuth() {
|
|
|
13740
13737
|
var response = yield fetch(url, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
13741
13738
|
signal: controller.signal,
|
|
13742
13739
|
// Add HTTP/2 optimization hints
|
|
13743
|
-
cache:
|
|
13744
|
-
mode:
|
|
13740
|
+
cache: 'no-cache',
|
|
13741
|
+
mode: 'cors'
|
|
13745
13742
|
}));
|
|
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
|
-
headers.set(
|
|
13747
|
+
headers.set('Authorization', "Bearer ".concat(newToken));
|
|
13752
13748
|
options.headers = headers;
|
|
13753
13749
|
// Retry the request with new token
|
|
13754
13750
|
return fetchWithAuth(url, options, false);
|
|
@@ -13756,13 +13752,12 @@ function _fetchWithAuth() {
|
|
|
13756
13752
|
return response;
|
|
13757
13753
|
} catch (error) {
|
|
13758
13754
|
clearTimeout(timeoutId);
|
|
13759
|
-
if (error instanceof Error && error.name ===
|
|
13760
|
-
throw new Error(
|
|
13755
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
13756
|
+
throw new Error('Request timeout - please try again');
|
|
13761
13757
|
}
|
|
13762
13758
|
throw error;
|
|
13763
13759
|
}
|
|
13764
13760
|
} catch (error) {
|
|
13765
|
-
console.error("Fetch error:", error);
|
|
13766
13761
|
throw error;
|
|
13767
13762
|
}
|
|
13768
13763
|
});
|
|
@@ -13802,10 +13797,10 @@ function apiRequest(_x3) {
|
|
|
13802
13797
|
}
|
|
13803
13798
|
function _apiRequest() {
|
|
13804
13799
|
_apiRequest = _asyncToGenerator(function* (endpoint) {
|
|
13805
|
-
var method = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] :
|
|
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
13802
|
var options = arguments.length > 3 ? arguments[3] : undefined;
|
|
13808
|
-
if (!baseUrl) throw new Error(
|
|
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));
|
|
13811
13806
|
// Check for duplicate in-flight requests
|
|
@@ -13814,7 +13809,7 @@ function _apiRequest() {
|
|
|
13814
13809
|
return duplicateRequest;
|
|
13815
13810
|
}
|
|
13816
13811
|
// Check cache for GET requests (except real-time endpoints)
|
|
13817
|
-
if (method ===
|
|
13812
|
+
if (method === 'GET' && options.cache !== false && !endpoint.includes('/send-message')) {
|
|
13818
13813
|
var cached = getCachedResponse(requestKey);
|
|
13819
13814
|
if (cached) {
|
|
13820
13815
|
return Promise.resolve(cached);
|
|
@@ -13823,9 +13818,9 @@ function _apiRequest() {
|
|
|
13823
13818
|
var requestOptions = {
|
|
13824
13819
|
method,
|
|
13825
13820
|
headers: {
|
|
13826
|
-
|
|
13827
|
-
|
|
13828
|
-
|
|
13821
|
+
'Content-Type': 'application/json',
|
|
13822
|
+
'Cache-Control': method === 'GET' ? 'max-age=30' : 'no-cache',
|
|
13823
|
+
'Accept-Language': options.language
|
|
13829
13824
|
},
|
|
13830
13825
|
body: body ? JSON.stringify(body) : null
|
|
13831
13826
|
};
|
|
@@ -13833,26 +13828,37 @@ function _apiRequest() {
|
|
|
13833
13828
|
try {
|
|
13834
13829
|
var response = yield fetchWithAuth(url, requestOptions);
|
|
13835
13830
|
if (!response.ok) {
|
|
13836
|
-
var errorMessage =
|
|
13831
|
+
var errorMessage = 'API request failed';
|
|
13837
13832
|
try {
|
|
13838
|
-
|
|
13839
|
-
|
|
13840
|
-
|
|
13841
|
-
errorMessage =
|
|
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
|
+
}
|
|
13842
13846
|
}
|
|
13843
13847
|
throw new Error(errorMessage);
|
|
13844
13848
|
}
|
|
13845
13849
|
// Cache successful GET responses
|
|
13846
|
-
|
|
13850
|
+
// Note: We clone before caching to avoid consuming the original response body
|
|
13851
|
+
if (method === 'GET' && options.cache !== false) {
|
|
13847
13852
|
var responseData = response.clone();
|
|
13848
13853
|
var data = yield responseData.json();
|
|
13849
13854
|
setCachedResponse(requestKey, {
|
|
13850
13855
|
json: () => Promise.resolve(data)
|
|
13851
13856
|
});
|
|
13852
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)
|
|
13853
13860
|
return response;
|
|
13854
13861
|
} catch (error) {
|
|
13855
|
-
console.error("API request failed for ".concat(endpoint, ":"), error);
|
|
13856
13862
|
throw error;
|
|
13857
13863
|
}
|
|
13858
13864
|
})();
|