yelda-webchat 1.1.24 → 1.1.25

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.24",
3
+ "version": "1.1.25",
4
4
  "description": "Website Chat Plugin",
5
5
  "main": "./dist/js/yeldaWebchatInjector.min.js",
6
6
  "license": "MIT",
@@ -51,7 +51,7 @@
51
51
  "less-loader": "^4.1.0",
52
52
  "mime": "^2.4.6",
53
53
  "mini-css-extract-plugin": "^0.4.1",
54
- "mocha": "^8.3.0",
54
+ "mocha": "^12.0.1",
55
55
  "optimize-css-assets-webpack-plugin": "^5.0.8",
56
56
  "postcss-import": "^12.0.0",
57
57
  "postcss-loader": "^3.0.0",
@@ -4,6 +4,8 @@ module.exports = {
4
4
  YELDA_PARAMETER: 'yparam',
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
+ // Prefix of an allowed domain that allows all its subdomains, but not the domain itself
8
+ ALLOWED_DOMAIN_WILDCARD_PREFIX: '*.',
7
9
  REGEX_HOST: {
8
10
  STAGING: /staging.yelda.ai/,
9
11
  YELDA: /.yelda.ai/
@@ -1136,9 +1136,27 @@ class YeldaChat {
1136
1136
  return false
1137
1137
  }
1138
1138
 
1139
+ // allowedDomains is only sent when the admins restricted the webchat to some websites
1140
+ if (webchatSettings.allowedDomains && !this.isHostAllowed(currentHost, webchatSettings.allowedDomains)) {
1141
+ return false
1142
+ }
1143
+
1139
1144
  return true
1140
1145
  }
1141
1146
 
1147
+ /**
1148
+ * Check the current website is in the webchat allowed domains
1149
+ * @param {String} host - hostname of the current website, e.g. 'www.site.com'
1150
+ * @param {Array<String>} allowedDomains - e.g. ['www.site.com', '*.site.com'], '*.site.com' allows the subdomains only
1151
+ * @returns {Boolean}
1152
+ */
1153
+ isHostAllowed(host, allowedDomains) {
1154
+ return allowedDomains.some(domain => domain.startsWith(config.ALLOWED_DOMAIN_WILDCARD_PREFIX)
1155
+ // '*.site.com' gives '.site.com', matched by 'www.site.com' but not by 'site.com' or 'mysite.com'
1156
+ ? host.endsWith(domain.slice(config.ALLOWED_DOMAIN_WILDCARD_PREFIX.length - 1))
1157
+ : host === domain)
1158
+ }
1159
+
1142
1160
  /**
1143
1161
  * Return if the webchat loadChat settings are different from the yeldaChat global assistant settings
1144
1162
  *