@builder.io/sdk 5.0.0 → 6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @builder.io/sdk
2
2
 
3
+ ## 6.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - c822422: Fix: symbols will now show published content instead of preview/autosave content while editing a page
8
+
9
+ ## 6.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - 56f9461: - Adds `apiEndpoint` prop to `builder` instance with permitted values being `'content'` or `'query'`. It dictates which API endpoint is used for fetching Builder content
14
+ - Breaking Change 🧨: Removes `apiEndpoint` argument from `builder.get()`, `builder.getAll()`, and the `options` prop of `<BuilderContent>` component. NOTE: this argument was not working as expected.
15
+
16
+ ### Patch Changes
17
+
18
+ - 06b1124: Fix: Content API invocations will have `includeRefs` set to `true` by default.
19
+ - 409aec9: Feat: add `meta` type to custom components
20
+ - 40d572d: Renders Symbol correctly when apiEndpoint is 'content'
21
+ - 2fc9fc5: Fix: `onChange` functions passed to builder inputs can now receive async functions
22
+
3
23
  ## 5.0.0
4
24
 
5
25
  ### Major Changes
@@ -1052,7 +1052,7 @@
1052
1052
 
1053
1053
  var DEFAULT_API_VERSION = 'v3';
1054
1054
 
1055
- var SDK_VERSION = '5.0.0';
1055
+ var SDK_VERSION = '6.0.1';
1056
1056
 
