yelda-webchat 1.1.13 → 1.1.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yelda-webchat",
3
- "version": "1.1.13",
3
+ "version": "1.1.16",
4
4
  "description": "Website Chat Plugin",
5
5
  "main": "./dist/js/yeldaWebchatInjector.min.js",
6
6
  "license": "MIT",
@@ -50,7 +50,7 @@
50
50
  "mime": "^2.4.6",
51
51
  "mini-css-extract-plugin": "^0.4.1",
52
52
  "mocha": "^8.3.0",
53
- "optimize-css-assets-webpack-plugin": "^5.0.3",
53
+ "optimize-css-assets-webpack-plugin": "^5.0.8",
54
54
  "postcss-import": "^12.0.0",
55
55
  "postcss-loader": "^3.0.0",
56
56
  "postcss-url": "^8.0.0",
@@ -5,7 +5,8 @@ module.exports = {
5
5
  DEFAULT_PUBLICATION_STATUS: true,
6
6
  ALWAYS_ALLOWED_SITES_REGEX : /^([a-z-]*.yelda.ai|localhost|0.0.0.0|127.0.0.1)$/,
7
7
  REGEX_HOST: {
8
- STAGING: /staging.yelda.ai/
8
+ STAGING: /staging.yelda.ai/,
9
+ YELDA: /.yelda.ai/
9
10
  },
10
11
  HOST: {
11
12
  PRODUCTION: 'app.yelda.ai',
@@ -1,5 +1,5 @@
1
- @import url(https://use.fontawesome.com/releases/v5.3.1/css/all.css);
2
-
1
+ @import url('https://yelda-chat.s3.eu-west-3.amazonaws.com/fontawesome-free-5.3.1-web/css/all.min.css');
2
+ @import url('https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.2.0/css/lightgallery.min.css');
3
3
 
4
4
  .yelda_assistant_img {
5
5
  cursor: pointer;
@@ -5,7 +5,7 @@ import 'lg-fullscreen.js'
5
5
  import 'lg-zoom.js'
6
6
  import 'lg-video.js'
7
7
  import 'lg-share.js'
8
- import 'lightgallery.js/dist/css/lightgallery.css'
8
+
9
9
  import config from '../config'
10
10
 
11
11
  class YeldaChat {
@@ -243,7 +243,7 @@ class YeldaChat {
243
243
  * @return {String} url
244
244
  */
245
245
  createWebChatURL(data) {
246
- let url = data.chatUrl
246
+ let url = data.iframeURL
247
247
  url = this.updateQueryStringParameter(url, 'assistantId', data.assistantId)
248
248
  url = this.updateQueryStringParameter(url, 'assistantSlug', data.assistantSlug)
249
249
  url = this.updateQueryStringParameter(url, 'locale', data.locale)
@@ -625,7 +625,7 @@ class YeldaChat {
625
625
 
626
626
  /**
627
627
  * Generate webchatURL and create webchatIframe
628
- * @param {Object} data { chatUrl, assistantId, assistantSlug, shouldBeOpened, isStartBtn, canBeClosed }
628
+ * @param {Object} data { iframeURL, assistantId, assistantSlug, shouldBeOpened, isStartBtn, canBeClosed }
629
629
  */
630
630
  setUpChatIFrame(data) {
631
631
  const webchatUrl = this.createWebChatURL(data)
@@ -653,10 +653,19 @@ class YeldaChat {
653
653
  * Update data object with assistantId, assistantSlug and locale if needed
654
654
  * @param {Object} data { data.assistantUrl, data.chatPath }
655
655
  * @param {Object} webchatSettings webchat settings from DB
656
+ * @param {String} href window.location.href
656
657
  * @param {Object} data
657
658
  */
658
- updateAssistantData(data, webchatSettings) {
659
- if (!data.settingId || !webchatSettings || !webchatSettings.assistantSlug) {
659
+ updateAssistantData(data, webchatSettings, href) {
660
+ if(!webchatSettings) {
661
+ return data
662
+ }
663
+
664
+ // we can overwrite the iframeURL on other domain than yelda ones
665
+ data.iframeURL = (!config.REGEX_HOST.YELDA.test(href) && webchatSettings.iframeURL) || data.iframeURL
666
+
667
+ // if no settingId, no need to go further, because the call has been done with the assistantId & assistantSlug
668
+ if (!data.settingId || !webchatSettings.assistantSlug) {
660
669
  return data
661
670
  }
662
671
 
@@ -697,7 +706,7 @@ class YeldaChat {
697
706
  */
698
707
  data.assistantUrl = this.setAssistantUrl(data.assistantUrl, window.location.href)
699
708
  data.chatPath = chatPath.replace(/^\//, '')
700
- data.chatUrl = `${data.assistantUrl}/${data.chatPath}`
709
+ data.iframeURL = `${data.assistantUrl}/${data.chatPath}`
701
710
  data.locale = data.locale || 'fr_FR'
702
711
  data.isAdmin = data.isAdmin ? true : false
703
712
  data.isStartBtn = data.isStartBtn ? true : false
@@ -747,6 +756,20 @@ class YeldaChat {
747
756
  return data
748
757
  }
749
758
 
759
+ /**
760
+ * Check whether the css href is yeldaWebchatInjector.css or yeldaWebchatInjector.min.css
761
+ * @param {String} cssHref
762
+ * @returns {Boolean}
763
+ */
764
+ isYeldaCssInjector(cssHref) {
765
+ const injectorCSSRegex = new RegExp('\\yeldaWebchatInjector(.min)?.css')
766
+ return injectorCSSRegex.test(cssHref)
767
+ }
768
+
769
+ /**
770
+ * Check whether the style sheet is already loaded
771
+ * @returns {Boolean}
772
+ */
750
773
  isStyleSheetLoaded() {
751
774
  const sheets = document.styleSheets
752
775
  let isFound = false
@@ -767,6 +790,10 @@ class YeldaChat {
767
790
  }
768
791
  }
769
792
  } catch (e) {
793
+ if(this.isYeldaCssInjector(sheet.href)) {
794
+ isFound = true
795
+ break sheetsLoop
796
+ }
770
797
  continue
771
798
  }
772
799
  }
@@ -777,7 +804,7 @@ class YeldaChat {
777
804
 
778
805
  /**
779
806
  * Get the app env from the assistant url
780
- * @param {String} assistantUrl
807
+ * @param {String} assistantUrl
781
808
  * @returns {String} env
782
809
  */
783
810
  getAppEnv(assistantUrl) {
@@ -834,10 +861,10 @@ class YeldaChat {
834
861
  try {
835
862
  const xhr = new XMLHttpRequest()
836
863
 
837
- // Get the url base depending on if we are doing the basic request (external chatbubble endpoint)
864
+ // Get the url base depending on if we are doing the basic request (external chatbubble endpoint)
838
865
  // or the fallback one (chatbubble endpoint in Yelda)
839
866
  const url = this.getAssistantSettingsUrl(data, isFallback)
840
-
867
+
841
868
  xhr.open('GET', url)
842
869
  if (customTimeout) {
843
870
  xhr.timeout = customTimeout
@@ -848,7 +875,7 @@ class YeldaChat {
848
875
  xhr.onreadystatechange = () => {
849
876
  if (xhr.readyState === 4) {
850
877
  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)
878
+ // Yelda endpoint returns { data: ...webchatSettings } (to be compatible with old versions of the chat-plugin)
852
879
  // whereas the external endpoint returns { ...webchatSettings }
853
880
  // We need to handle both format
854
881
  const webchatSettings = responseText && (responseText.data || responseText)
@@ -868,7 +895,7 @@ class YeldaChat {
868
895
  return resolve(this.getAssistantSettings(data, { isFallback: true }))
869
896
  }
870
897
  }
871
-
898
+
872
899
  xhr.ontimeout = () => {
873
900
  /*
874
901
  It the initial request to the external chatbubble endpoint timed out, (maybe the endpoint is down)
@@ -919,7 +946,7 @@ class YeldaChat {
919
946
  this.webchatSettings = await this.getAssistantSettings(data, { customTimeout: config.CHAT_BUBBLE_REQUEST_TIMEOUT })
920
947
  // Webchat can be loaded thanks to a single settingId or group of data : {assistantId, assistantSlug, locale}
921
948
  // If only settingId is provided, then we will fill {assistantId, assistantSlug, locale} thanks to the assistant settings
922
- data = this.updateAssistantData(data, this.webchatSettings)
949
+ data = this.updateAssistantData(data, this.webchatSettings, window.location.href)
923
950
 
924
951
  } catch (err) {
925
952
  this.webchatSettings = null
@@ -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}/${subFile}`,
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(filePath),
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()