@backstage/frontend-app-api 0.7.1 → 0.7.2
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
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @backstage/frontend-app-api
|
|
2
2
|
|
|
3
|
+
## 0.7.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5a5afe1: Allow for the disabling of external routes through config, which was rendered impossible after the introduction of default targets.
|
|
8
|
+
|
|
9
|
+
```yaml
|
|
10
|
+
app:
|
|
11
|
+
routes:
|
|
12
|
+
bindings:
|
|
13
|
+
# This has the effect of removing the button for registering new
|
|
14
|
+
# catalog entities in the scaffolder template list view
|
|
15
|
+
scaffolder.registerComponent: false
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @backstage/core-app-api@1.13.0
|
|
20
|
+
- @backstage/core-components@0.14.8
|
|
21
|
+
- @backstage/core-plugin-api@1.9.3
|
|
22
|
+
- @backstage/frontend-plugin-api@0.6.6
|
|
23
|
+
- @backstage/config@1.2.0
|
|
24
|
+
- @backstage/errors@1.2.4
|
|
25
|
+
- @backstage/theme@0.5.6
|
|
26
|
+
- @backstage/types@1.1.1
|
|
27
|
+
- @backstage/version-bridge@1.0.8
|
|
28
|
+
|
|
3
29
|
## 0.7.1
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/config.d.ts
CHANGED
|
@@ -26,9 +26,14 @@ export interface Config {
|
|
|
26
26
|
|
|
27
27
|
routes?: {
|
|
28
28
|
/**
|
|
29
|
+
* Maps external route references to regular route references. Both the
|
|
30
|
+
* key and the value is expected to be on the form `<pluginId>.<routeId>`.
|
|
31
|
+
* If the value is `false`, the route will be disabled even if it has a
|
|
32
|
+
* default mapping.
|
|
33
|
+
*
|
|
29
34
|
* @deepVisibility frontend
|
|
30
35
|
*/
|
|
31
|
-
bindings?: { [externalRouteRefId: string]: string };
|
|
36
|
+
bindings?: { [externalRouteRefId: string]: string | false };
|
|
32
37
|
};
|
|
33
38
|
|
|
34
39
|
/**
|
|
@@ -22,11 +22,12 @@ function resolveRouteBindings(bindRoutes, config, routesById) {
|
|
|
22
22
|
bindRoutes({ bind });
|
|
23
23
|
}
|
|
24
24
|
const bindings = config.getOptionalConfig("app.routes.bindings")?.get();
|
|
25
|
+
const disabledExternalRefs = /* @__PURE__ */ new Set();
|
|
25
26
|
if (bindings) {
|
|
26
27
|
for (const [externalRefId, targetRefId] of Object.entries(bindings)) {
|
|
27
|
-
if (
|
|
28
|
+
if (!isValidTargetRefId(targetRefId)) {
|
|
28
29
|
throw new Error(
|
|
29
|
-
`Invalid config at app.routes.bindings['${externalRefId}'], value must be a non-empty string`
|
|
30
|
+
`Invalid config at app.routes.bindings['${externalRefId}'], value must be a non-empty string or false`
|
|
30
31
|
);
|
|
31
32
|
}
|
|
32
33
|
const externalRef = routesById.externalRoutes.get(externalRefId);
|
|
@@ -35,20 +36,22 @@ function resolveRouteBindings(bindRoutes, config, routesById) {
|
|
|
35
36
|
`Invalid config at app.routes.bindings, '${externalRefId}' is not a valid external route`
|
|
36
37
|
);
|
|
37
38
|
}
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
if (targetRefId === false) {
|
|
40
|
+
disabledExternalRefs.add(externalRef);
|
|
41
|
+
result.delete(externalRef);
|
|
42
|
+
} else if (!result.has(externalRef)) {
|
|
43
|
+
const targetRef = routesById.routes.get(targetRefId);
|
|
44
|
+
if (!targetRef) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Invalid config at app.routes.bindings['${externalRefId}'], '${targetRefId}' is not a valid route`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
result.set(externalRef, targetRef);
|
|
46
50
|
}
|
|
47
|
-
result.set(externalRef, targetRef);
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
for (const externalRef of routesById.externalRoutes.values()) {
|
|
51
|
-
if (!result.has(externalRef)) {
|
|
54
|
+
if (!result.has(externalRef) && !disabledExternalRefs.has(externalRef)) {
|
|
52
55
|
const defaultRefId = toInternalExternalRouteRef(externalRef).getDefaultTarget();
|
|
53
56
|
if (defaultRefId) {
|
|
54
57
|
const defaultRef = routesById.routes.get(defaultRefId);
|
|
@@ -60,6 +63,15 @@ function resolveRouteBindings(bindRoutes, config, routesById) {
|
|
|
60
63
|
}
|
|
61
64
|
return result;
|
|
62
65
|
}
|
|
66
|
+
function isValidTargetRefId(value) {
|
|
67
|
+
if (value === false) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (typeof value === "string" && value) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
63
75
|
|
|
64
76
|
export { resolveRouteBindings };
|
|
65
77
|
//# sourceMappingURL=resolveRouteBindings.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveRouteBindings.esm.js","sources":["../../src/routing/resolveRouteBindings.ts"],"sourcesContent":["/*\n * Copyright 2020 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 RouteRef,\n SubRouteRef,\n ExternalRouteRef,\n} from '@backstage/frontend-plugin-api';\nimport { RouteRefsById } from './collectRouteIds';\nimport { Config } from '@backstage/config';\nimport { JsonObject } from '@backstage/types';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalExternalRouteRef } from '../../../frontend-plugin-api/src/routing/ExternalRouteRef';\n\n/**\n * Extracts a union of the keys in a map whose value extends the given type\n *\n * @ignore\n */\ntype KeysWithType<Obj extends { [key in string]: any }, Type> = {\n [key in keyof Obj]: Obj[key] extends Type ? key : never;\n}[keyof Obj];\n\n/**\n * Takes a map Map required values and makes all keys matching Keys optional\n *\n * @ignore\n */\ntype PartialKeys<\n Map extends { [name in string]: any },\n Keys extends keyof Map,\n> = Partial<Pick<Map, Keys>> & Required<Omit<Map, Keys>>;\n\n/**\n * Creates a map of target routes with matching parameters based on a map of external routes.\n *\n * @ignore\n */\ntype TargetRouteMap<\n ExternalRoutes extends { [name: string]: ExternalRouteRef },\n> = {\n [name in keyof ExternalRoutes]: ExternalRoutes[name] extends ExternalRouteRef<\n infer Params,\n any\n >\n ? RouteRef<Params> | SubRouteRef<Params>\n : never;\n};\n\n/**\n * A function that can bind from external routes of a given plugin, to concrete\n * routes of other plugins. See {@link createApp}.\n *\n * @public\n */\nexport type CreateAppRouteBinder = <\n TExternalRoutes extends { [name: string]: ExternalRouteRef },\n>(\n externalRoutes: TExternalRoutes,\n targetRoutes: PartialKeys<\n TargetRouteMap<TExternalRoutes>,\n KeysWithType<TExternalRoutes, ExternalRouteRef<any, true>>\n >,\n) => void;\n\n/** @internal */\nexport function resolveRouteBindings(\n bindRoutes: ((context: { bind: CreateAppRouteBinder }) => void) | undefined,\n config: Config,\n routesById: RouteRefsById,\n): Map<ExternalRouteRef, RouteRef | SubRouteRef> {\n const result = new Map<ExternalRouteRef, RouteRef | SubRouteRef>();\n\n // Perform callback bindings first with highest priority\n if (bindRoutes) {\n const bind: CreateAppRouteBinder = (\n externalRoutes,\n targetRoutes: { [name: string]: RouteRef | SubRouteRef },\n ) => {\n for (const [key, value] of Object.entries(targetRoutes)) {\n const externalRoute = externalRoutes[key];\n if (!externalRoute) {\n throw new Error(`Key ${key} is not an existing external route`);\n }\n if (!value && !externalRoute.optional) {\n throw new Error(\n `External route ${key} is required but was undefined`,\n );\n }\n if (value) {\n result.set(externalRoute, value);\n }\n }\n };\n bindRoutes({ bind });\n }\n\n // Then perform config based bindings with lower priority\n const bindings = config\n .getOptionalConfig('app.routes.bindings')\n ?.get<JsonObject>();\n if (bindings) {\n for (const [externalRefId, targetRefId] of Object.entries(bindings)) {\n if (
|
|
1
|
+
{"version":3,"file":"resolveRouteBindings.esm.js","sources":["../../src/routing/resolveRouteBindings.ts"],"sourcesContent":["/*\n * Copyright 2020 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 RouteRef,\n SubRouteRef,\n ExternalRouteRef,\n} from '@backstage/frontend-plugin-api';\nimport { RouteRefsById } from './collectRouteIds';\nimport { Config } from '@backstage/config';\nimport { JsonObject } from '@backstage/types';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalExternalRouteRef } from '../../../frontend-plugin-api/src/routing/ExternalRouteRef';\n\n/**\n * Extracts a union of the keys in a map whose value extends the given type\n *\n * @ignore\n */\ntype KeysWithType<Obj extends { [key in string]: any }, Type> = {\n [key in keyof Obj]: Obj[key] extends Type ? key : never;\n}[keyof Obj];\n\n/**\n * Takes a map Map required values and makes all keys matching Keys optional\n *\n * @ignore\n */\ntype PartialKeys<\n Map extends { [name in string]: any },\n Keys extends keyof Map,\n> = Partial<Pick<Map, Keys>> & Required<Omit<Map, Keys>>;\n\n/**\n * Creates a map of target routes with matching parameters based on a map of external routes.\n *\n * @ignore\n */\ntype TargetRouteMap<\n ExternalRoutes extends { [name: string]: ExternalRouteRef },\n> = {\n [name in keyof ExternalRoutes]: ExternalRoutes[name] extends ExternalRouteRef<\n infer Params,\n any\n >\n ? RouteRef<Params> | SubRouteRef<Params>\n : never;\n};\n\n/**\n * A function that can bind from external routes of a given plugin, to concrete\n * routes of other plugins. See {@link createApp}.\n *\n * @public\n */\nexport type CreateAppRouteBinder = <\n TExternalRoutes extends { [name: string]: ExternalRouteRef },\n>(\n externalRoutes: TExternalRoutes,\n targetRoutes: PartialKeys<\n TargetRouteMap<TExternalRoutes>,\n KeysWithType<TExternalRoutes, ExternalRouteRef<any, true>>\n >,\n) => void;\n\n/** @internal */\nexport function resolveRouteBindings(\n bindRoutes: ((context: { bind: CreateAppRouteBinder }) => void) | undefined,\n config: Config,\n routesById: RouteRefsById,\n): Map<ExternalRouteRef, RouteRef | SubRouteRef> {\n const result = new Map<ExternalRouteRef, RouteRef | SubRouteRef>();\n\n // Perform callback bindings first with highest priority\n if (bindRoutes) {\n const bind: CreateAppRouteBinder = (\n externalRoutes,\n targetRoutes: { [name: string]: RouteRef | SubRouteRef },\n ) => {\n for (const [key, value] of Object.entries(targetRoutes)) {\n const externalRoute = externalRoutes[key];\n if (!externalRoute) {\n throw new Error(`Key ${key} is not an existing external route`);\n }\n if (!value && !externalRoute.optional) {\n throw new Error(\n `External route ${key} is required but was undefined`,\n );\n }\n if (value) {\n result.set(externalRoute, value);\n }\n }\n };\n bindRoutes({ bind });\n }\n\n // Then perform config based bindings with lower priority\n const bindings = config\n .getOptionalConfig('app.routes.bindings')\n ?.get<JsonObject>();\n const disabledExternalRefs = new Set<ExternalRouteRef>();\n if (bindings) {\n for (const [externalRefId, targetRefId] of Object.entries(bindings)) {\n if (!isValidTargetRefId(targetRefId)) {\n throw new Error(\n `Invalid config at app.routes.bindings['${externalRefId}'], value must be a non-empty string or false`,\n );\n }\n\n const externalRef = routesById.externalRoutes.get(externalRefId);\n if (!externalRef) {\n throw new Error(\n `Invalid config at app.routes.bindings, '${externalRefId}' is not a valid external route`,\n );\n }\n\n if (targetRefId === false) {\n disabledExternalRefs.add(externalRef);\n\n result.delete(externalRef);\n } else if (!result.has(externalRef)) {\n const targetRef = routesById.routes.get(targetRefId);\n if (!targetRef) {\n throw new Error(\n `Invalid config at app.routes.bindings['${externalRefId}'], '${targetRefId}' is not a valid route`,\n );\n }\n\n result.set(externalRef, targetRef);\n }\n }\n }\n\n // Finally fall back to attempting to map defaults, at lowest priority\n for (const externalRef of routesById.externalRoutes.values()) {\n if (!result.has(externalRef) && !disabledExternalRefs.has(externalRef)) {\n const defaultRefId =\n toInternalExternalRouteRef(externalRef).getDefaultTarget();\n if (defaultRefId) {\n const defaultRef = routesById.routes.get(defaultRefId);\n if (defaultRef) {\n result.set(externalRef, defaultRef);\n }\n }\n }\n }\n\n return result;\n}\n\nfunction isValidTargetRefId(value: unknown): value is string | false {\n if (value === false) {\n return true;\n }\n\n if (typeof value === 'string' && value) {\n return true;\n }\n\n return false;\n}\n"],"names":[],"mappings":";;AA+EgB,SAAA,oBAAA,CACd,UACA,EAAA,MAAA,EACA,UAC+C,EAAA;AAC/C,EAAM,MAAA,MAAA,uBAAa,GAA8C,EAAA,CAAA;AAGjE,EAAA,IAAI,UAAY,EAAA;AACd,IAAM,MAAA,IAAA,GAA6B,CACjC,cAAA,EACA,YACG,KAAA;AACH,MAAA,KAAA,MAAW,CAAC,GAAK,EAAA,KAAK,KAAK,MAAO,CAAA,OAAA,CAAQ,YAAY,CAAG,EAAA;AACvD,QAAM,MAAA,aAAA,GAAgB,eAAe,GAAG,CAAA,CAAA;AACxC,QAAA,IAAI,CAAC,aAAe,EAAA;AAClB,UAAA,MAAM,IAAI,KAAA,CAAM,CAAO,IAAA,EAAA,GAAG,CAAoC,kCAAA,CAAA,CAAA,CAAA;AAAA,SAChE;AACA,QAAA,IAAI,CAAC,KAAA,IAAS,CAAC,aAAA,CAAc,QAAU,EAAA;AACrC,UAAA,MAAM,IAAI,KAAA;AAAA,YACR,kBAAkB,GAAG,CAAA,8BAAA,CAAA;AAAA,WACvB,CAAA;AAAA,SACF;AACA,QAAA,IAAI,KAAO,EAAA;AACT,UA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AA,sBAAA,CAAA;AAAA,WAC5E,CAAA;AAAA,SACF;AAEA,QAAO,MAAA,CAAA,GAAA,CAAI,aAAa,SAAS,CAAA,CAAA;AAAA,OACnC;AAAA,KACF;AAAA,GACF;AAGA,EAAA,KAAA,MAAW,WAAe,IAAA,UAAA,CAAW,cAAe,CAAA,MAAA,EAAU,EAAA;AAC5D,IAAI,IAAA,CAAC,OAAO,GAAI,CAAA,WAAW,KAAK,CAAC,oBAAA,CAAqB,GAAI,CAAA,WAAW,CAAG,EAAA;AACtE,MAAA,MAAM,YACJ,GAAA,0BAAA,CAA2B,WAAW,CAAA,CAAE,gBAAiB,EAAA,CAAA;AAC3D,MAAA,IAAI,YAAc,EAAA;AAChB,QAAA,MAAM,UAAa,GAAA,UAAA,CAAW,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AACrD,QAAA,IAAI,UAAY,EAAA;AACd,UAAO,MAAA,CAAA,GAAA,CAAI,aAAa,UAAU,CAAA,CAAA;AAAA,SACpC;AAAA,OACF;AAAA,KACF;AAAA,GACF;AAEA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAEA,SAAS,mBAAmB,KAAyC,EAAA;AACnE,EAAA,IAAI,UAAU,KAAO,EAAA;AACnB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAI,IAAA,OAAO,KAAU,KAAA,QAAA,IAAY,KAAO,EAAA;AACtC,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,KAAA,CAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/frontend-app-api",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "web-library"
|
|
6
6
|
},
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@backstage/config": "^1.2.0",
|
|
36
|
-
"@backstage/core-app-api": "^1.
|
|
36
|
+
"@backstage/core-app-api": "^1.13.0",
|
|
37
37
|
"@backstage/core-components": "^0.14.8",
|
|
38
38
|
"@backstage/core-plugin-api": "^1.9.3",
|
|
39
39
|
"@backstage/errors": "^1.2.4",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"lodash": "^4.17.21"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@backstage/cli": "^0.26.
|
|
51
|
-
"@backstage/test-utils": "^1.5.
|
|
50
|
+
"@backstage/cli": "^0.26.10",
|
|
51
|
+
"@backstage/test-utils": "^1.5.7",
|
|
52
52
|
"@testing-library/jest-dom": "^6.0.0",
|
|
53
53
|
"@testing-library/react": "^15.0.0"
|
|
54
54
|
},
|