Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@content-app/core

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@content-app/core - npm Package Compare versions

Comparing version 0.1.6 to 0.2.0

165

dist/core.cjs.development.js

@@ -350,2 +350,14 @@ 'use strict';

}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _unsupportedIterableToArray(o, minLen) {

@@ -898,5 +910,6 @@ if (!o) return;

var _excluded = ["title", "modules"];
var fetchCorePageBySlug = /*#__PURE__*/function () {
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
var pages, _pages$items$0$fields, _pages$items$0$fields2, articles, title, pageTitle, pageFields, page, articleData, cachedModules, _iterator, _step, articleItem, _articleItem$fields, _title, modules, moduleData, _loop, _iterator2, _step2, _ret;
var pages, _pages$items$0$fields, _pages$items$0$fields2, articles, title, pageTitle, page, articleData, cachedModules, _iterator, _step, articleItem, _articleItem$fields, _title, modules, articleFields, moduleData, _loop, _iterator2, _step2, _ret;
return _regeneratorRuntime().wrap(function _callee$(_context2) {

@@ -926,18 +939,17 @@ while (1) switch (_context2.prev = _context2.next) {

_pages$items$0$fields = pages.items[0].fields, _pages$items$0$fields2 = _pages$items$0$fields.articles, articles = _pages$items$0$fields2 === void 0 ? [] : _pages$items$0$fields2, title = _pages$items$0$fields.title, pageTitle = _pages$items$0$fields.pageTitle;
pageFields = pages.items[0].fields;
page = _extends({}, pageFields, {
page = {
title: title,
pageTitle: pageTitle,
slug: config.slug
});
};
articleData = [];
cachedModules = {};
_iterator = _createForOfIteratorHelperLoose(articles);
case 13:
case 12:
if ((_step = _iterator()).done) {
_context2.next = 29;
_context2.next = 28;
break;
}
articleItem = _step.value;
_articleItem$fields = articleItem.fields, _title = _articleItem$fields.title, modules = _articleItem$fields.modules;
_articleItem$fields = articleItem.fields, _title = _articleItem$fields.title, modules = _articleItem$fields.modules, articleFields = _objectWithoutPropertiesLoose(_articleItem$fields, _excluded);
moduleData = [];

@@ -985,30 +997,30 @@ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {

_iterator2 = _createForOfIteratorHelperLoose(modules);
case 19:
case 18:
if ((_step2 = _iterator2()).done) {
_context2.next = 26;
_context2.next = 25;
break;
}
return _context2.delegateYield(_loop(), "t0", 21);
case 21:
return _context2.delegateYield(_loop(), "t0", 20);
case 20:
_ret = _context2.t0;
if (!(_ret === "continue")) {
_context2.next = 24;
_context2.next = 23;
break;
}
return _context2.abrupt("continue", 24);
case 24:
_context2.next = 19;
return _context2.abrupt("continue", 23);
case 23:
_context2.next = 18;
break;
case 26:
articleData.push({
case 25:
articleData.push(_extends({}, articleFields, {
title: _title,
modules: moduleData
});
case 27:
_context2.next = 13;
}));
case 26:
_context2.next = 12;
break;
case 29:
case 28:
page.articles = articleData;
return _context2.abrupt("return", page);
case 31:
case 30:
case "end":

@@ -1024,17 +1036,14 @@ return _context2.stop();

var fetchPageByModule = /*#__PURE__*/function () {
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, pageModule) {
var fetchPageBySlug = /*#__PURE__*/function () {
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
var customFetchResult, _iterator, _step, pageModule;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!pageModule.shouldLoadContent({
client: config.client,
slug: config.slug,
moduleMapping: config.moduleMapping
})) {
_context.next = 4;
if (!config.customFetch) {
_context.next = 6;
break;
}
_context.next = 3;
return pageModule.loadContent({
return config.customFetch({
client: config.client,

@@ -1045,68 +1054,7 @@ slug: config.slug,

case 3:
return _context.abrupt("return", _context.sent);
case 4:
case "end":
return _context.stop();
}
}, _callee);
}));
return function fetchPageByModule(_x, _x2) {
return _ref.apply(this, arguments);
};
}();
var fetchCustomPage = /*#__PURE__*/function () {
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
var customFetchResult;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (config.customFetch) {
_context.next = 2;
break;
}
return _context.abrupt("return");
case 2:
_context.next = 4;
return config.customFetch({
client: config.client,
slug: config.slug,
moduleMapping: config.moduleMapping
});
case 4:
customFetchResult = _context.sent;
if (!(customFetchResult !== false)) {
_context.next = 7;
break;
}
return _context.abrupt("return", customFetchResult);
case 7:
case "end":
return _context.stop();
}
}, _callee);
}));
return function fetchCustomPage(_x) {
return _ref.apply(this, arguments);
};
}();
var fetchPageBySlug = /*#__PURE__*/function () {
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
var customFetchResult, _iterator, _step, pageModule, pageModuleResult;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!config.customFetch) {
_context.next = 6;
break;
}
_context.next = 3;
return fetchCustomPage(config);
case 3:
customFetchResult = _context.sent;
if (!customFetchResult) {
_context.next = 6;
break;
}
return _context.abrupt("return", customFetchResult);

@@ -1117,24 +1065,31 @@ case 6:

