@builder.io/sdk 4.0.0 → 4.0.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @builder.io/sdk
2
2
 
3
+ ## 4.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - cf33d45: Fix: increase coverage of `trustedHost` check to all messages.
8
+
3
9
  ## 4.0.0
4
10
 
5
11
  ### Major Changes
@@ -1052,7 +1052,7 @@
1052
1052
 
1053
1053
  var DEFAULT_API_VERSION = 'v3';
1054
1054
 
1055
- var SDK_VERSION = '4.0.0';
1055
+ var SDK_VERSION = '4.0.1';
1056
1056
 
1057
1057
  function datePlusMinutes(minutes) {
1058
1058
  if (minutes === void 0) { minutes = 30; }
@@ -1379,11 +1379,16 @@
1379
1379
  this.serverContext = context;
1380
1380
  };
1381
1381
  Builder.isTrustedHost = function (hostname) {
1382
- return (this.trustedHosts.findIndex(function (trustedHost) {
1382
+ var isTrusted = this.trustedHosts.findIndex(function (trustedHost) {
1383
1383
  return trustedHost.startsWith('*.')
1384
1384
  ? hostname.endsWith(trustedHost.slice(1))
1385
1385
  : trustedHost === hostname;
1386
- }) > -1);
1386
+ }) > -1;
1387
+ return isTrusted;
1388
+ };
1389
+ Builder.isTrustedHostForEvent = function (event) {
1390
+ var url = parse(event.origin);
1391
+ return url.hostname && Builder.isTrustedHost(url.hostname);
1387
1392
  };
1388
1393
  Builder.runAction = function (action) {
1389
1394
  // TODO
@@ -1933,18 +1938,16 @@
1933
1938
  var _this = this;
1934
1939
  if (isBrowser) {
1935
1940
  addEventListener('message', function (event) {
1936
- var _a, _b, _c, _d, _e;
1937
- var url = parse(event.origin);
1938
- var isRestricted = ['builder.register', 'builder.registerComponent'].indexOf((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === -1;
1939
- var isTrusted = url.hostname && Builder.isTrustedHost(url.hostname);
1940
- if (isRestricted && !isTrusted) {
1941
+ var _a, _b, _c, _d;
1942
+ var isTrusted = Builder.isTrustedHostForEvent(event);
1943
+ if (!isTrusted) {
1941
1944
  return;
1942
1945
  }
1943
1946
  var data = event.data;
1944
1947
  if (data) {
1945
1948
  switch (data.type) {
1946
1949
  case 'builder.ping': {
1947
- (_b = window.parent) === null || _b === void 0 ? void 0 : _b.postMessage({
1950
+ (_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
1948
1951
  type: 'builder.pong',
1949
1952
  data: {},
1950
1953
  }, '*');
@@ -2019,7 +2022,7 @@
2019
2022
  }
2020
2023
  break;
2021
2024
  case 'builder.getComponents':
2022
- (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
2025
+ (_b = window.parent) === null || _b === void 0 ? void 0 : _b.postMessage({
2023
2026
  type: 'builder.components',
2024
2027
  data: Builder.components.map(function (item) { return Builder.prepareComponentSpecToSend(item); }),
2025
2028
  }, '*');
@@ -2058,7 +2061,7 @@
2058
2061
  // TODO: refetch too
2059
2062
  break;
2060
2063
  case 'builder.overrideTestGroup':
2061
- var _f = data.data, variationId = _f.variationId, contentId = _f.contentId;
2064
+ var _e = data.data, variationId = _e.variationId, contentId = _e.contentId;
2062
2065
  if (variationId && contentId) {
2063
2066
  _this.setTestCookie(contentId, variationId);
2064
2067
  _this.flushGetContentQueue(true);
@@ -2079,7 +2082,7 @@
2079
2082
  error = toError(err);
2080
2083
  }
2081
2084
  if (error) {
2082
- (_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
2085
+ (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
2083
2086
  type: 'builder.evaluateError',
2084
2087
  data: { id: id_1, error: error.message },
2085
2088
  }, '*');
@@ -2097,7 +2100,7 @@
2097
2100
  .catch(console.error);
2098
2101
  }
2099
2102
  else {
2100
- (_e = window.parent) === null || _e === void 0 ? void 0 : _e.postMessage({
2103
+ (_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
2101
2104
  type: 'builder.evaluateResult',
2102
2105
  data: { result: result, id: id_1 },
2103
2106
  }, '*');