refactoring some codes, names and dependency
Signed-off-by: Alisson Fabiano <afabiano@eshopworld.com>
This commit is contained in:
@@ -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<string, JsonValue>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -84,10 +72,7 @@ export interface TechInsightsApi {
|
||||
// (undocumented)
|
||||
getCheckResultRenderers: (types: string[]) => CheckResultRenderer[];
|
||||
// (undocumented)
|
||||
getLatestFacts(
|
||||
entity: CompoundEntityRef,
|
||||
facts: string[],
|
||||
): Promise<InsightFact>;
|
||||
getFacts(entity: CompoundEntityRef, facts: string[]): Promise<InsightFacts>;
|
||||
// (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<InsightFact>;
|
||||
getFacts(entity: CompoundEntityRef, facts: string[]): Promise<InsightFacts>;
|
||||
// (undocumented)
|
||||
runBulkChecks(
|
||||
entities: CompoundEntityRef[],
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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<BulkCheckResponse>;
|
||||
getLatestFacts(
|
||||
entity: CompoundEntityRef,
|
||||
facts: string[],
|
||||
): Promise<InsightFact>;
|
||||
getFacts(entity: CompoundEntityRef, facts: string[]): Promise<InsightFacts>;
|
||||
}
|
||||
|
||||
@@ -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<InsightFact> {
|
||||
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<InsightFact>(
|
||||
`/facts/latest?${entityQuery}&${idsQuery}`,
|
||||
);
|
||||
): Promise<InsightFacts> {
|
||||
const query = qs.stringify({
|
||||
entity: stringifyEntityRef(entity),
|
||||
ids: facts,
|
||||
});
|
||||
return await this.api<InsightFacts>(`/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);
|
||||
}
|
||||
|
||||
@@ -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<string, JsonValue>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user