@builder.io/sdk 6.1.2 → 6.2.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 = '6.1.2';
961
+ var SDK_VERSION = '6.2.0';
962
962
 
963
963
  function datePlusMinutes(minutes) {
964
964
  if (minutes === void 0) { minutes = 30; }
@@ -1116,6 +1116,7 @@ var Builder = /** @class */ (function () {
1116
1116
  this.hasOverriddenCanTrack = false;
1117
1117
  this.apiKey$ = new BehaviorSubject(null);
1118
1118
  this.authToken$ = new BehaviorSubject(null);
1119
+ this.contentId$ = new BehaviorSubject(null);
1119
1120
  this.userAttributesChanged = new BehaviorSubject(null);
1120
1121
  this.editingMode$ = new BehaviorSubject(isIframe);
1121
1122
  // TODO: decorator to do this stuff with the get/set (how do with typing too? compiler?)
@@ -1711,7 +1712,21 @@ var Builder = /** @class */ (function () {
1711
1712
  }
1712
1713
  var meta = typeof contentId === 'object' ? contentId : customProperties;
1713
1714
  var useContentId = typeof contentId === 'string' ? contentId : undefined;
1714
- this.track('conversion', { amount: amount, variationId: variationId, meta: meta, contentId: useContentId }, context);
1715
+ if (!useContentId && !contentId && this.contentId) {
1716
+ useContentId = this.contentId;
1717
+ }
1718
+ var useVariationId = variationId;
1719
+ if (!useVariationId && useContentId) {
1720
+ useVariationId = this.getTestCookie(useContentId);
1721
+ }
1722
+ this.track('conversion', {
1723
+ amount: amount,
1724
+ variationId: useVariationId && useContentId && useVariationId !== useContentId
1725
+ ? useVariationId
1726
+ : undefined,
1727
+ meta: meta,
1728
+ contentId: useContentId,
1729
+ }, context);
1715
1730
  };
1716
1731
  Object.defineProperty(Builder.prototype, "isDevelopmentEnv", {
1717
1732
  // TODO: set this for QA
@@ -1789,6 +1804,16 @@ var Builder = /** @class */ (function () {
1789
1804
  enumerable: false,
1790
1805
  configurable: true
1791
1806
  });
1807
+ Object.defineProperty(Builder.prototype, "contentId", {
1808
+ get: function () {
1809
+ return this.contentId$.value;
1810
+ },
1811
+ set: function (id) {
1812
+ this.contentId$.next(id);
1813
+ },
1814
+ enumerable: false,
1815
+ configurable: true
1816
+ });
1792
1817
  Object.defineProperty(Builder.prototype, "authToken", {
1793
1818
  get: function () {
1794
1819
  return this.authToken$.value;
@@ -2489,6 +2514,14 @@ var Builder = /** @class */ (function () {
2489
2514
  if (this.apiEndpoint === 'content') {
2490
2515
  queryParams.includeRefs = true;
2491
2516
  }
2517
+ if (this.apiEndpoint === 'query') {
2518
+ if ('enrich' in options && options.enrich !== undefined) {
2519
+ queryParams.enrich = options.enrich;
2520
+ }
2521
+ if (options.enrichOptions) {
2522
+ this.flattenEnrichOptions(options.enrichOptions, 'enrichOptions', queryParams);
2523
+ }
2524
+ }
2492
2525
  var properties = [
2493
2526
  'prerender',
2494
2527
  'extractCss',
@@ -2516,6 +2549,15 @@ var Builder = /** @class */ (function () {
2516
2549
  }
2517
2550
  }
2518
2551
  }
2552
+ // Handle enrich and enrichOptions for content endpoint
2553
+ if (this.apiEndpoint === 'content') {
2554
+ if ('enrich' in options && options.enrich !== undefined) {
2555
+ queryParams.enrich = options.enrich;
2556
+ }
2557
+ if (options.enrichOptions) {
2558
+ this.flattenEnrichOptions(options.enrichOptions, 'enrichOptions', queryParams);
2559
+ }
2560
+ }
2519
2561
  }
2520
2562
  if (this.preview && this.previewingModel === ((_b = queue === null || queue === void 0 ? void 0 : queue[0]) === null || _b === void 0 ? void 0 : _b.model)) {
2521
2563
  queryParams.preview = 'true';
@@ -2674,6 +2716,22 @@ var Builder = /** @class */ (function () {
2674
2716
  }
2675
2717
  return Builder.isBrowser && setCookie(name, value, expires);
2676
2718
  };
2719
+ /**
2720
+ * Recursively flattens enrichOptions object into dot-notation query parameters
2721
+ * @private
2722
+ */
2723
+ Builder.prototype.flattenEnrichOptions = function (obj, prefix, result) {
2724
+ for (var _i = 0, _a = Object.entries(obj); _i < _a.length; _i++) {
2725
+ var _b = _a[_i], key = _b[0], value = _b[1];
2726
+ var newKey = "".concat(prefix, ".").concat(key);
2727
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
2728
+ this.flattenEnrichOptions(value, newKey, result);
2729
+ }
2730
+ else {
2731
+ result[newKey] = value;
2732
+ }
2733
+ }
2734
+ };
2677
2735
  Builder.prototype.getContent = function (modelName, options) {
2678
2736
  if (options === void 0) { options = {}; }
2679
2737
  if (!this.apiKey) {