contentful 9.3.2 → 9.3.4

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.
@@ -2852,6 +2852,8 @@ __webpack_require__.r(__webpack_exports__);
2852
2852
  /* harmony import */ var fast_copy__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(fast_copy__WEBPACK_IMPORTED_MODULE_0__);
2853
2853
  var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
2854
2854
 
2855
+ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
2856
+
2855
2857
  function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
2856
2858
 
2857
2859
 
@@ -2868,32 +2870,83 @@ var isLink = function isLink(object) {
2868
2870
  };
2869
2871
 
2870
2872
  /**
2871
- * Creates a string key for lookup in entityMap
2873
+ * isResourceLink Function
2874
+ * Checks if the object has sys.type "ResourceLink"
2875
+ * @param object
2876
+ */
2877
+ var isResourceLink = function isResourceLink(object) {
2878
+ return object && object.sys && object.sys.type === 'ResourceLink';
2879
+ };
2880
+
2881
+ /**
2882
+ * Creates a key with spaceId and a key without for entityMap
2872
2883
  *
2873
2884
  * @param {*} sys
2874
2885
  * @param {String} sys.type
2875
2886
  * @param {String} sys.id
2887
+ * @param {*} sys.space
2888
+ * @param {*} sys.space.sys
2889
+ * @param {String} sys.space.id
2890
+ * @return {string[]}
2891
+ */
2892
+ var makeEntityMapKeys = function makeEntityMapKeys(sys) {
2893
+ return sys.space ? [sys.type + '!' + sys.id, sys.space.sys.id + '!' + sys.type + '!' + sys.id] : [sys.type + '!' + sys.id];
2894
+ };
2895
+
2896
+ /**
2897
+ * Looks up in entityMap
2898
+ *
2899
+ * @param entityMap
2900
+ * @param {*} linkData
2901
+ * @param {String} linkData.type
2902
+ * @param {String} linkData.linkType
2903
+ * @param {String} linkData.id
2904
+ * @param {String} linkData.urn
2876
2905
  * @return {String}
2877
2906
  */
