UNPKG

@botonic/plugin-contentful

Version:

## What Does This Plugin Do?

51 lines 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContentfulInfo = void 0; const tslib_1 = require("tslib"); const cms_1 = require("../cms"); const cms_info_1 = require("../cms/cms-info"); const enums_1 = require("../util/enums"); const delivery_utils_1 = require("./delivery-utils"); class ContentfulInfo { constructor(options) { this.options = options; this.client = (0, delivery_utils_1.createContentfulClientApi)(options); } contentTypes() { return tslib_1.__awaiter(this, void 0, void 0, function* () { const models = yield this.client.getContentTypes(); return models.items .map(m => { if ((0, enums_1.isOfType)(m.sys.id, cms_1.ContentType)) { return m.sys.id; } return undefined; }) .filter(m => !!m); }); } defaultLocale() { return tslib_1.__awaiter(this, void 0, void 0, function* () { const locales = yield this.locales(); for (const locale of Object.values(locales)) { if (locale.isDefault) { return locale; } } throw new Error(`No default locale found`); }); } locales() { return tslib_1.__awaiter(this, void 0, void 0, function* () { const locales = (yield this.client.getLocales()).items; return locales .map(l => new cms_info_1.LocaleInfo(l.code, l.name, l.fallbackCode || undefined, l.default)) .reduce((newObj, l) => { newObj[l.code] = l; return newObj; }, {}); }); } } exports.ContentfulInfo = ContentfulInfo; //# sourceMappingURL=info-contentful.js.map