if ((_step = _iterator()).done) {
_context.next = 16;
_context.next = 15;
break;
}
pageModule = _step.value;
_context.next = 11;
return fetchPageByModule(config, pageModule);
case 11:
pageModuleResult = _context.sent;
if (!pageModuleResult) {
_context.next = 14;
if (!pageModule.shouldLoadContent({
client: config.client,
slug: config.slug,
moduleMapping: config.moduleMapping
})) {
_context.next = 13;
break;
}
return _context.abrupt("return", pageModuleResult);
case 14:
_context.next = 12;
return pageModule.loadContent({
client: config.client,
slug: config.slug,
moduleMapping: config.moduleMapping
});
case 12:
return _context.abrupt("return", _context.sent);
case 13:
_context.next = 7;
break;
case 16:
_context.next = 18;
case 15:
_context.next = 17;
return fetchCorePageBySlug(config);
case 17:
return _context.abrupt("return", _context.sent);
case 18:
return _context.abrupt("return", _context.sent);
case 19:
case "end":

@@ -1141,0 +1096,0 @@ return _context.stop();

@@ -1,2 +0,2 @@

"use strict";function e(){e=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(e,t,r){e[t]=r.value},a="function"==typeof Symbol?Symbol:{},o=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",c=a.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var a=Object.create((t&&t.prototype instanceof f?t:f).prototype),o=new S(n||[]);return i(a,"_invoke",{value:k(e,r,o)}),a}function p(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=l;var d={};function f(){}function h(){}function y(){}var m={};s(m,o,(function(){return this}));var v=Object.getPrototypeOf,g=v&&v(v(N([])));g&&g!==r&&n.call(g,o)&&(m=g);var x=y.prototype=f.prototype=Object.create(m);function b(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){var r;i(this,"_invoke",{value:function(i,a){function o(){return new t((function(r,o){!function r(i,a,o,u){var c=p(e[i],e,a);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?t.resolve(l.__await).then((function(e){r("next",e,o,u)}),(function(e){r("throw",e,o,u)})):t.resolve(l).then((function(e){s.value=e,o(s)}),(function(e){return r("throw",e,o,u)}))}u(c.arg)}(i,a,r,o)}))}return r=r?r.then(o,o):o()}})}function k(e,t,r){var n="suspendedStart";return function(i,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw a;return{value:void 0,done:!0}}for(r.method=i,r.arg=a;;){var o=r.delegate;if(o){var u=E(o,r);if(u){if(u===d)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=p(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function E(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,E(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),d;var i=p(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,d;var a=i.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,d):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}function L(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(L,this),this.reset(!0)}function N(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,i=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return h.prototype=y,i(x,"constructor",{value:y,configurable:!0}),i(y,"constructor",{value:h,configurable:!0}),h.displayName=s(y,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,s(e,c,"GeneratorFunction")),e.prototype=Object.create(x),e},t.awrap=function(e){return{__await:e}},b(w.prototype),s(w.prototype,u,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,i,a){void 0===a&&(a=Promise);var o=new w(l(e,r,n,i),a);return t.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},b(x),s(x,c,"Generator"),s(x,o,(function(){return this})),s(x,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=N,S.prototype={constructor:S,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(T),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(r,n){return o.type="throw",o.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],o=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),T(r),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;T(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:N(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},t}function t(e,t,r,n,i,a,o){try{var u=e[a](o),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function r(e){return function(){var r=this,n=arguments;return new Promise((function(i,a){var o=e.apply(r,n);function u(e){t(o,i,a,u,c,"next",e)}function c(e){t(o,i,a,u,c,"throw",e)}u(void 0)}))}}function n(){return(n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function a(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return i(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o;Object.defineProperty(exports,"__esModule",{value:!0}),function(e){e.Page="corePage",e.Article="coreArticle",e.Navigation="coreNavigation",e.NavigationItem="coreNavigationItem",e.OpenGraph="coreOpenGraph",e.Seo="coreSeo"}(o||(o={}));var u={name:"Core: Page",displayField:"title",fields:[{id:"title",name:"title",type:"Symbol",required:!0,localized:!1},{id:"pageTitle",name:"pageTitle",type:"Symbol",required:!0,localized:!1},{id:"slug",name:"slug",type:"Symbol",required:!1,localized:!1},{id:"seo",name:"seo",type:"Link",localized:!1,required:!1,validations:[{linkContentType:["coreSeo"]}],linkType:"Entry"},{id:"articles",name:"articles",type:"Array",required:!1,localized:!1,items:{type:"Link",validations:[{linkContentType:["coreArticle"]}],linkType:"Entry"}}],description:"Page model",sys:{id:"corePage"}},c={name:"Core: Open Graph",displayField:"title",description:"Open Graph model",fields:[{id:"title",name:"Title",type:"Symbol",required:!0,localized:!1},{id:"type",name:"Type",type:"Symbol",required:!0,localized:!1},{id:"url",name:"URL",type:"Symbol",required:!0,localized:!1},{id:"description",name:"Description",type:"Symbol",required:!0,localized:!1},{id:"images",name:"images",type:"Array",required:!0,localized:!1,items:{type:"Link",validations:[{linkMimetypeGroup:["image"]}],linkType:"Asset"}}],sys:{id:"coreOpenGraph"}},s={name:"Core: Article",description:"",displayField:"title",fields:[{id:"title",name:"title",type:"Symbol",required:!0,localized:!1},{id:"modules",name:"modules",type:"Array",items:{type:"Link",validations:[],linkType:"Entry"},required:!1,localized:!1}],sys:{id:"coreArticle"}},l={name:"Core: Seo",displayField:"title",description:"SEO model",fields:[{id:"title",name:"title",type:"Symbol",required:!0,localized:!1},{id:"metaTitle",name:"metaTitle",type:"Symbol",required:!0,localized:!1},{id:"metaDescription",name:"metaDescription",type:"Symbol",required:!0,localized:!1},{id:"openGraph",name:"openGraph",type:"Link",required:!1,localized:!1,validations:[{linkContentType:["coreOpenGraph"]}],linkType:"Entry"}],sys:{id:"coreSeo"}},p={name:"Core: Navigation",displayField:"title",description:"Navigation model",fields:[{id:"title",name:"title",type:"Symbol",required:!0,localized:!1},{id:"name",name:"name",type:"Symbol",required:!0,localized:!1},{id:"items",name:"items",type:"Array",items:{type:"Link",validations:[{linkContentType:["coreNavigationItem"]}],linkType:"Entry"},required:!1,localized:!1}],sys:{id:"coreNavigation"}},d={name:"Core: Navigation - Item",displayField:"title",description:"Navigation item model",fields:[{id:"title",name:"title",type:"Symbol",required:!0,localized:!1},{id:"page",name:"page",type:"Link",validations:[{linkContentType:["corePage"]}],linkType:"Entry",required:!1,localized:!1},{id:"childs",name:"childs",type:"Array",items:{type:"Link",validations:[{linkContentType:["coreNavigationItem"]}],linkType:"Entry"},required:!1,localized:!1}],sys:{id:"coreNavigationItem"}},f=function(){var t=r(e().mark((function t(r,n){var i,f,h,y,m,v,g,x,b,w,k,E;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r){e.next=2;break}throw new Error("Missing client");case 2:if(n.spaceId){e.next=4;break}throw new Error("Missing spaceId");case 4:if(n.environment){e.next=6;break}throw new Error("Missing environment");case 6:return console.log("Creating core models in space "+n.spaceId+" and environment "+n.environment),i=[],e.next=10,r.getSpace(n.spaceId);case 10:return f=e.sent,e.next=13,f.getEnvironment(n.environment);case 13:return h=e.sent,e.next=16,h.createContentTypeWithId(o.Seo,l);case 16:return y=e.sent,e.next=19,y.publish();case 19:return i.push(y),e.next=22,h.createContentTypeWithId(o.Article,s);case 22:return m=e.sent,e.next=25,m.publish();case 25:return i.push(m),e.next=28,h.createContentTypeWithId(o.OpenGraph,c);case 28:return v=e.sent,e.next=31,v.publish();case 31:return i.push(v),e.next=34,h.createContentTypeWithId(o.Page,u);case 34:return g=e.sent,e.next=37,g.publish();case 37:return i.push(g),e.next=40,h.createContentTypeWithId(o.NavigationItem,d);case 40:return x=e.sent,e.next=43,x.publish();case 43:return i.push(x),e.next=46,h.createContentTypeWithId(o.Navigation,p);case 46:return b=e.sent,e.next=49,b.publish();case 49:i.push(b),w=a(n.modules||[]);case 51:if((k=w()).done){e.next=59;break}return E=k.value,console.log("Creating module "+E.name),e.next=56,E.load({client:r,space:f,environment:h,contentTypes:i});case 56:console.log("Module "+E.name+" created successfully");case 57:e.next=51;break;case 59:console.log("Core models created successfully");case 60:case"end":return e.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),h=function(){var t=r(e().mark((function t(r){var n,i,a;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.client,i=r.name,e.next=3,n.getEntries({content_type:o.Navigation,"fields.name":i});case 3:if(0!==(a=e.sent).items.length){e.next=6;break}throw new Error("No navigation found with name "+i);case 6:return e.abrupt("return",a.items[0]);case 7:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),y=function(){var t=r(e().mark((function t(n){var i,o,u,c,s;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=n.client,o=n.name,t.next=3,h({client:i,name:o});case 3:return u=t.sent,c=function(){var t=r(e().mark((function t(r){var n,o,u,s,l,p,d,f,h;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.getEntry(r.sys.id);case 2:if(p={name:null==(s=(u=e.sent).fields.page)||null==(n=s.fields)?void 0:n.title,url:null==s||null==(o=s.fields)?void 0:o.slug,childs:[]},!((null==(l=u.fields.childs)?void 0:l.length)>0)){e.next=16;break}d=a(l);case 8:if((f=d()).done){e.next=16;break}return h=f.value,e.next=12,c(h);case 12:p.childs.push(e.sent);case 14:e.next=8;break;case 16:return e.abrupt("return",p);case 17:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),s=function(){var t=r(e().mark((function t(r){var n,i,o,u;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n={name:r.fields.name,childs:[]},i=a(r.fields.items);case 2:if((o=i()).done){e.next=10;break}return u=o.value,e.next=6,c(u);case 6:n.childs.push(e.sent);case 8:e.next=2;break;case 10:return e.abrupt("return",n);case 11:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.next=8,s(u);case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),m=function(){var t=r(e().mark((function t(r){var i,u,c,s,l,p,d,f,h,y,m,v,g,x,b,w;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r.client.getEntries({content_type:o.Page,"fields.slug":r.slug,include:2});case 2:if(0!==(i=t.sent).items.length){t.next=5;break}throw new Error("No page found with slug "+r.slug);case 5:if(!(i.total>1)){t.next=7;break}throw new Error("More than one page found with slug "+r.slug);case 7:s=void 0===(c=(u=i.items[0].fields).articles)?[]:c,l=n({},i.items[0].fields,{title:u.title,pageTitle:u.pageTitle,slug:r.slug}),p=[],d={},f=a(s);case 13:if((h=f()).done){t.next=29;break}m=(y=h.value.fields).title,v=y.modules,g=[],x=e().mark((function t(){var i,a,o,u;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!((a=(i=w.value).sys.id)in d)||r.byPassCache){e.next=5;break}return g.push(d[a]),e.abrupt("return","continue");case 5:if((o=i.sys.contentType.sys.id)&&r.moduleMapping&&o in r.moduleMapping){e.next=9;break}return g.push(n({},i)),e.abrupt("return","continue");case 9:return e.next=11,r.moduleMapping[o].fetch({client:r.client,moduleData:i,fetchFromContentful:function(){return r.client.getEntry(a)}});case 11:d[a]=u=e.sent,g.push(u);case 14:case"end":return e.stop()}}),t)})),b=a(v);case 19:if((w=b()).done){t.next=26;break}return t.delegateYield(x(),"t0",21);case 21:if("continue"!==t.t0){t.next=24;break}return t.abrupt("continue",24);case 24:t.next=19;break;case 26:p.push({title:m,modules:g});case 27:t.next=13;break;case 29:return l.articles=p,t.abrupt("return",l);case 31:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),v=function(){var t=r(e().mark((function t(r,n){return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!n.shouldLoadContent({client:r.client,slug:r.slug,moduleMapping:r.moduleMapping})){e.next=4;break}return e.next=3,n.loadContent({client:r.client,slug:r.slug,moduleMapping:r.moduleMapping});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),g=function(){var t=r(e().mark((function t(r){var n;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r.customFetch){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,r.customFetch({client:r.client,slug:r.slug,moduleMapping:r.moduleMapping});case 4:if(!1===(n=e.sent)){e.next=7;break}return e.abrupt("return",n);case 7:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),x=function(){var t=r(e().mark((function t(r){var n,i,o,u,c;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!r.customFetch){e.next=6;break}return e.next=3,g(r);case 3:if(!(n=e.sent)){e.next=6;break}return e.abrupt("return",n);case 6:i=a(r.pageModules||[]);case 7:if((o=i()).done){e.next=16;break}return u=o.value,e.next=11,v(r,u);case 11:if(!(c=e.sent)){e.next=14;break}return e.abrupt("return",c);case 14:e.next=7;break;case 16:return e.next=18,m(r);case 18:return e.abrupt("return",e.sent);case 19:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),b=function(){var t=r(e().mark((function t(n){var i,a;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=[],a=function(){var t=r(e().mark((function t(r){var o;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n(r);case 2:if(i.push.apply(i,(o=e.sent).items),!(o.skip+o.limit<o.total)){e.next=7;break}return e.next=7,a(o.skip+o.limit);case 7:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.next=4,a(0);case 4:return t.abrupt("return",i);case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),w=function(){var t=r(e().mark((function t(r){var n,i,u,c,s,l;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=[],e.next=3,b((function(e){return r.client.getEntries({content_type:o.Page,skip:e,limit:1})}));case 3:i=a(e.sent);case 5:if((u=i()).done){e.next=13;break}if(l=null==(s=u.value)||null==(c=s.fields)?void 0:c.slug){e.next=10;break}return e.abrupt("continue",11);case 10:n.push(l);case 11:e.next=5;break;case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),k=function(){var t=r(e().mark((function t(r){var n,i,o,u;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=[],i=a(r.modules||[]);case 2:if((o=i()).done){e.next=10;break}return u=o.value,e.next=6,u.loadRoutes({client:r.client,modules:r.modules,routes:n});case 6:n.push.apply(n,e.sent);case 8:e.next=2;break;case 10:return e.abrupt("return",n);case 11:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),E=function(){var t=r(e().mark((function t(r){var n;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=[],e.next=3,w(r);case 3:return n.push.apply(n,e.sent),e.next=7,k(r);case 7:return n.push.apply(n,e.sent),e.abrupt("return",n);case 10:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();exports.createCoreModels=f,exports.fetchAll=b,exports.fetchAndTransformNavigationByName=y,exports.fetchNavigationByName=h,exports.fetchPageBySlug=x,exports.fetchPages=E;
"use strict";function e(){e=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(e,t,r){e[t]=r.value},a="function"==typeof Symbol?Symbol:{},o=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",u=a.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var a=Object.create((t&&t.prototype instanceof f?t:f).prototype),o=new S(n||[]);return i(a,"_invoke",{value:k(e,r,o)}),a}function p(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=l;var d={};function f(){}function h(){}function y(){}var m={};s(m,o,(function(){return this}));var v=Object.getPrototypeOf,g=v&&v(v(O([])));g&&g!==r&&n.call(g,o)&&(m=g);var x=y.prototype=f.prototype=Object.create(m);function b(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){var r;i(this,"_invoke",{value:function(i,a){function o(){return new t((function(r,o){!function r(i,a,o,c){var u=p(e[i],e,a);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?t.resolve(l.__await).then((function(e){r("next",e,o,c)}),(function(e){r("throw",e,o,c)})):t.resolve(l).then((function(e){s.value=e,o(s)}),(function(e){return r("throw",e,o,c)}))}c(u.arg)}(i,a,r,o)}))}return r=r?r.then(o,o):o()}})}function k(e,t,r){var n="suspendedStart";return function(i,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw a;return{value:void 0,done:!0}}for(r.method=i,r.arg=a;;){var o=r.delegate;if(o){var c=E(o,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=p(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===d)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function E(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,E(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),d;var i=p(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,d;var a=i.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,d):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}function L(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(L,this),this.reset(!0)}function O(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,i=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:N}}function N(){return{value:void 0,done:!0}}return h.prototype=y,i(x,"constructor",{value:y,configurable:!0}),i(y,"constructor",{value:h,configurable:!0}),h.displayName=s(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,s(e,u,"GeneratorFunction")),e.prototype=Object.create(x),e},t.awrap=function(e){return{__await:e}},b(w.prototype),s(w.prototype,c,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,i,a){void 0===a&&(a=Promise);var o=new w(l(e,r,n,i),a);return t.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},b(x),s(x,u,"Generator"),s(x,o,(function(){return this})),s(x,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,S.prototype={constructor:S,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(T),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(r,n){return o.type="throw",o.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],o=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(c&&u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),T(r),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;T(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:O(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},t}function t(e,t,r,n,i,a,o){try{var c=e[a](o),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,i)}function r(e){return function(){var r=this,n=arguments;return new Promise((function(i,a){var o=e.apply(r,n);function c(e){t(o,i,a,c,u,"next",e)}function u(e){t(o,i,a,c,u,"throw",e)}c(void 0)}))}}function n(){return(n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function i(e,t){if(null==e)return{};var r,n,i={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(i[r]=e[r]);return i}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function o(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return a(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var c;Object.defineProperty(exports,"__esModule",{value:!0}),function(e){e.Page="corePage",e.Article="coreArticle",e.Navigation="coreNavigation",e.NavigationItem="coreNavigationItem",e.OpenGraph="coreOpenGraph",e.Seo="coreSeo"}(c||(c={}));var u={name:"Core: Page",displayField:"title",fields:[{id:"title",name:"title",type:"Symbol",required:!0,localized:!1},{id:"pageTitle",name:"pageTitle",type:"Symbol",required:!0,localized:!1},{id:"slug",name:"slug",type:"Symbol",required:!1,localized:!1},{id:"seo",name:"seo",type:"Link",localized:!1,required:!1,validations:[{linkContentType:["coreSeo"]}],linkType:"Entry"},{id:"articles",name:"articles",type:"Array",required:!1,localized:!1,items:{type:"Link",validations:[{linkContentType:["coreArticle"]}],linkType:"Entry"}}],description:"Page model",sys:{id:"corePage"}},s={name:"Core: Open Graph",displayField:"title",description:"Open Graph model",fields:[{id:"title",name:"Title",type:"Symbol",required:!0,localized:!1},{id:"type",name:"Type",type:"Symbol",required:!0,localized:!1},{id:"url",name:"URL",type:"Symbol",required:!0,localized:!1},{id:"description",name:"Description",type:"Symbol",required:!0,localized:!1},{id:"images",name:"images",type:"Array",required:!0,localized:!1,items:{type:"Link",validations:[{linkMimetypeGroup:["image"]}],linkType:"Asset"}}],sys:{id:"coreOpenGraph"}},l={name:"Core: Article",description:"",displayField:"title",fields:[{id:"title",name:"title",type:"Symbol",required:!0,localized:!1},{id:"modules",name:"modules",type:"Array",items:{type:"Link",validations:[],linkType:"Entry"},required:!1,localized:!1}],sys:{id:"coreArticle"}},p={name:"Core: Seo",displayField:"title",description:"SEO model",fields:[{id:"title",name:"title",type:"Symbol",required:!0,localized:!1},{id:"metaTitle",name:"metaTitle",type:"Symbol",required:!0,localized:!1},{id:"metaDescription",name:"metaDescription",type:"Symbol",required:!0,localized:!1},{id:"openGraph",name:"openGraph",type:"Link",required:!1,localized:!1,validations:[{linkContentType:["coreOpenGraph"]}],linkType:"Entry"}],sys:{id:"coreSeo"}},d={name:"Core: Navigation",displayField:"title",description:"Navigation model",fields:[{id:"title",name:"title",type:"Symbol",required:!0,localized:!1},{id:"name",name:"name",type:"Symbol",required:!0,localized:!1},{id:"items",name:"items",type:"Array",items:{type:"Link",validations:[{linkContentType:["coreNavigationItem"]}],linkType:"Entry"},required:!1,localized:!1}],sys:{id:"coreNavigation"}},f={name:"Core: Navigation - Item",displayField:"title",description:"Navigation item model",fields:[{id:"title",name:"title",type:"Symbol",required:!0,localized:!1},{id:"page",name:"page",type:"Link",validations:[{linkContentType:["corePage"]}],linkType:"Entry",required:!1,localized:!1},{id:"childs",name:"childs",type:"Array",items:{type:"Link",validations:[{linkContentType:["coreNavigationItem"]}],linkType:"Entry"},required:!1,localized:!1}],sys:{id:"coreNavigationItem"}},h=function(){var t=r(e().mark((function t(r,n){var i,a,h,y,m,v,g,x,b,w,k,E;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r){e.next=2;break}throw new Error("Missing client");case 2:if(n.spaceId){e.next=4;break}throw new Error("Missing spaceId");case 4:if(n.environment){e.next=6;break}throw new Error("Missing environment");case 6:return console.log("Creating core models in space "+n.spaceId+" and environment "+n.environment),i=[],e.next=10,r.getSpace(n.spaceId);case 10:return a=e.sent,e.next=13,a.getEnvironment(n.environment);case 13:return h=e.sent,e.next=16,h.createContentTypeWithId(c.Seo,p);case 16:return y=e.sent,e.next=19,y.publish();case 19:return i.push(y),e.next=22,h.createContentTypeWithId(c.Article,l);case 22:return m=e.sent,e.next=25,m.publish();case 25:return i.push(m),e.next=28,h.createContentTypeWithId(c.OpenGraph,s);case 28:return v=e.sent,e.next=31,v.publish();case 31:return i.push(v),e.next=34,h.createContentTypeWithId(c.Page,u);case 34:return g=e.sent,e.next=37,g.publish();case 37:return i.push(g),e.next=40,h.createContentTypeWithId(c.NavigationItem,f);case 40:return x=e.sent,e.next=43,x.publish();case 43:return i.push(x),e.next=46,h.createContentTypeWithId(c.Navigation,d);case 46:return b=e.sent,e.next=49,b.publish();case 49:i.push(b),w=o(n.modules||[]);case 51:if((k=w()).done){e.next=59;break}return E=k.value,console.log("Creating module "+E.name),e.next=56,E.load({client:r,space:a,environment:h,contentTypes:i});case 56:console.log("Module "+E.name+" created successfully");case 57:e.next=51;break;case 59:console.log("Core models created successfully");case 60:case"end":return e.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),y=function(){var t=r(e().mark((function t(r){var n,i,a;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.client,i=r.name,e.next=3,n.getEntries({content_type:c.Navigation,"fields.name":i});case 3:if(0!==(a=e.sent).items.length){e.next=6;break}throw new Error("No navigation found with name "+i);case 6:return e.abrupt("return",a.items[0]);case 7:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),m=function(){var t=r(e().mark((function t(n){var i,a,c,u,s;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=n.client,a=n.name,t.next=3,y({client:i,name:a});case 3:return c=t.sent,u=function(){var t=r(e().mark((function t(r){var n,a,c,s,l,p,d,f,h;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.getEntry(r.sys.id);case 2:if(p={name:null==(s=(c=e.sent).fields.page)||null==(n=s.fields)?void 0:n.title,url:null==s||null==(a=s.fields)?void 0:a.slug,childs:[]},!((null==(l=c.fields.childs)?void 0:l.length)>0)){e.next=16;break}d=o(l);case 8:if((f=d()).done){e.next=16;break}return h=f.value,e.next=12,u(h);case 12:p.childs.push(e.sent);case 14:e.next=8;break;case 16:return e.abrupt("return",p);case 17:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),s=function(){var t=r(e().mark((function t(r){var n,i,a,c;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n={name:r.fields.name,childs:[]},i=o(r.fields.items);case 2:if((a=i()).done){e.next=10;break}return c=a.value,e.next=6,u(c);case 6:n.childs.push(e.sent);case 8:e.next=2;break;case 10:return e.abrupt("return",n);case 11:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.next=8,s(c);case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),v=["title","modules"],g=function(){var t=r(e().mark((function t(r){var a,u,s,l,p,d,f,h,y,m,g,x,b,w,k,E;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r.client.getEntries({content_type:c.Page,"fields.slug":r.slug,include:2});case 2:if(0!==(a=t.sent).items.length){t.next=5;break}throw new Error("No page found with slug "+r.slug);case 5:if(!(a.total>1)){t.next=7;break}throw new Error("More than one page found with slug "+r.slug);case 7:l={title:(u=a.items[0].fields).title,pageTitle:u.pageTitle,slug:r.slug},p=[],d={},f=o(void 0===(s=u.articles)?[]:s);case 12:if((h=f()).done){t.next=28;break}m=(y=h.value.fields).title,g=y.modules,x=i(y,v),b=[],w=e().mark((function t(){var i,a,o,c;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!((a=(i=E.value).sys.id)in d)||r.byPassCache){e.next=5;break}return b.push(d[a]),e.abrupt("return","continue");case 5:if((o=i.sys.contentType.sys.id)&&r.moduleMapping&&o in r.moduleMapping){e.next=9;break}return b.push(n({},i)),e.abrupt("return","continue");case 9:return e.next=11,r.moduleMapping[o].fetch({client:r.client,moduleData:i,fetchFromContentful:function(){return r.client.getEntry(a)}});case 11:d[a]=c=e.sent,b.push(c);case 14:case"end":return e.stop()}}),t)})),k=o(g);case 18:if((E=k()).done){t.next=25;break}return t.delegateYield(w(),"t0",20);case 20:if("continue"!==t.t0){t.next=23;break}return t.abrupt("continue",23);case 23:t.next=18;break;case 25:p.push(n({},x,{title:m,modules:b}));case 26:t.next=12;break;case 28:return l.articles=p,t.abrupt("return",l);case 30:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),x=function(){var t=r(e().mark((function t(r){var n,i,a,c;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!r.customFetch){e.next=6;break}return e.next=3,r.customFetch({client:r.client,slug:r.slug,moduleMapping:r.moduleMapping});case 3:if(!1===(n=e.sent)){e.next=6;break}return e.abrupt("return",n);case 6:i=o(r.pageModules||[]);case 7:if((a=i()).done){e.next=15;break}if(!(c=a.value).shouldLoadContent({client:r.client,slug:r.slug,moduleMapping:r.moduleMapping})){e.next=13;break}return e.next=12,c.loadContent({client:r.client,slug:r.slug,moduleMapping:r.moduleMapping});case 12:return e.abrupt("return",e.sent);case 13:e.next=7;break;case 15:return e.next=17,g(r);case 17:return e.abrupt("return",e.sent);case 18:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),b=function(){var t=r(e().mark((function t(n){var i,a;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=[],a=function(){var t=r(e().mark((function t(r){var o;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n(r);case 2:if(i.push.apply(i,(o=e.sent).items),!(o.skip+o.limit<o.total)){e.next=7;break}return e.next=7,a(o.skip+o.limit);case 7:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.next=4,a(0);case 4:return t.abrupt("return",i);case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),w=function(){var t=r(e().mark((function t(r){var n,i,a,u,s,l;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=[],e.next=3,b((function(e){return r.client.getEntries({content_type:c.Page,skip:e,limit:1})}));case 3:i=o(e.sent);case 5:if((a=i()).done){e.next=13;break}if(l=null==(s=a.value)||null==(u=s.fields)?void 0:u.slug){e.next=10;break}return e.abrupt("continue",11);case 10:n.push(l);case 11:e.next=5;break;case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),k=function(){var t=r(e().mark((function t(r){var n,i,a,c;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=[],i=o(r.modules||[]);case 2:if((a=i()).done){e.next=10;break}return c=a.value,e.next=6,c.loadRoutes({client:r.client,modules:r.modules,routes:n});case 6:n.push.apply(n,e.sent);case 8:e.next=2;break;case 10:return e.abrupt("return",n);case 11:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),E=function(){var t=r(e().mark((function t(r){var n;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=[],e.next=3,w(r);case 3:return n.push.apply(n,e.sent),e.next=7,k(r);case 7:return n.push.apply(n,e.sent),e.abrupt("return",n);case 10:case"end":return e.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();exports.createCoreModels=h,exports.fetchAll=b,exports.fetchAndTransformNavigationByName=m,exports.fetchNavigationByName=y,exports.fetchPageBySlug=x,exports.fetchPages=E;
//# sourceMappingURL=core.cjs.production.min.js.map

@@ -346,2 +346,14 @@ function _regeneratorRuntime() {

}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _unsupportedIterableToArray(o, minLen) {

@@ -894,5 +906,6 @@ if (!o) return;

var _excluded = ["title", "modules"];
var fetchCorePageBySlug = /*#__PURE__*/function () {
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
var pages, _pages$items$0$fields, _pages$items$0$fields2, articles, title, pageTitle, pageFields, page, articleData, cachedModules, _iterator, _step, articleItem, _articleItem$fields, _title, modules, moduleData, _loop, _iterator2, _step2, _ret;
var pages, _pages$items$0$fields, _pages$items$0$fields2, articles, title, pageTitle, page, articleData, cachedModules, _iterator, _step, articleItem, _articleItem$fields, _title, modules, articleFields, moduleData, _loop, _iterator2, _step2, _ret;
return _regeneratorRuntime().wrap(function _callee$(_context2) {

@@ -922,18 +935,17 @@ while (1) switch (_context2.prev = _context2.next) {

_pages$items$0$fields = pages.items[0].fields, _pages$items$0$fields2 = _pages$items$0$fields.articles, articles = _pages$items$0$fields2 === void 0 ? [] : _pages$items$0$fields2, title = _pages$items$0$fields.title, pageTitle = _pages$items$0$fields.pageTitle;
pageFields = pages.items[0].fields;
page = _extends({}, pageFields, {
page = {
title: title,
pageTitle: pageTitle,
slug: config.slug
});
};
articleData = [];
cachedModules = {};
_iterator = _createForOfIteratorHelperLoose(articles);
case 13:
case 12:
if ((_step = _iterator()).done) {
_context2.next = 29;
_context2.next = 28;
break;
}
articleItem = _step.value;
_articleItem$fields = articleItem.fields, _title = _articleItem$fields.title, modules = _articleItem$fields.modules;
_articleItem$fields = articleItem.fields, _title = _articleItem$fields.title, modules = _articleItem$fields.modules, articleFields = _objectWithoutPropertiesLoose(_articleItem$fields, _excluded);
moduleData = [];

@@ -981,30 +993,30 @@ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {

_iterator2 = _createForOfIteratorHelperLoose(modules);
case 19:
case 18:
if ((_step2 = _iterator2()).done) {
_context2.next = 26;
_context2.next = 25;
break;
}
return _context2.delegateYield(_loop(), "t0", 21);
case 21:
return _context2.delegateYield(_loop(), "t0", 20);
case 20:
_ret = _context2.t0;
if (!(_ret === "continue")) {
_context2.next = 24;
_context2.next = 23;
break;
}
return _context2.abrupt("continue", 24);
case 24:
_context2.next = 19;
return _context2.abrupt("continue", 23);
case 23:
_context2.next = 18;
break;
case 26:
articleData.push({
case 25:
articleData.push(_extends({}, articleFields, {
title: _title,
modules: moduleData
});
case 27:
_context2.next = 13;
}));
case 26:
_context2.next = 12;
break;
case 29:
case 28:
page.articles = articleData;
return _context2.abrupt("return", page);
case 31:
case 30:
case "end":

@@ -1020,17 +1032,14 @@ return _context2.stop();

var fetchPageByModule = /*#__PURE__*/function () {
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, pageModule) {
var fetchPageBySlug = /*#__PURE__*/function () {
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
var customFetchResult, _iterator, _step, pageModule;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!pageModule.shouldLoadContent({
client: config.client,
slug: config.slug,
moduleMapping: config.moduleMapping
})) {
_context.next = 4;
if (!config.customFetch) {
_context.next = 6;
break;
}
_context.next = 3;
return pageModule.loadContent({
return config.customFetch({
client: config.client,

@@ -1041,68 +1050,7 @@ slug: config.slug,

case 3:
return _context.abrupt("return", _context.sent);
case 4:
case "end":
return _context.stop();
}
}, _callee);
}));
return function fetchPageByModule(_x, _x2) {
return _ref.apply(this, arguments);
};
}();
var fetchCustomPage = /*#__PURE__*/function () {
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
var customFetchResult;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (config.customFetch) {
_context.next = 2;
break;
}
return _context.abrupt("return");
case 2:
_context.next = 4;
return config.customFetch({
client: config.client,
slug: config.slug,
moduleMapping: config.moduleMapping
});
case 4:
customFetchResult = _context.sent;
if (!(customFetchResult !== false)) {
_context.next = 7;
break;
}
return _context.abrupt("return", customFetchResult);
case 7:
case "end":
return _context.stop();
}
}, _callee);
}));
return function fetchCustomPage(_x) {
return _ref.apply(this, arguments);
};
}();
var fetchPageBySlug = /*#__PURE__*/function () {
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
var customFetchResult, _iterator, _step, pageModule, pageModuleResult;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!config.customFetch) {
_context.next = 6;
break;
}
_context.next = 3;
return fetchCustomPage(config);
case 3:
customFetchResult = _context.sent;
if (!customFetchResult) {
_context.next = 6;
break;
}
return _context.abrupt("return", customFetchResult);

@@ -1113,24 +1061,31 @@ case 6:

if ((_step = _iterator()).done) {
_context.next = 16;
_context.next = 15;
break;
}
pageModule = _step.value;
_context.next = 11;
return fetchPageByModule(config, pageModule);
case 11:
pageModuleResult = _context.sent;
if (!pageModuleResult) {
_context.next = 14;
if (!pageModule.shouldLoadContent({
client: config.client,
slug: config.slug,
moduleMapping: config.moduleMapping
})) {
_context.next = 13;
break;
}
return _context.abrupt("return", pageModuleResult);
case 14:
_context.next = 12;
return pageModule.loadContent({
client: config.client,
slug: config.slug,
moduleMapping: config.moduleMapping
});
case 12:
return _context.abrupt("return", _context.sent);
case 13:
_context.next = 7;
break;
case 16:
_context.next = 18;
case 15:
_context.next = 17;
return fetchCorePageBySlug(config);
case 17:
return _context.abrupt("return", _context.sent);
case 18:
return _context.abrupt("return", _context.sent);
case 19:
case "end":

@@ -1137,0 +1092,0 @@ return _context.stop();

{
"version": "0.1.6",
"version": "0.2.0",
"license": "MIT",

@@ -4,0 +4,0 @@ "typings": "dist/index.d.ts",

@@ -53,3 +53,3 @@ <h1 align="center">content-app/core</h1>

# Modules - Add you own content types
# Add your own content types

@@ -56,0 +56,0 @@ If you want to use this feature you need to install the cli https://github.com/content-app/cli.

@@ -38,3 +38,2 @@ export interface NavigationItem {

articles?: Article[];
[key: string]: any;
};

@@ -26,6 +26,3 @@ import { ContentTypes } from '../constants';

const pageFields = pages.items[0].fields as any;
const page: PageInterface = {
...pageFields,
title,

@@ -43,3 +40,3 @@ pageTitle,

for (const articleItem of articles) {
const { title, modules } = articleItem.fields;
const { title, modules, ...articleFields } = articleItem.fields;
const moduleData: any[] = [];

@@ -73,2 +70,3 @@

articleData.push({
...articleFields,
title,

@@ -75,0 +73,0 @@ modules: moduleData,

import { FetchPageConfig } from './index.d';
import fetchCorePageBySlug from './fetchCorePageBySlug';
import fetchPageByModule from './fetchPageByModule';
import fetchCustomPage from './fetchCustomPage';
const fetchPageBySlug = async (config: FetchPageConfig) => {
if (config.customFetch) {
const customFetchResult = await fetchCustomPage(config);
if (customFetchResult) {
return customFetchResult;
}
const customFetchResult = await config.customFetch({
client: config.client,
slug: config.slug,
moduleMapping: config.moduleMapping,
});
if (customFetchResult !== false) {
return customFetchResult;
}
}
for (const pageModule of config.pageModules || []) {
const pageModuleResult = await fetchPageByModule(config, pageModule);
if (pageModuleResult) {
return pageModuleResult;
}
if (pageModule.shouldLoadContent({
client: config.client,
slug: config.slug,
moduleMapping: config.moduleMapping,
})) {
return await pageModule.loadContent({
client: config.client,
slug: config.slug,
moduleMapping: config.moduleMapping,
});
}
}
return await fetchCorePageBySlug(config);
};
};
export default fetchPageBySlug;

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc