contentful-resolve-response
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -49,3 +49,7 @@ 'use strict'; | ||
var makeEntityMapKeys = function makeEntityMapKeys(sys) { | ||
return sys.space ? [`${sys.type}!${sys.id}`, `${sys.space.sys.id}!${sys.type}!${sys.id}`] : [`${sys.type}!${sys.id}`]; | ||
if (sys.space && sys.environment) { | ||
return [`${sys.type}!${sys.id}`, `${sys.space.sys.id}!${sys.environment.sys.id}!${sys.type}!${sys.id}`]; | ||
} | ||
return [`${sys.type}!${sys.id}`]; | ||
}; | ||
@@ -67,10 +71,32 @@ | ||
linkType = linkData.linkType, | ||
spaceId = linkData.spaceId; | ||
spaceId = linkData.spaceId, | ||
environmentId = linkData.environmentId; | ||
if (spaceId) { | ||
return entityMap.get(`${spaceId}!${linkType}!${entryId}`); | ||
if (spaceId && environmentId) { | ||
return entityMap.get(`${spaceId}!${environmentId}!${linkType}!${entryId}`); | ||
} | ||
return entityMap.get(`${linkType}!${entryId}`); | ||
}; | ||
var getIdsFromUrn = function getIdsFromUrn(urn) { | ||
// TODO: Use the regex in resource-names package when it's public. | ||
var regExp = /.*:spaces\/(?<spaceId>[^/]+)(?:\/environments\/(?<environmentId>[^/]+))?\/entries\/(?<entityId>[^/]+)$/; | ||
if (!regExp.test(urn)) { | ||
return undefined; | ||
} | ||
var _urn$match = urn.match(regExp), | ||
_urn$match2 = _slicedToArray(_urn$match, 4), | ||
_ = _urn$match2[0], | ||
spaceId = _urn$match2[1], | ||
_urn$match2$ = _urn$match2[2], | ||
environmentId = _urn$match2$ === undefined ? 'master' : _urn$match2$, | ||
entryId = _urn$match2[3]; | ||
return { spaceId, environmentId, entryId }; | ||
}; | ||
/** | ||
@@ -91,16 +117,17 @@ * getResolvedLink Function | ||
var regExp = /.*:spaces\/([A-Za-z0-9]*)\/entries\/([A-Za-z0-9]*)/; | ||
if (!regExp.test(urn)) { | ||
return UNRESOLVED_LINK; | ||
} | ||
var _getIdsFromUrn = getIdsFromUrn(urn), | ||
spaceId = _getIdsFromUrn.spaceId, | ||
environmentId = _getIdsFromUrn.environmentId, | ||
_entryId = _getIdsFromUrn.entryId; | ||
var _urn$match = urn.match(regExp), | ||
_urn$match2 = _slicedToArray(_urn$match, 3), | ||
_ = _urn$match2[0], | ||
spaceId = _urn$match2[1], | ||
_entryId = _urn$match2[2]; | ||
var extractedLinkType = linkType.split(':')[1]; | ||
var extractedLinkType = linkType.split(':')[1]; | ||
return lookupInEntityMap(entityMap, { linkType: extractedLinkType, entryId: _entryId, spaceId }) || UNRESOLVED_LINK; | ||
return lookupInEntityMap(entityMap, { | ||
linkType: extractedLinkType, | ||
entryId: _entryId, | ||
spaceId, | ||
environmentId | ||
}) || UNRESOLVED_LINK; | ||
} | ||
var entryId = link.sys.id; | ||
@@ -107,0 +134,0 @@ |
@@ -41,3 +41,7 @@ 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; }; | ||
var makeEntityMapKeys = function makeEntityMapKeys(sys) { | ||
return sys.space ? [sys.type + '!' + sys.id, sys.space.sys.id + '!' + sys.type + '!' + sys.id] : [sys.type + '!' + sys.id]; | ||
if (sys.space && sys.environment) { | ||
return [sys.type + '!' + sys.id, sys.space.sys.id + '!' + sys.environment.sys.id + '!' + sys.type + '!' + sys.id]; | ||
} | ||
return [sys.type + '!' + sys.id]; | ||
}; | ||
@@ -59,10 +63,32 @@ | ||
linkType = linkData.linkType, | ||
spaceId = linkData.spaceId; | ||
spaceId = linkData.spaceId, | ||
environmentId = linkData.environmentId; | ||
if (spaceId) { | ||
return entityMap.get(spaceId + '!' + linkType + '!' + entryId); | ||
if (spaceId && environmentId) { | ||
return entityMap.get(spaceId + '!' + environmentId + '!' + linkType + '!' + entryId); | ||
} | ||
return entityMap.get(linkType + '!' + entryId); | ||
}; | ||
var getIdsFromUrn = function getIdsFromUrn(urn) { | ||
// TODO: Use the regex in resource-names package when it's public. | ||
var regExp = /.*:spaces\/(?<spaceId>[^/]+)(?:\/environments\/(?<environmentId>[^/]+))?\/entries\/(?<entityId>[^/]+)$/; | ||
if (!regExp.test(urn)) { | ||
return undefined; | ||
} | ||
var _urn$match = urn.match(regExp), | ||
_urn$match2 = _slicedToArray(_urn$match, 4), | ||
_ = _urn$match2[0], | ||
spaceId = _urn$match2[1], | ||
_urn$match2$ = _urn$match2[2], | ||
environmentId = _urn$match2$ === undefined ? 'master' : _urn$match2$, | ||
entryId = _urn$match2[3]; | ||
return { spaceId: spaceId, environmentId: environmentId, entryId: entryId }; | ||
}; | ||
/** | ||
@@ -83,16 +109,17 @@ * getResolvedLink Function | ||
var regExp = /.*:spaces\/([A-Za-z0-9]*)\/entries\/([A-Za-z0-9]*)/; | ||
if (!regExp.test(urn)) { | ||
return UNRESOLVED_LINK; | ||
} | ||
var _getIdsFromUrn = getIdsFromUrn(urn), | ||
spaceId = _getIdsFromUrn.spaceId, | ||
environmentId = _getIdsFromUrn.environmentId, | ||
_entryId = _getIdsFromUrn.entryId; | ||
var _urn$match = urn.match(regExp), | ||
_urn$match2 = _slicedToArray(_urn$match, 3), | ||
_ = _urn$match2[0], | ||
spaceId = _urn$match2[1], | ||
_entryId = _urn$match2[2]; | ||
var extractedLinkType = linkType.split(':')[1]; | ||
var extractedLinkType = linkType.split(':')[1]; | ||
return lookupInEntityMap(entityMap, { linkType: extractedLinkType, entryId: _entryId, spaceId: spaceId }) || UNRESOLVED_LINK; | ||
return lookupInEntityMap(entityMap, { | ||
linkType: extractedLinkType, | ||
entryId: _entryId, | ||
spaceId: spaceId, | ||
environmentId: environmentId | ||
}) || UNRESOLVED_LINK; | ||
} | ||
var entryId = link.sys.id; | ||
@@ -99,0 +126,0 @@ |
{ | ||
"name": "contentful-resolve-response", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "", | ||
@@ -44,7 +44,7 @@ "main": "./dist/cjs/index.js", | ||
"eslint": "^8.9.0", | ||
"eslint-config-prettier": "^8.4.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-mocha": "^10.0.3", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"eslint-plugin-promise": "^6.0.0", | ||
@@ -54,3 +54,3 @@ "eslint-plugin-standard": "^5.0.0", | ||
"mocha": "^10.0.0", | ||
"prettier": "^2.5.1", | ||
"prettier": "^3.0.0", | ||
"semantic-release": "^19.0.5" | ||
@@ -57,0 +57,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20353
416