@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.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 = '3.0.6';
961
+ var SDK_VERSION = '4.0.0';
962
962
 
963
963
  function datePlusMinutes(minutes) {
964
964
  if (minutes === void 0) { minutes = 30; }
@@ -1448,9 +1448,7 @@ var Builder = /** @class */ (function () {
1448
1448
  getFetch()("".concat(host, "/api/v1/track"), {
1449
1449
  method: 'POST',
1450
1450
  body: JSON.stringify({ events: events }),
1451
- headers: {
1452
- 'content-type': 'application/json',
1453
- },
1451
+ headers: tslib.__assign({ 'content-type': 'application/json' }, this.getSdkHeaders()),
1454
1452
  mode: 'cors',
1455
1453
  }).catch(function () {
1456
1454
  // Not the end of the world
@@ -2249,7 +2247,7 @@ var Builder = /** @class */ (function () {
2249
2247
  // even though we only use `fetch()` now, we prefer to keep the old behavior and use the `fetch` that comes from
2250
2248
  // the core SDK for consistency
2251
2249
  Builder.prototype.requestUrl = function (url, options) {
2252
- return getFetch()(url, options).then(function (res) { return res.json(); });
2250
+ return getFetch()(url, this.addSdkHeaders(options)).then(function (res) { return res.json(); });
2253
2251
  };
2254
2252
  Object.defineProperty(Builder.prototype, "host", {
2255
2253
  get: function () {
@@ -2278,8 +2276,21 @@ var Builder = /** @class */ (function () {
2278
2276
  enumerable: false,
2279
2277
  configurable: true
2280
2278
  });
2279
+ Builder.prototype.getSdkHeaders = function () {
2280
+ if (!Builder.sdkInfo) {
2281
+ return {};
2282
+ }
2283
+ return {
2284
+ 'X-Builder-SDK': Builder.sdkInfo.name,
2285
+ 'X-Builder-SDK-GEN': '1',
2286
+ 'X-Builder-SDK-Version': Builder.sdkInfo.version,
2287
+ };
2288
+ };
2289
+ Builder.prototype.addSdkHeaders = function (fetchOptions) {
2290
+ return tslib.__assign(tslib.__assign({}, fetchOptions), { headers: tslib.__assign(tslib.__assign({}, fetchOptions.headers), this.getSdkHeaders()) });
2291
+ };
2281
2292
  Builder.prototype.makeFetchApiCall = function (url, requestOptions) {
2282
- return getFetch()(url, requestOptions);
2293
+ return getFetch()(url, this.addSdkHeaders(requestOptions));
2283
2294
  };
2284
2295
  Builder.prototype.flattenMongoQuery = function (obj, _current, _res) {
2285
2296
  if (_res === void 0) { _res = {}; }
@@ -2300,6 +2311,7 @@ var Builder = /** @class */ (function () {
2300
2311
  };
2301
2312
  Builder.prototype.flushGetContentQueue = function (usePastQueue, useQueue) {
2302
2313
  var _this = this;
2314
+ var _a, _b;
2303
2315
  if (usePastQueue === void 0) { usePastQueue = false; }
2304
2316
  if (!this.apiKey) {
2305
2317
  throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
@@ -2316,7 +2328,6 @@ var Builder = /** @class */ (function () {
2316
2328
  return;
2317
2329
  }
2318
2330
  var queue = useQueue || (usePastQueue ? this.priorContentQueue : this.getContentQueue) || [];
2319
- var apiEndpoint = queue[0].apiEndpoint || 'query';
2320
2331
  // TODO: do this on every request send?
2321
2332
  this.getOverridesFromQueryString();
2322
2333
  var queryParams = tslib.__assign(tslib.__assign({
@@ -2391,6 +2402,7 @@ var Builder = /** @class */ (function () {
2391
2402
  }
2392
2403
  }
2393
2404
  }
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';
2394
2406
  for (var _i = 0, queue_2 = queue; _i < queue_2.length; _i++) {
2395
2407
  var options = queue_2[_i];
2396
2408
  var format_1 = options.format;
@@ -2422,11 +2434,11 @@ var Builder = /** @class */ (function () {
2422
2434
  'rev',
2423
2435
  'static',
2424
2436
  ];
2425
- for (var _a = 0, properties_1 = properties; _a < properties_1.length; _a++) {
2426
- var key = properties_1[_a];
2437
+ for (var _c = 0, properties_1 = properties; _c < properties_1.length; _c++) {
2438
+ var key = properties_1[_c];
2427
2439
  var value = options[key];
2428
2440
  if (value !== undefined) {
2429
- if (apiEndpoint === 'query') {
2441
+ if (isApiCallForCodegen) {
2430
2442
  queryParams.options = queryParams.options || {};
2431
2443
  queryParams.options[options.key] = queryParams.options[options.key] || {};
2432
2444
  queryParams.options[options.key][key] = JSON.stringify(value);
@@ -2448,10 +2460,8 @@ var Builder = /** @class */ (function () {
2448
2460
  var params = omit(QueryString.parse(this.overrideParams), 'apiKey');
2449
2461
  assign(queryParams, params);
2450
2462
  }
2451
- var format = queryParams.format;
2452
- var isApiCallForCodegen = format === 'solid' || format === 'react';
2453
- var isApiCallForCodegenOrQuery = isApiCallForCodegen || apiEndpoint === 'query';
2454
- if (apiEndpoint === 'content') {
2463
+ queryParams.format;
2464
+ if (!isApiCallForCodegen) {
2455
2465
  queryParams.enrich = true;
2456
2466
  if (queue[0].query) {
2457
2467
  var flattened = this.flattenMongoQuery({ query: queue[0].query });
@@ -2470,9 +2480,6 @@ var Builder = /** @class */ (function () {
2470
2480
  if (isApiCallForCodegen) {
2471
2481
  url = "".concat(host, "/api/v1/codegen/").concat(this.apiKey, "/").concat(keyNames);
2472
2482
  }
2473
- else if (apiEndpoint === 'query') {
2474
- url = "".concat(host, "/api/v3/query/").concat(this.apiKey, "/").concat(keyNames);
2475
- }
2476
2483
  else {
2477
2484
  url = "".concat(host, "/api/v3/content/").concat(queue[0].model);
2478
2485
  }
@@ -2495,7 +2502,7 @@ var Builder = /** @class */ (function () {
2495
2502
  if (!observer) {
2496
2503
  return;
2497
2504
  }
2498
- var data = isApiCallForCodegenOrQuery ? result[keyName] : result.results;
2505
+ var data = isApiCallForCodegen ? result[keyName] : result.results;
2499
2506
  var sorted = data; // sortBy(data, item => item.priority);
2500
2507
  if (data) {
2501
2508
  var testModifiedResults = Builder.isServer
@@ -2678,6 +2685,7 @@ var Builder = /** @class */ (function () {
2678
2685
  (location.search.indexOf('builder.preview=') !== -1 ||
2679
2686
  location.search.indexOf('builder.frameEditing=') !== -1));
2680
2687
  Builder.isReact = false;
2688
+ Builder.sdkInfo = undefined;
2681
2689
  Builder.overrideUserAttributes = {};
2682
2690
  return Builder;
2683
2691
  }());