@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/dist/index.esm.js CHANGED
@@ -950,7 +950,7 @@ function toError(err) {
950
950
 
951
951
  var DEFAULT_API_VERSION = 'v3';
952
952
 
953
- var SDK_VERSION = '4.0.0';
953
+ var SDK_VERSION = '4.0.1';
954
954
 
955
955
  function datePlusMinutes(minutes) {
956
956
  if (minutes === void 0) { minutes = 30; }
@@ -1277,11 +1277,16 @@ var Builder = /** @class */ (function () {
1277
1277
  this.serverContext = context;
1278
1278
  };
1279
1279
  Builder.isTrustedHost = function (hostname) {
1280
- return (this.trustedHosts.findIndex(function (trustedHost) {
1280
+ var isTrusted = this.trustedHosts.findIndex(function (trustedHost) {
1281
1281
  return trustedHost.startsWith('*.')
1282
1282
  ? hostname.endsWith(trustedHost.slice(1))
1283
1283
  : trustedHost === hostname;
1284
- }) > -1);
1284
+ }) > -1;
1285
+ return isTrusted;
1286
+ };
1287
+ Builder.isTrustedHostForEvent = function (event) {
1288
+ var url = parse(event.origin);
1289
+ return url.hostname && Builder.isTrustedHost(url.hostname);
1285
1290
  };
1286
1291
  Builder.runAction = function (action) {
1287
1292
  // TODO
@@ -1831,18 +1836,16 @@ var Builder = /** @class */ (function () {
1831
1836
  var _this = this;
1832
1837
  if (isBrowser) {
1833
1838
  addEventListener('message', function (event) {
1834
- var _a, _b, _c, _d, _e;
1835
- var url = parse(event.origin);
1836
- var isRestricted = ['builder.register', 'builder.registerComponent'].indexOf((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === -1;
1837
- var isTrusted = url.hostname && Builder.isTrustedHost(url.hostname);
1838
- if (isRestricted && !isTrusted) {
1839
+ var _a, _b, _c, _d;
1840
+ var isTrusted = Builder.isTrustedHostForEvent(event);
1841
+ if (!isTrusted) {
1839
1842
  return;
1840
1843
  }
1841
1844
  var data = event.data;
1842
1845
  if (data) {
1843
1846
  switch (data.type) {
1844
1847
  case 'builder.ping': {
1845
- (_b = window.parent) === null || _b === void 0 ? void 0 : _b.postMessage({
1848
+ (_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
1846
1849
  type: 'builder.pong',
1847
1850
  data: {},
1848
1851
  }, '*');
@@ -1917,7 +1920,7 @@ var Builder = /** @class */ (function () {
1917
1920
  }
1918
1921
  break;
1919
1922
  case 'builder.getComponents':
1920
- (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
1923
+ (_b = window.parent) === null || _b === void 0 ? void 0 : _b.postMessage({
1921
1924
  type: 'builder.components',
1922
1925
  data: Builder.components.map(function (item) { return Builder.prepareComponentSpecToSend(item); }),
1923
1926
  }, '*');
@@ -1956,7 +1959,7 @@ var Builder = /** @class */ (function () {
1956
1959
  // TODO: refetch too
1957
1960
  break;
1958
1961
  case 'builder.overrideTestGroup':
1959
- var _f = data.data, variationId = _f.variationId, contentId = _f.contentId;
1962
+ var _e = data.data, variationId = _e.variationId, contentId = _e.contentId;
1960
1963
  if (variationId && contentId) {
1961
1964
  _this.setTestCookie(contentId, variationId);
1962
1965
  _this.flushGetContentQueue(true);
@@ -1977,7 +1980,7 @@ var Builder = /** @class */ (function () {
1977
1980
  error = toError(err);
1978
1981
  }
1979
1982
  if (error) {
1980
- (_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
1983
+ (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
1981
1984
  type: 'builder.evaluateError',
1982
1985
  data: { id: id_1, error: error.message },
1983
1986
  }, '*');
@@ -1995,7 +1998,7 @@ var Builder = /** @class */ (function () {
1995
1998
  .catch(console.error);
1996
1999
  }
1997
2000
  else {
1998
- (_e = window.parent) === null || _e === void 0 ? void 0 : _e.postMessage({
2001
+ (_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
1999
2002
  type: 'builder.evaluateResult',
2000
2003
  data: { result: result, id: id_1 },
2001
2004
  }, '*');