@builder.io/sdk 3.0.7 → 4.0.1

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.umd.js CHANGED
@@ -1052,7 +1052,7 @@
1052
1052
 
1053
1053
  var DEFAULT_API_VERSION = 'v3';
1054
1054
 
1055
- var SDK_VERSION = '3.0.7';
1055
+ var SDK_VERSION = '4.0.1';
1056
1056
 
1057
1057
  function datePlusMinutes(minutes) {
1058
1058
  if (minutes === void 0) { minutes = 30; }
@@ -1379,11 +1379,16 @@
1379
1379
  this.serverContext = context;
1380
1380
  };
1381
1381
  Builder.isTrustedHost = function (hostname) {
1382
- return (this.trustedHosts.findIndex(function (trustedHost) {
1382
+ var isTrusted = this.trustedHosts.findIndex(function (trustedHost) {
1383
1383
  return trustedHost.startsWith('*.')
1384
1384
  ? hostname.endsWith(trustedHost.slice(1))
1385
1385
  : trustedHost === hostname;
1386
- }) > -1);
1386
+ }) > -1;
1387
+ return isTrusted;
1388
+ };
1389
+ Builder.isTrustedHostForEvent = function (event) {
1390
+ var url = parse(event.origin);
1391
+ return url.hostname && Builder.isTrustedHost(url.hostname);
1387
1392
  };
