@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/.yarnrc.yml ADDED
@@ -0,0 +1 @@
1
+ npmPublishAccess: "public"
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @builder.io/sdk
2
2
 
3
+ ## 2.2.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 11e118c: Fix: serialize all functions within registered component info.
8
+
9
+ ## 2.2.7
10
+
11
+ ### Patch Changes
12
+
13
+ - b965695: Fix: reverts `v2.2.5` change to `userAttributes` parsing logic, as it caused breaking changes in certain cases.
14
+
3
15
  ## 2.2.6
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.6";
155
+ var version = "2.2.8";
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,20 +1850,15 @@
1861
1850
  };
1862
1851
  Builder.prototype.setTestsFromUrl = function () {
1863
1852
  var search = this.getLocation().search;
1864
- try {
1865
- var params = QueryString.parseDeep(this.modifySearch(search || '').substr(1));
1866
- var tests = params.builder && params.builder.tests;
1867
- if (tests && typeof tests === 'object') {
1868
- for (var key in tests) {
1869
- if (tests.hasOwnProperty(key)) {
1870
- this.setTestCookie(key, tests[key]);
1871
- }
1853
+ var params = QueryString.parseDeep(this.modifySearch(search || '').substr(1));
1854
+ var tests = params.builder && params.builder.tests;
1855
+ if (tests && typeof tests === 'object') {
1856
+ for (var key in tests) {
1857
+ if (tests.hasOwnProperty(key)) {
1858
+ this.setTestCookie(key, tests[key]);
1872
1859
  }
1873
1860
  }
1874
1861
  }
1875
- catch (e) {
1876
- console.debug('Error parsing tests from URL', e);
1877
- }
1878
1862
  };
1879
1863
  Builder.prototype.resetOverrides = function () {
1880
1864
  // Ugly - pass down instances per request instead using react context
@@ -1892,46 +1876,41 @@
1892
1876
  };
1893
1877
  Builder.prototype.getOverridesFromQueryString = function () {
1894
1878
  var location = this.getLocation();
1895
- try {
1896
- var params = QueryString.parseDeep(this.modifySearch(location.search || '').substr(1));
1897
- var builder = params.builder;
1898
- if (builder) {
1899
- 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;
1900
- if (userAttributes) {
1901
- this.setUserAttributes(userAttributes);
1902
- }
1903
- if (options) {
1904
- // picking only locale, includeRefs, and enrich for now
1905
- this.queryOptions = __assign(__assign(__assign({}, (options.locale && { locale: options.locale })), (options.includeRefs && { includeRefs: options.includeRefs })), (options.enrich && { enrich: options.enrich }));
1906
- }
1907
- if (overrides) {
1908
- this.overrides = overrides;
1909
- }
1910
- if (validEnvList.indexOf(env || api) > -1) {
1911
- this.env = env || api;
1912
- }
1913
- if (Builder.isEditing) {
1914
- var editingModel = frameEditing || editing || preview;
1915
- if (editingModel && editingModel !== 'true') {
1916
- this.editingModel = editingModel;
1917
- }
1918
- }
1919
- if (cachebust) {
1920
- this.cachebust = true;
1921
- }
1922
- if (noCache) {
1923
- this.noCache = true;
1924
- }
1925
- if (preview) {
1926
- this.preview = true;
1927
- }
1928
- if (params) {
1929
- this.overrideParams = overrideParams;
1879
+ var params = QueryString.parseDeep(this.modifySearch(location.search || '').substr(1));
1880
+ var builder = params.builder;
1881
+ if (builder) {
1882
+ 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;
1883
+ if (userAttributes) {
1884
+ this.setUserAttributes(userAttributes);
1885
+ }
1886
+ if (options) {
1887
+ // picking only locale, includeRefs, and enrich for now
1888
+ this.queryOptions = __assign(__assign(__assign({}, (options.locale && { locale: options.locale })), (options.includeRefs && { includeRefs: options.includeRefs })), (options.enrich && { enrich: options.enrich }));
1889
+ }
1890
+ if (overrides) {
1891
+ this.overrides = overrides;
1892
+ }
1893
+ if (validEnvList.indexOf(env || api) > -1) {
1894
+ this.env = env || api;
1895
+ }
1896
+ if (Builder.isEditing) {
1897
+ var editingModel = frameEditing || editing || preview;
1898
+ if (editingModel && editingModel !== 'true') {
1899
+ this.editingModel = editingModel;
1930
1900
  }
1931
1901
  }
1932
- }
1933
- catch (e) {
1934
- console.debug('Error parsing overrides from URL', e);
1902
+ if (cachebust) {
1903
+ this.cachebust = true;
1904
+ }
1905
+ if (noCache) {
1906
+ this.noCache = true;
1907
+ }
1908
+ if (preview) {
1909
+ this.preview = true;
1910
+ }
1911
+ if (params) {
1912
+ this.overrideParams = overrideParams;
1913
+ }
1935
1914
  }
1936
1915
  };
1937
1916
  Builder.prototype.messageFrameLoaded = function () {