UNPKG

next-acms

Version:

Tools for building decoupled front-ends for Acquia CMS

1 lines 3.6 kB
{"version":3,"file":"index.modern.mjs","sources":["../src/revalidate.ts","../src/test-api-compatibility.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next';\n\nexport async function revalidate(\n request: NextApiRequest,\n response: NextApiResponse,\n) {\n let slug = request.query.slug as string;\n const secret = request.query.secret as string;\n\n // Validate secret.\n if (secret !== process.env.DRUPAL_PREVIEW_SECRET) {\n return response.status(401).json({ message: 'Invalid secret.' });\n }\n\n // Validate slug.\n if (!slug) {\n return response.status(400).json({ message: 'Invalid slug.' });\n }\n\n // Fix for home slug.\n if (slug === process.env.NEXT_PUBLIC_DRUPAL_FRONT_PAGE) {\n slug = '/';\n }\n\n try {\n await response.revalidate(slug);\n\n return response.json({});\n } catch (error) {\n return response.status(404).json({\n message: error.message,\n });\n }\n}\n","import { DrupalClient } from 'next-drupal';\n\nexport async function testApiCompatibility(\n contentTypes: Array<string>,\n drupal: DrupalClient,\n) {\n let index;\n try {\n index = await drupal.getIndex();\n } catch (e) {\n throw new Error(\n e.message +\n '\\n\\n' +\n 'Failed to connect to the backend. See here for documentation about common reasons: \\nhttps://github.com/acquia/next-acms/wiki/Debugging-common-errors-with-Next.js-and-Drupal-integration#incompatible-web-server-setup-or-incorrect-environment-variables-generated',\n );\n }\n for (const type of contentTypes) {\n if (!Object.keys(index.links).includes(type)) {\n throw new Error(\n `Content type ${type} does not exist in the backend. \\nSee here for documentation on content model mismatch: https://github.com/acquia/next-acms/wiki/Debugging-common-errors-with-Next.js-and-Drupal-integration#content-model-mismatch`,\n );\n }\n }\n}\n"],"names":["revalidate","request","response","slug","query","secret","process","env","DRUPAL_PREVIEW_SECRET","status","json","message","NEXT_PUBLIC_DRUPAL_FRONT_PAGE","error","testApiCompatibility","contentTypes","drupal","index","getIndex","e","Error","type","Object","keys","links","includes"],"mappings":"AAEO,eAAeA,UAAU,CAC9BC,OAAuB,EACvBC,QAAyB,EAAA;AAE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