UNPKG

@kontent-ai/gatsby-source

Version:
76 lines 3.8 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const _ = __importStar(require("lodash")); const createSchemaCustomization_items_1 = require("./src/createSchemaCustomization.items"); const sourceNodes_items_1 = require("./src/sourceNodes.items"); const createSchemaCustomization_taxonomies_1 = require("./src/createSchemaCustomization.taxonomies"); const sourceNodes_taxonomies_1 = require("./src/sourceNodes.taxonomies"); const createSchemaCustomization_types_1 = require("./src/createSchemaCustomization.types"); const sourceNodes_types_1 = require("./src/sourceNodes.types"); const webhookProcessor_1 = require("./src/webhookProcessor"); const pluginOptionsSchema_1 = require("./src/pluginOptionsSchema"); exports.pluginOptionsSchema = ({ Joi }) => { return (0, pluginOptionsSchema_1.pluginOptionsSchema)({ Joi }); }; exports.createSchemaCustomization = async (api, pluginConfig) => { try { await (0, createSchemaCustomization_items_1.kontentItemsCreateSchemaCustomization)(api, pluginConfig); if (pluginConfig.includeTaxonomies) { await (0, createSchemaCustomization_taxonomies_1.kontentTaxonomiesCreateSchemaCustomization)(api); } if (pluginConfig.includeTypes) { await (0, createSchemaCustomization_types_1.kontentTypesCreateSchemaCustomization)(api); } } catch (error) { api.reporter.error('Gatsby Kontent.ai source plugin resulted to error in `createSchemaCustomization` method', error); api.reporter.verbose(`Complete error: ${JSON.stringify(error, null, 2)}`); throw error; } }; exports.sourceNodes = async (api, pluginConfig) => { try { if (!_.isEmpty(api.webhookBody)) { //preview run const itemTypes = (await api.cache.get('kontent-item-types')) || []; await (0, webhookProcessor_1.handleIncomingWebhook)(api, pluginConfig, itemTypes); return; } const itemTypes = await (0, sourceNodes_items_1.kontentItemsSourceNodes)(api, pluginConfig); await api.cache.set('kontent-item-types', itemTypes); if (pluginConfig.includeTaxonomies) { await (0, sourceNodes_taxonomies_1.kontentTaxonomiesSourceNodes)(api, pluginConfig); } if (pluginConfig.includeTypes) { await (0, sourceNodes_types_1.kontentTypesSourceNodes)(api, pluginConfig); } } catch (error) { api.reporter.error('Gatsby Kontent.ai source plugin resulted to error in `sourceNodes` method', error); api.reporter.verbose(`Complete error: ${JSON.stringify(error, null, 2)}`); throw error; } }; //# sourceMappingURL=gatsby-node.js.map