@builder.io/sdk 3.0.6 → 4.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 = '3.0.6';
1055
+ var SDK_VERSION = '4.0.0';
1056
1056
 
1057
1057
  function datePlusMinutes(minutes) {
1058
1058
  if (minutes === void 0) { minutes = 30; }
@@ -1542,9 +1542,7 @@
1542
1542
  getFetch()("".concat(host, "/api/v1/track"), {
1543
1543
  method: 'POST',
1544
1544
  body: JSON.stringify({ events: events }),
1545
- headers: {
1546
- 'content-type': 'application/json',
1547
- },
1545
+ headers: __assign({ 'content-type': 'application/json' }, this.getSdkHeaders()),
1548
1546
  mode: 'cors',
1549
1547
  }).catch(function () {
1550
1548
  // Not the end of the world
@@ -2343,7 +2341,7 @@
2343
2341
  // even though we only use `fetch()` now, we prefer to keep the old behavior and use the `fetch` that comes from
2344
2342
  // the core SDK for consistency
2345
2343
  Builder.prototype.requestUrl = function (url, options) {
2346
- return getFetch()(url, options).then(function (res) { return res.json(); });
2344
+ return getFetch()(url, this.addSdkHeaders(options)).then(function (res) { return res.json(); });
2347
2345
  };
2348
2346
  Object.defineProperty(Builder.prototype, "host", {
2349
2347
  get: function () {
@@ -2372,8 +2370,21 @@
2372
2370
  enumerable: false,
2373
2371
  configurable: true
2374
2372
  });
2373
+ Builder.prototype.getSdkHeaders = function () {
2374
+ if (!Builder.sdkInfo) {
2375
+ return {};
2376
+ }
2377
+ return {
2378
+ 'X-Builder-SDK': Builder.sdkInfo.name,
2379
+ 'X-Builder-SDK-GEN': '1',
2380
+ 'X-Builder-SDK-Version': Builder.sdkInfo.version,
2381
+ };
2382
+ };
2383
+ Builder.prototype.addSdkHeaders = function (fetchOptions) {
2384
+ return __assign(__assign({}, fetchOptions), { headers: __assign(__assign({}, fetchOptions.headers), this.getSdkHeaders()) });
2385
+ };
2375
2386
  Builder.prototype.makeFetchApiCall = function (url, requestOptions) {
2376
- return getFetch()(url, requestOptions);
2387
+ return getFetch()(url, this.addSdkHeaders(requestOptions));
2377
2388
  };
2378
2389
  Builder.prototype.flattenMongoQuery = function (obj, _current, _res) {
2379
2390
  if (_res === void 0) { _res = {}; }
@@ -2394,6 +2405,7 @@
2394
2405
  };
2395
2406
  Builder.prototype.flushGetContentQueue = function (usePastQueue, useQueue) {
2396
2407
  var _this = this;
2408
+ var _a, _b;
2397
2409
  if (usePastQueue === void 0) { usePastQueue = false; }
2398
2410
  if (!this.apiKey) {
2399
2411
  throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
@@ -2410,7 +2422,6 @@
2410
2422
  return;
2411
2423
  }
2412
2424
  var queue = useQueue || (usePastQueue ? this.priorContentQueue : this.getContentQueue) || [];
2413
- var apiEndpoint = queue[0].apiEndpoint || 'query';
2414
2425
  // TODO: do this on every request send?
2415
2426
  this.getOverridesFromQueryString();
2416
2427
  var queryParams = __assign(__assign({
@@ -2485,6 +2496,7 @@
2485
2496
  }
2486
2497
  }
2487
2498
  }
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';
2488
2500
  for (var _i = 0, queue_2 = queue; _i < queue_2.length; _i++) {
2489
2501
  var options = queue_2[_i];
2490
2502
  var format_1 = options.format;
@@ -2516,11 +2528,11 @@
2516
2528
  'rev',
2517
2529
  'static',
2518
2530
  ];
2519
- for (var _a = 0, properties_1 = properties; _a < properties_1.length; _a++) {
2520
- var key = properties_1[_a];
2531
+ for (var _c = 0, properties_1 = properties; _c < properties_1.length; _c++) {
2532
+ var key = properties_1[_c];
2521
2533
  var value = options[key];
2522
2534
  if (value !== undefined) {
2523
- if (apiEndpoint === 'query') {
2535
+ if (isApiCallForCodegen) {
2524
2536
  queryParams.options = queryParams.options || {};
2525
2537
  queryParams.options[options.key] = queryParams.options[options.key] || {};
2526
2538
  queryParams.options[options.key][key] = JSON.stringify(value);
@@ -2542,10 +2554,8 @@
2542
2554
  var params = omit(QueryString.parse(this.overrideParams), 'apiKey');
2543
2555
  assign(queryParams, params);
2544
2556
  }
2545
- var format = queryParams.format;
2546
- var isApiCallForCodegen = format === 'solid' || format === 'react';
2547
- var isApiCallForCodegenOrQuery = isApiCallForCodegen || apiEndpoint === 'query';
2548
- if (apiEndpoint === 'content') {
2557
+ queryParams.format;
2558
+ if (!isApiCallForCodegen) {
2549
2559
  queryParams.enrich = true;
2550
2560
  if (queue[0].query) {
2551
2561
  var flattened = this.flattenMongoQuery({ query: queue[0].query });
@@ -2564,9 +2574,6 @@
2564
2574
  if (isApiCallForCodegen) {
2565
2575
  url = "".concat(host, "/api/v1/codegen/").concat(this.apiKey, "/").concat(keyNames);
2566
2576
  }
2567
- else if (apiEndpoint === 'query') {
2568
- url = "".concat(host, "/api/v3/query/").concat(this.apiKey, "/").concat(keyNames);
2569
- }
2570
2577
  else {
2571
2578
  url = "".concat(host, "/api/v3/content/").concat(queue[0].model);
2572
2579
  }
@@ -2589,7 +2596,7 @@
2589
2596
  if (!observer) {
2590
2597
  return;
2591
2598
  }
2592
- var data = isApiCallForCodegenOrQuery ? result[keyName] : result.results;
2599
+ var data = isApiCallForCodegen ? result[keyName] : result.results;
2593
2600
  var sorted = data; // sortBy(data, item => item.priority);
2594
2601
  if (data) {
2595
2602
  var testModifiedResults = Builder.isServer
@@ -2772,6 +2779,7 @@
2772
2779
  (location.search.indexOf('builder.preview=') !== -1 ||
2773
2780
  location.search.indexOf('builder.frameEditing=') !== -1));
2774
2781
  Builder.isReact = false;
2782
+ Builder.sdkInfo = undefined;
2775
2783
  Builder.overrideUserAttributes = {};
2776
2784
  return Builder;
2777
2785
  }());