@builder.io/sdk 6.1.3 → 6.2.1

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.3';
961
+ var SDK_VERSION = '6.2.1';
962
962
 
963
963
  function datePlusMinutes(minutes) {
964
964
  if (minutes === void 0) { minutes = 30; }
@@ -1710,7 +1710,15 @@ var Builder = /** @class */ (function () {
1710
1710
  if (isIframe || !isBrowser || Builder.isPreviewing) {
1711
1711
  return;
1712
1712
  }
1713
- var meta = typeof contentId === 'object' ? contentId : customProperties;
1713
+ var metadata = typeof contentId === 'object'
1714
+ ? tslib.__assign({}, contentId) : customProperties && typeof customProperties === 'object'
1715
+ ? tslib.__assign({}, customProperties) : undefined;
1716
+ if (amount !== undefined) {
1717
+ if (!metadata) {
1718
+ metadata = {};
1719
+ }
1720
+ metadata.amount = amount;
1721
+ }
1714
1722
  var useContentId = typeof contentId === 'string' ? contentId : undefined;
1715
1723
  if (!useContentId && !contentId && this.contentId) {
1716
1724
  useContentId = this.contentId;
@@ -1724,7 +1732,7 @@ var Builder = /** @class */ (function () {
1724
1732
  variationId: useVariationId && useContentId && useVariationId !== useContentId
1725
1733
  ? useVariationId
1726
1734
  : undefined,
1727
- meta: meta,
1735
+ meta: metadata,
1728
1736
  contentId: useContentId,
1729
1737
  }, context);
1730
1738
  };
@@ -2514,6 +2522,14 @@ var Builder = /** @class */ (function () {
2514
2522
  if (this.apiEndpoint === 'content') {
2515
2523
  queryParams.includeRefs = true;
2516
2524
  }
2525
+ if (this.apiEndpoint === 'query') {
2526
+ if ('enrich' in options && options.enrich !== undefined) {
2527
+ queryParams.enrich = options.enrich;
2528
+ }
2529
+ if (options.enrichOptions) {
2530
+ this.flattenEnrichOptions(options.enrichOptions, 'enrichOptions', queryParams);
2531
+ }
2532
+ }
2517
2533
  var properties = [
2518
2534
  'prerender',
2519
2535
  'extractCss',
@@ -2541,6 +2557,15 @@ var Builder = /** @class */ (function () {
2541
2557
  }
2542
2558
  }
2543
2559
  }
2560
+ // Handle enrich and enrichOptions for content endpoint
2561
+ if (this.apiEndpoint === 'content') {
2562
+ if ('enrich' in options && options.enrich !== undefined) {
2563
+ queryParams.enrich = options.enrich;
2564
+ }
2565
+ if (options.enrichOptions) {
2566
+ this.flattenEnrichOptions(options.enrichOptions, 'enrichOptions', queryParams);
2567
+ }
2568
+ }
2544
2569
  }
2545
2570
  if (this.preview && this.previewingModel === ((_b = queue === null || queue === void 0 ? void 0 : queue[0]) === null || _b === void 0 ? void 0 : _b.model)) {
2546
2571
  queryParams.preview = 'true';
@@ -2699,6 +2724,22 @@ var Builder = /** @class */ (function () {
2699
2724
  }
2700
2725
  return Builder.isBrowser && setCookie(name, value, expires);
2701
2726
  };
2727
+ /**
2728
+ * Recursively flattens enrichOptions object into dot-notation query parameters
2729
+ * @private
2730
+ */
2731
+ Builder.prototype.flattenEnrichOptions = function (obj, prefix, result) {
2732
+ for (var _i = 0, _a = Object.entries(obj); _i < _a.length; _i++) {
2733
+ var _b = _a[_i], key = _b[0], value = _b[1];
2734
+ var newKey = "".concat(prefix, ".").concat(key);
2735
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
2736
+ this.flattenEnrichOptions(value, newKey, result);
2737
+ }
2738
+ else {
2739
+ result[newKey] = value;
2740
+ }
2741
+ }
2742
+ };
2702
2743
  Builder.prototype.getContent = function (modelName, options) {
2703
2744
  if (options === void 0) { options = {}; }
2704
2745
  if (!this.apiKey) {