@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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @builder.io/sdk
2
2
 
3
+ ## 2.2.9
4
+
5
+ ### Patch Changes
6
+
7
+ - b7c00cf: Silence errors from non essential query params parsing
8
+
9
+ ## 2.2.8
10
+
11
+ ### Patch Changes
12
+
13
+ - 11e118c: Fix: serialize all functions within registered component info.
14
+
3
15
  ## 2.2.7
4
16
 
5
17
  ### Patch Changes
@@ -152,7 +152,7 @@
152
152
  throw new Error("Property name \"".concat(name, "\" is not allowed"));
153
153
  }
154
154
 
155
- var version = "2.2.7";
155
+ var version = "2.2.9";
156
156
 
157
157
  var Subscription = /** @class */ (function () {
158
158
  function Subscription(listeners, listener) {
@@ -1441,36 +1441,25 @@
1441
1441
  enumerable: false,
1442
1442
  configurable: true
1443
1443
  });
1444
+ Builder.serializeComponentInfo = function (info) {
1445
+ var serializeFn = function (fnValue) {
1446
+ var fnStr = fnValue.toString().trim();
1447
+ // we need to account for a few different fn syntaxes:
1448
+ // 1. `function name(args) => {code}`
1449
+ // 2. `name(args) => {code}`
1450
+ // 3. `(args) => {}`
1451
+ var appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
1452
+ return "return (".concat(appendFunction ? 'function ' : '').concat(fnStr, ").apply(this, arguments)");
1453
+ };
1454
+ return JSON.parse(JSON.stringify(info, function (key, value) {
1455
+ if (typeof value === 'function') {
1456
+ return serializeFn(value);
1457
+ }
1458
+ return value;
1459
+ }));
1460
+ };
1444
1461
  Builder.prepareComponentSpecToSend = function (spec) {
1445
- return __assign(__assign(__assign({}, spec), (spec.inputs && {
1446
- inputs: spec.inputs.map(function (input) {
1447
- var _a;
1448
- // TODO: do for nexted fields too
1449
- // TODO: probably just convert all functions, not just
1450
- // TODO: put this in input hooks: { onChange: ..., showIf: ... }
1451
- var keysToConvertFnToString = ['onChange', 'showIf'];
1452
- for (var _i = 0, keysToConvertFnToString_1 = keysToConvertFnToString; _i < keysToConvertFnToString_1.length; _i++) {
1453
- var key = keysToConvertFnToString_1[_i];
1454
- if (input[key] && typeof input[key] === 'function') {
1455
- var fn = input[key];
1456
- input = __assign(__assign({}, input), (_a = {}, _a[key] = "return (".concat(fn.toString(), ").apply(this, arguments)"), _a));
1457
- }
1458
- }
1459
- return input;
1460
- }),
1461
- })), { hooks: Object.keys(spec.hooks || {}).reduce(function (memo, key) {
1462
- var value = spec.hooks && spec.hooks[key];
1463
- if (!value) {
1464
- return memo;
1465
- }
1466
- if (typeof value === 'string') {
1467
- memo[key] = value;
1468
- }
1469
- else {
1470
- memo[key] = "return (".concat(value.toString(), ").apply(this, arguments)");
1471
- }
1472
- return memo;
1473
- }, {}), class: undefined });
1462
+ return __assign(__assign({}, this.serializeComponentInfo(spec)), { class: undefined });
1474
1463
  };
1475
1464
  Builder.registerBlock = function (component, options) {
1476
1465
  this.registerComponent(component, options);
@@ -1861,15 +1850,20 @@
1861
1850
  };
1862
1851
  Builder.prototype.setTestsFromUrl = function () {
1863
1852
  var search = this.getLocation().search;
1864
- var params = QueryString.parseDeep(this.modifySearch(search || '').substr(1));
1865
- var tests = params.builder && params.builder.tests;
1866
- if (tests && typeof tests === 'object') {
1867
- for (var key in tests) {
1868
- if (tests.hasOwnProperty(key)) {
1869
- this.setTestCookie(key, tests[key]);
1853
+ try {
1854
+ var params = QueryString.parseDeep(this.modifySearch(search || '').substr(1));
1855
+ var tests = params.builder && params.builder.tests;
1856
+ if (tests && typeof tests === 'object') {
1857
+ for (var key in tests) {
1858
+ if (tests.hasOwnProperty(key)) {
1859
+ this.setTestCookie(key, tests[key]);
1860
+ }
1870
1861
  }
1871
1862
  }
1872
1863
  }
1864
+ catch (e) {
1865
+ console.debug('Error parsing tests from URL', e);
1866
+ }
1873
1867
  };
1874
1868
  Builder.prototype.resetOverrides = function () {
1875
1869
  // Ugly - pass down instances per request instead using react context
@@ -1887,41 +1881,46 @@
1887
1881
  };
1888
1882
  Builder.prototype.getOverridesFromQueryString = function () {
1889
1883
  var location = this.getLocation();
1890
- var params = QueryString.parseDeep(this.modifySearch(location.search || '').substr(1));
1891
- var builder = params.builder;
1892
- if (builder) {
1893
- 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;
1894
- if (userAttributes) {
1895
- this.setUserAttributes(userAttributes);
1896
- }
1897
- if (options) {
1898
- // picking only locale, includeRefs, and enrich for now
1899
- this.queryOptions = __assign(__assign(__assign({}, (options.locale && { locale: options.locale })), (options.includeRefs && { includeRefs: options.includeRefs })), (options.enrich && { enrich: options.enrich }));
1900
- }
1901
- if (overrides) {
1902
- this.overrides = overrides;
1903
- }
1904
- if (validEnvList.indexOf(env || api) > -1) {
1905
- this.env = env || api;
1906
- }
1907
- if (Builder.isEditing) {
1908
- var editingModel = frameEditing || editing || preview;
1909
- if (editingModel && editingModel !== 'true') {
1910
- this.editingModel = editingModel;
1884
+ try {
1885
+ var params = QueryString.parseDeep(this.modifySearch(location.search || '').substr(1));
1886
+ var builder = params.builder;
1887
+ if (builder) {
1888
+ 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;
1889
+ if (userAttributes) {
1890
+ this.setUserAttributes(userAttributes);
1891
+ }
1892
+ if (options) {
1893
+ // picking only locale, includeRefs, and enrich for now
1894
+ this.queryOptions = __assign(__assign(__assign({}, (options.locale && { locale: options.locale })), (options.includeRefs && { includeRefs: options.includeRefs })), (options.enrich && { enrich: options.enrich }));
1895
+ }
1896
+ if (overrides) {
1897
+ this.overrides = overrides;
1898
+ }
1899
+ if (validEnvList.indexOf(env || api) > -1) {
1900
+ this.env = env || api;
1901
+ }
1902
+ if (Builder.isEditing) {
1903
+ var editingModel = frameEditing || editing || preview;
1904
+ if (editingModel && editingModel !== 'true') {
1905
+ this.editingModel = editingModel;
1906
+ }
1907
+ }
1908
+ if (cachebust) {
1909
+ this.cachebust = true;
1910
+ }
1911
+ if (noCache) {
1912
+ this.noCache = true;
1913
+ }
1914
+ if (preview) {
1915
+ this.preview = true;
1916
+ }
1917
+ if (params) {
1918
+ this.overrideParams = overrideParams;
1911
1919
  }
1912
1920
  }
1913
- if (cachebust) {
1914
- this.cachebust = true;
1915
- }
1916
- if (noCache) {
1917
- this.noCache = true;
1918
- }
1919
- if (preview) {
1920
- this.preview = true;
1921
- }
1922
- if (params) {
1923
- this.overrideParams = overrideParams;
1924
- }
1921
+ }
1922
+ catch (e) {
1923
+ console.debug('Error parsing overrides from URL', e);
1925
1924
  }
1926
1925
  };
1927
1926
  Builder.prototype.messageFrameLoaded = function () {