@builder.io/sdk 4.0.2 → 5.0.0-0

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 = '4.0.2';
1055
+ var SDK_VERSION = '5.0.0-0';
1056
1056
 
1057
1057
  function datePlusMinutes(minutes) {
1058
1058
  if (minutes === void 0) { minutes = 30; }
@@ -1452,7 +1452,9 @@
1452
1452
  // 1. `function name(args) => {code}`
1453
1453
  // 2. `name(args) => {code}`
1454
1454
  // 3. `(args) => {}`
1455
- var appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
1455
+ // 4. `args => {}`
1456
+ var isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
1457
+ var appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(') && !isArrowWithoutParens;
1456
1458
  return "return (".concat(appendFunction ? 'function ' : '').concat(fnStr, ").apply(this, arguments)");
1457
1459
  };
1458
1460
  return JSON.parse(JSON.stringify(info, function (key, value) {
@@ -2218,8 +2220,14 @@
2218
2220
  assign(this.trackingUserAttributes, attributes);
2219
2221
  };
2220
2222
  Builder.prototype.get = function (modelName, options) {
2223
+ var _a;
2221
2224
  if (options === void 0) { options = {}; }
2222
2225
  var instance = this;
2226
+ var finalLocale = options.locale || ((_a = options.userAttributes) === null || _a === void 0 ? void 0 : _a.locale) || this.getUserAttributes().locale;
2227
+ var finalOptions = __assign(__assign({}, options), (finalLocale && {
2228
+ locale: String(finalLocale),
2229
+ userAttributes: __assign({ locale: String(finalLocale) }, options.userAttributes),
2230
+ }));
2223
2231
  if (!Builder.isBrowser) {
2224
2232
  instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, undefined, options.authToken || this.authToken, options.apiVersion || this.apiVersion);
2225
2233
  instance.setUserAttributes(this.getUserAttributes());
@@ -2237,7 +2245,7 @@
2237
2245
  this.apiVersion = options.apiVersion;
2238
2246
  }
2239
2247
  }
2240
- return instance.queueGetContent(modelName, options).map(
2248
+ return instance.queueGetContent(modelName, finalOptions).map(
2241
2249
  /* map( */ function (matches) {
2242
2250
  var match = matches && matches[0];
2243
2251
  if (Builder.isStatic) {
@@ -2405,7 +2413,6 @@
2405
2413
  };
2406
2414
  Builder.prototype.flushGetContentQueue = function (usePastQueue, useQueue) {
2407
2415
  var _this = this;
2408
- var _a, _b;
2409
2416
  if (usePastQueue === void 0) { usePastQueue = false; }
2410
2417
  if (!this.apiKey) {
2411
2418
  throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
@@ -2422,6 +2429,7 @@
2422
2429
  return;
2423
2430
  }
2424
2431
  var queue = useQueue || (usePastQueue ? this.priorContentQueue : this.getContentQueue) || [];
2432
+ var apiEndpoint = queue[0].apiEndpoint || 'query';
2425
2433
  // TODO: do this on every request send?
2426
2434
  this.getOverridesFromQueryString();
2427
2435
  var queryParams = __assign(__assign({
@@ -2445,9 +2453,9 @@
2445
2453
  if (queue[0].sort) {
2446
2454
  queryParams.sort = queue[0].sort;
2447
2455
  }
2448
- var pageQueryParams = typeof location !== 'undefined'
2456
+ var pageQueryParams = (typeof location !== 'undefined'
2449
2457
  ? QueryString.parseDeep(location.search.substr(1))
2450
- : {}; // TODO: WHAT about SSR (this.request) ?
2458
+ : undefined) || {}; // TODO: WHAT about SSR (this.request) ?
2451
2459
  var userAttributes =
2452
2460
  // FIXME: HACK: only checks first in queue for user attributes overrides, should check all
2453
2461
  // TODO: merge user attributes provided here with defaults and current user attiributes (?)
@@ -2496,7 +2504,6 @@
2496
2504
  }
2497
2505
  }
2498
2506
  }
2499
- 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';
2500
2507
  for (var _i = 0, queue_2 = queue; _i < queue_2.length; _i++) {
2501
2508
  var options = queue_2[_i];
2502
2509
  var format_1 = options.format;
@@ -2528,11 +2535,11 @@
2528
2535
  'rev',
2529
2536
  'static',
2530
2537
  ];
2531
- for (var _c = 0, properties_1 = properties; _c < properties_1.length; _c++) {
2532
- var key = properties_1[_c];
2538
+ for (var _a = 0, properties_1 = properties; _a < properties_1.length; _a++) {
2539
+ var key = properties_1[_a];
2533
2540
  var value = options[key];
2534
2541
  if (value !== undefined) {
2535
- if (isApiCallForCodegen) {
2542
+ if (apiEndpoint === 'query') {
2536
2543
  queryParams.options = queryParams.options || {};
2537
2544
  queryParams.options[options.key] = queryParams.options[options.key] || {};
2538
2545
  queryParams.options[options.key][key] = JSON.stringify(value);
@@ -2554,8 +2561,10 @@
2554
2561
  var params = omit(QueryString.parse(this.overrideParams), 'apiKey');
2555
2562
  assign(queryParams, params);
2556
2563
  }
2557
- queryParams.format;
2558
- if (!isApiCallForCodegen) {
2564
+ var format = queryParams.format;
2565
+ var isApiCallForCodegen = format === 'solid' || format === 'react';
2566
+ var isApiCallForCodegenOrQuery = isApiCallForCodegen || apiEndpoint === 'query';
2567
+ if (apiEndpoint === 'content') {
2559
2568
  queryParams.enrich = true;
2560
2569
  if (queue[0].query) {
2561
2570
  var flattened = this.flattenMongoQuery({ query: queue[0].query });
@@ -2574,6 +2583,9 @@
2574
2583
  if (isApiCallForCodegen) {
2575
2584
  url = "".concat(host, "/api/v1/codegen/").concat(this.apiKey, "/").concat(keyNames);
2576
2585
  }
2586
+ else if (apiEndpoint === 'query') {
2587
+ url = "".concat(host, "/api/v3/query/").concat(this.apiKey, "/").concat(keyNames);
2588
+ }
2577
2589
  else {
2578
2590
  url = "".concat(host, "/api/v3/content/").concat(queue[0].model);
2579
2591
  }
@@ -2596,7 +2608,7 @@
2596
2608
  if (!observer) {
2597
2609
  return;
2598
2610
  }
2599
- var data = isApiCallForCodegen ? result[keyName] : result.results;
2611
+ var data = isApiCallForCodegenOrQuery ? result[keyName] : result.results;
2600
2612
  var sorted = data; // sortBy(data, item => item.priority);
2601
2613
  if (data) {
2602
2614
  var testModifiedResults = Builder.isServer