1057
1057
  function datePlusMinutes(minutes) {
1058
1058
  if (minutes === void 0) { minutes = 30; }
@@ -1200,6 +1200,11 @@
1200
1200
  this.overrideParams = '';
1201
1201
  this.noCache = false;
1202
1202
  this.preview = false;
1203
+ /**
1204
+ * Dictates which API endpoint is used when fetching content. Allows `'content'` and `'query'`.
1205
+ * Defaults to `'query'`.
1206
+ */
1207
+ this.apiEndpoint$ = new BehaviorSubject('query');
1203
1208
  this.apiVersion$ = new BehaviorSubject(undefined);
1204
1209
  this.canTrack$ = new BehaviorSubject(!this.browserTrackingDisabled);
1205
1210
  this.apiKey$ = new BehaviorSubject(null);
@@ -1453,8 +1458,14 @@
1453
1458
  // 2. `name(args) => {code}`
1454
1459
  // 3. `(args) => {}`
1455
1460
  // 4. `args => {}`
1461
+ // 5. `async function(args) {code}`
1462
+ // 6. `async (args) => {}`
1463
+ // 7. `async args => {}`
1456
1464
  var isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
1457
- var appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(') && !isArrowWithoutParens;
1465
+ var appendFunction = !fnStr.startsWith('function') &&
1466
+ !fnStr.startsWith('async') &&
1467
+ !fnStr.startsWith('(') &&
1468
+ !isArrowWithoutParens;
1458
1469
  return "return (".concat(appendFunction ? 'function ' : '').concat(fnStr, ").apply(this, arguments)");
1459
1470
  };
1460
1471
  return JSON.parse(JSON.stringify(info, function (key, value) {
@@ -1586,6 +1597,18 @@
1586
1597
  enumerable: false,
1587
1598
  configurable: true
1588
1599
  });
1600
+ Object.defineProperty(Builder.prototype, "apiEndpoint", {
1601
+ get: function () {
1602
+ return this.apiEndpoint$.value;
1603
+ },
1604
+ set: function (apiEndpoint) {
1605
+ if (this.apiEndpoint !== apiEndpoint) {
1606
+ this.apiEndpoint$.next(apiEndpoint);
1607
+ }
1608
+ },
1609
+ enumerable: false,
1610
+ configurable: true
1611
+ });
1589
1612
  Object.defineProperty(Builder.prototype, "editingMode", {
1590
1613
  get: function () {
1591
1614
  return this.editingMode$.value;
@@ -2224,12 +2247,16 @@
2224
2247
  if (options === void 0) { options = {}; }
2225
2248
  var instance = this;
2226
2249
  var finalLocale = options.locale || ((_a = options.userAttributes) === null || _a === void 0 ? void 0 : _a.locale) || this.getUserAttributes().locale;
2250
+ if (!('noTraverse' in options)) {
2251
+ options.noTraverse = false;
2252
+ }
2227
2253
  var finalOptions = __assign(__assign({}, options), (finalLocale && {
2228
2254
  locale: String(finalLocale),
2229
2255
  userAttributes: __assign({ locale: String(finalLocale) }, options.userAttributes),
2230
2256
  }));
2231
2257
  if (!Builder.isBrowser) {
2232
2258
  instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, undefined, options.authToken || this.authToken, options.apiVersion || this.apiVersion);
2259
+ instance.apiEndpoint = this.apiEndpoint;
2233
2260
  instance.setUserAttributes(this.getUserAttributes());
2234
2261
  }
2235
2262
  else {
@@ -2413,6 +2440,7 @@
2413
2440
  };
2414
2441
  Builder.prototype.flushGetContentQueue = function (usePastQueue, useQueue) {
2415
2442
  var _this = this;
2443
+ var _a;
2416
2444
  if (usePastQueue === void 0) { usePastQueue = false; }
2417
2445
  if (!this.apiKey) {
2418
2446
  throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
@@ -2429,7 +2457,6 @@
2429
2457
  return;
2430
2458
  }
2431
2459
  var queue = useQueue || (usePastQueue ? this.priorContentQueue : this.getContentQueue) || [];
2432
- var apiEndpoint = queue[0].apiEndpoint || 'query';
2433
2460
  // TODO: do this on every request send?
2434
2461
  this.getOverridesFromQueryString();
2435
2462
  var queryParams = __assign(__assign({
@@ -2523,6 +2550,9 @@
2523
2550
  if (isPositiveNumber(options.staleCacheSeconds)) {
2524
2551
  queryParams.staleCacheSeconds = options.staleCacheSeconds;
2525
2552
  }
2553
+ if (this.apiEndpoint === 'content') {
2554
+ queryParams.includeRefs = true;
2555
+ }
2526
2556
  var properties = [
2527
2557
  'prerender',
2528
2558
  'extractCss',
@@ -2534,12 +2564,13 @@
2534
2564
  'entry',
2535
2565
  'rev',
2536
2566
  'static',
2567
+ 'includeRefs',
2537
2568
  ];
2538
- for (var _a = 0, properties_1 = properties; _a < properties_1.length; _a++) {
2539
- var key = properties_1[_a];
2569
+ for (var _b = 0, properties_1 = properties; _b < properties_1.length; _b++) {
2570
+ var key = properties_1[_b];
2540
2571
  var value = options[key];
2541
2572
  if (value !== undefined) {
2542
- if (apiEndpoint === 'query') {
2573
+ if (this.apiEndpoint === 'query') {
2543
2574
  queryParams.options = queryParams.options || {};
2544
2575
  queryParams.options[options.key] = queryParams.options[options.key] || {};
2545
2576
  queryParams.options[options.key][key] = JSON.stringify(value);
@@ -2550,7 +2581,7 @@
2550
2581
  }
2551
2582
  }
2552
2583
  }
2553
- if (this.preview) {
2584
+ if (this.preview && this.previewingModel === ((_a = queue === null || queue === void 0 ? void 0 : queue[0]) === null || _a === void 0 ? void 0 : _a.model)) {
2554
2585
  queryParams.preview = 'true';
2555
2586
  }
2556
2587
  var hasParams = Object.keys(queryParams).length > 0;
@@ -2563,9 +2594,8 @@
2563
2594
  }
2564
2595
  var format = queryParams.format;
2565
2596
  var isApiCallForCodegen = format === 'solid' || format === 'react';
2566
- var isApiCallForCodegenOrQuery = isApiCallForCodegen || apiEndpoint === 'query';
2567
- if (apiEndpoint === 'content') {
2568
- queryParams.enrich = true;
2597
+ var isApiCallForCodegenOrQuery = isApiCallForCodegen || this.apiEndpoint === 'query';
2598
+ if (this.apiEndpoint === 'content') {
2569
2599
  if (queue[0].query) {
2570
2600
  var flattened = this.flattenMongoQuery({ query: queue[0].query });
2571
2601
  for (var key in flattened) {
@@ -2583,7 +2613,7 @@
2583
2613
  if (isApiCallForCodegen) {
2584
2614
  url = "".concat(host, "/api/v1/codegen/").concat(this.apiKey, "/").concat(keyNames);
2585
2615
  }
2586
- else if (apiEndpoint === 'query') {
2616
+ else if (this.apiEndpoint === 'query') {
2587
2617
  url = "".concat(host, "/api/v3/query/").concat(this.apiKey, "/").concat(keyNames);
2588
2618
  }
2589
2619
  else {