@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.esm.js CHANGED
@@ -950,7 +950,7 @@ function toError(err) {
950
950
 
951
951
  var DEFAULT_API_VERSION = 'v3';
952
952
 
953
- var SDK_VERSION = '6.1.2';
953
+ var SDK_VERSION = '6.2.0';
954
954
 
955
955
  function datePlusMinutes(minutes) {
956
956
  if (minutes === void 0) { minutes = 30; }
@@ -1108,6 +1108,7 @@ var Builder = /** @class */ (function () {
1108
1108
  this.hasOverriddenCanTrack = false;
1109
1109
  this.apiKey$ = new BehaviorSubject(null);
1110
1110
  this.authToken$ = new BehaviorSubject(null);
1111
+ this.contentId$ = new BehaviorSubject(null);
1111
1112
  this.userAttributesChanged = new BehaviorSubject(null);
1112
1113
  this.editingMode$ = new BehaviorSubject(isIframe);
1113
1114
  // TODO: decorator to do this stuff with the get/set (how do with typing too? compiler?)
@@ -1703,7 +1704,21 @@ var Builder = /** @class */ (function () {
1703
1704
  }
1704
1705
  var meta = typeof contentId === 'object' ? contentId : customProperties;
1705
1706
  var useContentId = typeof contentId === 'string' ? contentId : undefined;
1706
- this.track('conversion', { amount: amount, variationId: variationId, meta: meta, contentId: useContentId }, context);
1707
+ if (!useContentId && !contentId && this.contentId) {
1708
+ useContentId = this.contentId;
1709
+ }
1710
+ var useVariationId = variationId;
1711
+ if (!useVariationId && useContentId) {
1712
+ useVariationId = this.getTestCookie(useContentId);
1713
+ }
1714
+ this.track('conversion', {
1715
+ amount: amount,
1716
+ variationId: useVariationId && useContentId && useVariationId !== useContentId
1717
+ ? useVariationId
1718
+ : undefined,
1719
+ meta: meta,
1720
+ contentId: useContentId,
1721
+ }, context);
1707
1722
  };
1708
1723
  Object.defineProperty(Builder.prototype, "isDevelopmentEnv", {
1709
1724
  // TODO: set this for QA
@@ -1781,6 +1796,16 @@ var Builder = /** @class */ (function () {
1781
1796
  enumerable: false,
1782
1797
  configurable: true
1783
1798
  });
1799
+ Object.defineProperty(Builder.prototype, "contentId", {
1800
+ get: function () {
1801
+ return this.contentId$.value;
1802
+ },
1803
+ set: function (id) {
1804
+ this.contentId$.next(id);
1805
+ },
1806
+ enumerable: false,
1807
+ configurable: true
1808
+ });
1784
1809
  Object.defineProperty(Builder.prototype, "authToken", {
1785
1810
  get: function () {
1786
1811
  return this.authToken$.value;
@@ -2481,6 +2506,14 @@ var Builder = /** @class */ (function () {
2481
2506
  if (this.apiEndpoint === 'content') {
2482
2507
  queryParams.includeRefs = true;
2483
2508
  }
2509
+ if (this.apiEndpoint === 'query') {
2510
+ if ('enrich' in options && options.enrich !== undefined) {
2511
+ queryParams.enrich = options.enrich;
2512
+ }
2513
+ if (options.enrichOptions) {
2514
+ this.flattenEnrichOptions(options.enrichOptions, 'enrichOptions', queryParams);
2515
+ }
2516
+ }
2484
2517
  var properties = [
2485
2518
  'prerender',
2486
2519
  'extractCss',
@@ -2508,6 +2541,15 @@ var Builder = /** @class */ (function () {
2508
2541
  }
2509
2542
  }
2510
2543
  }
2544
+ // Handle enrich and enrichOptions for content endpoint
2545
+ if (this.apiEndpoint === 'content') {
2546
+ if ('enrich' in options && options.enrich !== undefined) {
2547
+ queryParams.enrich = options.enrich;
2548
+ }
2549
+ if (options.enrichOptions) {
2550
+ this.flattenEnrichOptions(options.enrichOptions, 'enrichOptions', queryParams);
2551
+ }
2552
+ }
2511
2553
  }
2512
2554
  if (this.preview && this.previewingModel === ((_b = queue === null || queue === void 0 ? void 0 : queue[0]) === null || _b === void 0 ? void 0 : _b.model)) {
2513
2555
  queryParams.preview = 'true';
@@ -2666,6 +2708,22 @@ var Builder = /** @class */ (function () {
2666
2708
  }
2667
2709
  return Builder.isBrowser && setCookie(name, value, expires);
2668
2710
  };
2711
+ /**
2712
+ * Recursively flattens enrichOptions object into dot-notation query parameters
2713
+ * @private
2714
+ */
2715
+ Builder.prototype.flattenEnrichOptions = function (obj, prefix, result) {
2716
+ for (var _i = 0, _a = Object.entries(obj); _i < _a.length; _i++) {
2717
+ var _b = _a[_i], key = _b[0], value = _b[1];
2718
+ var newKey = "".concat(prefix, ".").concat(key);
2719
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
2720
+ this.flattenEnrichOptions(value, newKey, result);
2721
+ }
2722
+ else {
2723
+ result[newKey] = value;
2724
+ }
2725
+ }
2726
+ };
2669
2727
  Builder.prototype.getContent = function (modelName, options) {
2670
2728
  if (options === void 0) { options = {}; }
2671
2729
  if (!this.apiKey) {