@craftercms/content
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -219,2 +219,12 @@ /* | ||
}; | ||
var ignoreProps = [ | ||
'orderDefault_f', | ||
'merge-strategy', | ||
'display-template', | ||
'objectGroupId', | ||
'folder-name', | ||
'createdDate', | ||
'lastModifiedDate', | ||
'no-template-required' | ||
]; | ||
var systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
@@ -228,11 +238,15 @@ function parseDescriptor(data) { | ||
} | ||
else if (data.descriptorDom) { | ||
return parseDescriptor(data.descriptorDom); | ||
else if (data.children) { | ||
return parseDescriptor(extractChildren(data.children)); | ||
} | ||
else if (data.page) { | ||
return parseDescriptor(data.page); | ||
else if (data.descriptorDom === null && data.descriptorUrl) { | ||
// This path catches calls to getChildren | ||
// /api/1/site/content_store/children.json?url=&crafterSite= | ||
// The getChildren call only certain items can be parsed as content items | ||
throw new Error('[parseDescriptor] Invalid descriptor supplied. Did you call ' + | ||
'parseDescriptor with a `getChildren` API response? The `getChildren` API ' + | ||
'response may contain certain items that are not parsable into ContentInstances. ' + | ||
'Try a different API (getItem, getDescriptor or getTree) or filter out the metadata ' + | ||
'items which descriptorDom property has a `page` or `component` property with the content item.'); | ||
} | ||
else if (data.component) { | ||
return parseDescriptor(data.component); | ||
} | ||
var parsed = { | ||
@@ -248,17 +262,38 @@ craftercms: { | ||
}; | ||
Object.entries(data).forEach(function (_a) { | ||
return parseProps(extractContent(data), parsed); | ||
} | ||
function parseProps(props, parsed) { | ||
if (parsed === void 0) { parsed = {}; } | ||
Object.entries(props).forEach(function (_a) { | ||
var prop = _a[0], value = _a[1]; | ||
var _b, _c, _d, _e; | ||
var _b, _c, _d; | ||
if (ignoreProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
} | ||
if (systemProps.includes(prop)) { | ||
// @ts-ignore | ||
parsed.craftercms[_b = systemPropMap[prop], (_b !== null && _b !== void 0 ? _b : prop)] = value; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
// In that case, here, parsed.craftercms might not be in the target object | ||
// and throw. We could do the below to de-risk but feels this needs assessment. | ||
// if (parsed.craftercms) { | ||
// parsed.craftercms[systemPropMap[prop] ?? prop] = value; | ||
// } else { | ||
// parsed[prop] = value; | ||
// } | ||
} | ||
else if (prop.endsWith('_o')) { | ||
parsed[prop] = (_d = (_c = value) === null || _c === void 0 ? void 0 : _c.item, (_d !== null && _d !== void 0 ? _d : [])); | ||
if ((_e = parsed[prop][0]) === null || _e === void 0 ? void 0 : _e.component) { | ||
parsed[prop] = parsed[prop].map(function (_a) { | ||
var key = _a.key, value = _a.value, component = _a.component; | ||
parsed[prop] = parsed[prop].map(function (item) { | ||
var key = item.key, value = item.value, component = item.component; | ||
if ((item.component) || (item.key && item.value)) { | ||
// Components | ||
var newComponent = __assign(__assign({ label: value }, component), { path: key.startsWith('/') ? key : null }); | ||
return parseDescriptor(newComponent); | ||
}); | ||
} | ||
} | ||
else { | ||
// Repeat group items | ||
return parseProps(item); | ||
} | ||
}); | ||
} | ||
@@ -271,2 +306,26 @@ else { | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
function extractContent(data) { | ||
var output = data; | ||
if (data.descriptorDom) { | ||
return __assign(__assign({}, (data.descriptorDom.page || data.descriptorDom.component)), { path: data.url }); | ||
} | ||
else if (data.page) { | ||
return data.page; | ||
} | ||
else if (data.component) { | ||
return data.component; | ||
} | ||
return output; | ||
} | ||
/** | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
function extractChildren(children) { | ||
return children.flatMap(function (child) { | ||
return child.children ? extractChildren(child.children) : child; | ||
}); | ||
} | ||
@@ -283,2 +342,3 @@ exports.ContentStoreService = ContentStoreService; | ||
exports.parseDescriptor = parseDescriptor; | ||
exports.parseProps = parseProps; | ||
exports.urlTransform = urlTransform; | ||
@@ -285,0 +345,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports,require("@craftercms/classes"),require("@craftercms/utils")):"function"==typeof define&&define.amd?define("@craftercms/content",["exports","@craftercms/classes","@craftercms/utils"],factory):factory(((global=global||self).craftercms=global.craftercms||{},global.craftercms.content={}),global.craftercms.classes,global.craftercms.utils)}(this,function(exports,classes,utils){"use strict";function getItem(path,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_ITEM_URL);return classes.SDKService.httpGet(requestURL,{url:path,crafterSite:config.site})}function getDescriptor(path,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_DESCRIPTOR);return classes.SDKService.httpGet(requestURL,{url:path,crafterSite:config.site})}function getChildren(path,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_CHILDREN);return classes.SDKService.httpGet(requestURL,{url:path,crafterSite:config.site})}function getTree(path,depth,config){void 0===depth&&(depth=1),"object"==typeof depth&&(config=depth,depth=1),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_TREE);return classes.SDKService.httpGet(requestURL,{url:path,depth:depth,crafterSite:config.site})}var ContentStoreService={getItem:getItem,getDescriptor:getDescriptor,getChildren:getChildren,getTree:getTree};function getNavTree(path,depth,currentPageUrl,config){void 0===depth&&(depth=1),void 0===currentPageUrl&&(currentPageUrl=""),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_NAV_TREE);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,currentPageUrl:currentPageUrl,url:path,depth:depth})}function getNavBreadcrumb(path,root,config){void 0===root&&(root=""),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_BREADCRUMB);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,url:path,root:root})}var NavigationService={getNavTree:getNavTree,getNavBreadcrumb:getNavBreadcrumb};function urlTransform(transformerName,url,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.TRANSFORM_URL);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,transformerName:transformerName,url:url})}var UrlTransformationService={transform:urlTransform,urlTransform:urlTransform},__assign=function(){return(__assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++)for(var p in s=arguments[i])Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p]);return t}).apply(this,arguments)},systemPropMap={guid:"id",cmsId:"id",objectId:"id",localId:"path","file-name":"fileName",file__name:"fileName",placeInNav:"placeInNav","internal-name":"label",internal__name:"label","content-type":"contentTypeId",content__type:"contentTypeId",createdDate_dt:"dateCreated",lastModifiedDate_dt:"dateModified",disabled:"disabled"},systemProps=Object.keys(systemPropMap).concat(Object.values(systemPropMap));exports.ContentStoreService=ContentStoreService,exports.NavigationService=NavigationService,exports.UrlTransformationService=UrlTransformationService,exports.getChildren=getChildren,exports.getDescriptor=getDescriptor,exports.getItem=getItem,exports.getNavBreadcrumb=getNavBreadcrumb,exports.getNavTree=getNavTree,exports.getTree=getTree,exports.parseDescriptor=function parseDescriptor(data){if(null==data)return null;if(Array.isArray(data))return data.map(function(item){return parseDescriptor(item)});if(data.descriptorDom)return parseDescriptor(data.descriptorDom);if(data.page)return parseDescriptor(data.page);if(data.component)return parseDescriptor(data.component);var parsed={craftercms:{id:null,path:null,label:null,contentTypeId:null,dateCreated:null,dateModified:null}};return Object.entries(data).forEach(function(_a){var _b,_c,_d,_e,prop=_a[0],value=_a[1];systemProps.includes(prop)?parsed.craftercms[(_b=systemPropMap[prop],null!==_b&&void 0!==_b?_b:prop)]=value:prop.endsWith("_o")?(parsed[prop]=null!==(_d=null===(_c=value)||void 0===_c?void 0:_c.item)&&void 0!==_d?_d:[],(null===(_e=parsed[prop][0])||void 0===_e?void 0:_e.component)&&(parsed[prop]=parsed[prop].map(function(_a){var key=_a.key,value=_a.value,component=_a.component;return parseDescriptor(__assign(__assign({label:value},component),{path:key.startsWith("/")?key:null}))}))):parsed[prop]=null!==value&&void 0!==value?value:null}),parsed},exports.urlTransform=urlTransform,Object.defineProperty(exports,"__esModule",{value:!0})}); | ||
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports,require("@craftercms/classes"),require("@craftercms/utils")):"function"==typeof define&&define.amd?define("@craftercms/content",["exports","@craftercms/classes","@craftercms/utils"],factory):factory(((global=global||self).craftercms=global.craftercms||{},global.craftercms.content={}),global.craftercms.classes,global.craftercms.utils)}(this,function(exports,classes,utils){"use strict";function getItem(path,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_ITEM_URL);return classes.SDKService.httpGet(requestURL,{url:path,crafterSite:config.site})}function getDescriptor(path,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_DESCRIPTOR);return classes.SDKService.httpGet(requestURL,{url:path,crafterSite:config.site})}function getChildren(path,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_CHILDREN);return classes.SDKService.httpGet(requestURL,{url:path,crafterSite:config.site})}function getTree(path,depth,config){void 0===depth&&(depth=1),"object"==typeof depth&&(config=depth,depth=1),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_TREE);return classes.SDKService.httpGet(requestURL,{url:path,depth:depth,crafterSite:config.site})}var ContentStoreService={getItem:getItem,getDescriptor:getDescriptor,getChildren:getChildren,getTree:getTree};function getNavTree(path,depth,currentPageUrl,config){void 0===depth&&(depth=1),void 0===currentPageUrl&&(currentPageUrl=""),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_NAV_TREE);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,currentPageUrl:currentPageUrl,url:path,depth:depth})}function getNavBreadcrumb(path,root,config){void 0===root&&(root=""),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_BREADCRUMB);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,url:path,root:root})}var NavigationService={getNavTree:getNavTree,getNavBreadcrumb:getNavBreadcrumb};function urlTransform(transformerName,url,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.TRANSFORM_URL);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,transformerName:transformerName,url:url})}var UrlTransformationService={transform:urlTransform,urlTransform:urlTransform},__assign=function(){return(__assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++)for(var p in s=arguments[i])Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p]);return t}).apply(this,arguments)},systemPropMap={guid:"id",cmsId:"id",objectId:"id",localId:"path","file-name":"fileName",file__name:"fileName",placeInNav:"placeInNav","internal-name":"label",internal__name:"label","content-type":"contentTypeId",content__type:"contentTypeId",createdDate_dt:"dateCreated",lastModifiedDate_dt:"dateModified",disabled:"disabled"},ignoreProps=["orderDefault_f","merge-strategy","display-template","objectGroupId","folder-name","createdDate","lastModifiedDate","no-template-required"],systemProps=Object.keys(systemPropMap).concat(Object.values(systemPropMap));function parseDescriptor(data){if(null==data)return null;if(Array.isArray(data))return data.map(function(item){return parseDescriptor(item)});if(data.children)return parseDescriptor(function extractChildren(children){return children.flatMap(function(child){return child.children?extractChildren(child.children):child})}(data.children));if(null===data.descriptorDom&&data.descriptorUrl)throw new Error("[parseDescriptor] Invalid descriptor supplied. Did you call parseDescriptor with a `getChildren` API response? The `getChildren` API response may contain certain items that are not parsable into ContentInstances. Try a different API (getItem, getDescriptor or getTree) or filter out the metadata items which descriptorDom property has a `page` or `component` property with the content item.");return parseProps(function(data){var output=data;if(data.descriptorDom)return __assign(__assign({},data.descriptorDom.page||data.descriptorDom.component),{path:data.url});if(data.page)return data.page;if(data.component)return data.component;return output}(data),{craftercms:{id:null,path:null,label:null,contentTypeId:null,dateCreated:null,dateModified:null}})}function parseProps(props,parsed){return void 0===parsed&&(parsed={}),Object.entries(props).forEach(function(_a){var _b,_c,_d,prop=_a[0],value=_a[1];ignoreProps.includes(prop)||(systemProps.includes(prop)?parsed.craftercms[(_b=systemPropMap[prop],null!==_b&&void 0!==_b?_b:prop)]=value:prop.endsWith("_o")?(parsed[prop]=null!==(_d=null===(_c=value)||void 0===_c?void 0:_c.item)&&void 0!==_d?_d:[],parsed[prop]=parsed[prop].map(function(item){var key=item.key,value=item.value,component=item.component;return item.component||item.key&&item.value?parseDescriptor(__assign(__assign({label:value},component),{path:key.startsWith("/")?key:null})):parseProps(item)})):parsed[prop]=null!==value&&void 0!==value?value:null)}),parsed}exports.ContentStoreService=ContentStoreService,exports.NavigationService=NavigationService,exports.UrlTransformationService=UrlTransformationService,exports.getChildren=getChildren,exports.getDescriptor=getDescriptor,exports.getItem=getItem,exports.getNavBreadcrumb=getNavBreadcrumb,exports.getNavTree=getNavTree,exports.getTree=getTree,exports.parseDescriptor=parseDescriptor,exports.parseProps=parseProps,exports.urlTransform=urlTransform,Object.defineProperty(exports,"__esModule",{value:!0})}); |
@@ -50,11 +50,15 @@ /* | ||
} | ||
else if (data.descriptorDom) { | ||
return parseDescriptor(data.descriptorDom); | ||
else if (data.children) { | ||
return parseDescriptor(extractChildren(data.children)); | ||
} | ||
else if (data.page) { | ||
return parseDescriptor(data.page); | ||
else if (data.descriptorDom === null && data.descriptorUrl) { | ||
// This path catches calls to getChildren | ||
// /api/1/site/content_store/children.json?url=&crafterSite= | ||
// The getChildren call only certain items can be parsed as content items | ||
throw new Error('[parseDescriptor] Invalid descriptor supplied. Did you call ' + | ||
'parseDescriptor with a `getChildren` API response? The `getChildren` API ' + | ||
'response may contain certain items that are not parsable into ContentInstances. ' + | ||
'Try a different API (getItem, getDescriptor or getTree) or filter out the metadata ' + | ||
'items which descriptorDom property has a `page` or `component` property with the content item.'); | ||
} | ||
else if (data.component) { | ||
return parseDescriptor(data.component); | ||
} | ||
let parsed = { | ||
@@ -70,15 +74,36 @@ craftercms: { | ||
}; | ||
Object.entries(data).forEach(([prop, value]) => { | ||
var _a, _b, _c, _d; | ||
return parseProps(extractContent(data), parsed); | ||
} | ||
export function parseProps(props, parsed = {}) { | ||
Object.entries(props).forEach(([prop, value]) => { | ||
var _a, _b, _c; | ||
if (ignoreProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
} | ||
if (systemProps.includes(prop)) { | ||
// @ts-ignore | ||
parsed.craftercms[_a = systemPropMap[prop], (_a !== null && _a !== void 0 ? _a : prop)] = value; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
// In that case, here, parsed.craftercms might not be in the target object | ||
// and throw. We could do the below to de-risk but feels this needs assessment. | ||
// if (parsed.craftercms) { | ||
// parsed.craftercms[systemPropMap[prop] ?? prop] = value; | ||
// } else { | ||
// parsed[prop] = value; | ||
// } | ||
} | ||
else if (prop.endsWith('_o')) { | ||
parsed[prop] = (_c = (_b = value) === null || _b === void 0 ? void 0 : _b.item, (_c !== null && _c !== void 0 ? _c : [])); | ||
if ((_d = parsed[prop][0]) === null || _d === void 0 ? void 0 : _d.component) { | ||
parsed[prop] = parsed[prop].map(({ key, value, component }) => { | ||
parsed[prop] = parsed[prop].map((item) => { | ||
const { key, value, component } = item; | ||
if ((item.component) || (item.key && item.value)) { | ||
// Components | ||
const newComponent = Object.assign(Object.assign({ label: value }, component), { path: key.startsWith('/') ? key : null }); | ||
return parseDescriptor(newComponent); | ||
}); | ||
} | ||
} | ||
else { | ||
// Repeat group items | ||
return parseProps(item); | ||
} | ||
}); | ||
} | ||
@@ -91,2 +116,26 @@ else { | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
function extractContent(data) { | ||
let output = data; | ||
if (data.descriptorDom) { | ||
return Object.assign(Object.assign({}, (data.descriptorDom.page || data.descriptorDom.component)), { path: data.url }); | ||
} | ||
else if (data.page) { | ||
return data.page; | ||
} | ||
else if (data.component) { | ||
return data.component; | ||
} | ||
return output; | ||
} | ||
/** | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
function extractChildren(children) { | ||
return children.flatMap((child) => { | ||
return child.children ? extractChildren(child.children) : child; | ||
}); | ||
} | ||
//# sourceMappingURL=utils.js.map |
@@ -51,11 +51,15 @@ /* | ||
} | ||
else if (data.descriptorDom) { | ||
return parseDescriptor(data.descriptorDom); | ||
else if (data.children) { | ||
return parseDescriptor(extractChildren(data.children)); | ||
} | ||
else if (data.page) { | ||
return parseDescriptor(data.page); | ||
else if (data.descriptorDom === null && data.descriptorUrl) { | ||
// This path catches calls to getChildren | ||
// /api/1/site/content_store/children.json?url=&crafterSite= | ||
// The getChildren call only certain items can be parsed as content items | ||
throw new Error('[parseDescriptor] Invalid descriptor supplied. Did you call ' + | ||
'parseDescriptor with a `getChildren` API response? The `getChildren` API ' + | ||
'response may contain certain items that are not parsable into ContentInstances. ' + | ||
'Try a different API (getItem, getDescriptor or getTree) or filter out the metadata ' + | ||
'items which descriptorDom property has a `page` or `component` property with the content item.'); | ||
} | ||
else if (data.component) { | ||
return parseDescriptor(data.component); | ||
} | ||
var parsed = { | ||
@@ -71,17 +75,38 @@ craftercms: { | ||
}; | ||
Object.entries(data).forEach(function (_a) { | ||
return parseProps(extractContent(data), parsed); | ||
} | ||
export function parseProps(props, parsed) { | ||
if (parsed === void 0) { parsed = {}; } | ||
Object.entries(props).forEach(function (_a) { | ||
var prop = _a[0], value = _a[1]; | ||
var _b, _c, _d, _e; | ||
var _b, _c, _d; | ||
if (ignoreProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
} | ||
if (systemProps.includes(prop)) { | ||
// @ts-ignore | ||
parsed.craftercms[_b = systemPropMap[prop], (_b !== null && _b !== void 0 ? _b : prop)] = value; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
// In that case, here, parsed.craftercms might not be in the target object | ||
// and throw. We could do the below to de-risk but feels this needs assessment. | ||
// if (parsed.craftercms) { | ||
// parsed.craftercms[systemPropMap[prop] ?? prop] = value; | ||
// } else { | ||
// parsed[prop] = value; | ||
// } | ||
} | ||
else if (prop.endsWith('_o')) { | ||
parsed[prop] = (_d = (_c = value) === null || _c === void 0 ? void 0 : _c.item, (_d !== null && _d !== void 0 ? _d : [])); | ||
if ((_e = parsed[prop][0]) === null || _e === void 0 ? void 0 : _e.component) { | ||
parsed[prop] = parsed[prop].map(function (_a) { | ||
var key = _a.key, value = _a.value, component = _a.component; | ||
parsed[prop] = parsed[prop].map(function (item) { | ||
var key = item.key, value = item.value, component = item.component; | ||
if ((item.component) || (item.key && item.value)) { | ||
// Components | ||
var newComponent = __assign(__assign({ label: value }, component), { path: key.startsWith('/') ? key : null }); | ||
return parseDescriptor(newComponent); | ||
}); | ||
} | ||
} | ||
else { | ||
// Repeat group items | ||
return parseProps(item); | ||
} | ||
}); | ||
} | ||
@@ -94,2 +119,26 @@ else { | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
function extractContent(data) { | ||
var output = data; | ||
if (data.descriptorDom) { | ||
return __assign(__assign({}, (data.descriptorDom.page || data.descriptorDom.component)), { path: data.url }); | ||
} | ||
else if (data.page) { | ||
return data.page; | ||
} | ||
else if (data.component) { | ||
return data.component; | ||
} | ||
return output; | ||
} | ||
/** | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
function extractChildren(children) { | ||
return children.flatMap(function (child) { | ||
return child.children ? extractChildren(child.children) : child; | ||
}); | ||
} | ||
//# sourceMappingURL=utils.js.map |
@@ -170,2 +170,12 @@ /* | ||
}; | ||
const ignoreProps = [ | ||
'orderDefault_f', | ||
'merge-strategy', | ||
'display-template', | ||
'objectGroupId', | ||
'folder-name', | ||
'createdDate', | ||
'lastModifiedDate', | ||
'no-template-required' | ||
]; | ||
const systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
@@ -179,11 +189,15 @@ function parseDescriptor(data) { | ||
} | ||
else if (data.descriptorDom) { | ||
return parseDescriptor(data.descriptorDom); | ||
else if (data.children) { | ||
return parseDescriptor(extractChildren(data.children)); | ||
} | ||
else if (data.page) { | ||
return parseDescriptor(data.page); | ||
else if (data.descriptorDom === null && data.descriptorUrl) { | ||
// This path catches calls to getChildren | ||
// /api/1/site/content_store/children.json?url=&crafterSite= | ||
// The getChildren call only certain items can be parsed as content items | ||
throw new Error('[parseDescriptor] Invalid descriptor supplied. Did you call ' + | ||
'parseDescriptor with a `getChildren` API response? The `getChildren` API ' + | ||
'response may contain certain items that are not parsable into ContentInstances. ' + | ||
'Try a different API (getItem, getDescriptor or getTree) or filter out the metadata ' + | ||
'items which descriptorDom property has a `page` or `component` property with the content item.'); | ||
} | ||
else if (data.component) { | ||
return parseDescriptor(data.component); | ||
} | ||
let parsed = { | ||
@@ -199,15 +213,36 @@ craftercms: { | ||
}; | ||
Object.entries(data).forEach(([prop, value]) => { | ||
var _a, _b, _c, _d; | ||
return parseProps(extractContent(data), parsed); | ||
} | ||
function parseProps(props, parsed = {}) { | ||
Object.entries(props).forEach(([prop, value]) => { | ||
var _a, _b, _c; | ||
if (ignoreProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
} | ||
if (systemProps.includes(prop)) { | ||
// @ts-ignore | ||
parsed.craftercms[_a = systemPropMap[prop], (_a !== null && _a !== void 0 ? _a : prop)] = value; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
// In that case, here, parsed.craftercms might not be in the target object | ||
// and throw. We could do the below to de-risk but feels this needs assessment. | ||
// if (parsed.craftercms) { | ||
// parsed.craftercms[systemPropMap[prop] ?? prop] = value; | ||
// } else { | ||
// parsed[prop] = value; | ||
// } | ||
} | ||
else if (prop.endsWith('_o')) { | ||
parsed[prop] = (_c = (_b = value) === null || _b === void 0 ? void 0 : _b.item, (_c !== null && _c !== void 0 ? _c : [])); | ||
if ((_d = parsed[prop][0]) === null || _d === void 0 ? void 0 : _d.component) { | ||
parsed[prop] = parsed[prop].map(({ key, value, component }) => { | ||
parsed[prop] = parsed[prop].map((item) => { | ||
const { key, value, component } = item; | ||
if ((item.component) || (item.key && item.value)) { | ||
// Components | ||
const newComponent = Object.assign(Object.assign({ label: value }, component), { path: key.startsWith('/') ? key : null }); | ||
return parseDescriptor(newComponent); | ||
}); | ||
} | ||
} | ||
else { | ||
// Repeat group items | ||
return parseProps(item); | ||
} | ||
}); | ||
} | ||
@@ -220,4 +255,28 @@ else { | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
function extractContent(data) { | ||
let output = data; | ||
if (data.descriptorDom) { | ||
return Object.assign(Object.assign({}, (data.descriptorDom.page || data.descriptorDom.component)), { path: data.url }); | ||
} | ||
else if (data.page) { | ||
return data.page; | ||
} | ||
else if (data.component) { | ||
return data.component; | ||
} | ||
return output; | ||
} | ||
/** | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
function extractChildren(children) { | ||
return children.flatMap((child) => { | ||
return child.children ? extractChildren(child.children) : child; | ||
}); | ||
} | ||
export { ContentStoreService, NavigationService, UrlTransformationService, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, urlTransform }; | ||
export { ContentStoreService, NavigationService, UrlTransformationService, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, parseProps, urlTransform }; | ||
//# sourceMappingURL=content.js.map |
@@ -170,2 +170,12 @@ /* | ||
}; | ||
const ignoreProps = [ | ||
'orderDefault_f', | ||
'merge-strategy', | ||
'display-template', | ||
'objectGroupId', | ||
'folder-name', | ||
'createdDate', | ||
'lastModifiedDate', | ||
'no-template-required' | ||
]; | ||
const systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
@@ -179,11 +189,15 @@ function parseDescriptor(data) { | ||
} | ||
else if (data.descriptorDom) { | ||
return parseDescriptor(data.descriptorDom); | ||
else if (data.children) { | ||
return parseDescriptor(extractChildren(data.children)); | ||
} | ||
else if (data.page) { | ||
return parseDescriptor(data.page); | ||
else if (data.descriptorDom === null && data.descriptorUrl) { | ||
// This path catches calls to getChildren | ||
// /api/1/site/content_store/children.json?url=&crafterSite= | ||
// The getChildren call only certain items can be parsed as content items | ||
throw new Error('[parseDescriptor] Invalid descriptor supplied. Did you call ' + | ||
'parseDescriptor with a `getChildren` API response? The `getChildren` API ' + | ||
'response may contain certain items that are not parsable into ContentInstances. ' + | ||
'Try a different API (getItem, getDescriptor or getTree) or filter out the metadata ' + | ||
'items which descriptorDom property has a `page` or `component` property with the content item.'); | ||
} | ||
else if (data.component) { | ||
return parseDescriptor(data.component); | ||
} | ||
let parsed = { | ||
@@ -199,15 +213,36 @@ craftercms: { | ||
}; | ||
Object.entries(data).forEach(([prop, value]) => { | ||
var _a, _b, _c, _d; | ||
return parseProps(extractContent(data), parsed); | ||
} | ||
function parseProps(props, parsed = {}) { | ||
Object.entries(props).forEach(([prop, value]) => { | ||
var _a, _b, _c; | ||
if (ignoreProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
} | ||
if (systemProps.includes(prop)) { | ||
// @ts-ignore | ||
parsed.craftercms[_a = systemPropMap[prop], (_a !== null && _a !== void 0 ? _a : prop)] = value; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
// In that case, here, parsed.craftercms might not be in the target object | ||
// and throw. We could do the below to de-risk but feels this needs assessment. | ||
// if (parsed.craftercms) { | ||
// parsed.craftercms[systemPropMap[prop] ?? prop] = value; | ||
// } else { | ||
// parsed[prop] = value; | ||
// } | ||
} | ||
else if (prop.endsWith('_o')) { | ||
parsed[prop] = (_c = (_b = value) === null || _b === void 0 ? void 0 : _b.item, (_c !== null && _c !== void 0 ? _c : [])); | ||
if ((_d = parsed[prop][0]) === null || _d === void 0 ? void 0 : _d.component) { | ||
parsed[prop] = parsed[prop].map(({ key, value, component }) => { | ||
parsed[prop] = parsed[prop].map((item) => { | ||
const { key, value, component } = item; | ||
if ((item.component) || (item.key && item.value)) { | ||
// Components | ||
const newComponent = Object.assign(Object.assign({ label: value }, component), { path: key.startsWith('/') ? key : null }); | ||
return parseDescriptor(newComponent); | ||
}); | ||
} | ||
} | ||
else { | ||
// Repeat group items | ||
return parseProps(item); | ||
} | ||
}); | ||
} | ||
@@ -220,4 +255,28 @@ else { | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
function extractContent(data) { | ||
let output = data; | ||
if (data.descriptorDom) { | ||
return Object.assign(Object.assign({}, (data.descriptorDom.page || data.descriptorDom.component)), { path: data.url }); | ||
} | ||
else if (data.page) { | ||
return data.page; | ||
} | ||
else if (data.component) { | ||
return data.component; | ||
} | ||
return output; | ||
} | ||
/** | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
function extractChildren(children) { | ||
return children.flatMap((child) => { | ||
return child.children ? extractChildren(child.children) : child; | ||
}); | ||
} | ||
export { ContentStoreService, NavigationService, UrlTransformationService, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, urlTransform }; | ||
export { ContentStoreService, NavigationService, UrlTransformationService, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, parseProps, urlTransform }; | ||
//# sourceMappingURL=content.js.map |
@@ -200,2 +200,12 @@ /* | ||
}; | ||
var ignoreProps = [ | ||
'orderDefault_f', | ||
'merge-strategy', | ||
'display-template', | ||
'objectGroupId', | ||
'folder-name', | ||
'createdDate', | ||
'lastModifiedDate', | ||
'no-template-required' | ||
]; | ||
var systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
@@ -209,11 +219,15 @@ function parseDescriptor(data) { | ||
} | ||
else if (data.descriptorDom) { | ||
return parseDescriptor(data.descriptorDom); | ||
else if (data.children) { | ||
return parseDescriptor(extractChildren(data.children)); | ||
} | ||
else if (data.page) { | ||
return parseDescriptor(data.page); | ||
else if (data.descriptorDom === null && data.descriptorUrl) { | ||
// This path catches calls to getChildren | ||
// /api/1/site/content_store/children.json?url=&crafterSite= | ||
// The getChildren call only certain items can be parsed as content items | ||
throw new Error('[parseDescriptor] Invalid descriptor supplied. Did you call ' + | ||
'parseDescriptor with a `getChildren` API response? The `getChildren` API ' + | ||
'response may contain certain items that are not parsable into ContentInstances. ' + | ||
'Try a different API (getItem, getDescriptor or getTree) or filter out the metadata ' + | ||
'items which descriptorDom property has a `page` or `component` property with the content item.'); | ||
} | ||
else if (data.component) { | ||
return parseDescriptor(data.component); | ||
} | ||
var parsed = { | ||
@@ -229,17 +243,38 @@ craftercms: { | ||
}; | ||
Object.entries(data).forEach(function (_a) { | ||
return parseProps(extractContent(data), parsed); | ||
} | ||
function parseProps(props, parsed) { | ||
if (parsed === void 0) { parsed = {}; } | ||
Object.entries(props).forEach(function (_a) { | ||
var prop = _a[0], value = _a[1]; | ||
var _b, _c, _d, _e; | ||
var _b, _c, _d; | ||
if (ignoreProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
} | ||
if (systemProps.includes(prop)) { | ||
// @ts-ignore | ||
parsed.craftercms[_b = systemPropMap[prop], (_b !== null && _b !== void 0 ? _b : prop)] = value; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
// In that case, here, parsed.craftercms might not be in the target object | ||
// and throw. We could do the below to de-risk but feels this needs assessment. | ||
// if (parsed.craftercms) { | ||
// parsed.craftercms[systemPropMap[prop] ?? prop] = value; | ||
// } else { | ||
// parsed[prop] = value; | ||
// } | ||
} | ||
else if (prop.endsWith('_o')) { | ||
parsed[prop] = (_d = (_c = value) === null || _c === void 0 ? void 0 : _c.item, (_d !== null && _d !== void 0 ? _d : [])); | ||
if ((_e = parsed[prop][0]) === null || _e === void 0 ? void 0 : _e.component) { | ||
parsed[prop] = parsed[prop].map(function (_a) { | ||
var key = _a.key, value = _a.value, component = _a.component; | ||
parsed[prop] = parsed[prop].map(function (item) { | ||
var key = item.key, value = item.value, component = item.component; | ||
if ((item.component) || (item.key && item.value)) { | ||
// Components | ||
var newComponent = __assign(__assign({ label: value }, component), { path: key.startsWith('/') ? key : null }); | ||
return parseDescriptor(newComponent); | ||
}); | ||
} | ||
} | ||
else { | ||
// Repeat group items | ||
return parseProps(item); | ||
} | ||
}); | ||
} | ||
@@ -252,4 +287,28 @@ else { | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
function extractContent(data) { | ||
var output = data; | ||
if (data.descriptorDom) { | ||
return __assign(__assign({}, (data.descriptorDom.page || data.descriptorDom.component)), { path: data.url }); | ||
} | ||
else if (data.page) { | ||
return data.page; | ||
} | ||
else if (data.component) { | ||
return data.component; | ||
} | ||
return output; | ||
} | ||
/** | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
function extractChildren(children) { | ||
return children.flatMap(function (child) { | ||
return child.children ? extractChildren(child.children) : child; | ||
}); | ||
} | ||
export { ContentStoreService, NavigationService, UrlTransformationService, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, urlTransform }; | ||
export { ContentStoreService, NavigationService, UrlTransformationService, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, parseProps, urlTransform }; | ||
//# sourceMappingURL=content.js.map |
@@ -200,2 +200,12 @@ /* | ||
}; | ||
var ignoreProps = [ | ||
'orderDefault_f', | ||
'merge-strategy', | ||
'display-template', | ||
'objectGroupId', | ||
'folder-name', | ||
'createdDate', | ||
'lastModifiedDate', | ||
'no-template-required' | ||
]; | ||
var systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
@@ -209,11 +219,15 @@ function parseDescriptor(data) { | ||
} | ||
else if (data.descriptorDom) { | ||
return parseDescriptor(data.descriptorDom); | ||
else if (data.children) { | ||
return parseDescriptor(extractChildren(data.children)); | ||
} | ||
else if (data.page) { | ||
return parseDescriptor(data.page); | ||
else if (data.descriptorDom === null && data.descriptorUrl) { | ||
// This path catches calls to getChildren | ||
// /api/1/site/content_store/children.json?url=&crafterSite= | ||
// The getChildren call only certain items can be parsed as content items | ||
throw new Error('[parseDescriptor] Invalid descriptor supplied. Did you call ' + | ||
'parseDescriptor with a `getChildren` API response? The `getChildren` API ' + | ||
'response may contain certain items that are not parsable into ContentInstances. ' + | ||
'Try a different API (getItem, getDescriptor or getTree) or filter out the metadata ' + | ||
'items which descriptorDom property has a `page` or `component` property with the content item.'); | ||
} | ||
else if (data.component) { | ||
return parseDescriptor(data.component); | ||
} | ||
var parsed = { | ||
@@ -229,17 +243,38 @@ craftercms: { | ||
}; | ||
Object.entries(data).forEach(function (_a) { | ||
return parseProps(extractContent(data), parsed); | ||
} | ||
function parseProps(props, parsed) { | ||
if (parsed === void 0) { parsed = {}; } | ||
Object.entries(props).forEach(function (_a) { | ||
var prop = _a[0], value = _a[1]; | ||
var _b, _c, _d, _e; | ||
var _b, _c, _d; | ||
if (ignoreProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
} | ||
if (systemProps.includes(prop)) { | ||
// @ts-ignore | ||
parsed.craftercms[_b = systemPropMap[prop], (_b !== null && _b !== void 0 ? _b : prop)] = value; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
// In that case, here, parsed.craftercms might not be in the target object | ||
// and throw. We could do the below to de-risk but feels this needs assessment. | ||
// if (parsed.craftercms) { | ||
// parsed.craftercms[systemPropMap[prop] ?? prop] = value; | ||
// } else { | ||
// parsed[prop] = value; | ||
// } | ||
} | ||
else if (prop.endsWith('_o')) { | ||
parsed[prop] = (_d = (_c = value) === null || _c === void 0 ? void 0 : _c.item, (_d !== null && _d !== void 0 ? _d : [])); | ||
if ((_e = parsed[prop][0]) === null || _e === void 0 ? void 0 : _e.component) { | ||
parsed[prop] = parsed[prop].map(function (_a) { | ||
var key = _a.key, value = _a.value, component = _a.component; | ||
parsed[prop] = parsed[prop].map(function (item) { | ||
var key = item.key, value = item.value, component = item.component; | ||
if ((item.component) || (item.key && item.value)) { | ||
// Components | ||
var newComponent = __assign(__assign({ label: value }, component), { path: key.startsWith('/') ? key : null }); | ||
return parseDescriptor(newComponent); | ||
}); | ||
} | ||
} | ||
else { | ||
// Repeat group items | ||
return parseProps(item); | ||
} | ||
}); | ||
} | ||
@@ -252,4 +287,28 @@ else { | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
function extractContent(data) { | ||
var output = data; | ||
if (data.descriptorDom) { | ||
return __assign(__assign({}, (data.descriptorDom.page || data.descriptorDom.component)), { path: data.url }); | ||
} | ||
else if (data.page) { | ||
return data.page; | ||
} | ||
else if (data.component) { | ||
return data.component; | ||
} | ||
return output; | ||
} | ||
/** | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
function extractChildren(children) { | ||
return children.flatMap(function (child) { | ||
return child.children ? extractChildren(child.children) : child; | ||
}); | ||
} | ||
export { ContentStoreService, NavigationService, UrlTransformationService, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, urlTransform }; | ||
export { ContentStoreService, NavigationService, UrlTransformationService, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, parseProps, urlTransform }; | ||
//# sourceMappingURL=content.js.map |
{ | ||
"name": "@craftercms/content", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Crafter CMS services for content and navigation retrieval", | ||
@@ -29,5 +29,5 @@ "main": "./bundles/content.umd.js", | ||
"dependencies": { | ||
"@craftercms/classes": "1.2.0", | ||
"@craftercms/models": "1.2.0", | ||
"@craftercms/utils": "1.2.0", | ||
"@craftercms/classes": "1.2.1", | ||
"@craftercms/models": "1.2.1", | ||
"@craftercms/utils": "1.2.1", | ||
"rxjs": "^6.5.4", | ||
@@ -34,0 +34,0 @@ "tslib": "^1.10.0" |
@@ -14,2 +14,3 @@ import { ContentInstance, Descriptor, Item } from '@craftercms/models'; | ||
export declare function parseDescriptor(data: DescriptorResponse | DescriptorResponse[]): ContentInstance | ContentInstance[]; | ||
export declare function parseProps<Props = object, Target = object>(props: Props, parsed?: Target): Target; | ||
export {}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
309926
2190
0
+ Added@craftercms/classes@1.2.1(transitive)
+ Added@craftercms/models@1.2.1(transitive)
+ Added@craftercms/utils@1.2.1(transitive)
- Removed@craftercms/classes@1.2.0(transitive)
- Removed@craftercms/models@1.2.0(transitive)
- Removed@craftercms/utils@1.2.0(transitive)
Updated@craftercms/classes@1.2.1
Updated@craftercms/models@1.2.1
Updated@craftercms/utils@1.2.1