diff --git a/plugins/tech-insights/api-report.md b/plugins/tech-insights/api-report.md index b40bf9fe92..2d25d6d39d 100644 --- a/plugins/tech-insights/api-report.md +++ b/plugins/tech-insights/api-report.md @@ -10,7 +10,6 @@ import { BackstagePlugin } from '@backstage/core-plugin-api'; import { BulkCheckResponse } from '@backstage/plugin-tech-insights-common'; import { CheckResult } from '@backstage/plugin-tech-insights-common'; import { CompoundEntityRef } from '@backstage/catalog-model'; -import { DateTime } from 'luxon'; import { DiscoveryApi } from '@backstage/core-plugin-api'; import { IdentityApi } from '@backstage/core-plugin-api'; import { JsonValue } from '@backstage/types'; @@ -54,23 +53,12 @@ export const EntityTechInsightsScorecardContent: (props: { }) => JSX.Element; // @public -export interface InsightFact { +export interface InsightFacts { // (undocumented) [factId: string]: { timestamp: string; version: string; - facts: Record< - string, - | number - | string - | boolean - | DateTime - | number[] - | string[] - | boolean[] - | DateTime[] - | JsonValue - >; + facts: Record; }; } @@ -84,10 +72,7 @@ export interface TechInsightsApi { // (undocumented) getCheckResultRenderers: (types: string[]) => CheckResultRenderer[]; // (undocumented) - getLatestFacts( - entity: CompoundEntityRef, - facts: string[], - ): Promise; + getFacts(entity: CompoundEntityRef, facts: string[]): Promise; // (undocumented) runBulkChecks( entities: CompoundEntityRef[], @@ -115,10 +100,7 @@ export class TechInsightsClient implements TechInsightsApi { // (undocumented) getCheckResultRenderers(types: string[]): CheckResultRenderer[]; // (undocumented) - getLatestFacts( - entity: CompoundEntityRef, - facts: string[], - ): Promise; + getFacts(entity: CompoundEntityRef, facts: string[]): Promise; // (undocumented) runBulkChecks( entities: CompoundEntityRef[], diff --git a/plugins/tech-insights/package.json b/plugins/tech-insights/package.json index 3903881daa..7d1d091095 100644 --- a/plugins/tech-insights/package.json +++ b/plugins/tech-insights/package.json @@ -38,8 +38,7 @@ "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", "@material-ui/lab": "4.0.0-alpha.57", - "@types/luxon": "^3.0.1", - "luxon": "^3.0.3", + "qs": "^6.11.0", "react-use": "^17.2.4" }, "peerDependencies": { diff --git a/plugins/tech-insights/src/api/TechInsightsApi.ts b/plugins/tech-insights/src/api/TechInsightsApi.ts index 79754d53b1..166f1d2782 100644 --- a/plugins/tech-insights/src/api/TechInsightsApi.ts +++ b/plugins/tech-insights/src/api/TechInsightsApi.ts @@ -19,7 +19,7 @@ import { CheckResult, BulkCheckResponse, } from '@backstage/plugin-tech-insights-common'; -import { Check, InsightFact } from './types'; +import { Check, InsightFacts } from './types'; import { CheckResultRenderer } from '../components/CheckResultRenderer'; import { CompoundEntityRef } from '@backstage/catalog-model'; @@ -48,8 +48,5 @@ export interface TechInsightsApi { entities: CompoundEntityRef[], checks?: Check[], ): Promise; - getLatestFacts( - entity: CompoundEntityRef, - facts: string[], - ): Promise; + getFacts(entity: CompoundEntityRef, facts: string[]): Promise; } diff --git a/plugins/tech-insights/src/api/TechInsightsClient.ts b/plugins/tech-insights/src/api/TechInsightsClient.ts index bcfb045d00..9bdeb119f9 100644 --- a/plugins/tech-insights/src/api/TechInsightsClient.ts +++ b/plugins/tech-insights/src/api/TechInsightsClient.ts @@ -19,15 +19,19 @@ import { BulkCheckResponse, CheckResult, } from '@backstage/plugin-tech-insights-common'; -import { Check, InsightFact } from './types'; +import { Check, InsightFacts } from './types'; import { DiscoveryApi, IdentityApi } from '@backstage/core-plugin-api'; import { ResponseError } from '@backstage/errors'; -import { CompoundEntityRef } from '@backstage/catalog-model'; +import { + CompoundEntityRef, + stringifyEntityRef, +} from '@backstage/catalog-model'; import { CheckResultRenderer, jsonRulesEngineCheckResultRenderer, } from '../components/CheckResultRenderer'; +import qs from 'qs'; /** @public */ export class TechInsightsClient implements TechInsightsApi { @@ -45,18 +49,15 @@ export class TechInsightsClient implements TechInsightsApi { this.renderers = options.renderers; } - async getLatestFacts( + async getFacts( entity: CompoundEntityRef, facts: string[], - ): Promise { - const { namespace, kind, name } = entity; - const entityQuery = `entity=${encodeURIComponent( - kind.toLocaleLowerCase('en-US'), - )}:${encodeURIComponent(namespace)}/${encodeURIComponent(name)}`; - const idsQuery = facts.map(id => `ids[]=${id}`).join('&'); - return await this.api( - `/facts/latest?${entityQuery}&${idsQuery}`, - ); + ): Promise { + const query = qs.stringify({ + entity: stringifyEntityRef(entity), + ids: facts, + }); + return await this.api(`/facts/latest?${query}`); } getCheckResultRenderers(types: string[]): CheckResultRenderer[] { @@ -104,13 +105,15 @@ export class TechInsightsClient implements TechInsightsApi { const url = await this.discoveryApi.getBaseUrl('tech-insights'); const { token } = await this.identityApi.getCredentials(); - return fetch(`${url}${path}`, { - ...init, - headers: { - 'Content-Type': 'application/json', - ...(token && { Authorization: `Bearer ${token}` }), - }, - }).then(async response => { + const request = new Request(`${url}${path}`, init); + if (!request.headers.has('content-type')) { + request.headers.set('content-type', 'application/json'); + } + if (token && !request.headers.has('authorization')) { + request.headers.set('authorization', `Bearer ${token}`); + } + + return fetch(request).then(async response => { if (!response.ok) { throw await ResponseError.fromResponse(response); } diff --git a/plugins/tech-insights/src/api/types.ts b/plugins/tech-insights/src/api/types.ts index b69d4d6264..ac1f2e44ee 100644 --- a/plugins/tech-insights/src/api/types.ts +++ b/plugins/tech-insights/src/api/types.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { DateTime } from 'luxon'; import { JsonValue } from '@backstage/types'; /** @@ -35,21 +34,10 @@ export type Check = { * * @public */ -export interface InsightFact { +export interface InsightFacts { [factId: string]: { timestamp: string; version: string; - facts: Record< - string, - | number - | string - | boolean - | DateTime - | number[] - | string[] - | boolean[] - | DateTime[] - | JsonValue - >; + facts: Record; }; } diff --git a/plugins/tech-insights/src/index.ts b/plugins/tech-insights/src/index.ts index ae2f9d53a7..9e075df038 100644 --- a/plugins/tech-insights/src/index.ts +++ b/plugins/tech-insights/src/index.ts @@ -20,7 +20,7 @@ export { } from './plugin'; export { techInsightsApiRef, TechInsightsClient } from './api'; -export type { TechInsightsApi, Check, InsightFact } from './api'; +export type { TechInsightsApi, Check, InsightFacts } from './api'; export { BooleanCheck } from './components/BooleanCheck'; export { jsonRulesEngineCheckResultRenderer } from './components/CheckResultRenderer'; export type { CheckResultRenderer } from './components/CheckResultRenderer'; diff --git a/yarn.lock b/yarn.lock index 116e774711..03e3a36d0b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6934,11 +6934,10 @@ __metadata: "@testing-library/jest-dom": ^5.10.1 "@testing-library/react": ^12.1.3 "@testing-library/user-event": ^14.0.0 - "@types/luxon": ^3.0.1 "@types/node": ^16.11.26 cross-fetch: ^3.1.5 - luxon: ^3.0.3 msw: ^0.47.0 + qs: ^6.11.0 react-use: ^17.2.4 peerDependencies: "@types/react": ^16.13.1 || ^17.0.0 @@ -14476,13 +14475,6 @@ __metadata: languageName: node linkType: hard -"@types/luxon@npm:^3.0.1": - version: 3.0.1 - resolution: "@types/luxon@npm:3.0.1" - checksum: a81444f9b474ea9b3063ab4cc68b917a2634e38b4e229f86c78c35023a32bf5e8d1044d7c229c011291662c976cb6c4cf109dc3d2077c571790a31779a554178 - languageName: node - linkType: hard - "@types/markdown-it@npm:^12.2.3": version: 12.2.3 resolution: "@types/markdown-it@npm:12.2.3" @@ -29349,13 +29341,6 @@ __metadata: languageName: node linkType: hard -"luxon@npm:^3.0.3": - version: 3.0.3 - resolution: "luxon@npm:3.0.3" - checksum: 67d143f102f520761c4202086579a5cf30b230ea299da27cacb31e9f9d372cadef90f14cbe7e2621b70825b267fe00128b8176ed8b7172b48f77a403a662d5aa - languageName: node - linkType: hard - "lz-string@npm:^1.4.4": version: 1.4.4 resolution: "lz-string@npm:1.4.4" @@ -34244,6 +34229,15 @@ __metadata: languageName: node linkType: hard +"qs@npm:^6.11.0": + version: 6.11.0 + resolution: "qs@npm:6.11.0" + dependencies: + side-channel: ^1.0.4 + checksum: 6e1f29dd5385f7488ec74ac7b6c92f4d09a90408882d0c208414a34dd33badc1a621019d4c799a3df15ab9b1d0292f97c1dd71dc7c045e69f81a8064e5af7297 + languageName: node + linkType: hard + "qs@npm:~6.5.2": version: 6.5.2 resolution: "qs@npm:6.5.2"