@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.cjs.js CHANGED
@@ -958,7 +958,7 @@ function toError(err) {
958
958
 
959
959
  var DEFAULT_API_VERSION = 'v3';
960
960
 
961
- var SDK_VERSION = '4.0.2';
961
+ var SDK_VERSION = '5.0.0-0';
962
962
 
963
963
  function datePlusMinutes(minutes) {
964
964
  if (minutes === void 0) { minutes = 30; }
@@ -1358,7 +1358,9 @@ var Builder = /** @class */ (function () {
1358
1358
  // 1. `function name(args) => {code}`
1359
1359
  // 2. `name(args) => {code}`
1360
1360
  // 3. `(args) => {}`
1361
- var appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
1361
+ // 4. `args => {}`
1362
+ var isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
1363
+ var appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(') && !isArrowWithoutParens;
1362
1364
  return "return (".concat(appendFunction ? 'function ' : '').concat(fnStr, ").apply(this, arguments)");
1363
1365
  };
1364
1366
  return JSON.parse(JSON.stringify(info, function (key, value) {
@@ -2124,8 +2126,14 @@ var Builder = /** @class */ (function () {
2124
2126
  assign(this.trackingUserAttributes, attributes);
2125
2127
  };
2126
2128
  Builder.prototype.get = function (modelName, options) {
2129
+ var _a;
2127
2130
  if (options === void 0) { options = {}; }
2128
2131
  var instance = this;
2132
+ var finalLocale = options.locale || ((_a = options.userAttributes) === null || _a === void 0 ? void 0 : _a.locale) || this.getUserAttributes().locale;
2133
+ var finalOptions = tslib.__assign(tslib.__assign({}, options), (finalLocale && {
2134
+ locale: String(finalLocale),
2135
+ userAttributes: tslib.__assign({ locale: String(finalLocale) }, options.userAttributes),
2136
+ }));
2129
2137
  if (!Builder.isBrowser) {
2130
2138
  instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, undefined, options.authToken || this.authToken, options.apiVersion || this.apiVersion);
2131
2139
  instance.setUserAttributes(this.getUserAttributes());
@@ -2143,7 +2151,7 @@ var Builder = /** @class */ (function () {
2143
2151
  this.apiVersion = options.apiVersion;
2144
2152
  }
2145
2153
  }
2146
- return instance.queueGetContent(modelName, options).map(
2154
+ return instance.queueGetContent(modelName, finalOptions).map(
2147
2155
  /* map( */ function (matches) {
2148
2156
  var match = matches && matches[0];
2149
2157
  if (Builder.isStatic) {
@@ -2311,7 +2319,6 @@ var Builder = /** @class */ (function () {
2311
2319
  };
2312
2320
  Builder.prototype.flushGetContentQueue = function (usePastQueue, useQueue) {
2313
2321
  var _this = this;
2314
- var _a, _b;
2315
2322
  if (usePastQueue === void 0) { usePastQueue = false; }
2316
2323
  if (!this.apiKey) {
2317
2324
  throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
@@ -2328,6 +2335,7 @@ var Builder = /** @class */ (function () {
2328
2335
  return;
2329
2336
  }
2330
2337
  var queue = useQueue || (usePastQueue ? this.priorContentQueue : this.getContentQueue) || [];
2338
+ var apiEndpoint = queue[0].apiEndpoint || 'query';
2331
2339
  // TODO: do this on every request send?
2332
2340
  this.getOverridesFromQueryString();
2333
2341
  var queryParams = tslib.__assign(tslib.__assign({
@@ -2351,9 +2359,9 @@ var Builder = /** @class */ (function () {
2351
2359
  if (queue[0].sort) {
2352
2360
  queryParams.sort = queue[0].sort;
2353
2361
  }
2354
- var pageQueryParams = typeof location !== 'undefined'
2362
+ var pageQueryParams = (typeof location !== 'undefined'
2355
2363
  ? QueryString.parseDeep(location.search.substr(1))
2356
- : {}; // TODO: WHAT about SSR (this.request) ?
2364
+ : undefined) || {}; // TODO: WHAT about SSR (this.request) ?
2357
2365
  var userAttributes =
2358
2366
  // FIXME: HACK: only checks first in queue for user attributes overrides, should check all
2359
2367
  // TODO: merge user attributes provided here with defaults and current user attiributes (?)
@@ -2402,7 +2410,6 @@ var Builder = /** @class */ (function () {
2402
2410
  }
2403
2411
  }
2404
2412
  }
2405
- 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';
2406
2413
  for (var _i = 0, queue_2 = queue; _i < queue_2.length; _i++) {
2407
2414
  var options = queue_2[_i];
2408
2415
  var format_1 = options.format;
@@ -2434,11 +2441,11 @@ var Builder = /** @class */ (function () {
2434
2441
  'rev',
2435
2442
  'static',
2436
2443
  ];
2437
- for (var _c = 0, properties_1 = properties; _c < properties_1.length; _c++) {
2438
- var key = properties_1[_c];
2444
+ for (var _a = 0, properties_1 = properties; _a < properties_1.length; _a++) {
2445
+ var key = properties_1[_a];
2439
2446
  var value = options[key];
2440
2447
  if (value !== undefined) {
2441
- if (isApiCallForCodegen) {
2448
+ if (apiEndpoint === 'query') {
2442
2449
  queryParams.options = queryParams.options || {};
2443
2450
  queryParams.options[options.key] = queryParams.options[options.key] || {};
2444
2451
  queryParams.options[options.key][key] = JSON.stringify(value);
@@ -2460,8 +2467,10 @@ var Builder = /** @class */ (function () {
2460
2467
  var params = omit(QueryString.parse(this.overrideParams), 'apiKey');
2461
2468
  assign(queryParams, params);
2462
2469
  }
2463
- queryParams.format;
2464
- if (!isApiCallForCodegen) {
2470
+ var format = queryParams.format;
2471
+ var isApiCallForCodegen = format === 'solid' || format === 'react';
2472
+ var isApiCallForCodegenOrQuery = isApiCallForCodegen || apiEndpoint === 'query';
2473
+ if (apiEndpoint === 'content') {
2465
2474
  queryParams.enrich = true;
2466
2475
  if (queue[0].query) {
2467
2476
  var flattened = this.flattenMongoQuery({ query: queue[0].query });
@@ -2480,6 +2489,9 @@ var Builder = /** @class */ (function () {
2480
2489
  if (isApiCallForCodegen) {
2481
2490
  url = "".concat(host, "/api/v1/codegen/").concat(this.apiKey, "/").concat(keyNames);
2482
2491
  }
2492
+ else if (apiEndpoint === 'query') {
2493
+ url = "".concat(host, "/api/v3/query/").concat(this.apiKey, "/").concat(keyNames);
2494
+ }
2483
2495
  else {
2484
2496
  url = "".concat(host, "/api/v3/content/").concat(queue[0].model);
2485
2497
  }
@@ -2502,7 +2514,7 @@ var Builder = /** @class */ (function () {
2502
2514
  if (!observer) {
2503
2515
  return;
2504
2516
  }
2505
- var data = isApiCallForCodegen ? result[keyName] : result.results;
2517
+ var data = isApiCallForCodegenOrQuery ? result[keyName] : result.results;
2506
2518
  var sorted = data; // sortBy(data, item => item.priority);
2507
2519
  if (data) {
2508
2520
  var testModifiedResults = Builder.isServer