@builder.io/sdk 2.2.7 → 2.2.9

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
@@ -126,7 +126,7 @@ function assertAllowedPropertyName(name) {
126
126
  throw new Error("Property name \"".concat(name, "\" is not allowed"));
127
127
  }
128
128
 
129
- var version = "2.2.7";
129
+ var version = "2.2.9";
130
130
 
131
131
  var Subscription = /** @class */ (function () {
132
132
  function Subscription(listeners, listener) {
@@ -1347,36 +1347,25 @@ var Builder = /** @class */ (function () {
1347
1347
  enumerable: false,
1348
1348
  configurable: true
1349
1349
  });
1350
+ Builder.serializeComponentInfo = function (info) {
1351
+ var serializeFn = function (fnValue) {
1352
+ var fnStr = fnValue.toString().trim();
1353
+ // we need to account for a few different fn syntaxes:
1354
+ // 1. `function name(args) => {code}`
1355
+ // 2. `name(args) => {code}`
1356
+ // 3. `(args) => {}`
1357
+ var appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
1358
+ return "return (".concat(appendFunction ? 'function ' : '').concat(fnStr, ").apply(this, arguments)");
1359
+ };
1360
+ return JSON.parse(JSON.stringify(info, function (key, value) {
1361
+ if (typeof value === 'function') {
1362
+ return serializeFn(value);
1363
+ }
1364
+ return value;
1365
+ }));
1366
+ };
1350
1367
  Builder.prepareComponentSpecToSend = function (spec) {
1351
- return tslib.__assign(tslib.__assign(tslib.__assign({}, spec), (spec.inputs && {
1352
- inputs: spec.inputs.map(function (input) {
1353
- var _a;
1354
- // TODO: do for nexted fields too
1355
- // TODO: probably just convert all functions, not just
1356
- // TODO: put this in input hooks: { onChange: ..., showIf: ... }
1357
- var keysToConvertFnToString = ['onChange', 'showIf'];
1358
- for (var _i = 0, keysToConvertFnToString_1 = keysToConvertFnToString; _i < keysToConvertFnToString_1.length; _i++) {
1359
- var key = keysToConvertFnToString_1[_i];
1360
- if (input[key] && typeof input[key] === 'function') {
1361
- var fn = input[key];
1362
- input = tslib.__assign(tslib.__assign({}, input), (_a = {}, _a[key] = "return (".concat(fn.toString(), ").apply(this, arguments)"), _a));
1363
- }
1364
- }
1365
- return input;
1366
- }),
1367
- })), { hooks: Object.keys(spec.hooks || {}).reduce(function (memo, key) {
1368
- var value = spec.hooks && spec.hooks[key];
1369
- if (!value) {
1370
- return memo;
1371
- }
1372
- if (typeof value === 'string') {
1373
- memo[key] = value;
1374
- }
1375
- else {
1376
- memo[key] = "return (".concat(value.toString(), ").apply(this, arguments)");
1377
- }
1378
- return memo;
1379
- }, {}), class: undefined });
1368
+ return tslib.__assign(tslib.__assign({}, this.serializeComponentInfo(spec)), { class: undefined });
1380
1369
  };
1381
1370
  Builder.registerBlock = function (component, options) {
1382
1371
  this.registerComponent(component, options);
@@ -1767,15 +1756,20 @@ var Builder = /** @class */ (function () {
1767
1756
  };
1768
1757
  Builder.prototype.setTestsFromUrl = function () {
1769
1758
  var search = this.getLocation().search;
1770
- var params = QueryString.parseDeep(this.modifySearch(search || '').substr(1));
1771
- var tests = params.builder && params.builder.tests;
1772
- if (tests && typeof tests === 'object') {
1773
- for (var key in tests) {
1774
- if (tests.hasOwnProperty(key)) {
1775
- this.setTestCookie(key, tests[key]);
1759
+ try {
1760
+ var params = QueryString.parseDeep(this.modifySearch(search || '').substr(1));
1761
+ var tests = params.builder && params.builder.tests;
1762
+ if (tests && typeof tests === 'object') {
1763
+ for (var key in tests) {
1764
+ if (tests.hasOwnProperty(key)) {
1765
+ this.setTestCookie(key, tests[key]);
1766
+ }
1776
1767
  }
1777
1768
  }
1778
1769
  }
1770
+ catch (e) {
1771
+ console.debug('Error parsing tests from URL', e);
1772
+ }
1779
1773
  };
1780
1774
  Builder.prototype.resetOverrides = function () {
1781
1775
  // Ugly - pass down instances per request instead using react context
@@ -1793,41 +1787,46 @@ var Builder = /** @class */ (function () {
1793
1787
  };
1794
1788
  Builder.prototype.getOverridesFromQueryString = function () {
1795
1789
  var location = this.getLocation();
1796
- var params = QueryString.parseDeep(this.modifySearch(location.search || '').substr(1));
1797
- var builder = params.builder;
1798
- if (builder) {
1799
- var userAttributes = builder.userAttributes, overrides = builder.overrides, env = builder.env; builder.host; var api = builder.api, cachebust = builder.cachebust, noCache = builder.noCache, preview = builder.preview, editing = builder.editing, frameEditing = builder.frameEditing, options = builder.options, overrideParams = builder.params;
1800
- if (userAttributes) {
1801
- this.setUserAttributes(userAttributes);
1802
- }
1803
- if (options) {
1804
- // picking only locale, includeRefs, and enrich for now
1805
- this.queryOptions = tslib.__assign(tslib.__assign(tslib.__assign({}, (options.locale && { locale: options.locale })), (options.includeRefs && { includeRefs: options.includeRefs })), (options.enrich && { enrich: options.enrich }));
1806
- }
1807
- if (overrides) {
1808
- this.overrides = overrides;
1809
- }
1810
- if (validEnvList.indexOf(env || api) > -1) {
1811
- this.env = env || api;
1812
- }
1813
- if (Builder.isEditing) {
1814
- var editingModel = frameEditing || editing || preview;
1815
- if (editingModel && editingModel !== 'true') {
1816
- this.editingModel = editingModel;
1790
+ try {
1791
+ var params = QueryString.parseDeep(this.modifySearch(location.search || '').substr(1));
1792
+ var builder = params.builder;
1793
+ if (builder) {
1794
+ var userAttributes = builder.userAttributes, overrides = builder.overrides, env = builder.env, host = builder.host, api = builder.api, cachebust = builder.cachebust, noCache = builder.noCache, preview = builder.preview, editing = builder.editing, frameEditing = builder.frameEditing, options = builder.options, overrideParams = builder.params;
1795
+ if (userAttributes) {
1796
+ this.setUserAttributes(userAttributes);
1797
+ }
1798
+ if (options) {
1799
+ // picking only locale, includeRefs, and enrich for now
1800
+ this.queryOptions = tslib.__assign(tslib.__assign(tslib.__assign({}, (options.locale && { locale: options.locale })), (options.includeRefs && { includeRefs: options.includeRefs })), (options.enrich && { enrich: options.enrich }));
1801
+ }
1802
+ if (overrides) {
1803
+ this.overrides = overrides;
1804
+ }
1805
+ if (validEnvList.indexOf(env || api) > -1) {
1806
+ this.env = env || api;
1807
+ }
1808
+ if (Builder.isEditing) {
1809
+ var editingModel = frameEditing || editing || preview;
1810
+ if (editingModel && editingModel !== 'true') {
1811
+ this.editingModel = editingModel;
1812
+ }
1813
+ }
1814
+ if (cachebust) {
1815
+ this.cachebust = true;
1816
+ }
1817
+ if (noCache) {
1818
+ this.noCache = true;
1819
+ }
1820
+ if (preview) {
1821
+ this.preview = true;
1822
+ }
1823
+ if (params) {
1824
+ this.overrideParams = overrideParams;
1817
1825
  }
1818
1826
  }
1819
- if (cachebust) {
1820
- this.cachebust = true;
1821
- }
1822
- if (noCache) {
1823
- this.noCache = true;
1824
- }
1825
- if (preview) {
1826
- this.preview = true;
1827
- }
1828
- if (params) {
1829
- this.overrideParams = overrideParams;
1830
- }
1827
+ }
1828
+ catch (e) {
1829
+ console.debug('Error parsing overrides from URL', e);
1831
1830
  }
1832
1831
  };
1833
1832
  Builder.prototype.messageFrameLoaded = function () {