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