2878
- var makeLookupKey = function makeLookupKey(sys) {
2879
- return sys.type + '!' + sys.id;
2907
+ var lookupInEntityMap = function lookupInEntityMap(entityMap, linkData) {
2908
+ var entryId = linkData.entryId,
2909
+ linkType = linkData.linkType,
2910
+ spaceId = linkData.spaceId;
2911
+
2912
+ if (spaceId) {
2913
+ return entityMap.get(spaceId + '!' + linkType + '!' + entryId);
2914
+ }
2915
+ return entityMap.get(linkType + '!' + entryId);
2880
2916
  };
2881
2917
 
2882
2918
  /**
2883
- * getLink Function
2919
+ * getResolvedLink Function
2884
2920
  *
2885
- * @param response
2921
+ * @param entityMap
2886
2922
  * @param link
2887
2923
  * @return {undefined}
2888
2924
  */
2889
- var getLink = function getLink(entityMap, link) {
2925
+ var getResolvedLink = function getResolvedLink(entityMap, link) {
2890
2926
  var _link$sys = link.sys,
2891
- type = _link$sys.linkType,
2892
- id = _link$sys.id;
2927
+ type = _link$sys.type,
2928
+ linkType = _link$sys.linkType;
2929
+
2930
+ if (type === 'ResourceLink') {
2931
+ var urn = link.sys.urn;
2932
+
2933
+ var regExp = /.*:spaces\/([A-Za-z0-9]*)\/entries\/([A-Za-z0-9]*)/;
2934
+ if (!regExp.test(urn)) {
2935
+ return UNRESOLVED_LINK;
2936
+ }
2893
2937
 
2894
- var lookupKey = makeLookupKey({ type: type, id: id });
2938
+ var _urn$match = urn.match(regExp),
2939
+ _urn$match2 = _slicedToArray(_urn$match, 3),
2940
+ _ = _urn$match2[0],
2941
+ spaceId = _urn$match2[1],
2942
+ _entryId = _urn$match2[2];
2895
2943
 
2896
- return entityMap.get(lookupKey) || UNRESOLVED_LINK;
2944
+ var extractedLinkType = linkType.split(':')[1];
2945
+ return lookupInEntityMap(entityMap, { linkType: extractedLinkType, entryId: _entryId, spaceId: spaceId }) || UNRESOLVED_LINK;
2946
+ }
2947
+ var entryId = link.sys.id;
2948
+
2949
+ return lookupInEntityMap(entityMap, { linkType: linkType, entryId: entryId }) || UNRESOLVED_LINK;
2897
2950
  };
2898
2951
 
2899
2952
  /**
@@ -2921,6 +2974,7 @@ var cleanUpLinks = function cleanUpLinks(input) {
2921
2974
  * @param input
2922
2975
  * @param predicate
2923
2976
  * @param mutator
2977
+ * @param removeUnresolved
2924
2978
  * @return {*}
2925
2979
  */
2926
2980
  var walkMutate = function walkMutate(input, predicate, mutator, removeUnresolved) {
@@ -2943,7 +2997,7 @@ var walkMutate = function walkMutate(input, predicate, mutator, removeUnresolved
2943
2997
  };
2944
2998
 
2945
2999
  var normalizeLink = function normalizeLink(entityMap, link, removeUnresolved) {
2946
- var resolvedLink = getLink(entityMap, link);
3000
+ var resolvedLink = getResolvedLink(entityMap, link);
2947
3001
  if (resolvedLink === UNRESOLVED_LINK) {
2948
3002
  return removeUnresolved ? resolvedLink : link;
2949
3003
  }
@@ -2984,16 +3038,24 @@ var resolveResponse = function resolveResponse(response, options) {
2984
3038
  return [].concat(_toConsumableArray(all), _toConsumableArray(response.includes[type]));
2985
3039
  }, []);
2986
3040
 
2987
- var allEntries = [].concat(_toConsumableArray(responseClone.items), _toConsumableArray(allIncludes));
3041
+ var allEntries = [].concat(_toConsumableArray(responseClone.items), _toConsumableArray(allIncludes)).filter(function (entity) {
3042
+ return Boolean(entity.sys);
3043
+ });
2988
3044
 
2989
- var entityMap = new Map(allEntries.map(function (entity) {
2990
- return [makeLookupKey(entity.sys), entity];
2991
- }));
3045
+ var entityMap = new Map(allEntries.reduce(function (acc, entity) {
3046
+ var entries = makeEntityMapKeys(entity.sys).map(function (key) {
3047
+ return [key, entity];
3048
+ });
3049
+ acc.push.apply(acc, _toConsumableArray(entries));
3050
+ return acc;
3051
+ }, []));
2992
3052
 
2993
3053
  allEntries.forEach(function (item) {
2994
3054
  var entryObject = makeEntryObject(item, options.itemEntryPoints);
2995
3055
 
2996
- Object.assign(item, walkMutate(entryObject, isLink, function (link) {
3056
+ Object.assign(item, walkMutate(entryObject, function (x) {
3057
+ return isLink(x) || isResourceLink(x);
3058
+ }, function (link) {
2997
3059
  return normalizeLink(entityMap, link, options.removeUnresolved);
2998
3060
  }, options.removeUnresolved));
2999
3061
  });
@@ -8872,7 +8934,7 @@ function createClient(params) {
8872
8934
  environment: 'master'
8873
8935
  };
8874
8936
  const config = _objectSpread(_objectSpread({}, defaultConfig), params);
8875
- const userAgentHeader = Object(contentful_sdk_core__WEBPACK_IMPORTED_MODULE_1__["getUserAgentHeader"])(`contentful.js/${"9.3.2"}`, config.application, config.integration);
8937
+ const userAgentHeader = Object(contentful_sdk_core__WEBPACK_IMPORTED_MODULE_1__["getUserAgentHeader"])(`contentful.js/${"9.3.4"}`, config.application, config.integration);
8876
8938
  config.headers = _objectSpread(_objectSpread({}, config.headers), {}, {
8877
8939
  'Content-Type': 'application/vnd.contentful.delivery.v1+json',
8878
8940
  'X-Contentful-User-Agent': userAgentHeader