@builder.io/sdk 2.2.7-0 → 2.2.8

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.
Files changed (34) hide show
  1. package/.yarnrc.yml +1 -0
  2. package/CHANGELOG.md +12 -0
  3. package/dist/index.browser.js +58 -79
  4. package/dist/index.browser.js.map +1 -1
  5. package/dist/index.cjs.js +58 -79
  6. package/dist/index.cjs.js.map +1 -1
  7. package/dist/index.esm.js +58 -79
  8. package/dist/index.esm.js.map +1 -1
  9. package/dist/index.umd.js +58 -79
  10. package/dist/index.umd.js.map +1 -1
  11. package/dist/package.json +1 -1
  12. package/dist/src/builder.class.d.ts +1 -0
  13. package/dist/src/builder.class.js +57 -78
  14. package/dist/src/builder.class.js.map +1 -1
  15. package/dist/src/builder.class.test.js +136 -0
  16. package/dist/src/builder.class.test.js.map +1 -1
  17. package/dist/src/classes/promise.class.js +154 -150
  18. package/dist/src/classes/query-string.class.js +74 -73
  19. package/dist/src/classes/query-string.class.test.js +20 -20
  20. package/dist/src/functions/assign.function.js +19 -19
  21. package/dist/src/functions/fetch.function.js +75 -97
  22. package/dist/src/functions/finder.function.js +274 -389
  23. package/dist/src/functions/get-top-level-domain.js +8 -8
  24. package/dist/src/functions/next-tick.function.js +23 -26
  25. package/dist/src/functions/omit.function.js +13 -13
  26. package/dist/src/functions/server-only-require.function.js +9 -10
  27. package/dist/src/functions/throttle.function.js +37 -35
  28. package/dist/src/functions/to-error.js +6 -5
  29. package/dist/src/functions/uuid.js +8 -9
  30. package/dist/src/types/api-version.js +3 -3
  31. package/dist/src/types/element.js +3 -3
  32. package/dist/src/url.test.js +118 -222
  33. package/dist/tsconfig.tsbuildinfo +1 -1
  34. package/package.json +3 -4
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.6";
129
+ var version = "2.2.8";
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,20 +1756,15 @@ var Builder = /** @class */ (function () {
1767
1756
  };
1768
1757
  Builder.prototype.setTestsFromUrl = function () {
1769
1758
  var search = this.getLocation().search;
1770
- try {
1771
- var params = QueryString.parseDeep(this.modifySearch(search || '').substr(1));
1772
- var tests = params.builder && params.builder.tests;
1773
- if (tests && typeof tests === 'object') {
1774
- for (var key in tests) {
1775
- if (tests.hasOwnProperty(key)) {
1776
- this.setTestCookie(key, tests[key]);
1777
- }
1759
+ var params = QueryString.parseDeep(this.modifySearch(search || '').substr(1));
1760
+ var tests = params.builder && params.builder.tests;
1761
+ if (tests && typeof tests === 'object') {
1762
+ for (var key in tests) {
1763
+ if (tests.hasOwnProperty(key)) {
1764
+ this.setTestCookie(key, tests[key]);
1778
1765
  }
1779
1766
  }
1780
1767
  }
1781
- catch (e) {
1782
- console.debug('Error parsing tests from URL', e);
1783
- }
1784
1768
  };
1785
1769
  Builder.prototype.resetOverrides = function () {
1786
1770
  // Ugly - pass down instances per request instead using react context
@@ -1798,46 +1782,41 @@ var Builder = /** @class */ (function () {
1798
1782
  };
1799
1783
  Builder.prototype.getOverridesFromQueryString = function () {
1800
1784
  var location = this.getLocation();
1801
- try {
1802
- var params = QueryString.parseDeep(this.modifySearch(location.search || '').substr(1));
1803
- var builder = params.builder;
1804
- if (builder) {
1805
- 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;
1806
- if (userAttributes) {
1807
- this.setUserAttributes(userAttributes);
1808
- }
1809
- if (options) {
1810
- // picking only locale, includeRefs, and enrich for now
1811
- this.queryOptions = tslib.__assign(tslib.__assign(tslib.__assign({}, (options.locale && { locale: options.locale })), (options.includeRefs && { includeRefs: options.includeRefs })), (options.enrich && { enrich: options.enrich }));
1812
- }
1813
- if (overrides) {
1814
- this.overrides = overrides;
1815
- }
1816
- if (validEnvList.indexOf(env || api) > -1) {
1817
- this.env = env || api;
1818
- }
1819
- if (Builder.isEditing) {
1820
- var editingModel = frameEditing || editing || preview;
1821
- if (editingModel && editingModel !== 'true') {
1822
- this.editingModel = editingModel;
1823
- }
1824
- }
1825
- if (cachebust) {
1826
- this.cachebust = true;
1827
- }
1828
- if (noCache) {
1829
- this.noCache = true;
1830
- }
1831
- if (preview) {
1832
- this.preview = true;
1833
- }
1834
- if (params) {
1835
- this.overrideParams = overrideParams;
1785
+ var params = QueryString.parseDeep(this.modifySearch(location.search || '').substr(1));
1786
+ var builder = params.builder;
1787
+ if (builder) {
1788
+ 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;
1789
+ if (userAttributes) {
1790
+ this.setUserAttributes(userAttributes);
1791
+ }
1792
+ if (options) {
1793
+ // picking only locale, includeRefs, and enrich for now
1794
+ this.queryOptions = tslib.__assign(tslib.__assign(tslib.__assign({}, (options.locale && { locale: options.locale })), (options.includeRefs && { includeRefs: options.includeRefs })), (options.enrich && { enrich: options.enrich }));
1795
+ }
1796
+ if (overrides) {
1797
+ this.overrides = overrides;
1798
+ }
1799
+ if (validEnvList.indexOf(env || api) > -1) {
1800
+ this.env = env || api;
1801
+ }
1802
+ if (Builder.isEditing) {
1803
+ var editingModel = frameEditing || editing || preview;
1804
+ if (editingModel && editingModel !== 'true') {
1805
+ this.editingModel = editingModel;
1836
1806
  }
1837
1807
  }
1838
- }
1839
- catch (e) {
1840
- console.debug('Error parsing overrides from URL', e);
1808
+ if (cachebust) {
1809
+ this.cachebust = true;
1810
+ }
1811
+ if (noCache) {
1812
+ this.noCache = true;
1813
+ }
1814
+ if (preview) {
1815
+ this.preview = true;
1816
+ }
1817
+ if (params) {
1818
+ this.overrideParams = overrideParams;
1819
+ }
1841
1820
  }
1842
1821
  };
1843
1822
  Builder.prototype.messageFrameLoaded = function () {