@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/dist/index.esm.js CHANGED
@@ -950,7 +950,7 @@ function toError(err) {
950
950
 
951
951
  var DEFAULT_API_VERSION = 'v3';
952
952
 
953
- var SDK_VERSION = '5.0.0';
953
+ var SDK_VERSION = '6.0.1';
954
954
 
955
955
  function datePlusMinutes(minutes) {
956
956
  if (minutes === void 0) { minutes = 30; }
@@ -1098,6 +1098,11 @@ var Builder = /** @class */ (function () {
1098
1098
  this.overrideParams = '';
1099
1099
  this.noCache = false;
1100
1100
  this.preview = false;
1101
+ /**
1102
+ * Dictates which API endpoint is used when fetching content. Allows `'content'` and `'query'`.
1103
+ * Defaults to `'query'`.
1104
+ */
1105
+ this.apiEndpoint$ = new BehaviorSubject('query');
1101
1106
  this.apiVersion$ = new BehaviorSubject(undefined);
1102
1107
  this.canTrack$ = new BehaviorSubject(!this.browserTrackingDisabled);
1103
1108
  this.apiKey$ = new BehaviorSubject(null);
@@ -1351,8 +1356,14 @@ var Builder = /** @class */ (function () {
1351
1356
  // 2. `name(args) => {code}`
1352
1357
  // 3. `(args) => {}`
1353
1358
  // 4. `args => {}`
1359
+ // 5. `async function(args) {code}`
1360
+ // 6. `async (args) => {}`
1361
+ // 7. `async args => {}`
1354
1362
  var isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
1355
- var appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(') && !isArrowWithoutParens;
1363
+ var appendFunction = !fnStr.startsWith('function') &&
1364
+ !fnStr.startsWith('async') &&
1365
+ !fnStr.startsWith('(') &&
1366
+ !isArrowWithoutParens;
1356
1367
  return "return (".concat(appendFunction ? 'function ' : '').concat(fnStr, ").apply(this, arguments)");
1357
1368
  };
1358
1369
  return JSON.parse(JSON.stringify(info, function (key, value) {
@@ -1484,6 +1495,18 @@ var Builder = /** @class */ (function () {
1484
1495
  enumerable: false,
1485
1496
  configurable: true
1486
1497
  });
1498
+ Object.defineProperty(Builder.prototype, "apiEndpoint", {
1499
+ get: function () {
1500
+ return this.apiEndpoint$.value;
1501
+ },
1502
+ set: function (apiEndpoint) {
1503
+ if (this.apiEndpoint !== apiEndpoint) {
1504
+ this.apiEndpoint$.next(apiEndpoint);
1505
+ }
1506
+ },
1507
+ enumerable: false,
1508
+ configurable: true
1509
+ });
1487
1510
  Object.defineProperty(Builder.prototype, "editingMode", {
1488
1511
  get: function () {
1489
1512
  return this.editingMode$.value;
@@ -2122,12 +2145,16 @@ var Builder = /** @class */ (function () {
2122
2145
  if (options === void 0) { options = {}; }
2123
2146
  var instance = this;
2124
2147
  var finalLocale = options.locale || ((_a = options.userAttributes) === null || _a === void 0 ? void 0 : _a.locale) || this.getUserAttributes().locale;
2148
+ if (!('noTraverse' in options)) {
2149
+ options.noTraverse = false;
2150
+ }
2125
2151
  var finalOptions = __assign(__assign({}, options), (finalLocale && {
2126
2152
  locale: String(finalLocale),
2127
2153
  userAttributes: __assign({ locale: String(finalLocale) }, options.userAttributes),
2128
2154
  }));
2129
2155
  if (!Builder.isBrowser) {
2130
2156
  instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, undefined, options.authToken || this.authToken, options.apiVersion || this.apiVersion);
2157
+ instance.apiEndpoint = this.apiEndpoint;
2131
2158
  instance.setUserAttributes(this.getUserAttributes());
2132
2159
  }
2133
2160
  else {
@@ -2311,6 +2338,7 @@ var Builder = /** @class */ (function () {
2311
2338
  };
2312
2339
  Builder.prototype.flushGetContentQueue = function (usePastQueue, useQueue) {
2313
2340
  var _this = this;
2341
+ var _a;
2314
2342
  if (usePastQueue === void 0) { usePastQueue = false; }
2315
2343
  if (!this.apiKey) {
2316
2344
  throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
@@ -2327,7 +2355,6 @@ var Builder = /** @class */ (function () {
2327
2355
  return;
2328
2356
  }
2329
2357
  var queue = useQueue || (usePastQueue ? this.priorContentQueue : this.getContentQueue) || [];
2330
- var apiEndpoint = queue[0].apiEndpoint || 'query';
2331
2358
  // TODO: do this on every request send?
2332
2359
  this.getOverridesFromQueryString();
2333
2360
  var queryParams = __assign(__assign({
@@ -2421,6 +2448,9 @@ var Builder = /** @class */ (function () {
2421
2448
  if (isPositiveNumber(options.staleCacheSeconds)) {
2422
2449
  queryParams.staleCacheSeconds = options.staleCacheSeconds;
2423
2450
  }
2451
+ if (this.apiEndpoint === 'content') {
2452
+ queryParams.includeRefs = true;
2453
+ }
2424
2454
  var properties = [
2425
2455
  'prerender',
2426
2456
  'extractCss',
@@ -2432,12 +2462,13 @@ var Builder = /** @class */ (function () {
2432
2462
  'entry',
2433
2463
  'rev',
2434
2464
  'static',
2465
+ 'includeRefs',
2435
2466
  ];
2436
- for (var _a = 0, properties_1 = properties; _a < properties_1.length; _a++) {
2437
- var key = properties_1[_a];
2467
+ for (var _b = 0, properties_1 = properties; _b < properties_1.length; _b++) {
2468
+ var key = properties_1[_b];
2438
2469
  var value = options[key];
2439
2470
  if (value !== undefined) {
2440
- if (apiEndpoint === 'query') {
2471
+ if (this.apiEndpoint === 'query') {
2441
2472
  queryParams.options = queryParams.options || {};
2442
2473
  queryParams.options[options.key] = queryParams.options[options.key] || {};
2443
2474
  queryParams.options[options.key][key] = JSON.stringify(value);
@@ -2448,7 +2479,7 @@ var Builder = /** @class */ (function () {
2448
2479
  }
2449
2480
  }
2450
2481
  }
2451
- if (this.preview) {
2482
+ if (this.preview && this.previewingModel === ((_a = queue === null || queue === void 0 ? void 0 : queue[0]) === null || _a === void 0 ? void 0 : _a.model)) {
2452
2483
  queryParams.preview = 'true';
2453
2484
  }
2454
2485
  var hasParams = Object.keys(queryParams).length > 0;
@@ -2461,9 +2492,8 @@ var Builder = /** @class */ (function () {
2461
2492
  }
2462
2493
  var format = queryParams.format;
2463
2494
  var isApiCallForCodegen = format === 'solid' || format === 'react';
2464
- var isApiCallForCodegenOrQuery = isApiCallForCodegen || apiEndpoint === 'query';
2465
- if (apiEndpoint === 'content') {
2466
- queryParams.enrich = true;
2495
+ var isApiCallForCodegenOrQuery = isApiCallForCodegen || this.apiEndpoint === 'query';
2496
+ if (this.apiEndpoint === 'content') {
2467
2497
  if (queue[0].query) {
2468
2498
  var flattened = this.flattenMongoQuery({ query: queue[0].query });
2469
2499
  for (var key in flattened) {
@@ -2481,7 +2511,7 @@ var Builder = /** @class */ (function () {
2481
2511
  if (isApiCallForCodegen) {
2482
2512
  url = "".concat(host, "/api/v1/codegen/").concat(this.apiKey, "/").concat(keyNames);
2483
2513
  }
2484
- else if (apiEndpoint === 'query') {
2514
+ else if (this.apiEndpoint === 'query') {
2485
2515
  url = "".concat(host, "/api/v3/query/").concat(this.apiKey, "/").concat(keyNames);
2486
2516
  }
2487
2517
  else {