@backstage-community/plugin-badges 0.10.0 → 0.11.1
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.
- package/CHANGELOG.md +12 -0
- package/dist/api/BadgesClient.esm.js +12 -3
- package/dist/api/BadgesClient.esm.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @backstage-community/plugin-badges
|
|
2
2
|
|
|
3
|
+
## 0.11.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2681d87: Fixes a bug where badge style and color query parameters were not passed when badge obfuscation was enabled, causing badge style filtering to not work in the UI.
|
|
8
|
+
|
|
9
|
+
## 0.11.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- dad55b1: Backstage version bump to v1.41.1
|
|
14
|
+
|
|
3
15
|
## 0.10.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -22,7 +22,8 @@ class BadgesClient {
|
|
|
22
22
|
return data.uuid;
|
|
23
23
|
});
|
|
24
24
|
const entityUuidBadgeSpecsUrl = await this.getEntityUuidBadgeSpecsUrl(
|
|
25
|
-
entityUuid
|
|
25
|
+
entityUuid,
|
|
26
|
+
badgeOptions
|
|
26
27
|
);
|
|
27
28
|
const response2 = await this.fetchApi.fetch(entityUuidBadgeSpecsUrl);
|
|
28
29
|
if (!response2.ok) {
|
|
@@ -54,9 +55,17 @@ class BadgesClient {
|
|
|
54
55
|
}
|
|
55
56
|
return await responseEntityUuid.json();
|
|
56
57
|
}
|
|
57
|
-
async getEntityUuidBadgeSpecsUrl(entityUuid) {
|
|
58
|
+
async getEntityUuidBadgeSpecsUrl(entityUuid, badgeOptions) {
|
|
58
59
|
const baseUrl = await this.discoveryApi.getBaseUrl("badges");
|
|
59
|
-
|
|
60
|
+
const queries = [];
|
|
61
|
+
if (badgeOptions.style) {
|
|
62
|
+
queries.push(`style=${badgeOptions.style}`);
|
|
63
|
+
}
|
|
64
|
+
if (badgeOptions.color) {
|
|
65
|
+
queries.push(`color=${badgeOptions.color}`);
|
|
66
|
+
}
|
|
67
|
+
const queryString = queries.length > 0 ? `?${queries.join("&")}` : "";
|
|
68
|
+
return `${baseUrl}/entity/${entityUuid}/badge-specs${queryString}`;
|
|
60
69
|
}
|
|
61
70
|
async getEntityBadgeSpecsUrl(entity, badgeOptions) {
|
|
62
71
|
const routeParams = this.getEntityRouteParams(entity);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BadgesClient.esm.js","sources":["../../src/api/BadgesClient.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 { generatePath } from 'react-router-dom';\nimport { ResponseError } from '@backstage/errors';\nimport { Entity, DEFAULT_NAMESPACE } from '@backstage/catalog-model';\nimport { BadgesApi, BadgeSpec, BadgeStyleOptions } from './types';\nimport { ConfigApi, DiscoveryApi, FetchApi } from '@backstage/core-plugin-api';\n\nexport class BadgesClient implements BadgesApi {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n private readonly configApi: ConfigApi;\n\n constructor(options: {\n discoveryApi: DiscoveryApi;\n fetchApi: FetchApi;\n configApi: ConfigApi;\n }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi;\n this.configApi = options.configApi;\n }\n\n static fromConfig(options: {\n fetchApi: FetchApi;\n discoveryApi: DiscoveryApi;\n configApi: ConfigApi;\n }) {\n return new BadgesClient(options);\n }\n\n public async getEntityBadgeSpecs(\n entity: Entity,\n badgeOptions: BadgeStyleOptions,\n ): Promise<BadgeSpec[]> {\n // Check if obfuscation is enabled in the configuration\n const obfuscate = this.configApi.getOptionalBoolean('app.badges.obfuscate');\n\n if (obfuscate) {\n const entityUuidUrl = await this.getEntityUuidUrl(entity);\n const entityUuid = await this.getEntityUuid(entityUuidUrl).then(data => {\n return data.uuid;\n });\n const entityUuidBadgeSpecsUrl = await this.getEntityUuidBadgeSpecsUrl(\n entityUuid,\n );\n\n const response = await this.fetchApi.fetch(entityUuidBadgeSpecsUrl);\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n return await response.json();\n }\n\n // If obfuscation is disabled, get the badge specs directly as the previous implementation\n const entityBadgeSpecsUrl = await this.getEntityBadgeSpecsUrl(\n entity,\n badgeOptions,\n );\n const response = await this.fetchApi.fetch(entityBadgeSpecsUrl);\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n return await response.json();\n }\n\n private async getEntityUuidUrl(entity: Entity): Promise<string> {\n const routeParams = this.getEntityRouteParams(entity);\n const path = generatePath(`:namespace/:kind/:name`, routeParams);\n const baseUrl = await this.discoveryApi.getBaseUrl('badges');\n const obfuscatedEntityUrl = `${baseUrl}/entity/${path}/obfuscated`;\n\n return obfuscatedEntityUrl;\n }\n\n private async getEntityUuid(entityUuidUrl: string): Promise<any> {\n const responseEntityUuid = await this.fetchApi.fetch(entityUuidUrl);\n\n if (!responseEntityUuid.ok) {\n throw await ResponseError.fromResponse(responseEntityUuid);\n }\n return await responseEntityUuid.json();\n }\n\n private async getEntityUuidBadgeSpecsUrl(entityUuid: {
|
|
1
|
+
{"version":3,"file":"BadgesClient.esm.js","sources":["../../src/api/BadgesClient.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 { generatePath } from 'react-router-dom';\nimport { ResponseError } from '@backstage/errors';\nimport { Entity, DEFAULT_NAMESPACE } from '@backstage/catalog-model';\nimport { BadgesApi, BadgeSpec, BadgeStyleOptions } from './types';\nimport { ConfigApi, DiscoveryApi, FetchApi } from '@backstage/core-plugin-api';\n\nexport class BadgesClient implements BadgesApi {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n private readonly configApi: ConfigApi;\n\n constructor(options: {\n discoveryApi: DiscoveryApi;\n fetchApi: FetchApi;\n configApi: ConfigApi;\n }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi;\n this.configApi = options.configApi;\n }\n\n static fromConfig(options: {\n fetchApi: FetchApi;\n discoveryApi: DiscoveryApi;\n configApi: ConfigApi;\n }) {\n return new BadgesClient(options);\n }\n\n public async getEntityBadgeSpecs(\n entity: Entity,\n badgeOptions: BadgeStyleOptions,\n ): Promise<BadgeSpec[]> {\n // Check if obfuscation is enabled in the configuration\n const obfuscate = this.configApi.getOptionalBoolean('app.badges.obfuscate');\n\n if (obfuscate) {\n const entityUuidUrl = await this.getEntityUuidUrl(entity);\n const entityUuid = await this.getEntityUuid(entityUuidUrl).then(data => {\n return data.uuid;\n });\n const entityUuidBadgeSpecsUrl = await this.getEntityUuidBadgeSpecsUrl(\n entityUuid,\n badgeOptions,\n );\n\n const response = await this.fetchApi.fetch(entityUuidBadgeSpecsUrl);\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n return await response.json();\n }\n\n // If obfuscation is disabled, get the badge specs directly as the previous implementation\n const entityBadgeSpecsUrl = await this.getEntityBadgeSpecsUrl(\n entity,\n badgeOptions,\n );\n const response = await this.fetchApi.fetch(entityBadgeSpecsUrl);\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n return await response.json();\n }\n\n private async getEntityUuidUrl(entity: Entity): Promise<string> {\n const routeParams = this.getEntityRouteParams(entity);\n const path = generatePath(`:namespace/:kind/:name`, routeParams);\n const baseUrl = await this.discoveryApi.getBaseUrl('badges');\n const obfuscatedEntityUrl = `${baseUrl}/entity/${path}/obfuscated`;\n\n return obfuscatedEntityUrl;\n }\n\n private async getEntityUuid(entityUuidUrl: string): Promise<any> {\n const responseEntityUuid = await this.fetchApi.fetch(entityUuidUrl);\n\n if (!responseEntityUuid.ok) {\n throw await ResponseError.fromResponse(responseEntityUuid);\n }\n return await responseEntityUuid.json();\n }\n\n private async getEntityUuidBadgeSpecsUrl(\n entityUuid: { uuid: string },\n badgeOptions: BadgeStyleOptions,\n ): Promise<string> {\n const baseUrl = await this.discoveryApi.getBaseUrl('badges');\n const queries: string[] = [];\n if (badgeOptions.style) {\n queries.push(`style=${badgeOptions.style}`);\n }\n if (badgeOptions.color) {\n queries.push(`color=${badgeOptions.color}`);\n }\n const queryString = queries.length > 0 ? `?${queries.join('&')}` : '';\n return `${baseUrl}/entity/${entityUuid}/badge-specs${queryString}`;\n }\n\n private async getEntityBadgeSpecsUrl(\n entity: Entity,\n badgeOptions: BadgeStyleOptions,\n ): Promise<string> {\n const routeParams = this.getEntityRouteParams(entity);\n const path = generatePath(`:namespace/:kind/:name`, routeParams);\n const baseUrl = await this.discoveryApi.getBaseUrl('badges');\n const queries: string[] = [];\n if (badgeOptions.style) {\n queries.push(`style=${badgeOptions.style}`);\n }\n if (badgeOptions.color) {\n queries.push(`color=${badgeOptions.color}`);\n }\n return `${baseUrl}/entity/${path}/badge-specs?${queries.join('&')}`;\n }\n\n // This function is used to generate the route parameters using the entity kind, namespace and name\n private getEntityRouteParams(entity: Entity) {\n return {\n kind: entity.kind.toLocaleLowerCase('en-US'),\n namespace:\n entity.metadata.namespace?.toLocaleLowerCase('en-US') ??\n DEFAULT_NAMESPACE,\n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,iBAAA,CAAkB,OAAO,CACpD,IAAA,iBAAA;AAAA,MACF,IAAA,EAAM,OAAO,QAAS,CAAA;AAAA,KACxB;AAAA;AAEJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage-community/plugin-badges",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "A Backstage plugin that generates README badges for your entities",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "frontend-plugin",
|
|
@@ -38,19 +38,19 @@
|
|
|
38
38
|
"test": "backstage-cli package test"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@backstage/catalog-model": "^1.7.
|
|
42
|
-
"@backstage/core-components": "^0.17.
|
|
43
|
-
"@backstage/core-plugin-api": "^1.10.
|
|
41
|
+
"@backstage/catalog-model": "^1.7.5",
|
|
42
|
+
"@backstage/core-components": "^0.17.4",
|
|
43
|
+
"@backstage/core-plugin-api": "^1.10.9",
|
|
44
44
|
"@backstage/errors": "^1.2.7",
|
|
45
|
-
"@backstage/plugin-catalog-react": "^1.19.
|
|
45
|
+
"@backstage/plugin-catalog-react": "^1.19.1",
|
|
46
46
|
"@material-ui/core": "^4.12.2",
|
|
47
47
|
"@types/react": "^16.13.1 || ^17.0.0 || ^18.0.0",
|
|
48
48
|
"react-use": "^17.2.4"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@backstage/cli": "^0.33.
|
|
52
|
-
"@backstage/dev-utils": "^1.1.
|
|
53
|
-
"@backstage/test-utils": "^1.7.
|
|
51
|
+
"@backstage/cli": "^0.33.1",
|
|
52
|
+
"@backstage/dev-utils": "^1.1.12",
|
|
53
|
+
"@backstage/test-utils": "^1.7.10",
|
|
54
54
|
"@testing-library/dom": "^10.0.0",
|
|
55
55
|
"@testing-library/jest-dom": "^6.0.0",
|
|
56
56
|
"@testing-library/react": "^15.0.0",
|