@craftercms/content
Advanced tools
Comparing version 1.1.2 to 1.2.0
/* | ||
* Copyright (C) 2007-2018 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
@@ -20,175 +19,251 @@ (function (global, factory) { | ||
typeof define === 'function' && define.amd ? define('@craftercms/content', ['exports', '@craftercms/classes', '@craftercms/utils'], factory) : | ||
(factory((global.craftercms = global.craftercms || {}, global.craftercms.content = {}),global.craftercms.classes,global.craftercms.utils)); | ||
}(this, (function (exports,classes,utils) { 'use strict'; | ||
(global = global || self, factory((global.craftercms = global.craftercms || {}, global.craftercms.content = {}), global.craftercms.classes, global.craftercms.utils)); | ||
}(this, (function (exports, classes, utils) { 'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
/* | ||
* Copyright (C) 2007-2018 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/* | ||
* Copyright (C) 2007-2019 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/** | ||
* Content Store Service API | ||
*/ | ||
var ContentStoreService = /** @class */ (function (_super) { | ||
__extends(ContentStoreService, _super); | ||
function ContentStoreService() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
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) { | ||
if (depth === void 0) { depth = 1; } | ||
if (typeof depth === 'object') { | ||
config = depth; | ||
depth = 1; | ||
} | ||
ContentStoreService.getItem = function (url, config) { | ||
if (config === void 0) { config = classes.crafterConf.getConfig(); } | ||
var requestURL = utils.composeUrl(config, config.endpoints.GET_ITEM_URL); | ||
return classes.SDKService.httpGet(requestURL, { url: url, crafterSite: config.site }); | ||
}; | ||
ContentStoreService.getDescriptor = function (url, config) { | ||
if (config === void 0) { config = classes.crafterConf.getConfig(); } | ||
var requestURL = utils.composeUrl(config, config.endpoints.GET_DESCRIPTOR); | ||
return classes.SDKService.httpGet(requestURL, { url: url, crafterSite: config.site }); | ||
}; | ||
ContentStoreService.getChildren = function (url, config) { | ||
if (config === void 0) { config = classes.crafterConf.getConfig(); } | ||
var requestURL = utils.composeUrl(config, config.endpoints.GET_CHILDREN); | ||
return classes.SDKService.httpGet(requestURL, { url: url, crafterSite: config.site }); | ||
}; | ||
ContentStoreService.getTree = function (url, depth, config) { | ||
if (depth === void 0) { depth = 1; } | ||
if (config === void 0) { config = classes.crafterConf.getConfig(); } | ||
var requestURL = utils.composeUrl(config, config.endpoints.GET_TREE); | ||
return classes.SDKService.httpGet(requestURL, { url: url, depth: depth, crafterSite: config.site }); | ||
}; | ||
return ContentStoreService; | ||
}(classes.SDKService)); | ||
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 | ||
}; | ||
/* | ||
* Copyright (C) 2007-2019 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
function getNavTree(path, depth, currentPageUrl, config) { | ||
if (depth === void 0) { depth = 1; } | ||
if (currentPageUrl === void 0) { 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) { | ||
if (root === void 0) { 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 | ||
}); | ||
} | ||
/** | ||
* Navigation Service API | ||
*/ | ||
var NavigationService = /** @class */ (function (_super) { | ||
__extends(NavigationService, _super); | ||
function NavigationService() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
NavigationService.getNavTree = function (url, depth, currentPageUrl, config) { | ||
if (depth === void 0) { depth = 1; } | ||
if (currentPageUrl === void 0) { currentPageUrl = ''; } | ||
if (config === void 0) { config = classes.crafterConf.getConfig(); } | ||
var requestURL = utils.composeUrl(config, config.endpoints.GET_NAV_TREE); | ||
return classes.SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, url: url, depth: depth, currentPageUrl: currentPageUrl | ||
}); | ||
}; | ||
NavigationService.getNavBreadcrumb = function (url, root, config) { | ||
if (root === void 0) { root = ''; } | ||
if (config === void 0) { config = classes.crafterConf.getConfig(); } | ||
var requestURL = utils.composeUrl(config, config.endpoints.GET_BREADCRUMB); | ||
return classes.SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, url: url, root: root | ||
}); | ||
}; | ||
return NavigationService; | ||
}(classes.SDKService)); | ||
var NavigationService = { | ||
getNavTree: getNavTree, | ||
getNavBreadcrumb: getNavBreadcrumb | ||
}; | ||
/* | ||
* Copyright (C) 2007-2019 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
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 | ||
}); | ||
} | ||
/** | ||
* URL Transformation Service API | ||
*/ | ||
var UrlTransformationService = /** @class */ (function (_super) { | ||
__extends(UrlTransformationService, _super); | ||
function UrlTransformationService() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
var UrlTransformationService = { | ||
transform: urlTransform, | ||
urlTransform: urlTransform | ||
}; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
/* | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
var 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' | ||
}; | ||
var systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
function parseDescriptor(data) { | ||
if (data == null) { | ||
return null; | ||
} | ||
UrlTransformationService.transform = function (transformerName, url, config) { | ||
if (config === void 0) { config = classes.crafterConf.getConfig(); } | ||
var requestURL = utils.composeUrl(config, config.endpoints.TRANSFORM_URL); | ||
return classes.SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, | ||
transformerName: transformerName, | ||
url: url | ||
}); | ||
else if (Array.isArray(data)) { | ||
return data.map(function (item) { return parseDescriptor(item); }); | ||
} | ||
else if (data.descriptorDom) { | ||
return parseDescriptor(data.descriptorDom); | ||
} | ||
else if (data.page) { | ||
return parseDescriptor(data.page); | ||
} | ||
else if (data.component) { | ||
return parseDescriptor(data.component); | ||
} | ||
var parsed = { | ||
craftercms: { | ||
id: null, | ||
path: null, | ||
label: null, | ||
contentTypeId: null, | ||
dateCreated: null, | ||
dateModified: null | ||
} | ||
}; | ||
return UrlTransformationService; | ||
}(classes.SDKService)); | ||
Object.entries(data).forEach(function (_a) { | ||
var prop = _a[0], value = _a[1]; | ||
var _b, _c, _d, _e; | ||
if (systemProps.includes(prop)) { | ||
parsed.craftercms[_b = systemPropMap[prop], (_b !== null && _b !== void 0 ? _b : 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; | ||
var newComponent = __assign(__assign({ label: value }, component), { path: key.startsWith('/') ? key : null }); | ||
return parseDescriptor(newComponent); | ||
}); | ||
} | ||
} | ||
else { | ||
parsed[prop] = (value !== null && value !== void 0 ? value : null); | ||
} | ||
}); | ||
return parsed; | ||
} | ||
@@ -198,2 +273,10 @@ exports.ContentStoreService = ContentStoreService; | ||
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.urlTransform = urlTransform; | ||
@@ -200,0 +283,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -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.craftercms=global.craftercms||{},global.craftercms.content={}),global.craftercms.classes,global.craftercms.utils)}(this,function(exports,classes,utils){"use strict";var extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)b.hasOwnProperty(p)&&(d[p]=b[p])};function __extends(d,b){function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}var ContentStoreService=function(_super){function ContentStoreService(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(ContentStoreService,_super),ContentStoreService.getItem=function(url,config){void 0===config&&(config=classes.crafterConf.getConfig());var requestURL=utils.composeUrl(config,config.endpoints.GET_ITEM_URL);return classes.SDKService.httpGet(requestURL,{url:url,crafterSite:config.site})},ContentStoreService.getDescriptor=function(url,config){void 0===config&&(config=classes.crafterConf.getConfig());var requestURL=utils.composeUrl(config,config.endpoints.GET_DESCRIPTOR);return classes.SDKService.httpGet(requestURL,{url:url,crafterSite:config.site})},ContentStoreService.getChildren=function(url,config){void 0===config&&(config=classes.crafterConf.getConfig());var requestURL=utils.composeUrl(config,config.endpoints.GET_CHILDREN);return classes.SDKService.httpGet(requestURL,{url:url,crafterSite:config.site})},ContentStoreService.getTree=function(url,depth,config){void 0===depth&&(depth=1),void 0===config&&(config=classes.crafterConf.getConfig());var requestURL=utils.composeUrl(config,config.endpoints.GET_TREE);return classes.SDKService.httpGet(requestURL,{url:url,depth:depth,crafterSite:config.site})},ContentStoreService}(classes.SDKService),NavigationService=function(_super){function NavigationService(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(NavigationService,_super),NavigationService.getNavTree=function(url,depth,currentPageUrl,config){void 0===depth&&(depth=1),void 0===currentPageUrl&&(currentPageUrl=""),void 0===config&&(config=classes.crafterConf.getConfig());var requestURL=utils.composeUrl(config,config.endpoints.GET_NAV_TREE);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,url:url,depth:depth,currentPageUrl:currentPageUrl})},NavigationService.getNavBreadcrumb=function(url,root,config){void 0===root&&(root=""),void 0===config&&(config=classes.crafterConf.getConfig());var requestURL=utils.composeUrl(config,config.endpoints.GET_BREADCRUMB);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,url:url,root:root})},NavigationService}(classes.SDKService),UrlTransformationService=function(_super){function UrlTransformationService(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(UrlTransformationService,_super),UrlTransformationService.transform=function(transformerName,url,config){void 0===config&&(config=classes.crafterConf.getConfig());var requestURL=utils.composeUrl(config,config.endpoints.TRANSFORM_URL);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,transformerName:transformerName,url:url})},UrlTransformationService}(classes.SDKService);exports.ContentStoreService=ContentStoreService,exports.NavigationService=NavigationService,exports.UrlTransformationService=UrlTransformationService,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"},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})}); |
@@ -1,3 +0,4 @@ | ||
export * from './src/content-store-service'; | ||
export * from './src/navigation-service'; | ||
export * from './src/url-transformation-service'; | ||
export * from './src/ContentStoreService'; | ||
export * from './src/NavigationService'; | ||
export * from './src/UrlTransformationService'; | ||
export * from './src/utils'; |
@@ -17,5 +17,6 @@ /* | ||
*/ | ||
export * from './src/content-store-service'; | ||
export * from './src/navigation-service'; | ||
export * from './src/url-transformation-service'; | ||
export * from './src/ContentStoreService'; | ||
export * from './src/NavigationService'; | ||
export * from './src/UrlTransformationService'; | ||
export * from './src/utils'; | ||
//# sourceMappingURL=content.js.map |
@@ -17,5 +17,6 @@ /* | ||
*/ | ||
export * from './src/content-store-service'; | ||
export * from './src/navigation-service'; | ||
export * from './src/url-transformation-service'; | ||
export * from './src/ContentStoreService'; | ||
export * from './src/NavigationService'; | ||
export * from './src/UrlTransformationService'; | ||
export * from './src/utils'; | ||
//# sourceMappingURL=content.js.map |
/* | ||
* Copyright (C) 2007-2018 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
@@ -21,121 +20,201 @@ import { crafterConf, SDKService } from '@craftercms/classes'; | ||
/* | ||
* Copyright (C) 2007-2019 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/** | ||
* Content Store Service API | ||
*/ | ||
class ContentStoreService extends SDKService { | ||
static getItem(url, config = crafterConf.getConfig()) { | ||
const requestURL = composeUrl(config, config.endpoints.GET_ITEM_URL); | ||
return SDKService.httpGet(requestURL, { url, crafterSite: config.site }); | ||
function getItem(path, config) { | ||
config = crafterConf.mix(config); | ||
const requestURL = composeUrl(config, config.endpoints.GET_ITEM_URL); | ||
return SDKService.httpGet(requestURL, { url: path, crafterSite: config.site }); | ||
} | ||
function getDescriptor(path, config) { | ||
config = crafterConf.mix(config); | ||
const requestURL = composeUrl(config, config.endpoints.GET_DESCRIPTOR); | ||
return SDKService.httpGet(requestURL, { url: path, crafterSite: config.site }); | ||
} | ||
function getChildren(path, config) { | ||
config = crafterConf.mix(config); | ||
const requestURL = composeUrl(config, config.endpoints.GET_CHILDREN); | ||
return SDKService.httpGet(requestURL, { url: path, crafterSite: config.site }); | ||
} | ||
function getTree(path, depth = 1, config) { | ||
if (typeof depth === 'object') { | ||
config = depth; | ||
depth = 1; | ||
} | ||
static getDescriptor(url, config = crafterConf.getConfig()) { | ||
const requestURL = composeUrl(config, config.endpoints.GET_DESCRIPTOR); | ||
return SDKService.httpGet(requestURL, { url, crafterSite: config.site }); | ||
} | ||
static getChildren(url, config = crafterConf.getConfig()) { | ||
const requestURL = composeUrl(config, config.endpoints.GET_CHILDREN); | ||
return SDKService.httpGet(requestURL, { url, crafterSite: config.site }); | ||
} | ||
static getTree(url, depth = 1, config = crafterConf.getConfig()) { | ||
const requestURL = composeUrl(config, config.endpoints.GET_TREE); | ||
return SDKService.httpGet(requestURL, { url, depth, crafterSite: config.site }); | ||
} | ||
config = crafterConf.mix(config); | ||
const requestURL = composeUrl(config, config.endpoints.GET_TREE); | ||
return SDKService.httpGet(requestURL, { url: path, depth, crafterSite: config.site }); | ||
} | ||
const ContentStoreService = { | ||
getItem, | ||
getDescriptor, | ||
getChildren, | ||
getTree | ||
}; | ||
/* | ||
* Copyright (C) 2007-2019 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
function getNavTree(path, depth = 1, currentPageUrl = '', config) { | ||
config = crafterConf.mix(config); | ||
const requestURL = composeUrl(config, config.endpoints.GET_NAV_TREE); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, | ||
currentPageUrl, | ||
url: path, | ||
depth | ||
}); | ||
} | ||
function getNavBreadcrumb(path, root = '', config) { | ||
config = crafterConf.mix(config); | ||
const requestURL = composeUrl(config, config.endpoints.GET_BREADCRUMB); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, | ||
url: path, | ||
root | ||
}); | ||
} | ||
/** | ||
* Navigation Service API | ||
*/ | ||
class NavigationService extends SDKService { | ||
static getNavTree(url, depth = 1, currentPageUrl = '', config = crafterConf.getConfig()) { | ||
const requestURL = composeUrl(config, config.endpoints.GET_NAV_TREE); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, url, depth, currentPageUrl | ||
}); | ||
} | ||
static getNavBreadcrumb(url, root = '', config = crafterConf.getConfig()) { | ||
const requestURL = composeUrl(config, config.endpoints.GET_BREADCRUMB); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, url, root | ||
}); | ||
} | ||
} | ||
const NavigationService = { | ||
getNavTree, | ||
getNavBreadcrumb | ||
}; | ||
/* | ||
* Copyright (C) 2007-2019 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
function urlTransform(transformerName, url, config) { | ||
config = crafterConf.mix(config); | ||
const requestURL = composeUrl(config, config.endpoints.TRANSFORM_URL); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, | ||
transformerName, | ||
url | ||
}); | ||
} | ||
/** | ||
* URL Transformation Service API | ||
*/ | ||
class UrlTransformationService extends SDKService { | ||
static transform(transformerName, url, config = crafterConf.getConfig()) { | ||
const requestURL = composeUrl(config, config.endpoints.TRANSFORM_URL); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, | ||
transformerName, | ||
url | ||
}); | ||
} | ||
} | ||
const UrlTransformationService = { | ||
transform: urlTransform, | ||
urlTransform | ||
}; | ||
/* | ||
* Copyright (C) 2007-2019 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
const 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' | ||
}; | ||
const systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
function parseDescriptor(data) { | ||
if (data == null) { | ||
return null; | ||
} | ||
else if (Array.isArray(data)) { | ||
return data.map((item) => parseDescriptor(item)); | ||
} | ||
else if (data.descriptorDom) { | ||
return parseDescriptor(data.descriptorDom); | ||
} | ||
else if (data.page) { | ||
return parseDescriptor(data.page); | ||
} | ||
else if (data.component) { | ||
return parseDescriptor(data.component); | ||
} | ||
let parsed = { | ||
craftercms: { | ||
id: null, | ||
path: null, | ||
label: null, | ||
contentTypeId: null, | ||
dateCreated: null, | ||
dateModified: null | ||
} | ||
}; | ||
Object.entries(data).forEach(([prop, value]) => { | ||
var _a, _b, _c, _d; | ||
if (systemProps.includes(prop)) { | ||
parsed.craftercms[_a = systemPropMap[prop], (_a !== null && _a !== void 0 ? _a : 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 }) => { | ||
const newComponent = Object.assign(Object.assign({ label: value }, component), { path: key.startsWith('/') ? key : null }); | ||
return parseDescriptor(newComponent); | ||
}); | ||
} | ||
} | ||
else { | ||
parsed[prop] = (value !== null && value !== void 0 ? value : null); | ||
} | ||
}); | ||
return parsed; | ||
} | ||
export { ContentStoreService, NavigationService, UrlTransformationService }; | ||
export { ContentStoreService, NavigationService, UrlTransformationService, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, urlTransform }; | ||
//# sourceMappingURL=content.js.map |
/* | ||
* Copyright (C) 2007-2018 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import { __extends } from 'tslib'; | ||
import { crafterConf, SDKService } from '@craftercms/classes'; | ||
@@ -22,147 +20,233 @@ import { composeUrl } from '@craftercms/utils'; | ||
/* | ||
* Copyright (C) 2007-2019 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/** | ||
* Content Store Service API | ||
*/ | ||
var ContentStoreService = /** @class */ (function (_super) { | ||
__extends(ContentStoreService, _super); | ||
function ContentStoreService() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
function getItem(path, config) { | ||
config = crafterConf.mix(config); | ||
var requestURL = composeUrl(config, config.endpoints.GET_ITEM_URL); | ||
return SDKService.httpGet(requestURL, { url: path, crafterSite: config.site }); | ||
} | ||
function getDescriptor(path, config) { | ||
config = crafterConf.mix(config); | ||
var requestURL = composeUrl(config, config.endpoints.GET_DESCRIPTOR); | ||
return SDKService.httpGet(requestURL, { url: path, crafterSite: config.site }); | ||
} | ||
function getChildren(path, config) { | ||
config = crafterConf.mix(config); | ||
var requestURL = composeUrl(config, config.endpoints.GET_CHILDREN); | ||
return SDKService.httpGet(requestURL, { url: path, crafterSite: config.site }); | ||
} | ||
function getTree(path, depth, config) { | ||
if (depth === void 0) { depth = 1; } | ||
if (typeof depth === 'object') { | ||
config = depth; | ||
depth = 1; | ||
} | ||
ContentStoreService.getItem = function (url, config) { | ||
if (config === void 0) { config = crafterConf.getConfig(); } | ||
var requestURL = composeUrl(config, config.endpoints.GET_ITEM_URL); | ||
return SDKService.httpGet(requestURL, { url: url, crafterSite: config.site }); | ||
}; | ||
ContentStoreService.getDescriptor = function (url, config) { | ||
if (config === void 0) { config = crafterConf.getConfig(); } | ||
var requestURL = composeUrl(config, config.endpoints.GET_DESCRIPTOR); | ||
return SDKService.httpGet(requestURL, { url: url, crafterSite: config.site }); | ||
}; | ||
ContentStoreService.getChildren = function (url, config) { | ||
if (config === void 0) { config = crafterConf.getConfig(); } | ||
var requestURL = composeUrl(config, config.endpoints.GET_CHILDREN); | ||
return SDKService.httpGet(requestURL, { url: url, crafterSite: config.site }); | ||
}; | ||
ContentStoreService.getTree = function (url, depth, config) { | ||
if (depth === void 0) { depth = 1; } | ||
if (config === void 0) { config = crafterConf.getConfig(); } | ||
var requestURL = composeUrl(config, config.endpoints.GET_TREE); | ||
return SDKService.httpGet(requestURL, { url: url, depth: depth, crafterSite: config.site }); | ||
}; | ||
return ContentStoreService; | ||
}(SDKService)); | ||
config = crafterConf.mix(config); | ||
var requestURL = composeUrl(config, config.endpoints.GET_TREE); | ||
return SDKService.httpGet(requestURL, { url: path, depth: depth, crafterSite: config.site }); | ||
} | ||
var ContentStoreService = { | ||
getItem: getItem, | ||
getDescriptor: getDescriptor, | ||
getChildren: getChildren, | ||
getTree: getTree | ||
}; | ||
/* | ||
* Copyright (C) 2007-2019 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
function getNavTree(path, depth, currentPageUrl, config) { | ||
if (depth === void 0) { depth = 1; } | ||
if (currentPageUrl === void 0) { currentPageUrl = ''; } | ||
config = crafterConf.mix(config); | ||
var requestURL = composeUrl(config, config.endpoints.GET_NAV_TREE); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, | ||
currentPageUrl: currentPageUrl, | ||
url: path, | ||
depth: depth | ||
}); | ||
} | ||
function getNavBreadcrumb(path, root, config) { | ||
if (root === void 0) { root = ''; } | ||
config = crafterConf.mix(config); | ||
var requestURL = composeUrl(config, config.endpoints.GET_BREADCRUMB); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, | ||
url: path, | ||
root: root | ||
}); | ||
} | ||
/** | ||
* Navigation Service API | ||
*/ | ||
var NavigationService = /** @class */ (function (_super) { | ||
__extends(NavigationService, _super); | ||
function NavigationService() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
NavigationService.getNavTree = function (url, depth, currentPageUrl, config) { | ||
if (depth === void 0) { depth = 1; } | ||
if (currentPageUrl === void 0) { currentPageUrl = ''; } | ||
if (config === void 0) { config = crafterConf.getConfig(); } | ||
var requestURL = composeUrl(config, config.endpoints.GET_NAV_TREE); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, url: url, depth: depth, currentPageUrl: currentPageUrl | ||
}); | ||
}; | ||
NavigationService.getNavBreadcrumb = function (url, root, config) { | ||
if (root === void 0) { root = ''; } | ||
if (config === void 0) { config = crafterConf.getConfig(); } | ||
var requestURL = composeUrl(config, config.endpoints.GET_BREADCRUMB); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, url: url, root: root | ||
}); | ||
}; | ||
return NavigationService; | ||
}(SDKService)); | ||
var NavigationService = { | ||
getNavTree: getNavTree, | ||
getNavBreadcrumb: getNavBreadcrumb | ||
}; | ||
/* | ||
* Copyright (C) 2007-2019 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
function urlTransform(transformerName, url, config) { | ||
config = crafterConf.mix(config); | ||
var requestURL = composeUrl(config, config.endpoints.TRANSFORM_URL); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, | ||
transformerName: transformerName, | ||
url: url | ||
}); | ||
} | ||
/** | ||
* URL Transformation Service API | ||
*/ | ||
var UrlTransformationService = /** @class */ (function (_super) { | ||
__extends(UrlTransformationService, _super); | ||
function UrlTransformationService() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
UrlTransformationService.transform = function (transformerName, url, config) { | ||
if (config === void 0) { config = crafterConf.getConfig(); } | ||
var requestURL = composeUrl(config, config.endpoints.TRANSFORM_URL); | ||
return SDKService.httpGet(requestURL, { | ||
crafterSite: config.site, | ||
transformerName: transformerName, | ||
url: url | ||
}); | ||
var UrlTransformationService = { | ||
transform: urlTransform, | ||
urlTransform: urlTransform | ||
}; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return UrlTransformationService; | ||
}(SDKService)); | ||
return __assign.apply(this, arguments); | ||
}; | ||
/* | ||
* Copyright (C) 2007-2019 Crafter Software Corporation. All rights reserved. | ||
* Copyright (C) 2007-2020 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
var 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' | ||
}; | ||
var systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
function parseDescriptor(data) { | ||
if (data == null) { | ||
return null; | ||
} | ||
else if (Array.isArray(data)) { | ||
return data.map(function (item) { return parseDescriptor(item); }); | ||
} | ||
else if (data.descriptorDom) { | ||
return parseDescriptor(data.descriptorDom); | ||
} | ||
else if (data.page) { | ||
return parseDescriptor(data.page); | ||
} | ||
else if (data.component) { | ||
return parseDescriptor(data.component); | ||
} | ||
var parsed = { | ||
craftercms: { | ||
id: null, | ||
path: null, | ||
label: null, | ||
contentTypeId: null, | ||
dateCreated: null, | ||
dateModified: null | ||
} | ||
}; | ||
Object.entries(data).forEach(function (_a) { | ||
var prop = _a[0], value = _a[1]; | ||
var _b, _c, _d, _e; | ||
if (systemProps.includes(prop)) { | ||
parsed.craftercms[_b = systemPropMap[prop], (_b !== null && _b !== void 0 ? _b : 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; | ||
var newComponent = __assign(__assign({ label: value }, component), { path: key.startsWith('/') ? key : null }); | ||
return parseDescriptor(newComponent); | ||
}); | ||
} | ||
} | ||
else { | ||
parsed[prop] = (value !== null && value !== void 0 ? value : null); | ||
} | ||
}); | ||
return parsed; | ||
} | ||
export { ContentStoreService, NavigationService, UrlTransformationService }; | ||
export { ContentStoreService, NavigationService, UrlTransformationService, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, urlTransform }; | ||
//# sourceMappingURL=content.js.map |
{ | ||
"name": "@craftercms/content", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Crafter CMS services for content and navigation retrieval", | ||
@@ -29,7 +29,19 @@ "main": "./bundles/content.umd.js", | ||
"dependencies": { | ||
"@craftercms/classes": "1.1.2", | ||
"@craftercms/models": "1.1.2", | ||
"@craftercms/utils": "1.1.2", | ||
"rxjs": "^6.2.0" | ||
"@craftercms/classes": "1.2.0", | ||
"@craftercms/models": "1.2.0", | ||
"@craftercms/utils": "1.2.0", | ||
"rxjs": "^6.5.4", | ||
"tslib": "^1.10.0" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^11.0.2", | ||
"@rollup/plugin-node-resolve": "^7.1.1", | ||
"@types/mocha": "^7.0.1", | ||
"mocha": "^7.0.1", | ||
"rollup": "^1.31.1", | ||
"rollup-plugin-sourcemaps": "^0.5.0", | ||
"typescript": "^3.7.5", | ||
"uglify-es": "^3.3.9", | ||
"xhr-mock": "^2.5.1" | ||
} | ||
} |
283
README.md
# @craftercms/content | ||
This package contains services for retrieving content and navigation using APIs offered by craftercms. | ||
This package contains services for retrieving content and navigation using APIs offered by Crafter CMS. | ||
@@ -11,14 +11,66 @@ ## Usage | ||
- Import and use the service(s) you need | ||
- You may pre-configure content services to a certain configuration and then you may omit the config param on subsequent calls | ||
## Services - Content Store | ||
--- | ||
```typescript | ||
import { Item } from '@craftercms/models'; | ||
import { getItem } from '@craftercms/content'; | ||
import { crafterConf } from '@craftercms/classes'; | ||
// Configure crafter services "globally". Your config will be cached. | ||
// All content services use the specified configuration on subsequent calls. | ||
crafterConf.configure({ | ||
baseUrl: 'http://authoring.company.com', | ||
site: 'editorial' | ||
}); | ||
// Second param "config" will use "http://authoring.company.com" as | ||
// crafter base url and "editorial" as the site to query | ||
getItem('/site/website/index.xml').subscribe((item: Item) => { | ||
console.log(item); | ||
}); | ||
``` | ||
## parseDescriptor | ||
Parse a [Descriptor](../models/src/descriptor.ts), [Item](../models/src/item.ts) or a GraphQL response into a [Content Instance](../models/src/ContentInstance.ts). It could also be a collection of any of these types. | ||
`parseDescriptor(response: Descriptor | Item | GraphQLResponse | Descriptor[] | Item[] | GraphQLResponse)` | ||
| Parameters | | | ||
| ------------- |:--------------:| | ||
| response | The response of a getItem, getDescriptor or GraphQL fetch call | | ||
### Returns | ||
[ContentInstance](../models/src/ContentInstance.ts) | ||
### Examples | ||
- If you want a cleaner/parsed response, you may use `parseDescriptor` util to parse the response for you. You may use it to parse getItem, getDescriptor or GraphQL responses. | ||
```typescript | ||
import { map } from 'rxjs/operators'; | ||
import { ContentInstance } from '@craftercms/models'; | ||
import { getChildren, getItem, parseDescriptor } from '@craftercms/content'; | ||
getItem('/site/website/index.xml', { site: 'editorial' }).pipe( | ||
map(parseDescriptor) | ||
).subscribe((content: ContentInstance) => { | ||
console.log(content); | ||
}); | ||
getChildren('/site/website', { site: 'editorial' }).pipe( | ||
map(parseDescriptor) | ||
).subscribe((content: ContentInstance[]) => { | ||
console.log(content); | ||
}); | ||
``` | ||
## Get Item | ||
Get an Item from the content store. | ||
`getItem(url: string, config: CrafterConfig)` | ||
`getItem(path: string, config?: CrafterConfig)` | ||
| Parameters | | | ||
| ------------- |:--------------:| | ||
| url | The item’s url in the content store | | ||
| path | The item’s path in the content store | | ||
| config | Crafter configuration. Optional. Default value in [here](../models/README.md#CrafterConfig). | | ||
@@ -34,46 +86,35 @@ | ||
```ts | ||
import { crafterConf } from '@craftercms/classes'; | ||
import { ContentStoreService } from '@craftercms/content'; | ||
//First, set the Crafter configuration to _cache_ your config. | ||
//All subsequent calls to `getConfig` will use that configuration. | ||
crafterConf.configure({ | ||
baseUrl: 'http://localhost:8090', //by default - http://localhost:8080 | ||
site: 'editorial' | ||
}) | ||
ContentStoreService.getItem('/site/website/index.xml') | ||
.subscribe(item => { | ||
// ... | ||
}); | ||
```typescript | ||
import { Item } from '@craftercms/models'; | ||
import { getItem } from '@craftercms/content'; | ||
getItem('/site/website/index.xml', { site: 'editorial' }).subscribe((item: Item) => { | ||
console.log(item); | ||
}); | ||
``` | ||
You may alternatively use a different config by supplying the config object at the service call invoking time | ||
- If you want a cleaner/parsed response, you may use `parseDescriptor` util to parse the response for you. | ||
```ts | ||
import { ContentStoreService } from '@craftercms/content'; | ||
ContentStoreService | ||
.getItem('/site/website/index.xml', { | ||
baseUrl: 'http://localhost:8080', | ||
site: 'editorial' | ||
}) | ||
.subscribe(item => { | ||
// ... | ||
}); | ||
```typescript | ||
import { map } from 'rxjs/operators'; | ||
import { ContentInstance } from '@craftercms/models'; | ||
import { getItem, parseDescriptor } from '@craftercms/content'; | ||
getItem('/site/website/index.xml', { site: 'editorial' }).pipe( | ||
map(parseDescriptor) | ||
).subscribe((content: ContentInstance) => { | ||
console.log(content); | ||
}); | ||
``` | ||
## Get Descriptor | ||
Get the descriptor data of an Item in the content store. | ||
`getDescriptor(url: string, config: CrafterConfig)` | ||
`getDescriptor(path: string, config?: CrafterConfig)` | ||
| Parameters | | | ||
| ------------- |:--------------:| | ||
| url | The item’s url in the content store | | ||
| path | The item’s path in the content store | | ||
| config | Crafter configuration. Optional. Default value in [here](../models/README.md#CrafterConfig). | | ||
### Returns | ||
@@ -87,25 +128,32 @@ | ||
```ts | ||
import { ContentStoreService } from '@craftercms/content'; | ||
```typescript | ||
import { map } from 'rxjs/operators'; | ||
import { getDescriptor, parseDescriptor } from '@craftercms/content'; | ||
import { Descriptor, ContentInstance } from '@craftercms/models'; | ||
// Assuming that you already set the configuration (as explained above) | ||
// Example 1: Supplying config inline, Descriptor response... | ||
getDescriptor('/site/website/index.xml', { site: 'editorial' }).subscribe((descriptor: Descriptor) => { | ||
console.log(descriptor); | ||
}); | ||
ContentStoreService.getDescriptor('/site/website/index.xml') | ||
.subscribe(descriptor => { | ||
// ... | ||
}); | ||
// Example 2: | ||
// - Omit config (must have configured earlier @see Usage section above) | ||
// - Parse the response | ||
getDescriptor('/site/website/index.xml').pipe( | ||
map(parseDescriptor) // Optional. Use for a cleaner parsed response. | ||
).subscribe((content: ContentInstance) => { | ||
console.log(content); | ||
}); | ||
``` | ||
## Get Children | ||
Get the list of Items directly under a folder in the content store. | ||
`getChildren(url: string, config: CrafterConfig)` | ||
`getChildren(path: string, config?: CrafterConfig)` | ||
| Parameters | | | ||
| ------------- |:--------------:| | ||
| url | The folder’s url | | ||
| path | The folder’s path | | ||
| config | Crafter configuration. Optional. Default value in [here](../models/README.md#CrafterConfig). | | ||
### Returns | ||
@@ -119,26 +167,27 @@ | ||
```ts | ||
import { ContentStoreService } from '@craftercms/content'; | ||
```typescript | ||
import { getChildren } from '@craftercms/content'; | ||
// Assuming that you already set the configuration (as explained above) | ||
ContentStoreService.getChildren('/site/website') | ||
.subscribe(children => { | ||
// ... | ||
}); | ||
// Example 1: Supplying config inline | ||
getChildren('/site/website', { site: 'editorial' }).subscribe((children) => { | ||
console.log(children); | ||
}); | ||
// Example 2: Omits the config param (must have been previously configured, see Usage section above) | ||
getChildren('/site/website').subscribe((children) => { | ||
console.log(children); | ||
}); | ||
``` | ||
## Get Tree | ||
Get the complete Item hierarchy under the specified folder in the content store. | ||
`getTree(url: string, depth: int, config: CrafterConfig)` | ||
`getTree(path: string, depth: number, config: CrafterConfig)` | ||
| Parameters | | | ||
| ------------- |:--------------:| | ||
| url | The folder’s url | | ||
| path | The folder’s path | | ||
| depth | Amount of levels to include. Optional. Default is `1` | | ||
| config | Crafter configuration. Optional. Default value in [here](../models/README.md#CrafterConfig). | | ||
### Returns | ||
@@ -152,29 +201,29 @@ | ||
```ts | ||
import { ContentStoreService } from '@craftercms/content'; | ||
```typescript | ||
import { getTree } from '@craftercms/content'; | ||
// Assuming that you already set the configuration (as explained above) | ||
// This call will get 3 levels of the tree under the specified folder | ||
//This call will get 3 levels of the tree under the specified folder | ||
ContentStoreService.getTree('/site/website', 3) | ||
.subscribe(tree => { | ||
// ... | ||
}); | ||
// Example 1: Config supplied inline | ||
getTree('/site/website', 3, { site: 'editorial' }).subscribe((tree) => { | ||
console.log(tree); | ||
}); | ||
// Example 2: Services pre-configured (see "Usage" section above), config param omitted. | ||
getTree('/site/website', 3).subscribe((tree) => { | ||
console.log(tree); | ||
}); | ||
``` | ||
## Services - Navigation | ||
--- | ||
## Get Navigation Tree | ||
Returns the navigation tree with the specified depth for the specified store URL. | ||
`getNavTree(url: string, depth: string, currentPageUrl: string, config: CrafterConfig)` | ||
`getNavTree(path: string, depth: number, currentPageUrl: string, config: CrafterConfig)` | ||
| Parameters | | | ||
| -------------- |:--------------:| | ||
| url | The folder’s url | | ||
| path | The folder’s path | | ||
| depth | Amount of levels to include. Optional. Default is `1` | | ||
| currentPageUrl | The URL of the current page. Optional. Default is `''` | | ||
| config | Crafter configuration. Optional. Default value in [here](../models/README.md#CrafterConfig). | | ||
| config | Crafter configuration. Optional. Default value in [here](../models/README.md#CrafterConfig). | | ||
@@ -189,23 +238,24 @@ ### Returns | ||
```ts | ||
import { NavigationService } from '@craftercms/content'; | ||
```typescript | ||
import { getTree } from '@craftercms/content'; | ||
// Assuming that you already set the configuration (as explained above) | ||
// Example 1: Config supplied inline | ||
getTree('/site/website', 3, { site: 'editorial' }).subscribe((tree) => { | ||
console.log(tree); | ||
}); | ||
//This call will get 3 levels of the tree under the specified folder | ||
NavigationService.getTree('/site/website', 3) | ||
.subscribe(tree => { | ||
// ... | ||
}); | ||
// Example 2: Services pre-configured (see "Usage" section above), config param omitted. | ||
getTree('/site/website', 3).subscribe((tree) => { | ||
console.log(tree); | ||
}); | ||
``` | ||
## Get Navigation Breadcrumb | ||
Returns the navigation items that form the breadcrumb for the specified store URL. | ||
`getNavBreadcrumb(url: string, root: string, config: CrafterConfig)` | ||
`getNavBreadcrumb(path: string, root: string, config: CrafterConfig)` | ||
| Parameters | | | ||
| -------------- |:--------------:| | ||
| url | The folder’s url | | ||
| path | The folder’s path | | ||
| root | the root URL, basically the starting point of the breadcrumb. Optional. Default is `''` | | ||
@@ -222,21 +272,20 @@ | config | Crafter configuration. Optional. Default value in [here](../models/README.md#CrafterConfig). | | ||
```ts | ||
import { NavigationService } from '@craftercms/content'; | ||
```typescript | ||
import { getNavBreadcrumb } from '@craftercms/content'; | ||
// Assuming that you already set the configuration (as explained above) | ||
// Example 1: Config supplied inline | ||
getNavBreadcrumb('/site/website').subscribe((navBreadcrumb) => { | ||
console.log(navBreadcrumb); | ||
}); | ||
NavigationService.getNavBreadcrumb('/site/website') | ||
.subscribe(navBreadcrumb => { | ||
// ... | ||
}); | ||
// Example 2: Services pre-configured (see "Usage" section above), config param omitted. | ||
getNavBreadcrumb('/site/website').subscribe((navBreadcrumb) => { | ||
console.log(navBreadcrumb); | ||
}); | ||
``` | ||
## Services - URL Transformation | ||
--- | ||
## Transform | ||
Transforms a URL, based on the current site’s configuration. | ||
- `transform(transformerName: string, url: string, config: CrafterConfig)` | ||
- `transform(transformerName: string, path: string, config: CrafterConfig)` | ||
@@ -246,3 +295,3 @@ | Parameters | | | ||
| transformerName | Name of the transformer to apply | | ||
| url | URL that will be transformed | | ||
| path | URL that will be transformed | | ||
| config | Crafter configuration. Optional. Default value in [here](../models/README.md#CrafterConfig). | | ||
@@ -256,26 +305,34 @@ | ||
- Transform a store url into a render url | ||
- Transform a store path into a render path | ||
```ts | ||
import { UrlTransformationService } from '@craftercms/content'; | ||
```typescript | ||
import { urlTransform } from '@craftercms/content'; | ||
// Assuming that you already set the configuration (as explained above) | ||
// Example 1: Config supplied inline | ||
urlTransform('storeUrlToRenderUrl', '/site/website/style/index.xml', { site: 'editorial' }).subscribe((webUrl) => { | ||
console.log(webUrl); // "/style" | ||
}); | ||
UrlTransformationService.transform("storeUrlToRenderUrl", "/site/website/style/index.xml") | ||
.subscribe((url) => { | ||
// url = '/style' | ||
}) | ||
// Example 2: Services pre-configured (see "Usage" section above), config param omitted. | ||
urlTransform('storeUrlToRenderUrl', '/site/website/style/index.xml').subscribe((webUrl) => { | ||
console.log(webUrl); // "/style" | ||
}); | ||
``` | ||
- Transform a render url into a store url | ||
- Transform a render path into a store path | ||
```js | ||
import { UrlTransformationService } from '@craftercms/content'; | ||
```typescript | ||
import { transform } from '@craftercms/content'; | ||
// Assuming that you already set the configuration (as explained above) | ||
// Example 1: Config supplied inline | ||
transform('renderUrlToStoreUrl', '/technology', { site: 'editorial' }).subscribe((path) => { | ||
console.log(path); // "/site/website/technology/index.xml" | ||
}); | ||
UrlTransformationService.transform("renderUrlToStoreUrl", "/technology") | ||
.subscribe((url) => { | ||
// url = '/site/website/technology/index.xml' | ||
}) | ||
// Example 2: Services pre-configured (see "Usage" section above), config param omitted. | ||
transform('renderUrlToStoreUrl', '/technology').subscribe((path) => { | ||
console.log(path); // "/site/website/technology/index.xml" | ||
}) | ||
``` |
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
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
267483
44
3
1795
330
5
9
2
+ Addedtslib@^1.10.0
+ Added@craftercms/classes@1.2.0(transitive)
+ Added@craftercms/models@1.2.0(transitive)
+ Added@craftercms/utils@1.2.0(transitive)
- Removed@craftercms/classes@1.1.2(transitive)
- Removed@craftercms/models@1.1.2(transitive)
- Removed@craftercms/utils@1.1.2(transitive)
Updated@craftercms/classes@1.2.0
Updated@craftercms/models@1.2.0
Updated@craftercms/utils@1.2.0
Updatedrxjs@^6.5.4