diff --git a/scripts/actions/fetch-quickstarts.js b/scripts/actions/fetch-quickstarts.js index 27eb5a80..d47adc76 100644 --- a/scripts/actions/fetch-quickstarts.js +++ b/scripts/actions/fetch-quickstarts.js @@ -16,47 +16,76 @@ const get = require('lodash.get'); const QUICKSTARTS_FILE_PATH = './src/data/quickstarts.json'; const NR_API_URL = process.env.NR_API_URL; const NR_API_TOKEN = process.env.NR_API_TOKEN; +const gql = String.raw; // Hack to trick editors into syntax highlighting for graphql without pulling in a package -const quickstartQuery = `# gql - { - docs { - openInstallation { - quickstartSearch { - count +const nr1CatalogQuickstartQuery = gql` + query QuickstartFetchQuery { + actor { + nr1Catalog { + quickstarts { results { - quickstarts { - authors - dashboards { - description + featured + id + sourceUrl + supportLevel + metadata { + authors { name - screenshots - url - } - alerts { - name - details - type - url - } - documentation { - name - description - url } + categoryTerms description - iconUrl - packUrl - id - title - level - logoUrl - name + displayName + slug summary - websiteUrl keywords - installPlans { - id - name + icon { + url + } + installer { + type + ... on Nr1CatalogInstallPlan { + steps { + description + displayName + id + } + } + } + quickstartComponents { + ... on Nr1CatalogQuickstartAlertCondition { + __typename + id + metadata { + description + displayName + type + } + } + ... on Nr1CatalogQuickstartDashboard { + __typename + id + metadata { + description + displayName + previews { + url + ... on Nr1CatalogPreview { + url + } + ... on Nr1CatalogScreenshot { + url + } + } + } + } + ... on Nr1CatalogQuickstartDocumentation { + __typename + metadata { + description + displayName + url + } + } } } } @@ -95,12 +124,97 @@ const fetchQuickstarts = async (queryString, url, token) => { throw new Error(JSON.stringify(results.errors, null, 2)); } - return get(results, 'data.docs.openInstallation.quickstartSearch.results'); + return get(results, 'data.actor.nr1Catalog.quickstarts.results'); } catch (error) { console.error('Encountered a problem querying the graphql api', error); } }; +const DASHBOARD_TYPENAME = 'Nr1CatalogQuickstartDashboard'; +const ALERT_TYPENAME = 'Nr1CatalogQuickstartAlertCondition'; +const DOCUMENTATION_TYPENAME = 'Nr1CatalogQuickstartDocumentation'; + +const formatQuickstart = (nr1CatQuickstart) => { + const metadata = nr1CatQuickstart.metadata; + const formatted = {}; + + formatted.title = metadata.displayName ?? ''; + formatted.name = metadata.slug ?? ''; + formatted.description = metadata.description ?? ''; + formatted.packUrl = nr1CatQuickstart.sourceUrl; + formatted.id = nr1CatQuickstart.id; + formatted.level = nr1CatQuickstart.supportLevel; + formatted.logoUrl = metadata.icon.url; + formatted.summary = metadata.summary ?? ''; + formatted.websiteUrl = null; // not in the nr1Catalog schema + formatted.keywords = metadata.keywords; + + formatted.authors = metadata.authors.map(({ name }) => name); + + const components = nr1CatQuickstart?.metadata?.quickstartComponents ?? []; + + formatted.dashboards = components + .filter((c) => c.__typename === DASHBOARD_TYPENAME) + .map(formatDashboard); + + formatted.alerts = components + .filter((c) => c.__typename === ALERT_TYPENAME) + .map(formatAlert); + + formatted.documentation = components + .filter((c) => c.__typename === DOCUMENTATION_TYPENAME) + .map(formatDoc); + + const installSteps = metadata?.installer?.steps ?? []; + formatted.installPlans = installSteps.map(formatInstallPlan); + + return formatted; +}; + +const formatDashboard = (nr1CatDashboard) => { + const metadata = nr1CatDashboard.metadata; + const formatted = {}; + + formatted.name = metadata.displayName; + formatted.description = metadata.description; + formatted.url = null; // Doesn't exist in nr1Catalog schema + formatted.screenshots = metadata?.previews?.map(({ url }) => url) ?? []; + + return formatted; +}; + +const formatDoc = (nr1CatDoc) => { + const metadata = nr1CatDoc.metadata; + const formatted = {}; + + formatted.name = metadata.displayName; + formatted.description = metadata.description; + formatted.url = metadata.url; // Doesn't exist in nr1Catalog schema + + return formatted; +}; + +const formatAlert = (nr1CatAlert) => { + const metadata = nr1CatAlert.metadata; + const formatted = {}; + + formatted.name = metadata.displayName; + formatted.details = metadata.description; + formatted.type = metadata.type; + formatted.url = null; // Doesn't exist in nr1Catalog schema + + return formatted; +}; + +const formatInstallPlan = (nr1CatInstallPlan) => { + const formatted = {}; + + formatted.name = nr1CatInstallPlan.displayName; + formatted.id = nr1CatInstallPlan.id; + + return formatted; +}; + const validateEnvVars = () => { if (typeof NR_API_URL !== 'string') { throw new Error('NR_GQL_URL environment variable not set, exiting...'); @@ -120,12 +234,12 @@ const main = async (query, url, token) => { const results = await fetchQuickstarts(query, url, token); if (results) { - const quickstarts = results.quickstarts; - console.log(`Found ${quickstarts.length} quickstarts.`); + const convertedQuickstarts = results.map(formatQuickstart); + console.log(`Found ${results.length} quickstarts.`); console.log(`Writing ${QUICKSTARTS_FILE_PATH}`); fs.writeFileSync( QUICKSTARTS_FILE_PATH, - JSON.stringify(quickstarts, null, 2) + JSON.stringify(convertedQuickstarts, null, 2) ); } else { console.log( @@ -139,7 +253,7 @@ const main = async (query, url, token) => { if (require.main === module) { validateEnvVars(); - main(quickstartQuery, NR_API_URL, NR_API_TOKEN); + main(nr1CatalogQuickstartQuery, NR_API_URL, NR_API_TOKEN); } module.exports = main; diff --git a/src/data/constants.js b/src/data/constants.js index 63ba5ccb..489deabd 100644 --- a/src/data/constants.js +++ b/src/data/constants.js @@ -10,7 +10,7 @@ export const CODESTREAM_QUICKSTART_ID = '29bd9a4a-1c19-4219-9694-0942f6411ce7'; export const NR1_EXPLORER_NERDLET = 'nr1-core.listing'; export const QUICKSTART_SUPPORT_LEVELS = { - NEWRELIC: 'NEWRELIC', + NEWRELIC: 'NEW_RELIC', VERIFIED: 'VERIFIED', COMMUNITY: 'COMMUNITY', }; diff --git a/src/pages/index.jsx b/src/pages/index.jsx index a1160546..08a3c0e7 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -682,7 +682,6 @@ export const pageQuery = graphql` id title name - websiteUrl logoUrl packUrl level @@ -691,12 +690,10 @@ export const pageQuery = graphql` description name screenshots - url } alerts { details name - url type } documentation { diff --git a/src/templates/QuickstartDetails.js b/src/templates/QuickstartDetails.js index c41c109a..28687ba7 100644 --- a/src/templates/QuickstartDetails.js +++ b/src/templates/QuickstartDetails.js @@ -440,12 +440,10 @@ export const pageQuery = graphql` description name screenshots - url } alerts { details name - url type } documentation {