1388
1393
  Builder.runAction = function (action) {
1389
1394
  // TODO
@@ -1933,18 +1938,16 @@
1933
1938
  var _this = this;
1934
1939
  if (isBrowser) {
1935
1940
  addEventListener('message', function (event) {
1936
- var _a, _b, _c, _d, _e;
1937
- var url = parse(event.origin);
1938
- var isRestricted = ['builder.register', 'builder.registerComponent'].indexOf((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === -1;
1939
- var isTrusted = url.hostname && Builder.isTrustedHost(url.hostname);
1940
- if (isRestricted && !isTrusted) {
1941
+ var _a, _b, _c, _d;
1942
+ var isTrusted = Builder.isTrustedHostForEvent(event);
1943
+ if (!isTrusted) {
1941
1944
  return;
1942
1945
  }
1943
1946
  var data = event.data;
1944
1947
  if (data) {
1945
1948
  switch (data.type) {
1946
1949
  case 'builder.ping': {
1947
- (_b = window.parent) === null || _b === void 0 ? void 0 : _b.postMessage({
1950
+ (_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
1948
1951
  type: 'builder.pong',
1949
1952
  data: {},
1950
1953
  }, '*');
@@ -2019,7 +2022,7 @@
2019
2022
  }
2020
2023
  break;
2021
2024
  case 'builder.getComponents':
2022
- (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
2025
+ (_b = window.parent) === null || _b === void 0 ? void 0 : _b.postMessage({
2023
2026
  type: 'builder.components',
2024
2027
  data: Builder.components.map(function (item) { return Builder.prepareComponentSpecToSend(item); }),
2025
2028
  }, '*');
@@ -2058,7 +2061,7 @@
2058
2061
  // TODO: refetch too
2059
2062
  break;
2060
2063
  case 'builder.overrideTestGroup':
2061
- var _f = data.data, variationId = _f.variationId, contentId = _f.contentId;
2064
+ var _e = data.data, variationId = _e.variationId, contentId = _e.contentId;
2062
2065
  if (variationId && contentId) {
2063
2066
  _this.setTestCookie(contentId, variationId);
2064
2067
  _this.flushGetContentQueue(true);
@@ -2079,7 +2082,7 @@
2079
2082
  error = toError(err);
2080
2083
  }
2081
2084
  if (error) {
2082
- (_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
2085
+ (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
2083
2086
  type: 'builder.evaluateError',
2084
2087
  data: { id: id_1, error: error.message },
2085
2088
  }, '*');
@@ -2097,7 +2100,7 @@
2097
2100
  .catch(console.error);
2098
2101
  }
2099
2102
  else {
2100
- (_e = window.parent) === null || _e === void 0 ? void 0 : _e.postMessage({
2103
+ (_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
2101
2104
  type: 'builder.evaluateResult',
2102
2105
  data: { result: result, id: id_1 },
2103
2106
  }, '*');
@@ -2405,6 +2408,7 @@
2405
2408
  };
2406
2409
  Builder.prototype.flushGetContentQueue = function (usePastQueue, useQueue) {
2407
2410
  var _this = this;
2411
+ var _a, _b;
2408
2412
  if (usePastQueue === void 0) { usePastQueue = false; }
2409
2413
  if (!this.apiKey) {
2410
2414
  throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
@@ -2421,7 +2425,6 @@
2421
2425
  return;
2422
2426
  }
2423
2427
  var queue = useQueue || (usePastQueue ? this.priorContentQueue : this.getContentQueue) || [];
2424
- var apiEndpoint = queue[0].apiEndpoint || 'query';
2425
2428
  // TODO: do this on every request send?
2426
2429
  this.getOverridesFromQueryString();
2427
2430
  var queryParams = __assign(__assign({
@@ -2496,6 +2499,7 @@
2496
2499
  }
2497
2500
  }
2498
2501
  }
2502
+ var isApiCallForCodegen = ((_a = queue[0].options) === null || _a === void 0 ? void 0 : _a.format) === 'solid' || ((_b = queue[0].options) === null || _b === void 0 ? void 0 : _b.format) === 'react';
2499
2503
  for (var _i = 0, queue_2 = queue; _i < queue_2.length; _i++) {
2500
2504
  var options = queue_2[_i];
2501
2505
  var format_1 = options.format;
@@ -2527,11 +2531,11 @@
2527
2531
  'rev',
2528
2532
  'static',
2529
2533
  ];
2530
- for (var _a = 0, properties_1 = properties; _a < properties_1.length; _a++) {
2531
- var key = properties_1[_a];
2534
+ for (var _c = 0, properties_1 = properties; _c < properties_1.length; _c++) {
2535
+ var key = properties_1[_c];
2532
2536
  var value = options[key];
2533
2537
  if (value !== undefined) {
2534
- if (apiEndpoint === 'query') {
2538
+ if (isApiCallForCodegen) {
2535
2539
  queryParams.options = queryParams.options || {};
2536
2540
  queryParams.options[options.key] = queryParams.options[options.key] || {};
2537
2541
  queryParams.options[options.key][key] = JSON.stringify(value);
@@ -2553,10 +2557,8 @@
2553
2557
  var params = omit(QueryString.parse(this.overrideParams), 'apiKey');
2554
2558
  assign(queryParams, params);
2555
2559
  }
2556
- var format = queryParams.format;
2557
- var isApiCallForCodegen = format === 'solid' || format === 'react';
2558
- var isApiCallForCodegenOrQuery = isApiCallForCodegen || apiEndpoint === 'query';
2559
- if (apiEndpoint === 'content') {
2560
+ queryParams.format;
2561
+ if (!isApiCallForCodegen) {
2560
2562
  queryParams.enrich = true;
2561
2563
  if (queue[0].query) {
2562
2564
  var flattened = this.flattenMongoQuery({ query: queue[0].query });
@@ -2575,9 +2577,6 @@
2575
2577
  if (isApiCallForCodegen) {
2576
2578
  url = "".concat(host, "/api/v1/codegen/").concat(this.apiKey, "/").concat(keyNames);
2577
2579
  }
2578
- else if (apiEndpoint === 'query') {
2579
- url = "".concat(host, "/api/v3/query/").concat(this.apiKey, "/").concat(keyNames);
2580
- }
2581
2580
  else {
2582
2581
  url = "".concat(host, "/api/v3/content/").concat(queue[0].model);
2583
2582
  }
@@ -2600,7 +2599,7 @@
2600
2599
  if (!observer) {
2601
2600
  return;
2602
2601
  }
2603
- var data = isApiCallForCodegenOrQuery ? result[keyName] : result.results;
2602
+ var data = isApiCallForCodegen ? result[keyName] : result.results;
2604
2603
  var sorted = data; // sortBy(data, item => item.priority);
2605
2604
  if (data) {
2606
2605
  var testModifiedResults = Builder.isServer