@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.cjs.js CHANGED
@@ -958,7 +958,7 @@ function toError(err) {
958
958
 
959
959
  var DEFAULT_API_VERSION = 'v3';
960
960
 
961
- var SDK_VERSION = '4.0.0';
961
+ var SDK_VERSION = '4.0.1';
962
962
 
963
963
  function datePlusMinutes(minutes) {
964
964
  if (minutes === void 0) { minutes = 30; }
@@ -1285,11 +1285,16 @@ var Builder = /** @class */ (function () {
1285
1285
  this.serverContext = context;
1286
1286
  };
1287
1287
  Builder.isTrustedHost = function (hostname) {
1288
- return (this.trustedHosts.findIndex(function (trustedHost) {
1288
+ var isTrusted = this.trustedHosts.findIndex(function (trustedHost) {
1289
1289
  return trustedHost.startsWith('*.')
1290
1290
  ? hostname.endsWith(trustedHost.slice(1))
1291
1291
  : trustedHost === hostname;
1292
- }) > -1);
1292
+ }) > -1;
1293
+ return isTrusted;
1294
+ };
1295
+ Builder.isTrustedHostForEvent = function (event) {
1296
+ var url = parse(event.origin);
1297
+ return url.hostname && Builder.isTrustedHost(url.hostname);
1293
1298
  };
1294
1299
  Builder.runAction = function (action) {
1295
1300
  // TODO
@@ -1839,18 +1844,16 @@ var Builder = /** @class */ (function () {
1839
1844
  var _this = this;
1840
1845
  if (isBrowser) {
1841
1846
  addEventListener('message', function (event) {
1842
- var _a, _b, _c, _d, _e;
1843
- var url = parse(event.origin);
1844
- var isRestricted = ['builder.register', 'builder.registerComponent'].indexOf((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === -1;
1845
- var isTrusted = url.hostname && Builder.isTrustedHost(url.hostname);
1846
- if (isRestricted && !isTrusted) {
1847
+ var _a, _b, _c, _d;
1848
+ var isTrusted = Builder.isTrustedHostForEvent(event);
1849
+ if (!isTrusted) {
1847
1850
  return;
1848
1851
  }
1849
1852
  var data = event.data;
1850
1853
  if (data) {
1851
1854
  switch (data.type) {
1852
1855
  case 'builder.ping': {
1853
- (_b = window.parent) === null || _b === void 0 ? void 0 : _b.postMessage({
1856
+ (_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
1854
1857
  type: 'builder.pong',
1855
1858
  data: {},
1856
1859
  }, '*');
@@ -1925,7 +1928,7 @@ var Builder = /** @class */ (function () {
1925
1928
  }
1926
1929
  break;
1927
1930
  case 'builder.getComponents':
1928
- (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
1931
+ (_b = window.parent) === null || _b === void 0 ? void 0 : _b.postMessage({
1929
1932
  type: 'builder.components',
1930
1933
  data: Builder.components.map(function (item) { return Builder.prepareComponentSpecToSend(item); }),
1931
1934
  }, '*');
@@ -1964,7 +1967,7 @@ var Builder = /** @class */ (function () {
1964
1967
  // TODO: refetch too
1965
1968
  break;
1966
1969
  case 'builder.overrideTestGroup':
1967
- var _f = data.data, variationId = _f.variationId, contentId = _f.contentId;
1970
+ var _e = data.data, variationId = _e.variationId, contentId = _e.contentId;
1968
1971
  if (variationId && contentId) {
1969
1972
  _this.setTestCookie(contentId, variationId);
1970
1973
  _this.flushGetContentQueue(true);
@@ -1985,7 +1988,7 @@ var Builder = /** @class */ (function () {
1985
1988
  error = toError(err);
1986
1989
  }
1987
1990
  if (error) {
1988
- (_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
1991
+ (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
1989
1992
  type: 'builder.evaluateError',
1990
1993
  data: { id: id_1, error: error.message },
1991
1994
  }, '*');
@@ -2003,7 +2006,7 @@ var Builder = /** @class */ (function () {
2003
2006
  .catch(console.error);
2004
2007
  }
2005
2008
  else {
2006
- (_e = window.parent) === null || _e === void 0 ? void 0 : _e.postMessage({
2009
+ (_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
2007
2010
  type: 'builder.evaluateResult',
2008
2011
  data: { result: result, id: id_1 },
2009
2012
  }, '*');