@builder.io/sdk 3.0.5 → 3.0.7

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
@@ -118,8 +118,6 @@ function assertAllowedPropertyName(name) {
118
118
  throw new Error("Property name \"".concat(name, "\" is not allowed"));
119
119
  }
120
120
 
121
- var version = "3.0.5";
122
-
123
121
  var Subscription = /** @class */ (function () {
124
122
  function Subscription(listeners, listener) {
125
123
  this.listeners = listeners;
@@ -952,6 +950,8 @@ function toError(err) {
952
950
 
953
951
  var DEFAULT_API_VERSION = 'v3';
954
952
 
953
+ var SDK_VERSION = '3.0.7';
954
+
955
955
  function datePlusMinutes(minutes) {
956
956
  if (minutes === void 0) { minutes = 30; }
957
957
  return new Date(Date.now() + minutes * 60000);
@@ -1440,9 +1440,7 @@ var Builder = /** @class */ (function () {
1440
1440
  getFetch()("".concat(host, "/api/v1/track"), {
1441
1441
  method: 'POST',
1442
1442
  body: JSON.stringify({ events: events }),
1443
- headers: {
1444
- 'content-type': 'application/json',
1445
- },
1443
+ headers: __assign({ 'content-type': 'application/json' }, this.getSdkHeaders()),
1446
1444
  mode: 'cors',
1447
1445
  }).catch(function () {
1448
1446
  // Not the end of the world
@@ -2241,7 +2239,7 @@ var Builder = /** @class */ (function () {
2241
2239
  // even though we only use `fetch()` now, we prefer to keep the old behavior and use the `fetch` that comes from
2242
2240
  // the core SDK for consistency
2243
2241
  Builder.prototype.requestUrl = function (url, options) {
2244
- return getFetch()(url, options).then(function (res) { return res.json(); });
2242
+ return getFetch()(url, this.addSdkHeaders(options)).then(function (res) { return res.json(); });
2245
2243
  };
2246
2244
  Object.defineProperty(Builder.prototype, "host", {
2247
2245
  get: function () {
@@ -2270,8 +2268,21 @@ var Builder = /** @class */ (function () {
2270
2268
  enumerable: false,
2271
2269
  configurable: true
2272
2270
  });
2271
+ Builder.prototype.getSdkHeaders = function () {
2272
+ if (!Builder.sdkInfo) {
2273
+ return {};
2274
+ }
2275
+ return {
2276
+ 'X-Builder-SDK': Builder.sdkInfo.name,
2277
+ 'X-Builder-SDK-GEN': '1',
2278
+ 'X-Builder-SDK-Version': Builder.sdkInfo.version,
2279
+ };
2280
+ };
2281
+ Builder.prototype.addSdkHeaders = function (fetchOptions) {
2282
+ return __assign(__assign({}, fetchOptions), { headers: __assign(__assign({}, fetchOptions.headers), this.getSdkHeaders()) });
2283
+ };
2273
2284
  Builder.prototype.makeFetchApiCall = function (url, requestOptions) {
2274
- return getFetch()(url, requestOptions);
2285
+ return getFetch()(url, this.addSdkHeaders(requestOptions));
2275
2286
  };
2276
2287
  Builder.prototype.flattenMongoQuery = function (obj, _current, _res) {
2277
2288
  if (_res === void 0) { _res = {}; }
@@ -2626,11 +2637,7 @@ var Builder = /** @class */ (function () {
2626
2637
  : undefined }))
2627
2638
  .promise();
2628
2639
  };
2629
- /**
2630
- * @hidden
2631
- * @deprecated. This is buggy, and always behind by a version.
2632
- */
2633
- Builder.VERSION = version;
2640
+ Builder.VERSION = SDK_VERSION;
2634
2641
  Builder.components = [];
2635
2642
  /**
2636
2643
  * Makes it so that a/b tests generate code like {@link
@@ -2674,6 +2681,7 @@ var Builder = /** @class */ (function () {
2674
2681
  (location.search.indexOf('builder.preview=') !== -1 ||
2675
2682
  location.search.indexOf('builder.frameEditing=') !== -1));
2676
2683
  Builder.isReact = false;
2684
+ Builder.sdkInfo = undefined;
2677
2685
  Builder.overrideUserAttributes = {};
2678
2686
  return Builder;
2679
2687
  }());