yelda-webchat 1.1.13 → 1.1.14
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/css/yeldaWebchatInjector.css.gz +0 -0
- package/dist/css/yeldaWebchatInjector.min.css.gz +0 -0
- package/dist/js/yeldaWebchatInjector.js +2 -8248
- package/dist/js/yeldaWebchatInjector.js.gz +0 -0
- package/dist/js/yeldaWebchatInjector.js.map +1 -1
- package/dist/js/yeldaWebchatInjector.min.js +3 -2
- package/dist/js/yeldaWebchatInjector.min.js.gz +0 -0
- package/dist/js/yeldaWebchatInjector.min.js.map +1 -0
- package/package.json +1 -1
- package/src/js/yeldaWebchatInjector.js +23 -5
- package/uploadBuildToS3.js +13 -2
package/package.json
CHANGED
|
@@ -747,6 +747,20 @@ class YeldaChat {
|
|
|
747
747
|
return data
|
|
748
748
|
}
|
|
749
749
|
|
|
750
|
+
/**
|
|
751
|
+
* Check whether the css href is yeldaWebchatInjector.css or yeldaWebchatInjector.min.css
|
|
752
|
+
* @param {String} cssHref
|
|
753
|
+
* @returns {Boolean}
|
|
754
|
+
*/
|
|
755
|
+
isYeldaCssInjector(cssHref) {
|
|
756
|
+
const injectorCSSRegex = new RegExp('\\yeldaWebchatInjector(.min)?.css')
|
|
757
|
+
return injectorCSSRegex.test(cssHref)
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Check whether the style sheet is already loaded
|
|
762
|
+
* @returns {Boolean}
|
|
763
|
+
*/
|
|
750
764
|
isStyleSheetLoaded() {
|
|
751
765
|
const sheets = document.styleSheets
|
|
752
766
|
let isFound = false
|
|
@@ -767,6 +781,10 @@ class YeldaChat {
|
|
|
767
781
|
}
|
|
768
782
|
}
|
|
769
783
|
} catch (e) {
|
|
784
|
+
if(this.isYeldaCssInjector(sheet.href)) {
|
|
785
|
+
isFound = true
|
|
786
|
+
break sheetsLoop
|
|
787
|
+
}
|
|
770
788
|
continue
|
|
771
789
|
}
|
|
772
790
|
}
|
|
@@ -777,7 +795,7 @@ class YeldaChat {
|
|
|
777
795
|
|
|
778
796
|
/**
|
|
779
797
|
* Get the app env from the assistant url
|
|
780
|
-
* @param {String} assistantUrl
|
|
798
|
+
* @param {String} assistantUrl
|
|
781
799
|
* @returns {String} env
|
|
782
800
|
*/
|
|
783
801
|
getAppEnv(assistantUrl) {
|
|
@@ -834,10 +852,10 @@ class YeldaChat {
|
|
|
834
852
|
try {
|
|
835
853
|
const xhr = new XMLHttpRequest()
|
|
836
854
|
|
|
837
|
-
// Get the url base depending on if we are doing the basic request (external chatbubble endpoint)
|
|
855
|
+
// Get the url base depending on if we are doing the basic request (external chatbubble endpoint)
|
|
838
856
|
// or the fallback one (chatbubble endpoint in Yelda)
|
|
839
857
|
const url = this.getAssistantSettingsUrl(data, isFallback)
|
|
840
|
-
|
|
858
|
+
|
|
841
859
|
xhr.open('GET', url)
|
|
842
860
|
if (customTimeout) {
|
|
843
861
|
xhr.timeout = customTimeout
|
|
@@ -848,7 +866,7 @@ class YeldaChat {
|
|
|
848
866
|
xhr.onreadystatechange = () => {
|
|
849
867
|
if (xhr.readyState === 4) {
|
|
850
868
|
const responseText = xhr.responseText ? JSON.parse(xhr.responseText) : null
|
|
851
|
-
// Yelda endpoint returns { data: ...webchatSettings } (to be compatible with old versions of the chat-plugin)
|
|
869
|
+
// Yelda endpoint returns { data: ...webchatSettings } (to be compatible with old versions of the chat-plugin)
|
|
852
870
|
// whereas the external endpoint returns { ...webchatSettings }
|
|
853
871
|
// We need to handle both format
|
|
854
872
|
const webchatSettings = responseText && (responseText.data || responseText)
|
|
@@ -868,7 +886,7 @@ class YeldaChat {
|
|
|
868
886
|
return resolve(this.getAssistantSettings(data, { isFallback: true }))
|
|
869
887
|
}
|
|
870
888
|
}
|
|
871
|
-
|
|
889
|
+
|
|
872
890
|
xhr.ontimeout = () => {
|
|
873
891
|
/*
|
|
874
892
|
It the initial request to the external chatbubble endpoint timed out, (maybe the endpoint is down)
|
package/uploadBuildToS3.js
CHANGED
|
@@ -174,7 +174,15 @@ const uploadToS3 = async () => {
|
|
|
174
174
|
const subFiles = fs.readdirSync(folderPath)
|
|
175
175
|
|
|
176
176
|
for (const subFile of subFiles) {
|
|
177
|
+
const ext = path.extname(subFile)
|
|
178
|
+
// Only upload renamed gzip and map files to s3
|
|
179
|
+
if (!['.gz', '.map'].includes(ext)) {
|
|
180
|
+
continue
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const unzippedFile = subFile.replace('.gz', '')
|
|
177
184
|
const filePath = path.join(folderPath, subFile)
|
|
185
|
+
const unzippedFilePath = path.join(folderPath, unzippedFile)
|
|
178
186
|
|
|
179
187
|
const fileContent = fs.readFileSync(filePath)
|
|
180
188
|
|
|
@@ -182,10 +190,13 @@ const uploadToS3 = async () => {
|
|
|
182
190
|
const s3Response = await s3
|
|
183
191
|
.putObject({
|
|
184
192
|
Bucket: process.env.AWS_BUCKET || 'yelda-webchat',
|
|
185
|
-
Key: `${file}/${
|
|
193
|
+
Key: `${file}/${unzippedFile}`,
|
|
186
194
|
Body: fileContent,
|
|
187
195
|
// ContentType is required to serve the file to browser properly, otherwise s3 sets octet-stream
|
|
188
|
-
ContentType: mime.getType(
|
|
196
|
+
ContentType: mime.getType(unzippedFilePath),
|
|
197
|
+
...(ext === '.gz' && {
|
|
198
|
+
ContentEncoding: 'gzip'
|
|
199
|
+
}),
|
|
189
200
|
ACL: 'public-read' //Public read permission
|
|
190
201
|
})
|
|
191
202
|
.promise()
|