@backstage-community/plugin-tech-insights-backend 0.5.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/service/fact/createFactRetriever.ts","../src/service/fact/factRetrievers/entityMetadataFactRetriever.ts","../src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts","../src/service/fact/factRetrievers/utils.ts","../src/service/fact/factRetrievers/techdocsFactRetriever.ts","../src/service/persistence/TechInsightsDatabase.ts","../src/service/persistence/persistenceContext.ts","../src/service/router.ts","../src/service/fact/FactRetrieverEngine.ts","../src/service/fact/FactRetrieverRegistry.ts","../src/service/techInsightsContextBuilder.ts","../src/plugin/config.ts","../src/plugin/plugin.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HumanDuration } from '@backstage/types';\nimport {\n FactLifecycle,\n FactRetriever,\n FactRetrieverRegistration,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { Duration } from 'luxon';\n\n/**\n * @public\n *\n * @param cadence - cron expression to indicate when the fact retriever should be triggered\n * @param factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler\n * @param lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run\n * @param timeout - Optional duration to determine how long the fact retriever should be allowed to run, defaults to 5 minutes\n *\n */\nexport type FactRetrieverRegistrationOptions = {\n cadence: string;\n factRetriever: FactRetriever;\n lifecycle?: FactLifecycle;\n timeout?: Duration | HumanDuration;\n initialDelay?: Duration | HumanDuration;\n};\n\n/**\n * @public\n *\n * A helper function to construct fact retriever registrations.\n * @param cadence - Cron expression to indicate when the fact retriever should be triggered\n * @param factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler\n * @param lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run\n * @param timeout - Optional duration to determine how long the fact retriever should be allowed to run, defaults to 5 minutes\n * @param initialDelay - Optional initial delay to determine how long the fact retriever should wait before the initial run, defaults to 5 seconds\n *\n *\n * @remarks\n *\n * Cron expressions help:\n * ┌────────────── second (optional)\n # │ ┌──────────── minute\n # │ │ ┌────────── hour\n # │ │ │ ┌──────── day of month\n # │ │ │ │ ┌────── month\n # │ │ │ │ │ ┌──── day of week\n # │ │ │ │ │ │\n # │ │ │ │ │ │\n # * * * * * *\n *\n * Valid lifecycle values:\n * \\{ ttl: \\{ weeks: 2 \\} \\} -- This fact retriever will remove items that are older than 2 weeks when it is run\n * \\{ maxItems: 7 \\} -- This fact retriever will leave 7 newest items in the database when it is run\n *\n */\nexport function createFactRetrieverRegistration(\n options: FactRetrieverRegistrationOptions,\n): FactRetrieverRegistration {\n const { cadence, factRetriever, lifecycle, timeout, initialDelay } = options;\n return {\n cadence,\n factRetriever,\n lifecycle,\n timeout,\n initialDelay,\n };\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n FactRetriever,\n FactRetrieverContext,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { CatalogClient } from '@backstage/catalog-client';\nimport { Entity } from '@backstage/catalog-model';\nimport isEmpty from 'lodash/isEmpty';\n\n/**\n * Generates facts which indicate the completeness of entity metadata.\n *\n * @public\n */\nexport const entityMetadataFactRetriever: FactRetriever = {\n id: 'entityMetadataFactRetriever',\n version: '0.0.1',\n title: 'Entity Metadata',\n description:\n 'Generates facts which indicate the completeness of entity metadata',\n schema: {\n hasTitle: {\n type: 'boolean',\n description: 'The entity has a title in metadata',\n },\n hasDescription: {\n type: 'boolean',\n description: 'The entity has a description in metadata',\n },\n hasTags: {\n type: 'boolean',\n description: 'The entity has tags in metadata',\n },\n },\n handler: async ({ discovery, entityFilter, auth }: FactRetrieverContext) => {\n const { token } = await auth.getPluginRequestToken({\n onBehalfOf: await auth.getOwnServiceCredentials(),\n targetPluginId: 'catalog',\n });\n const catalogClient = new CatalogClient({\n discoveryApi: discovery,\n });\n const entities = await catalogClient.getEntities(\n { filter: entityFilter },\n { token },\n );\n\n return entities.items.map((entity: Entity) => {\n return {\n entity: {\n namespace: entity.metadata.namespace!,\n kind: entity.kind,\n name: entity.metadata.name,\n },\n facts: {\n hasTitle: Boolean(entity.metadata?.title),\n hasDescription: Boolean(entity.metadata?.description),\n hasTags: !isEmpty(entity.metadata?.tags),\n },\n };\n });\n },\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n FactRetriever,\n FactRetrieverContext,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { CatalogClient } from '@backstage/catalog-client';\nimport { Entity } from '@backstage/catalog-model';\n\n/**\n * Generates facts which indicate the quality of data in the spec.owner field.\n *\n * @public\n */\nexport const entityOwnershipFactRetriever: FactRetriever = {\n id: 'entityOwnershipFactRetriever',\n version: '0.0.1',\n title: 'Entity Ownership',\n description:\n 'Generates facts which indicate the quality of data in the spec.owner field',\n entityFilter: [\n { kind: ['component', 'domain', 'system', 'api', 'resource', 'template'] },\n ],\n schema: {\n hasOwner: {\n type: 'boolean',\n description: 'The spec.owner field is set',\n },\n hasGroupOwner: {\n type: 'boolean',\n description: 'The spec.owner field is set and refers to a group',\n },\n },\n handler: async ({ discovery, entityFilter, auth }: FactRetrieverContext) => {\n const { token } = await auth.getPluginRequestToken({\n onBehalfOf: await auth.getOwnServiceCredentials(),\n targetPluginId: 'catalog',\n });\n const catalogClient = new CatalogClient({\n discoveryApi: discovery,\n });\n const entities = await catalogClient.getEntities(\n { filter: entityFilter },\n { token },\n );\n\n return entities.items.map((entity: Entity) => {\n return {\n entity: {\n namespace: entity.metadata.namespace!,\n kind: entity.kind,\n name: entity.metadata.name,\n },\n facts: {\n hasOwner: Boolean(entity.spec?.owner),\n hasGroupOwner: Boolean(\n entity.spec?.owner &&\n !(entity.spec?.owner as string).startsWith('user:'),\n ),\n },\n };\n });\n },\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport camelCase from 'lodash/camelCase';\nimport { Entity } from '@backstage/catalog-model';\nimport { get } from 'lodash';\nimport {\n FactLifecycle,\n MaxItems,\n TTL,\n} from '@backstage-community/plugin-tech-insights-node';\n\nexport const generateAnnotationFactName = (annotation: string) =>\n camelCase(`hasAnnotation-${annotation}`);\n\nexport const entityHasAnnotation = (entity: Entity, annotation: string) =>\n Boolean(get(entity, ['metadata', 'annotations', annotation]));\n\nexport const isTtl = (lifecycle: FactLifecycle): lifecycle is TTL => {\n return !!(lifecycle as TTL).timeToLive;\n};\n\nexport const isMaxItems = (lifecycle: FactLifecycle): lifecycle is MaxItems => {\n return !!(lifecycle as MaxItems).maxItems;\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n FactRetriever,\n FactRetrieverContext,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { CatalogClient } from '@backstage/catalog-client';\nimport { Entity } from '@backstage/catalog-model';\nimport { entityHasAnnotation, generateAnnotationFactName } from './utils';\n\nconst techdocsAnnotation = 'backstage.io/techdocs-ref';\nconst techdocsAnnotationFactName =\n generateAnnotationFactName(techdocsAnnotation);\n\n/**\n * Generates facts related to the completeness of techdocs configuration for entities.\n *\n * @public\n */\nexport const techdocsFactRetriever: FactRetriever = {\n id: 'techdocsFactRetriever',\n version: '0.0.1',\n title: 'Tech Docs',\n description:\n 'Generates facts related to the completeness of techdocs configuration for entities',\n schema: {\n [techdocsAnnotationFactName]: {\n type: 'boolean',\n description: 'The entity has a TechDocs reference annotation',\n },\n },\n handler: async ({ discovery, entityFilter, auth }: FactRetrieverContext) => {\n const { token } = await auth.getPluginRequestToken({\n onBehalfOf: await auth.getOwnServiceCredentials(),\n targetPluginId: 'catalog',\n });\n const catalogClient = new CatalogClient({\n discoveryApi: discovery,\n });\n const entities = await catalogClient.getEntities(\n { filter: entityFilter },\n { token },\n );\n\n return entities.items.map((entity: Entity) => {\n return {\n entity: {\n namespace: entity.metadata.namespace!,\n kind: entity.kind,\n name: entity.metadata.name,\n },\n facts: {\n [techdocsAnnotationFactName]: entityHasAnnotation(\n entity,\n techdocsAnnotation,\n ),\n },\n };\n });\n },\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Knex } from 'knex';\nimport {\n FactLifecycle,\n FactSchemaDefinition,\n FlatTechInsightFact,\n TechInsightFact,\n TechInsightsStore,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { FactSchema } from '@backstage-community/plugin-tech-insights-common';\nimport { rsort } from 'semver';\nimport { groupBy, omit } from 'lodash';\nimport { DateTime } from 'luxon';\nimport { parseEntityRef, stringifyEntityRef } from '@backstage/catalog-model';\nimport { isMaxItems, isTtl } from '../fact/factRetrievers/utils';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\ntype Transaction = Knex.Transaction;\n\nexport type RawDbFactRow = {\n id: string;\n version: string;\n timestamp: Date | string;\n entity: string;\n facts: string;\n};\n\ntype RawDbFactSchemaRow = {\n id: string;\n version: string;\n schema: string;\n entityFilter?: string;\n};\n\n/**\n * Default TechInsightsDatabase implementation.\n *\n * @internal\n */\nexport class TechInsightsDatabase implements TechInsightsStore {\n private readonly CHUNK_SIZE = 50;\n\n constructor(\n private readonly db: Knex,\n private readonly logger: LoggerService,\n ) {}\n\n async getLatestSchemas(ids?: string[]): Promise<FactSchema[]> {\n const queryBuilder = this.db<RawDbFactSchemaRow>('fact_schemas');\n if (ids) {\n queryBuilder.whereIn('id', ids);\n }\n const existingSchemas = await queryBuilder.orderBy('id', 'desc').select();\n\n const groupedSchemas = groupBy(existingSchemas, 'id');\n return Object.values(groupedSchemas)\n .map(schemas => {\n const sorted = rsort(schemas.map(it => it.version));\n return schemas.find(it => it.version === sorted[0])!;\n })\n .map((it: RawDbFactSchemaRow) => ({\n ...omit(it, 'schema'),\n ...JSON.parse(it.schema),\n entityFilter: it.entityFilter ? JSON.parse(it.entityFilter) : null,\n }));\n }\n\n async insertFactSchema(schemaDefinition: FactSchemaDefinition) {\n const { id, version, schema, entityFilter } = schemaDefinition;\n const existingSchemas = await this.db<RawDbFactSchemaRow>('fact_schemas')\n .where({ id })\n .and.where({ version })\n .select();\n\n if (!existingSchemas || existingSchemas.length === 0) {\n await this.db<RawDbFactSchemaRow>('fact_schemas').insert({\n id,\n version,\n entityFilter: entityFilter ? JSON.stringify(entityFilter) : undefined,\n schema: JSON.stringify(schema),\n });\n }\n }\n\n async insertFacts({\n id,\n facts,\n lifecycle,\n }: {\n id: string;\n facts: TechInsightFact[];\n lifecycle?: FactLifecycle;\n }): Promise<void> {\n if (facts.length === 0) return;\n const currentSchema = await this.getLatestSchema(id);\n const factRows = facts.map(it => {\n const ts = it.timestamp?.toISO();\n return {\n id,\n version: currentSchema.version,\n entity: stringifyEntityRef(it.entity),\n facts: JSON.stringify(it.facts),\n ...(ts && { timestamp: ts }),\n };\n });\n\n await this.db.transaction(async tx => {\n await tx.batchInsert<RawDbFactRow>('facts', factRows, this.CHUNK_SIZE);\n\n if (lifecycle && isTtl(lifecycle)) {\n const expiration = DateTime.now().minus(lifecycle.timeToLive);\n await this.deleteExpiredFactsByDate(tx, id, expiration);\n }\n if (lifecycle && isMaxItems(lifecycle)) {\n await this.deleteExpiredFactsByNumber(tx, id, lifecycle.maxItems);\n }\n });\n }\n\n async getLatestFactsByIds(\n ids: string[],\n entityTriplet: string,\n ): Promise<{ [factId: string]: FlatTechInsightFact }> {\n const results = await this.db<RawDbFactRow>('facts')\n .where({ entity: entityTriplet })\n .and.whereIn('id', ids)\n .join(\n this.db('facts')\n .max('timestamp as maxTimestamp')\n .column('id as subId')\n .where({ entity: entityTriplet })\n .and.whereIn('id', ids)\n .groupBy('id')\n .as('subQ'),\n {\n 'facts.id': 'subQ.subId',\n 'facts.timestamp': 'subQ.maxTimestamp',\n },\n );\n return this.dbFactRowsToTechInsightFacts(results);\n }\n\n async getFactsBetweenTimestampsByIds(\n ids: string[],\n entityTriplet: string,\n startDateTime: DateTime,\n endDateTime: DateTime,\n ): Promise<{\n [factId: string]: FlatTechInsightFact[];\n }> {\n const results = await this.db<RawDbFactRow>('facts')\n .where({ entity: entityTriplet })\n .and.whereIn('id', ids)\n .and.whereBetween('timestamp', [\n startDateTime.toISO(),\n endDateTime.toISO(),\n ]);\n\n return groupBy(\n results.map(it => {\n const { namespace, kind, name } = parseEntityRef(it.entity);\n const timestamp =\n typeof it.timestamp === 'string'\n ? DateTime.fromISO(it.timestamp)\n : DateTime.fromJSDate(it.timestamp);\n return {\n id: it.id,\n entity: { namespace, kind, name },\n timestamp,\n version: it.version,\n facts: JSON.parse(it.facts),\n };\n }),\n 'id',\n );\n }\n\n private async getLatestSchema(id: string): Promise<RawDbFactSchemaRow> {\n const existingSchemas = await this.db<RawDbFactSchemaRow>('fact_schemas')\n .where({ id })\n .orderBy('id', 'desc')\n .select();\n if (existingSchemas.length < 1) {\n this.logger.warn(`No schema found for ${id}. `);\n throw new Error(`No schema found for ${id}. `);\n }\n const sorted = rsort(existingSchemas.map(it => it.version));\n return existingSchemas.find(it => it.version === sorted[0])!;\n }\n\n private async deleteExpiredFactsByDate(\n tx: Transaction,\n factRetrieverId: string,\n timestamp: DateTime,\n ) {\n await tx<RawDbFactRow>('facts')\n .where({ id: factRetrieverId })\n .and.where('timestamp', '<', timestamp.toISO())\n .delete();\n }\n\n private async deleteExpiredFactsByNumber(\n tx: Transaction,\n factRetrieverId: string,\n maxItems: number,\n ) {\n const deletionFilterQuery = (subTx: Knex.QueryBuilder<any, unknown[]>) =>\n subTx\n .select(['id', 'entity', 'timestamp'])\n .from('facts')\n .where({ id: factRetrieverId })\n .and.whereIn('entity', db =>\n db.distinct('entity').where({ id: factRetrieverId }),\n )\n .and.leftJoin(\n joinTable =>\n joinTable\n .select('*')\n .from(\n this.db('facts')\n .column(\n { fid: 'id' },\n { fentity: 'entity' },\n { ftimestamp: 'timestamp' },\n )\n .column(\n this.db.raw(\n 'row_number() over (partition by id, entity order by timestamp desc) as fact_rank',\n ),\n )\n .as('ranks'),\n )\n .where('fact_rank', '<=', maxItems)\n .as('filterjoin'),\n joinClause => {\n joinClause\n .on('filterjoin.fid', 'facts.id')\n .on('filterjoin.fentity', 'facts.entity')\n .on('filterjoin.ftimestamp', 'facts.timestamp');\n },\n )\n .whereNull('filterjoin.fid');\n await tx('facts')\n .whereIn(['id', 'entity', 'timestamp'], database =>\n deletionFilterQuery(database),\n )\n .delete();\n }\n\n private dbFactRowsToTechInsightFacts(rows: RawDbFactRow[]) {\n return rows.reduce((acc, it) => {\n const { namespace, kind, name } = parseEntityRef(it.entity);\n const timestamp =\n typeof it.timestamp === 'string'\n ? DateTime.fromISO(it.timestamp)\n : DateTime.fromJSDate(it.timestamp);\n return {\n ...acc,\n [it.id]: {\n id: it.id,\n entity: { namespace, kind, name },\n timestamp,\n version: it.version,\n facts: JSON.parse(it.facts),\n },\n };\n }, {});\n }\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n getVoidLogger,\n PluginDatabaseManager,\n resolvePackagePath,\n} from '@backstage/backend-common';\nimport { TechInsightsDatabase } from './TechInsightsDatabase';\nimport { PersistenceContext } from '@backstage-community/plugin-tech-insights-node';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\nconst migrationsDir = resolvePackagePath(\n '@backstage-community/plugin-tech-insights-backend',\n 'migrations',\n);\n\n/**\n * A Container for persistence context initialization options\n *\n * @public\n */\nexport type PersistenceContextOptions = {\n logger: LoggerService;\n};\n\nconst defaultOptions: PersistenceContextOptions = {\n logger: getVoidLogger(),\n};\n\n/**\n * A factory function to construct persistence context for running implementation.\n *\n * @public\n */\nexport const initializePersistenceContext = async (\n database: PluginDatabaseManager,\n options: PersistenceContextOptions = defaultOptions,\n): Promise<PersistenceContext> => {\n const client = await database.getClient();\n\n if (!database.migrations?.skip) {\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return {\n techInsightsStore: new TechInsightsDatabase(client, options.logger),\n };\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { Config } from '@backstage/config';\nimport {\n FactChecker,\n PersistenceContext,\n TechInsightCheck,\n} from '@backstage-community/plugin-tech-insights-node';\n\nimport { CheckResult } from '@backstage-community/plugin-tech-insights-common';\nimport { DateTime } from 'luxon';\nimport {\n CompoundEntityRef,\n parseEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { errorHandler } from '@backstage/backend-common';\nimport { serializeError } from '@backstage/errors';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\n/**\n * @public\n *\n * RouterOptions to construct TechInsights endpoints\n * @typeParam CheckType - Type of the check for the fact checker this builder returns\n * @typeParam CheckResultType - Type of the check result for the fact checker this builder returns\n */\nexport interface RouterOptions<\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n> {\n /**\n * Optional FactChecker implementation. If omitted, endpoints are not constructed\n */\n factChecker?: FactChecker<CheckType, CheckResultType>;\n\n /**\n * TechInsights PersistenceContext. Should contain an implementation of TechInsightsStore\n */\n persistenceContext: PersistenceContext;\n\n /**\n * Backstage config object\n */\n config: Config;\n\n /**\n * Implementation of Winston logger\n */\n logger: LoggerService;\n}\n\n/**\n * @public\n *\n * Constructs a tech-insights router.\n *\n * Exposes endpoints to handle facts\n * Exposes optional endpoints to handle checks if a FactChecker implementation is passed in\n *\n * @param options - RouterOptions object\n */\nexport async function createRouter<\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n>(options: RouterOptions<CheckType, CheckResultType>): Promise<express.Router> {\n const router = Router();\n router.use(express.json());\n const { persistenceContext, factChecker, logger } = options;\n const { techInsightsStore } = persistenceContext;\n\n if (factChecker) {\n logger.info('Fact checker configured. Enabling fact checking endpoints.');\n router.get('/checks', async (_req, res) => {\n return res.json(await factChecker.getChecks());\n });\n\n router.post('/checks/run/:namespace/:kind/:name', async (req, res) => {\n const { namespace, kind, name } = req.params;\n const { checks }: { checks: string[] } = req.body;\n const entityTriplet = stringifyEntityRef({ namespace, kind, name });\n const checkResult = await factChecker.runChecks(entityTriplet, checks);\n return res.json(checkResult);\n });\n\n router.post('/checks/run', async (req, res) => {\n const {\n checks,\n entities,\n }: { checks: string[]; entities: CompoundEntityRef[] } = req.body;\n const tasks = entities.map(async entity => {\n const entityTriplet =\n typeof entity === 'string' ? entity : stringifyEntityRef(entity);\n try {\n const results = await factChecker.runChecks(entityTriplet, checks);\n return {\n entity: entityTriplet,\n results,\n };\n } catch (e: any) {\n const error = serializeError(e);\n logger.error(`${error.name}: ${error.message}`);\n return {\n entity: entityTriplet,\n error: error,\n results: [],\n };\n }\n });\n const results = await Promise.all(tasks);\n return res.json(results);\n });\n } else {\n logger.info(\n 'Starting tech insights module without fact checking endpoints.',\n );\n }\n\n router.get('/fact-schemas', async (req, res) => {\n const ids = req.query.ids as string[];\n return res.json(await techInsightsStore.getLatestSchemas(ids));\n });\n\n /**\n * /facts/latest?entity=component:default/mycomponent&ids[]=factRetrieverId1&ids[]=factRetrieverId2\n */\n router.get('/facts/latest', async (req, res) => {\n const { entity } = req.query;\n const { namespace, kind, name } = parseEntityRef(entity as string);\n\n if (!req.query.ids) {\n return res\n .status(422)\n .json({ error: 'Failed to parse ids from request' });\n }\n const ids = [req.query.ids].flat() as string[];\n return res.json(\n await techInsightsStore.getLatestFactsByIds(\n ids,\n stringifyEntityRef({ namespace, kind, name }),\n ),\n );\n });\n\n /**\n * /facts/range?entity=component:default/mycomponent&startDateTime=2021-12-24T01:23:45&endDateTime=2021-12-31T23:59:59&ids[]=factRetrieverId1&ids[]=factRetrieverId2\n */\n router.get('/facts/range', async (req, res) => {\n const { entity } = req.query;\n const { namespace, kind, name } = parseEntityRef(entity as string);\n\n if (!req.query.ids) {\n return res\n .status(422)\n .json({ error: 'Failed to parse ids from request' });\n }\n const ids = [req.query.ids].flat() as string[];\n const startDatetime = DateTime.fromISO(req.query.startDatetime as string);\n const endDatetime = DateTime.fromISO(req.query.endDatetime as string);\n if (!startDatetime.isValid || !endDatetime.isValid) {\n return res.status(422).json({\n message: 'Failed to parse datetime from request',\n field: !startDatetime.isValid ? 'startDateTime' : 'endDateTime',\n value: !startDatetime.isValid ? startDatetime : endDatetime,\n });\n }\n const entityTriplet = stringifyEntityRef({ namespace, kind, name });\n return res.json(\n await techInsightsStore.getFactsBetweenTimestampsByIds(\n ids,\n entityTriplet,\n startDatetime,\n endDatetime,\n ),\n );\n });\n\n router.use(errorHandler());\n return router;\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n FactLifecycle,\n FactRetriever,\n FactRetrieverContext,\n FactRetrieverRegistration,\n FactRetrieverRegistry,\n TechInsightFact,\n TechInsightsStore,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { PluginTaskScheduler } from '@backstage/backend-tasks';\nimport { Duration } from 'luxon';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\nfunction randomDailyCron() {\n const rand = (min: number, max: number) =>\n Math.floor(Math.random() * (max - min + 1) + min);\n return `${rand(0, 59)} ${rand(0, 23)} * * *`;\n}\n\nfunction duration(startTimestamp: [number, number]): string {\n const delta = process.hrtime(startTimestamp);\n const seconds = delta[0] + delta[1] / 1e9;\n return `${seconds.toFixed(1)}s`;\n}\n\n/**\n * @public\n *\n * FactRetrieverEngine responsible scheduling and running fact retrieval tasks.\n */\nexport interface FactRetrieverEngine {\n /**\n * Schedules fact retriever run cycles based on configuration provided in the registration.\n *\n * Default implementation uses backend-tasks to handle scheduling. This function can be called multiple\n * times, where initial calls schedule the tasks and subsequent invocations update the schedules.\n */\n schedule(): Promise<void>;\n\n /**\n * Provides possibility to manually run a fact retriever job and construct fact data\n *\n * @param ref - Reference to the task name stored in the executor database. By convention this is the fact retriever id\n */\n triggerJob(ref: string): Promise<void>;\n\n /**\n * Exposes fact retriever job configuration information about previous and next runs and schedule\n *\n * @param ref - Reference to the task name stored in the executor database. By convention this is the fact retriever id\n */\n getJobRegistration(ref: string): Promise<FactRetrieverRegistration>;\n}\n\nexport class DefaultFactRetrieverEngine implements FactRetrieverEngine {\n private constructor(\n private readonly repository: TechInsightsStore,\n private readonly factRetrieverRegistry: FactRetrieverRegistry,\n private readonly factRetrieverContext: FactRetrieverContext,\n private readonly logger: LoggerService,\n private readonly scheduler: PluginTaskScheduler,\n private readonly defaultCadence?: string,\n private readonly defaultTimeout?: Duration,\n private readonly defaultInitialDelay?: Duration,\n ) {}\n\n static async create(options: {\n repository: TechInsightsStore;\n factRetrieverRegistry: FactRetrieverRegistry;\n factRetrieverContext: FactRetrieverContext;\n scheduler: PluginTaskScheduler;\n defaultCadence?: string;\n defaultTimeout?: Duration;\n defaultInitialDelay?: Duration;\n }) {\n const {\n repository,\n factRetrieverRegistry,\n factRetrieverContext,\n scheduler,\n defaultCadence,\n defaultTimeout,\n defaultInitialDelay,\n } = options;\n\n const retrievers = await factRetrieverRegistry.listRetrievers();\n await Promise.all(retrievers.map(it => repository.insertFactSchema(it)));\n\n return new DefaultFactRetrieverEngine(\n repository,\n factRetrieverRegistry,\n factRetrieverContext,\n factRetrieverContext.logger,\n scheduler,\n defaultCadence,\n defaultTimeout,\n defaultInitialDelay,\n );\n }\n\n async schedule() {\n const registrations = await this.factRetrieverRegistry.listRegistrations();\n const newRegs: string[] = [];\n\n await Promise.all(\n registrations.map(async registration => {\n const { factRetriever, cadence, lifecycle, timeout, initialDelay } =\n registration;\n const cronExpression =\n cadence || this.defaultCadence || randomDailyCron();\n const timeLimit =\n timeout || this.defaultTimeout || Duration.fromObject({ minutes: 5 });\n const initialDelaySetting =\n initialDelay ||\n this.defaultInitialDelay ||\n Duration.fromObject({ seconds: 5 });\n try {\n await this.scheduler.scheduleTask({\n id: factRetriever.id,\n frequency: { cron: cronExpression },\n fn: this.createFactRetrieverHandler(factRetriever, lifecycle),\n timeout: timeLimit,\n // We add a delay in order to prevent errors due to the\n // fact that the backend is not yet online in a cold-start scenario\n initialDelay: initialDelaySetting,\n });\n newRegs.push(factRetriever.id);\n } catch (e) {\n this.logger.warn(\n `Failed to schedule fact retriever ${factRetriever.id}, ${e}`,\n );\n }\n }),\n );\n\n this.logger.info(\n `Scheduled ${newRegs.length}/${registrations.length} fact retrievers into the tech-insights engine`,\n );\n }\n\n getJobRegistration(ref: string): Promise<FactRetrieverRegistration> {\n return this.factRetrieverRegistry.get(ref);\n }\n\n async triggerJob(ref: string): Promise<void> {\n await this.scheduler.triggerTask(ref);\n }\n\n private createFactRetrieverHandler(\n factRetriever: FactRetriever,\n lifecycle?: FactLifecycle,\n ) {\n return async () => {\n const startTimestamp = process.hrtime();\n this.logger.info(\n `Retrieving facts for fact retriever ${factRetriever.id}`,\n );\n\n let facts: TechInsightFact[] = [];\n try {\n facts = await factRetriever.handler({\n ...this.factRetrieverContext,\n logger: this.logger.child({ factRetrieverId: factRetriever.id }),\n entityFilter: factRetriever.entityFilter,\n });\n this.logger.debug(\n `Retrieved ${facts.length} facts for fact retriever ${\n factRetriever.id\n } in ${duration(startTimestamp)}`,\n );\n } catch (e) {\n this.logger.error(\n `Failed to retrieve facts for retriever ${factRetriever.id}`,\n e,\n );\n }\n\n try {\n await this.repository.insertFacts({\n id: factRetriever.id,\n facts,\n lifecycle,\n });\n this.logger.info(\n `Stored ${facts.length} facts for fact retriever ${\n factRetriever.id\n } in ${duration(startTimestamp)}`,\n );\n } catch (e) {\n this.logger.warn(\n `Failed to insert facts for fact retriever ${factRetriever.id}`,\n e,\n );\n }\n };\n }\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n FactRetriever,\n FactRetrieverRegistration,\n FactRetrieverRegistry,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { FactSchema } from '@backstage-community/plugin-tech-insights-common';\nimport { ConflictError, NotFoundError } from '@backstage/errors';\n\n/**\n * A basic in memory fact retriever registry.\n *\n * You can replace this with a persistence based version using the FactRetrieverRegistry interface.\n *\n */\nexport class DefaultFactRetrieverRegistry implements FactRetrieverRegistry {\n private readonly retrievers = new Map<string, FactRetrieverRegistration>();\n\n constructor(retrievers: FactRetrieverRegistration[]) {\n retrievers.forEach(r => {\n this.registerSync(r);\n });\n }\n\n registerSync(registration: FactRetrieverRegistration) {\n if (this.retrievers.has(registration.factRetriever.id)) {\n throw new ConflictError(\n `Tech insight fact retriever with identifier '${registration.factRetriever.id}' has already been registered`,\n );\n }\n this.retrievers.set(registration.factRetriever.id, registration);\n }\n\n async register(registration: FactRetrieverRegistration) {\n this.registerSync(registration);\n }\n\n async get(retrieverReference: string): Promise<FactRetrieverRegistration> {\n const registration = this.retrievers.get(retrieverReference);\n if (!registration) {\n throw new NotFoundError(\n `Tech insight fact retriever with identifier '${retrieverReference}' is not registered.`,\n );\n }\n return registration;\n }\n\n async listRetrievers(): Promise<FactRetriever[]> {\n return [...this.retrievers.values()].map(it => it.factRetriever);\n }\n\n async listRegistrations(): Promise<FactRetrieverRegistration[]> {\n return [...this.retrievers.values()];\n }\n\n async getSchemas(): Promise<FactSchema[]> {\n const retrievers = await this.listRetrievers();\n return retrievers.map(it => it.schema);\n }\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DefaultFactRetrieverEngine,\n FactRetrieverEngine,\n} from './fact/FactRetrieverEngine';\nimport { DefaultFactRetrieverRegistry } from './fact/FactRetrieverRegistry';\nimport { Config } from '@backstage/config';\nimport {\n createLegacyAuthAdapters,\n PluginDatabaseManager,\n PluginEndpointDiscovery,\n TokenManager,\n} from '@backstage/backend-common';\nimport {\n FactChecker,\n FactCheckerFactory,\n FactRetrieverRegistration,\n FactRetrieverRegistry,\n PersistenceContext,\n TechInsightCheck,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { initializePersistenceContext } from './persistence';\nimport { CheckResult } from '@backstage-community/plugin-tech-insights-common';\nimport { PluginTaskScheduler } from '@backstage/backend-tasks';\nimport { AuthService, LoggerService } from '@backstage/backend-plugin-api';\n\n/**\n * @public\n * @typeParam CheckType - Type of the check for the fact checker this builder returns\n * @typeParam CheckResultType - Type of the check result for the fact checker this builder returns\n *\n * Configuration options to initialize TechInsightsBuilder. Generic types params are needed if FactCheckerFactory\n * is included for FactChecker creation.\n */\nexport interface TechInsightsOptions<\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n> {\n /**\n * Optional collection of FactRetrieverRegistrations (required if no factRetrieverRegistry passed in).\n * Used to register FactRetrievers and their schemas and schedule an execution loop for them.\n *\n * Not needed if passing in your own FactRetrieverRegistry implementation. Required otherwise.\n */\n factRetrievers?: FactRetrieverRegistration[];\n\n /**\n * Optional factory exposing a `construct` method to initialize a FactChecker implementation\n */\n factCheckerFactory?: FactCheckerFactory<CheckType, CheckResultType>;\n\n /**\n * Optional FactRetrieverRegistry implementation that replaces the default one.\n *\n * If passing this in you don't need to pass in factRetrievers also.\n */\n factRetrieverRegistry?: FactRetrieverRegistry;\n\n /**\n * Optional persistenceContext implementation that replaces the default one.\n * This can be used to replace underlying database with a more suitable implementation if needed\n */\n persistenceContext?: PersistenceContext;\n\n logger: LoggerService;\n config: Config;\n discovery: PluginEndpointDiscovery;\n database: PluginDatabaseManager;\n scheduler: PluginTaskScheduler;\n tokenManager: TokenManager;\n auth?: AuthService;\n}\n\n/**\n * @public\n * @typeParam CheckType - Type of the check for the fact checker this builder returns\n * @typeParam CheckResultType - Type of the check result for the fact checker this builder returns\n *\n * A container for exported implementations related to TechInsights.\n * FactChecker is present if an optional FactCheckerFactory is included in the build stage.\n */\nexport type TechInsightsContext<\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n> = {\n factChecker?: FactChecker<CheckType, CheckResultType>;\n persistenceContext: PersistenceContext;\n factRetrieverEngine: FactRetrieverEngine;\n};\n\n/**\n * @public\n *\n * Constructs needed persistence context, fact retriever engine\n * and optionally fact checker implementations to be used in the tech insights module.\n *\n * @param options - Needed options to construct TechInsightsContext\n * @returns TechInsightsContext with persistence implementations and optionally an implementation of a FactChecker\n */\nexport const buildTechInsightsContext = async <\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n>(\n options: TechInsightsOptions<CheckType, CheckResultType>,\n): Promise<TechInsightsContext<CheckType, CheckResultType>> => {\n const {\n factRetrievers,\n factCheckerFactory,\n config,\n discovery,\n database,\n logger,\n scheduler,\n tokenManager,\n } = options;\n\n const buildFactRetrieverRegistry = (): FactRetrieverRegistry => {\n if (!options.factRetrieverRegistry) {\n if (!factRetrievers) {\n throw new Error(\n 'Failed to build FactRetrieverRegistry because no factRetrievers found',\n );\n }\n return new DefaultFactRetrieverRegistry(factRetrievers);\n }\n return options.factRetrieverRegistry;\n };\n\n const factRetrieverRegistry = buildFactRetrieverRegistry();\n\n const persistenceContext =\n options.persistenceContext ??\n (await initializePersistenceContext(database, {\n logger,\n }));\n\n const { auth } = createLegacyAuthAdapters({\n auth: options.auth,\n tokenManager,\n discovery,\n });\n\n const factRetrieverEngine = await DefaultFactRetrieverEngine.create({\n scheduler,\n repository: persistenceContext.techInsightsStore,\n factRetrieverRegistry,\n factRetrieverContext: {\n config,\n discovery,\n logger,\n tokenManager,\n auth,\n },\n });\n\n await factRetrieverEngine.schedule();\n\n if (factCheckerFactory) {\n const factChecker = factCheckerFactory.construct(\n persistenceContext.techInsightsStore,\n );\n return {\n persistenceContext,\n factChecker,\n factRetrieverEngine,\n };\n }\n\n return {\n persistenceContext,\n factRetrieverEngine,\n };\n};\n","/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config, readDurationFromConfig } from '@backstage/config';\nimport {\n FactLifecycle,\n FactRetriever,\n FactRetrieverRegistration,\n} from '@backstage-community/plugin-tech-insights-node';\nimport {\n createFactRetrieverRegistration,\n FactRetrieverRegistrationOptions,\n} from '../service';\n\ntype FactRetrieverConfig = Omit<\n FactRetrieverRegistrationOptions,\n 'factRetriever'\n>;\n\nfunction readLifecycleConfig(\n config: Config | undefined,\n): FactLifecycle | undefined {\n if (!config) {\n return undefined;\n }\n\n if (config.has('maxItems')) {\n return {\n maxItems: config.getNumber('maxItems'),\n };\n }\n\n return {\n timeToLive: readDurationFromConfig(config.getConfig('timeToLive')),\n };\n}\n\nfunction readFactRetrieverConfig(\n config: Config,\n name: string,\n): FactRetrieverConfig | undefined {\n const factRetrieverConfig = config.getOptionalConfig(\n `techInsights.factRetrievers.${name}`,\n );\n if (!factRetrieverConfig) {\n return undefined;\n }\n\n const cadence = factRetrieverConfig.getString('cadence');\n const initialDelay = factRetrieverConfig.has('initialDelay')\n ? readDurationFromConfig(factRetrieverConfig.getConfig('initialDelay'))\n : undefined;\n const lifecycle = readLifecycleConfig(\n factRetrieverConfig.getOptionalConfig('lifecycle'),\n );\n const timeout = factRetrieverConfig.has('timeout')\n ? readDurationFromConfig(factRetrieverConfig.getConfig('timeout'))\n : undefined;\n\n return {\n cadence,\n initialDelay,\n lifecycle,\n timeout,\n };\n}\n\nexport function createFactRetrieverRegistrationFromConfig(\n config: Config,\n name: string,\n factRetriever: FactRetriever,\n): FactRetrieverRegistration | undefined {\n const factRetrieverConfig = readFactRetrieverConfig(config, name);\n\n return factRetrieverConfig\n ? createFactRetrieverRegistration({\n ...factRetrieverConfig,\n factRetriever,\n })\n : undefined;\n}\n","/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { CheckResult } from '@backstage-community/plugin-tech-insights-common';\nimport {\n FactCheckerFactory,\n FactRetriever,\n FactRetrieverRegistration,\n FactRetrieverRegistry,\n PersistenceContext,\n TechInsightCheck,\n techInsightsFactCheckerFactoryExtensionPoint,\n techInsightsFactRetrieverRegistryExtensionPoint,\n techInsightsFactRetrieversExtensionPoint,\n techInsightsPersistenceContextExtensionPoint,\n} from '@backstage-community/plugin-tech-insights-node';\nimport {\n buildTechInsightsContext,\n createRouter,\n entityMetadataFactRetriever,\n entityOwnershipFactRetriever,\n techdocsFactRetriever,\n} from '../service';\nimport { createFactRetrieverRegistrationFromConfig } from './config';\n\n/**\n * The tech-insights backend plugin.\n *\n * @public\n */\nexport const techInsightsPlugin = createBackendPlugin({\n pluginId: 'tech-insights',\n register(env) {\n let factCheckerFactory:\n | FactCheckerFactory<TechInsightCheck, CheckResult>\n | undefined = undefined;\n env.registerExtensionPoint(techInsightsFactCheckerFactoryExtensionPoint, {\n setFactCheckerFactory<\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n >(factory: FactCheckerFactory<CheckType, CheckResultType>): void {\n factCheckerFactory = factory;\n },\n });\n\n let factRetrieverRegistry: FactRetrieverRegistry | undefined = undefined;\n env.registerExtensionPoint(\n techInsightsFactRetrieverRegistryExtensionPoint,\n {\n setFactRetrieverRegistry(registry: FactRetrieverRegistry): void {\n factRetrieverRegistry = registry;\n },\n },\n );\n\n // initialized with built-in fact retrievers\n // only added as registration if there is config for them\n const addedFactRetrievers: Record<string, FactRetriever> = {\n entityMetadataFactRetriever,\n entityOwnershipFactRetriever,\n techdocsFactRetriever,\n };\n env.registerExtensionPoint(techInsightsFactRetrieversExtensionPoint, {\n addFactRetrievers(factRetrievers: Record<string, FactRetriever>): void {\n Object.entries(factRetrievers).forEach(([key, value]) => {\n addedFactRetrievers[key] = value;\n });\n },\n });\n\n let persistenceContext: PersistenceContext | undefined = undefined;\n env.registerExtensionPoint(techInsightsPersistenceContextExtensionPoint, {\n setPersistenceContext(context: PersistenceContext): void {\n persistenceContext = context;\n },\n });\n\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n database: coreServices.database,\n discovery: coreServices.discovery,\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n tokenManager: coreServices.tokenManager,\n auth: coreServices.auth,\n },\n async init({\n config,\n database,\n discovery,\n httpRouter,\n logger,\n scheduler,\n tokenManager,\n auth,\n }) {\n const factRetrievers: FactRetrieverRegistration[] = Object.entries(\n addedFactRetrievers,\n )\n .map(([name, factRetriever]) =>\n createFactRetrieverRegistrationFromConfig(\n config,\n name,\n factRetriever,\n ),\n )\n .filter(registration => registration) as FactRetrieverRegistration[];\n\n const context = await buildTechInsightsContext({\n config,\n database,\n discovery,\n factCheckerFactory,\n factRetrieverRegistry,\n factRetrievers,\n logger,\n persistenceContext,\n scheduler,\n tokenManager,\n auth,\n });\n\n httpRouter.use(\n await createRouter({\n ...context,\n config,\n logger,\n }),\n );\n },\n });\n },\n});\n"],"names":["catalogClient","CatalogClient","isEmpty","camelCase","get","__publicField","groupBy","rsort","omit","stringifyEntityRef","DateTime","parseEntityRef","resolvePackagePath","getVoidLogger","Router","express","results","serializeError","errorHandler","Duration","ConflictError","NotFoundError","createLegacyAuthAdapters","config","readDurationFromConfig","createBackendPlugin","techInsightsFactCheckerFactoryExtensionPoint","techInsightsFactRetrieverRegistryExtensionPoint","techInsightsFactRetrieversExtensionPoint","techInsightsPersistenceContextExtensionPoint","coreServices"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsEO,SAAS,gCACd,OAC2B,EAAA;A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AAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;;;;;;;"}
@@ -0,0 +1,240 @@
1
+ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
+ import { LoggerService, AuthService } from '@backstage/backend-plugin-api';
3
+ import { FactRetrieverRegistry as FactRetrieverRegistry$1, PersistenceContext as PersistenceContext$1, FactRetriever, FactLifecycle, FactRetrieverRegistration, TechInsightCheck, FactChecker, FactCheckerFactory } from '@backstage-community/plugin-tech-insights-node';
4
+ import { HumanDuration } from '@backstage/types';
5
+ import { Duration } from 'luxon';
6
+ import { PluginDatabaseManager, PluginEndpointDiscovery, TokenManager } from '@backstage/backend-common';
7
+ import express from 'express';
8
+ import { Config } from '@backstage/config';
9
+ import { CheckResult } from '@backstage-community/plugin-tech-insights-common';
10
+ import { PluginTaskScheduler } from '@backstage/backend-tasks';
11
+
12
+ /**
13
+ * The tech-insights backend plugin.
14
+ *
15
+ * @public
16
+ */
17
+ declare const techInsightsPlugin: () => _backstage_backend_plugin_api.BackendFeature;
18
+
19
+ /**
20
+ * @public
21
+ * @deprecated Use FactRetrieverRegistry from `@backstage-community/plugin-tech-insights-node` instead.
22
+ */
23
+ type FactRetrieverRegistry = FactRetrieverRegistry$1;
24
+ /**
25
+ * @public
26
+ * @deprecated Use PersistenceContext from `@backstage-community/plugin-tech-insights-node` instead.
27
+ */
28
+ type PersistenceContext = PersistenceContext$1;
29
+
30
+ /**
31
+ * @public
32
+ *
33
+ * @param cadence - cron expression to indicate when the fact retriever should be triggered
34
+ * @param factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler
35
+ * @param lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run
36
+ * @param timeout - Optional duration to determine how long the fact retriever should be allowed to run, defaults to 5 minutes
37
+ *
38
+ */
39
+ type FactRetrieverRegistrationOptions = {
40
+ cadence: string;
41
+ factRetriever: FactRetriever;
42
+ lifecycle?: FactLifecycle;
43
+ timeout?: Duration | HumanDuration;
44
+ initialDelay?: Duration | HumanDuration;
45
+ };
46
+ /**
47
+ * @public
48
+ *
49
+ * A helper function to construct fact retriever registrations.
50
+ * @param cadence - Cron expression to indicate when the fact retriever should be triggered
51
+ * @param factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler
52
+ * @param lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run
53
+ * @param timeout - Optional duration to determine how long the fact retriever should be allowed to run, defaults to 5 minutes
54
+ * @param initialDelay - Optional initial delay to determine how long the fact retriever should wait before the initial run, defaults to 5 seconds
55
+ *
56
+ *
57
+ * @remarks
58
+ *
59
+ * Cron expressions help:
60
+ * ┌────────────── second (optional)
61
+ # │ ┌──────────── minute
62
+ # │ │ ┌────────── hour
63
+ # │ │ │ ┌──────── day of month
64
+ # │ │ │ │ ┌────── month
65
+ # │ │ │ │ │ ┌──── day of week
66
+ # │ │ │ │ │ │
67
+ # │ │ │ │ │ │
68
+ # * * * * * *
69
+ *
70
+ * Valid lifecycle values:
71
+ * \{ ttl: \{ weeks: 2 \} \} -- This fact retriever will remove items that are older than 2 weeks when it is run
72
+ * \{ maxItems: 7 \} -- This fact retriever will leave 7 newest items in the database when it is run
73
+ *
74
+ */
75
+ declare function createFactRetrieverRegistration(options: FactRetrieverRegistrationOptions): FactRetrieverRegistration;
76
+
77
+ /**
78
+ * @public
79
+ *
80
+ * FactRetrieverEngine responsible scheduling and running fact retrieval tasks.
81
+ */
82
+ interface FactRetrieverEngine {
83
+ /**
84
+ * Schedules fact retriever run cycles based on configuration provided in the registration.
85
+ *
86
+ * Default implementation uses backend-tasks to handle scheduling. This function can be called multiple
87
+ * times, where initial calls schedule the tasks and subsequent invocations update the schedules.
88
+ */
89
+ schedule(): Promise<void>;
90
+ /**
91
+ * Provides possibility to manually run a fact retriever job and construct fact data
92
+ *
93
+ * @param ref - Reference to the task name stored in the executor database. By convention this is the fact retriever id
94
+ */
95
+ triggerJob(ref: string): Promise<void>;
96
+ /**
97
+ * Exposes fact retriever job configuration information about previous and next runs and schedule
98
+ *
99
+ * @param ref - Reference to the task name stored in the executor database. By convention this is the fact retriever id
100
+ */
101
+ getJobRegistration(ref: string): Promise<FactRetrieverRegistration>;
102
+ }
103
+
104
+ /**
105
+ * Generates facts which indicate the completeness of entity metadata.
106
+ *
107
+ * @public
108
+ */
109
+ declare const entityMetadataFactRetriever: FactRetriever;
110
+
111
+ /**
112
+ * Generates facts which indicate the quality of data in the spec.owner field.
113
+ *
114
+ * @public
115
+ */
116
+ declare const entityOwnershipFactRetriever: FactRetriever;
117
+
118
+ /**
119
+ * Generates facts related to the completeness of techdocs configuration for entities.
120
+ *
121
+ * @public
122
+ */
123
+ declare const techdocsFactRetriever: FactRetriever;
124
+
125
+ /**
126
+ * A Container for persistence context initialization options
127
+ *
128
+ * @public
129
+ */
130
+ type PersistenceContextOptions = {
131
+ logger: LoggerService;
132
+ };
133
+ /**
134
+ * A factory function to construct persistence context for running implementation.
135
+ *
136
+ * @public
137
+ */
138
+ declare const initializePersistenceContext: (database: PluginDatabaseManager, options?: PersistenceContextOptions) => Promise<PersistenceContext$1>;
139
+
140
+ /**
141
+ * @public
142
+ *
143
+ * RouterOptions to construct TechInsights endpoints
144
+ * @typeParam CheckType - Type of the check for the fact checker this builder returns
145
+ * @typeParam CheckResultType - Type of the check result for the fact checker this builder returns
146
+ */
147
+ interface RouterOptions<CheckType extends TechInsightCheck, CheckResultType extends CheckResult> {
148
+ /**
149
+ * Optional FactChecker implementation. If omitted, endpoints are not constructed
150
+ */
151
+ factChecker?: FactChecker<CheckType, CheckResultType>;
152
+ /**
153
+ * TechInsights PersistenceContext. Should contain an implementation of TechInsightsStore
154
+ */
155
+ persistenceContext: PersistenceContext$1;
156
+ /**
157
+ * Backstage config object
158
+ */
159
+ config: Config;
160
+ /**
161
+ * Implementation of Winston logger
162
+ */
163
+ logger: LoggerService;
164
+ }
165
+ /**
166
+ * @public
167
+ *
168
+ * Constructs a tech-insights router.
169
+ *
170
+ * Exposes endpoints to handle facts
171
+ * Exposes optional endpoints to handle checks if a FactChecker implementation is passed in
172
+ *
173
+ * @param options - RouterOptions object
174
+ */
175
+ declare function createRouter<CheckType extends TechInsightCheck, CheckResultType extends CheckResult>(options: RouterOptions<CheckType, CheckResultType>): Promise<express.Router>;
176
+
177
+ /**
178
+ * @public
179
+ * @typeParam CheckType - Type of the check for the fact checker this builder returns
180
+ * @typeParam CheckResultType - Type of the check result for the fact checker this builder returns
181
+ *
182
+ * Configuration options to initialize TechInsightsBuilder. Generic types params are needed if FactCheckerFactory
183
+ * is included for FactChecker creation.
184
+ */
185
+ interface TechInsightsOptions<CheckType extends TechInsightCheck, CheckResultType extends CheckResult> {
186
+ /**
187
+ * Optional collection of FactRetrieverRegistrations (required if no factRetrieverRegistry passed in).
188
+ * Used to register FactRetrievers and their schemas and schedule an execution loop for them.
189
+ *
190
+ * Not needed if passing in your own FactRetrieverRegistry implementation. Required otherwise.
191
+ */
192
+ factRetrievers?: FactRetrieverRegistration[];
193
+ /**
194
+ * Optional factory exposing a `construct` method to initialize a FactChecker implementation
195
+ */
196
+ factCheckerFactory?: FactCheckerFactory<CheckType, CheckResultType>;
197
+ /**
198
+ * Optional FactRetrieverRegistry implementation that replaces the default one.
199
+ *
200
+ * If passing this in you don't need to pass in factRetrievers also.
201
+ */
202
+ factRetrieverRegistry?: FactRetrieverRegistry$1;
203
+ /**
204
+ * Optional persistenceContext implementation that replaces the default one.
205
+ * This can be used to replace underlying database with a more suitable implementation if needed
206
+ */
207
+ persistenceContext?: PersistenceContext$1;
208
+ logger: LoggerService;
209
+ config: Config;
210
+ discovery: PluginEndpointDiscovery;
211
+ database: PluginDatabaseManager;
212
+ scheduler: PluginTaskScheduler;
213
+ tokenManager: TokenManager;
214
+ auth?: AuthService;
215
+ }
216
+ /**
217
+ * @public
218
+ * @typeParam CheckType - Type of the check for the fact checker this builder returns
219
+ * @typeParam CheckResultType - Type of the check result for the fact checker this builder returns
220
+ *
221
+ * A container for exported implementations related to TechInsights.
222
+ * FactChecker is present if an optional FactCheckerFactory is included in the build stage.
223
+ */
224
+ type TechInsightsContext<CheckType extends TechInsightCheck, CheckResultType extends CheckResult> = {
225
+ factChecker?: FactChecker<CheckType, CheckResultType>;
226
+ persistenceContext: PersistenceContext$1;
227
+ factRetrieverEngine: FactRetrieverEngine;
228
+ };
229
+ /**
230
+ * @public
231
+ *
232
+ * Constructs needed persistence context, fact retriever engine
233
+ * and optionally fact checker implementations to be used in the tech insights module.
234
+ *
235
+ * @param options - Needed options to construct TechInsightsContext
236
+ * @returns TechInsightsContext with persistence implementations and optionally an implementation of a FactChecker
237
+ */
238
+ declare const buildTechInsightsContext: <CheckType extends TechInsightCheck, CheckResultType extends CheckResult>(options: TechInsightsOptions<CheckType, CheckResultType>) => Promise<TechInsightsContext<CheckType, CheckResultType>>;
239
+
240
+ export { type FactRetrieverEngine, type FactRetrieverRegistrationOptions, type FactRetrieverRegistry, type PersistenceContext, type PersistenceContextOptions, type RouterOptions, type TechInsightsContext, type TechInsightsOptions, buildTechInsightsContext, createFactRetrieverRegistration, createRouter, techInsightsPlugin as default, entityMetadataFactRetriever, entityOwnershipFactRetriever, initializePersistenceContext, techdocsFactRetriever };
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright 2021 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // @ts-check
18
+
19
+ /**
20
+ * @param {import('knex').Knex} knex
21
+ */
22
+ exports.up = async function up(knex) {
23
+ await knex.schema.createTable('fact_schemas', table => {
24
+ table.comment(
25
+ 'The table for tech insight fact schemas. Containing a versioned data model definition for a collection of facts.',
26
+ );
27
+ table
28
+ .string('id')
29
+ .notNullable()
30
+ .comment('Identifier of the fact retriever plugin/package');
31
+ table
32
+ .string('version')
33
+ .notNullable()
34
+ .comment('SemVer string defining the version of schema.');
35
+ table
36
+ .string('entityFilter')
37
+ .nullable()
38
+ .comment(
39
+ 'A serialized entity filter object used to determine which entities this schema is applicable to.',
40
+ );
41
+ table
42
+ .text('schema')
43
+ .notNullable()
44
+ .comment(
45
+ 'Fact schema defining the values/types what this version of the fact would contain.',
46
+ );
47
+ table.primary(['id', 'version']);
48
+ table.index('id', 'fact_schema_id_idx');
49
+ });
50
+ };
51
+
52
+ /**
53
+ * @param {import('knex').Knex} knex
54
+ */
55
+ exports.down = async function down(knex) {
56
+ await knex.schema.alterTable('fact_schemas', table => {
57
+ table.dropIndex([], 'fact_schema_id_idx');
58
+ });
59
+ await knex.schema.dropTable('fact_schemas');
60
+ };
@@ -0,0 +1,72 @@
1
+ /*
2
+ * Copyright 2021 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // @ts-check
18
+
19
+ /**
20
+ * @param {import('knex').Knex} knex
21
+ */
22
+ exports.up = async function up(knex) {
23
+ await knex.schema.createTable('facts', table => {
24
+ table.comment(
25
+ 'The table for tech insight fact collections. Contains facts for individual fact retriever namespace/ref.',
26
+ );
27
+ table
28
+ .string('id')
29
+ .notNullable()
30
+ .comment('Unique identifier of the fact retriever plugin/package');
31
+ table
32
+ .string('version')
33
+ .notNullable()
34
+ .comment(
35
+ 'SemVer string defining the version of schema this fact is based on.',
36
+ );
37
+ table
38
+ .dateTime('timestamp')
39
+ .defaultTo(knex.fn.now())
40
+ .notNullable()
41
+ .comment('The timestamp when this entry was created');
42
+ table
43
+ .string('entity')
44
+ .notNullable()
45
+ .comment('Identifier of the entity these facts relate to');
46
+ table
47
+ .text('facts')
48
+ .notNullable()
49
+ .comment(
50
+ 'Values of the fact collection stored as key-value pairs in JSON format.',
51
+ );
52
+
53
+ table
54
+ .foreign(['id', 'version'])
55
+ .references(['id', 'version'])
56
+ .inTable('fact_schemas');
57
+
58
+ table.index(['id', 'entity'], 'fact_id_entity_idx');
59
+ table.index('id', 'fact_id_idx');
60
+ });
61
+ };
62
+
63
+ /**
64
+ * @param {import('knex').Knex} knex
65
+ */
66
+ exports.down = async function down(knex) {
67
+ await knex.schema.alterTable('facts', table => {
68
+ table.dropIndex([], 'fact_id_idx');
69
+ table.dropIndex([], 'fact_id_entity_idx');
70
+ });
71
+ await knex.schema.dropTable('facts');
72
+ };
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright 2021 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // @ts-check
18
+
19
+ /**
20
+ * @param {import('knex').Knex} knex
21
+ */
22
+ exports.up = async function up(knex) {
23
+ await knex.schema.alterTable('facts', table => {
24
+ table
25
+ .dateTime('timestamp', { precision: 0 })
26
+ .defaultTo(knex.fn.now())
27
+ .notNullable()
28
+ .comment('The timestamp when this entry was created')
29
+ .alter();
30
+ });
31
+ };
32
+
33
+ /**
34
+ * @param {import('knex').Knex} _knex
35
+ */
36
+ exports.down = async function down(_knex) {};
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright 2023 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const indexName = 'fact_id_entity_timestamp_idx';
18
+ /**
19
+ * @param { import("knex").Knex } knex
20
+ * @returns { Promise<void> }
21
+ */
22
+ exports.up = async knex => {
23
+ await knex.schema.alterTable('facts', table => {
24
+ table.index(['id', 'entity', 'timestamp'], indexName);
25
+ });
26
+ };
27
+
28
+ /**
29
+ * @param { import("knex").Knex } knex
30
+ * @returns { Promise<void> }
31
+ */
32
+ exports.down = async knex => {
33
+ await knex.schema.alterTable('facts', table => {
34
+ table.dropIndex(indexName);
35
+ });
36
+ };