@backstage/frontend-app-api 0.16.9-next.0 → 0.16.9-next.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 +10 -0
- package/dist/routing/RouteResolver.esm.js +23 -9
- package/dist/routing/RouteResolver.esm.js.map +1 -1
- package/dist/wiring/phaseApis.esm.js +22 -2
- package/dist/wiring/phaseApis.esm.js.map +1 -1
- package/dist/wiring/prepareSpecializedApp.esm.js +8 -5
- package/dist/wiring/prepareSpecializedApp.esm.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @backstage/frontend-app-api
|
|
2
2
|
|
|
3
|
+
## 0.16.9-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0caa896: Provided an implementation of `AppLifecycleApi` and updated the app preparation and finalization process to utilize this API.
|
|
8
|
+
- d810cc9: Improved link resolution performance by reusing route matches for recently visited locations.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- @backstage/frontend-plugin-api@0.18.2-next.1
|
|
11
|
+
- @backstage/core-app-api@1.20.6-next.1
|
|
12
|
+
|
|
3
13
|
## 0.16.9-next.0
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { matchRoutes, generatePath } from 'react-router-dom';
|
|
2
2
|
import mapValues from 'lodash/mapValues';
|
|
3
3
|
import { joinPaths } from './joinPaths.esm.js';
|
|
4
4
|
import { OpaqueExternalRouteRef } from '../frontend-internal/src/routing/OpaqueExternalRouteRef.esm.js';
|
|
5
5
|
import { OpaqueRouteRef } from '../frontend-internal/src/routing/OpaqueRouteRef.esm.js';
|
|
6
6
|
import { OpaqueSubRouteRef } from '../frontend-internal/src/routing/OpaqueSubRouteRef.esm.js';
|
|
7
7
|
|
|
8
|
+
const MAX_CACHED_SOURCE_LOCATIONS = 32;
|
|
8
9
|
function resolveTargetRef(targetRouteRef, routePaths, routeBindings, routeRefsById) {
|
|
9
10
|
let ref = targetRouteRef;
|
|
10
11
|
let path = "";
|
|
@@ -38,14 +39,11 @@ function resolveTargetRef(targetRouteRef, routePaths, routeBindings, routeRefsBy
|
|
|
38
39
|
}
|
|
39
40
|
return [ref, path ? joinPaths(resolvedPath, path) : resolvedPath];
|
|
40
41
|
}
|
|
41
|
-
function resolveBasePath(targetRef,
|
|
42
|
-
const match = matchRoutes(routeObjects, sourceLocation) ?? [];
|
|
42
|
+
function resolveBasePath(targetRef, match, routePaths, routeParents) {
|
|
43
43
|
const refDiffList = Array();
|
|
44
44
|
let matchIndex = -1;
|
|
45
45
|
for (let targetSearchRef = targetRef; targetSearchRef; targetSearchRef = routeParents.get(targetSearchRef)) {
|
|
46
|
-
matchIndex = match.findIndex(
|
|
47
|
-
(m) => m.route.routeRefs.has(targetSearchRef)
|
|
48
|
-
);
|
|
46
|
+
matchIndex = match.findIndex((m) => m.route.routeRefs.has(targetSearchRef));
|
|
49
47
|
if (matchIndex !== -1) {
|
|
50
48
|
break;
|
|
51
49
|
}
|
|
@@ -78,6 +76,7 @@ class RouteResolver {
|
|
|
78
76
|
// base path without a trailing slash
|
|
79
77
|
routeAliasResolver;
|
|
80
78
|
routeRefsById;
|
|
79
|
+
routeMatches = /* @__PURE__ */ new Map();
|
|
81
80
|
constructor(routePaths, routeParents, routeObjects, routeBindings, appBasePath, routeAliasResolver, routeRefsById) {
|
|
82
81
|
this.routePaths = routePaths;
|
|
83
82
|
this.routeParents = routeParents;
|
|
@@ -100,10 +99,9 @@ class RouteResolver {
|
|
|
100
99
|
const relativeSourceLocation = this.trimPath(options?.sourcePath ?? "");
|
|
101
100
|
const basePath = resolveBasePath(
|
|
102
101
|
targetRef,
|
|
103
|
-
relativeSourceLocation,
|
|
102
|
+
this.matchSourceLocation(relativeSourceLocation),
|
|
104
103
|
this.routePaths,
|
|
105
|
-
this.routeParents
|
|
106
|
-
this.routeObjects
|
|
104
|
+
this.routeParents
|
|
107
105
|
);
|
|
108
106
|
const routeFunc = (...[params]) => {
|
|
109
107
|
const encodedParams = params && mapValues(params, (value) => {
|
|
@@ -116,6 +114,22 @@ class RouteResolver {
|
|
|
116
114
|
};
|
|
117
115
|
return routeFunc;
|
|
118
116
|
}
|
|
117
|
+
matchSourceLocation(sourceLocation) {
|
|
118
|
+
let match = this.routeMatches.get(sourceLocation);
|
|
119
|
+
if (match) {
|
|
120
|
+
this.routeMatches.delete(sourceLocation);
|
|
121
|
+
} else {
|
|
122
|
+
match = matchRoutes(this.routeObjects, sourceLocation) ?? [];
|
|
123
|
+
}
|
|
124
|
+
this.routeMatches.set(sourceLocation, match);
|
|
125
|
+
if (this.routeMatches.size > MAX_CACHED_SOURCE_LOCATIONS) {
|
|
126
|
+
const oldestLocation = this.routeMatches.keys().next().value;
|
|
127
|
+
if (oldestLocation !== void 0) {
|
|
128
|
+
this.routeMatches.delete(oldestLocation);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return match;
|
|
132
|
+
}
|
|
119
133
|
trimPath(targetPath) {
|
|
120
134
|
if (!targetPath) {
|
|
121
135
|
return targetPath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouteResolver.esm.js","sources":["../../src/routing/RouteResolver.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 { generatePath, matchRoutes } from 'react-router-dom';\nimport {\n RouteRef,\n ExternalRouteRef,\n SubRouteRef,\n AnyRouteRefParams,\n RouteFunc,\n RouteResolutionApi,\n} from '@backstage/frontend-plugin-api';\nimport mapValues from 'lodash/mapValues';\nimport { AnyRouteRef, BackstageRouteObject } from './types';\nimport {\n OpaqueRouteRef,\n OpaqueExternalRouteRef,\n OpaqueSubRouteRef,\n} from '@internal/frontend';\nimport { RouteAliasResolver } from './RouteAliasResolver';\nimport { joinPaths } from './joinPaths';\n\n/**\n * Resolves the absolute route ref that our target route ref is pointing pointing to, as well\n * as the relative target path.\n *\n * Returns an undefined target ref if one could not be fully resolved.\n */\nfunction resolveTargetRef(\n targetRouteRef: AnyRouteRef,\n routePaths: Map<RouteRef, string>,\n routeBindings: Map<AnyRouteRef, AnyRouteRef | undefined>,\n routeRefsById: Map<string, RouteRef | SubRouteRef>,\n): readonly [RouteRef | undefined, string] {\n // First we figure out which absolute route ref we're dealing with, an if there was an sub route path to append.\n // For sub routes it will be the parent path, while for external routes it will be the bound route.\n let ref: AnyRouteRef = targetRouteRef;\n let path = '';\n\n if (OpaqueExternalRouteRef.isType(ref)) {\n let resolvedRoute = routeBindings.get(ref);\n if (!resolvedRoute) {\n const internal = OpaqueExternalRouteRef.toInternal(ref);\n const defaultTarget = internal.getDefaultTarget();\n if (defaultTarget) {\n resolvedRoute = routeRefsById.get(defaultTarget);\n }\n }\n if (!resolvedRoute) {\n return [undefined, ''];\n }\n ref = resolvedRoute;\n }\n\n if (OpaqueSubRouteRef.isType(ref)) {\n const internal = OpaqueSubRouteRef.toInternal(ref);\n path = ref.path;\n ref = internal.getParent();\n }\n\n if (!OpaqueRouteRef.isType(ref)) {\n throw new Error(\n `Unexpectedly resolved ${targetRouteRef} to a non-route ref ${ref}`,\n );\n }\n\n // Find the path that our target route is bound to\n const resolvedPath = routePaths.get(ref);\n if (resolvedPath === undefined) {\n return [undefined, ''];\n }\n\n return [ref, path ? joinPaths(resolvedPath, path) : resolvedPath];\n}\n\n/**\n * Resolves the complete base path for navigating to the target RouteRef.\n */\nfunction resolveBasePath(\n targetRef: RouteRef,\n sourceLocation: Parameters<typeof matchRoutes>[1],\n routePaths: Map<RouteRef, string>,\n routeParents: Map<RouteRef, RouteRef | undefined>,\n routeObjects: BackstageRouteObject[],\n) {\n // While traversing the app element tree we build up the routeObjects structure\n // used here. It is the same kind of structure that react-router creates, with the\n // addition that associated route refs are stored throughout the tree. This lets\n // us look up all route refs that can be reached from our source location.\n // Because of the similar route object structure, we can use `matchRoutes` from\n // react-router to do the lookup of our current location.\n const match = matchRoutes(routeObjects, sourceLocation) ?? [];\n\n // While we search for a common routing root between our current location and\n // the target route, we build a list of all route refs we find that we need\n // to traverse to reach the target.\n const refDiffList = Array<RouteRef>();\n\n let matchIndex = -1;\n for (\n let targetSearchRef: RouteRef | undefined = targetRef;\n targetSearchRef;\n targetSearchRef = routeParents.get(targetSearchRef)\n ) {\n // The match contains a list of all ancestral route refs present at our current location\n // Starting at the desired target ref and traversing back through its parents, we search\n // for a target ref that is present in the match for our current location. When a match\n // is found it means we have found a common base to resolve the route from.\n matchIndex = match.findIndex(m =>\n (m.route as BackstageRouteObject).routeRefs.has(targetSearchRef!),\n );\n if (matchIndex !== -1) {\n break;\n }\n\n // Every time we move a step up in the ancestry of the target ref, we add the current ref\n // to the diff list, which ends up being the list of route refs to traverse form the common base\n // in order to reach our target.\n refDiffList.unshift(targetSearchRef);\n }\n\n // If our target route is present in the initial match we need to construct the final path\n // from the parent of the matched route segment. That's to allow the caller of the route\n // function to supply their own params.\n if (refDiffList.length === 0) {\n matchIndex -= 1;\n }\n\n // This is the part of the route tree that the target and source locations have in common.\n // We re-use the existing pathname directly along with all params.\n const parentPath = matchIndex === -1 ? '' : match[matchIndex].pathname;\n\n // This constructs the mid section of the path using paths resolved from all route refs\n // we need to traverse to reach our target except for the very last one. None of these\n // paths are allowed to require any parameters, as the caller would have no way of knowing\n // what parameters those are.\n const diffPaths = refDiffList.slice(0, -1).map(ref => {\n const path = routePaths.get(ref);\n if (path === undefined) {\n throw new Error(`No path for ${ref}`);\n }\n if (path.includes(':')) {\n throw new Error(\n `Cannot route to ${targetRef} with parent ${ref} as it has parameters`,\n );\n }\n return path;\n });\n\n return `${joinPaths(parentPath, ...diffPaths)}/`;\n}\n\nexport class RouteResolver implements RouteResolutionApi {\n private readonly routePaths: Map<RouteRef, string>;\n private readonly routeParents: Map<RouteRef, RouteRef | undefined>;\n private readonly routeObjects: BackstageRouteObject[];\n private readonly routeBindings: Map<ExternalRouteRef, RouteRef | SubRouteRef>;\n private readonly appBasePath: string; // base path without a trailing slash\n private readonly routeAliasResolver: RouteAliasResolver;\n private readonly routeRefsById: Map<string, RouteRef | SubRouteRef>;\n\n constructor(\n routePaths: Map<RouteRef, string>,\n routeParents: Map<RouteRef, RouteRef | undefined>,\n routeObjects: BackstageRouteObject[],\n routeBindings: Map<ExternalRouteRef, RouteRef | SubRouteRef>,\n appBasePath: string, // base path without a trailing slash\n routeAliasResolver: RouteAliasResolver,\n routeRefsById: Map<string, RouteRef | SubRouteRef>,\n ) {\n this.routePaths = routePaths;\n this.routeParents = routeParents;\n this.routeObjects = routeObjects;\n this.routeBindings = routeBindings;\n this.appBasePath = appBasePath;\n this.routeAliasResolver = routeAliasResolver;\n this.routeRefsById = routeRefsById;\n }\n\n resolve<TParams extends AnyRouteRefParams>(\n anyRouteRef:\n | RouteRef<TParams>\n | SubRouteRef<TParams>\n | ExternalRouteRef<TParams>,\n options?: { sourcePath?: string },\n ): RouteFunc<TParams> | undefined {\n // First figure out what our target absolute ref is, as well as our target path.\n const [targetRef, targetPath] = resolveTargetRef(\n anyRouteRef?.$$type === '@backstage/RouteRef'\n ? this.routeAliasResolver(anyRouteRef)\n : anyRouteRef,\n this.routePaths,\n this.routeBindings,\n this.routeRefsById,\n );\n if (!targetRef) {\n return undefined;\n }\n\n // The location that we get passed in uses the full path, so start by trimming off\n // the app base path prefix in case we're running the app on a sub-path.\n const relativeSourceLocation = this.trimPath(options?.sourcePath ?? '');\n\n // Next we figure out the base path, which is the combination of the common parent path\n // between our current location and our target location, as well as the additional path\n // that is the difference between the parent path and the base of our target location.\n const basePath = resolveBasePath(\n targetRef,\n relativeSourceLocation,\n this.routePaths,\n this.routeParents,\n this.routeObjects,\n );\n\n const routeFunc: RouteFunc<TParams> = (...[params]) => {\n // We selectively encode some some known-dangerous characters in the\n // params. The reason that we don't perform a blanket `encodeURIComponent`\n // here is that this encoding was added defensively long after the initial\n // release of this code. There's likely to be many users of this code that\n // already encode their parameters knowing that this code didn't do this\n // for them in the past. Therefore, we are extra careful NOT to include\n // the percent character in this set, even though that might seem like a\n // bad idea.\n const encodedParams =\n params &&\n mapValues(params, value => {\n if (typeof value === 'string') {\n return value.replaceAll(/[&?#;\\/]/g, c => encodeURIComponent(c));\n }\n return value;\n });\n return joinPaths(basePath, generatePath(targetPath, encodedParams));\n };\n return routeFunc;\n }\n\n private trimPath(targetPath: string) {\n if (!targetPath) {\n return targetPath;\n }\n\n if (targetPath.startsWith(this.appBasePath)) {\n return targetPath.slice(this.appBasePath.length);\n }\n return targetPath;\n }\n}\n"],"names":[],"mappings":";;;;;;;AAyCA,SAAS,gBAAA,CACP,cAAA,EACA,UAAA,EACA,aAAA,EACA,aAAA,EACyC;AAGzC,EAAA,IAAI,GAAA,GAAmB,cAAA;AACvB,EAAA,IAAI,IAAA,GAAO,EAAA;AAEX,EAAA,IAAI,sBAAA,CAAuB,MAAA,CAAO,GAAG,CAAA,EAAG;AACtC,IAAA,IAAI,aAAA,GAAgB,aAAA,CAAc,GAAA,CAAI,GAAG,CAAA;AACzC,IAAA,IAAI,CAAC,aAAA,EAAe;AAClB,MAAA,MAAM,QAAA,GAAW,sBAAA,CAAuB,UAAA,CAAW,GAAG,CAAA;AACtD,MAAA,MAAM,aAAA,GAAgB,SAAS,gBAAA,EAAiB;AAChD,MAAA,IAAI,aAAA,EAAe;AACjB,QAAA,aAAA,GAAgB,aAAA,CAAc,IAAI,aAAa,CAAA;AAAA,MACjD;AAAA,IACF;AACA,IAAA,IAAI,CAAC,aAAA,EAAe;AAClB,MAAA,OAAO,CA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A,EAAY,aAAa,CAAC,CAAA;AAAA,IACpE,CAAA;AACA,IAAA,OAAO,SAAA;AAAA,EACT;AAAA,EAEQ,SAAS,UAAA,EAAoB;AACnC,IAAA,IAAI,CAAC,UAAA,EAAY;AACf,MAAA,OAAO,UAAA;AAAA,IACT;AAEA,IAAA,IAAI,UAAA,CAAW,UAAA,CAAW,IAAA,CAAK,WAAW,CAAA,EAAG;AAC3C,MAAA,OAAO,UAAA,CAAW,KAAA,CAAM,IAAA,CAAK,WAAA,CAAY,MAAM,CAAA;AAAA,IACjD;AACA,IAAA,OAAO,UAAA;AAAA,EACT;AACF;;"}
|
|
1
|
+
{"version":3,"file":"RouteResolver.esm.js","sources":["../../src/routing/RouteResolver.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 { generatePath, matchRoutes, RouteMatch } from 'react-router-dom';\nimport {\n RouteRef,\n ExternalRouteRef,\n SubRouteRef,\n AnyRouteRefParams,\n RouteFunc,\n RouteResolutionApi,\n} from '@backstage/frontend-plugin-api';\nimport mapValues from 'lodash/mapValues';\nimport { AnyRouteRef, BackstageRouteObject } from './types';\nimport {\n OpaqueRouteRef,\n OpaqueExternalRouteRef,\n OpaqueSubRouteRef,\n} from '@internal/frontend';\nimport { RouteAliasResolver } from './RouteAliasResolver';\nimport { joinPaths } from './joinPaths';\n\nconst MAX_CACHED_SOURCE_LOCATIONS = 32;\n\n/**\n * Resolves the absolute route ref that our target route ref is pointing pointing to, as well\n * as the relative target path.\n *\n * Returns an undefined target ref if one could not be fully resolved.\n */\nfunction resolveTargetRef(\n targetRouteRef: AnyRouteRef,\n routePaths: Map<RouteRef, string>,\n routeBindings: Map<AnyRouteRef, AnyRouteRef | undefined>,\n routeRefsById: Map<string, RouteRef | SubRouteRef>,\n): readonly [RouteRef | undefined, string] {\n // First we figure out which absolute route ref we're dealing with, an if there was an sub route path to append.\n // For sub routes it will be the parent path, while for external routes it will be the bound route.\n let ref: AnyRouteRef = targetRouteRef;\n let path = '';\n\n if (OpaqueExternalRouteRef.isType(ref)) {\n let resolvedRoute = routeBindings.get(ref);\n if (!resolvedRoute) {\n const internal = OpaqueExternalRouteRef.toInternal(ref);\n const defaultTarget = internal.getDefaultTarget();\n if (defaultTarget) {\n resolvedRoute = routeRefsById.get(defaultTarget);\n }\n }\n if (!resolvedRoute) {\n return [undefined, ''];\n }\n ref = resolvedRoute;\n }\n\n if (OpaqueSubRouteRef.isType(ref)) {\n const internal = OpaqueSubRouteRef.toInternal(ref);\n path = ref.path;\n ref = internal.getParent();\n }\n\n if (!OpaqueRouteRef.isType(ref)) {\n throw new Error(\n `Unexpectedly resolved ${targetRouteRef} to a non-route ref ${ref}`,\n );\n }\n\n // Find the path that our target route is bound to\n const resolvedPath = routePaths.get(ref);\n if (resolvedPath === undefined) {\n return [undefined, ''];\n }\n\n return [ref, path ? joinPaths(resolvedPath, path) : resolvedPath];\n}\n\n/**\n * Resolves the complete base path for navigating to the target RouteRef.\n */\nfunction resolveBasePath(\n targetRef: RouteRef,\n match: RouteMatch<string, BackstageRouteObject>[],\n routePaths: Map<RouteRef, string>,\n routeParents: Map<RouteRef, RouteRef | undefined>,\n) {\n // While we search for a common routing root between our current location and\n // the target route, we build a list of all route refs we find that we need\n // to traverse to reach the target.\n const refDiffList = Array<RouteRef>();\n\n let matchIndex = -1;\n for (\n let targetSearchRef: RouteRef | undefined = targetRef;\n targetSearchRef;\n targetSearchRef = routeParents.get(targetSearchRef)\n ) {\n // The match contains a list of all ancestral route refs present at our current location\n // Starting at the desired target ref and traversing back through its parents, we search\n // for a target ref that is present in the match for our current location. When a match\n // is found it means we have found a common base to resolve the route from.\n matchIndex = match.findIndex(m => m.route.routeRefs.has(targetSearchRef!));\n if (matchIndex !== -1) {\n break;\n }\n\n // Every time we move a step up in the ancestry of the target ref, we add the current ref\n // to the diff list, which ends up being the list of route refs to traverse form the common base\n // in order to reach our target.\n refDiffList.unshift(targetSearchRef);\n }\n\n // If our target route is present in the initial match we need to construct the final path\n // from the parent of the matched route segment. That's to allow the caller of the route\n // function to supply their own params.\n if (refDiffList.length === 0) {\n matchIndex -= 1;\n }\n\n // This is the part of the route tree that the target and source locations have in common.\n // We re-use the existing pathname directly along with all params.\n const parentPath = matchIndex === -1 ? '' : match[matchIndex].pathname;\n\n // This constructs the mid section of the path using paths resolved from all route refs\n // we need to traverse to reach our target except for the very last one. None of these\n // paths are allowed to require any parameters, as the caller would have no way of knowing\n // what parameters those are.\n const diffPaths = refDiffList.slice(0, -1).map(ref => {\n const path = routePaths.get(ref);\n if (path === undefined) {\n throw new Error(`No path for ${ref}`);\n }\n if (path.includes(':')) {\n throw new Error(\n `Cannot route to ${targetRef} with parent ${ref} as it has parameters`,\n );\n }\n return path;\n });\n\n return `${joinPaths(parentPath, ...diffPaths)}/`;\n}\n\nexport class RouteResolver implements RouteResolutionApi {\n private readonly routePaths: Map<RouteRef, string>;\n private readonly routeParents: Map<RouteRef, RouteRef | undefined>;\n private readonly routeObjects: BackstageRouteObject[];\n private readonly routeBindings: Map<ExternalRouteRef, RouteRef | SubRouteRef>;\n private readonly appBasePath: string; // base path without a trailing slash\n private readonly routeAliasResolver: RouteAliasResolver;\n private readonly routeRefsById: Map<string, RouteRef | SubRouteRef>;\n private readonly routeMatches = new Map<\n string,\n RouteMatch<string, BackstageRouteObject>[]\n >();\n\n constructor(\n routePaths: Map<RouteRef, string>,\n routeParents: Map<RouteRef, RouteRef | undefined>,\n routeObjects: BackstageRouteObject[],\n routeBindings: Map<ExternalRouteRef, RouteRef | SubRouteRef>,\n appBasePath: string, // base path without a trailing slash\n routeAliasResolver: RouteAliasResolver,\n routeRefsById: Map<string, RouteRef | SubRouteRef>,\n ) {\n this.routePaths = routePaths;\n this.routeParents = routeParents;\n this.routeObjects = routeObjects;\n this.routeBindings = routeBindings;\n this.appBasePath = appBasePath;\n this.routeAliasResolver = routeAliasResolver;\n this.routeRefsById = routeRefsById;\n }\n\n resolve<TParams extends AnyRouteRefParams>(\n anyRouteRef:\n | RouteRef<TParams>\n | SubRouteRef<TParams>\n | ExternalRouteRef<TParams>,\n options?: { sourcePath?: string },\n ): RouteFunc<TParams> | undefined {\n // First figure out what our target absolute ref is, as well as our target path.\n const [targetRef, targetPath] = resolveTargetRef(\n anyRouteRef?.$$type === '@backstage/RouteRef'\n ? this.routeAliasResolver(anyRouteRef)\n : anyRouteRef,\n this.routePaths,\n this.routeBindings,\n this.routeRefsById,\n );\n if (!targetRef) {\n return undefined;\n }\n\n // The location that we get passed in uses the full path, so start by trimming off\n // the app base path prefix in case we're running the app on a sub-path.\n const relativeSourceLocation = this.trimPath(options?.sourcePath ?? '');\n\n // Next we figure out the base path, which is the combination of the common parent path\n // between our current location and our target location, as well as the additional path\n // that is the difference between the parent path and the base of our target location.\n const basePath = resolveBasePath(\n targetRef,\n this.matchSourceLocation(relativeSourceLocation),\n this.routePaths,\n this.routeParents,\n );\n\n const routeFunc: RouteFunc<TParams> = (...[params]) => {\n // We selectively encode some some known-dangerous characters in the\n // params. The reason that we don't perform a blanket `encodeURIComponent`\n // here is that this encoding was added defensively long after the initial\n // release of this code. There's likely to be many users of this code that\n // already encode their parameters knowing that this code didn't do this\n // for them in the past. Therefore, we are extra careful NOT to include\n // the percent character in this set, even though that might seem like a\n // bad idea.\n const encodedParams =\n params &&\n mapValues(params, value => {\n if (typeof value === 'string') {\n return value.replaceAll(/[&?#;\\/]/g, c => encodeURIComponent(c));\n }\n return value;\n });\n return joinPaths(basePath, generatePath(targetPath, encodedParams));\n };\n return routeFunc;\n }\n\n private matchSourceLocation(sourceLocation: string) {\n // The route tree is fixed for the lifetime of this resolver. Share the match\n // across links from the same location, retaining only a few recent locations\n // to avoid unbounded growth as users navigate through parameterized routes.\n let match = this.routeMatches.get(sourceLocation);\n if (match) {\n this.routeMatches.delete(sourceLocation);\n } else {\n match = matchRoutes(this.routeObjects, sourceLocation) ?? [];\n }\n this.routeMatches.set(sourceLocation, match);\n if (this.routeMatches.size > MAX_CACHED_SOURCE_LOCATIONS) {\n const oldestLocation = this.routeMatches.keys().next().value;\n if (oldestLocation !== undefined) {\n this.routeMatches.delete(oldestLocation);\n }\n }\n return match;\n }\n\n private trimPath(targetPath: string) {\n if (!targetPath) {\n return targetPath;\n }\n\n if (targetPath.startsWith(this.appBasePath)) {\n return targetPath.slice(this.appBasePath.length);\n }\n return targetPath;\n }\n}\n"],"names":[],"mappings":";;;;;;;AAmCA,MAAM,2BAAA,GAA8B,EAAA;AAQpC,SAAS,gBAAA,CACP,cAAA,EACA,UAAA,EACA,aAAA,EACA,aAAA,EACyC;AAGzC,EAAA,IAAI,GAAA,GAAmB,cAAA;AACvB,EAAA,IAAI,IAAA,GAAO,EAAA;AAEX,EAAA,IAAI,sBAAA,CAAuB,MAAA,CAAO,GAAG,CAAA,EAAG;AACtC,IAAA,IAAI,aAAA,GAAgB,aAAA,CAAc,GAAA,CAAI,GAAG,CAAA;AACzC,IAAA,IAAI,CAAC,aAAA,EAAe;AAClB,MAAA,MAAM,QAAA,GAAW,sBAAA,CAAuB,UAAA,CAAW,GAAG,CAAA;AACtD,MAAA,MAAM,aAAA,GAAgB,SAAS,gBAAA,EAAiB;AAChD,MAAA,IAAI,aAAA,EAAe;AACjB,QAAA,aAAA,GAAgB,aAAA,CAAc,IAAI,aAAa,CAAA;AAAA,MACjD;AAAA,IACF;AACA,IAAA,IAAI,CAAC,aAAA,EAAe;AAClB,MAAA,OAAO,CAAC,QAAW,EAAE,CAAA;AAAA,IACvB;AACA,IAAA,GAAA,GAAM,aAAA;AAAA,EACR;AAEA,EAAA,IAAI,iBAAA,CAAkB,M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A,CAAa,GAAA,CAAI,cAAc,CAAA;AAChD,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,IAAA,CAAK,YAAA,CAAa,OAAO,cAAc,CAAA;AAAA,IACzC,CAAA,MAAO;AACL,MAAA,KAAA,GAAQ,WAAA,CAAY,IAAA,CAAK,YAAA,EAAc,cAAc,KAAK,EAAC;AAAA,IAC7D;AACA,IAAA,IAAA,CAAK,YAAA,CAAa,GAAA,CAAI,cAAA,EAAgB,KAAK,CAAA;AAC3C,IAAA,IAAI,IAAA,CAAK,YAAA,CAAa,IAAA,GAAO,2BAAA,EAA6B;AACxD,MAAA,MAAM,iBAAiB,IAAA,CAAK,YAAA,CAAa,IAAA,EAAK,CAAE,MAAK,CAAE,KAAA;AACvD,MAAA,IAAI,mBAAmB,MAAA,EAAW;AAChC,QAAA,IAAA,CAAK,YAAA,CAAa,OAAO,cAAc,CAAA;AAAA,MACzC;AAAA,IACF;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AAAA,EAEQ,SAAS,UAAA,EAAoB;AACnC,IAAA,IAAI,CAAC,UAAA,EAAY;AACf,MAAA,OAAO,UAAA;AAAA,IACT;AAEA,IAAA,IAAI,UAAA,CAAW,UAAA,CAAW,IAAA,CAAK,WAAW,CAAA,EAAG;AAC3C,MAAA,OAAO,UAAA,CAAW,KAAA,CAAM,IAAA,CAAK,WAAA,CAAY,MAAM,CAAA;AAAA,IACjD;AACA,IAAA,OAAO,UAAA;AAAA,EACT;AACF;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createApiFactory, appTreeApiRef, configApiRef, routeResolutionApiRef, identityApiRef } from '@backstage/frontend-plugin-api';
|
|
1
|
+
import { createApiFactory, appTreeApiRef, appLifecycleApiRef, configApiRef, routeResolutionApiRef, identityApiRef } from '@backstage/frontend-plugin-api';
|
|
2
2
|
import { matchRoutes } from 'react-router-dom';
|
|
3
3
|
import { AppIdentityProxy } from '../core-app-api/src/apis/implementations/IdentityApi/AppIdentityProxy.esm.js';
|
|
4
4
|
import { createRouteAliasResolver } from '../routing/RouteAliasResolver.esm.js';
|
|
@@ -83,6 +83,23 @@ class RouteResolutionApiProxy {
|
|
|
83
83
|
return this.#routeObjects;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
+
class DefaultAppLifecycleApi {
|
|
87
|
+
#finalized = false;
|
|
88
|
+
#listeners = /* @__PURE__ */ new Set();
|
|
89
|
+
isFinalized = () => this.#finalized;
|
|
90
|
+
subscribe = (listener) => {
|
|
91
|
+
this.#listeners.add(listener);
|
|
92
|
+
return () => {
|
|
93
|
+
this.#listeners.delete(listener);
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
markFinalized() {
|
|
97
|
+
this.#finalized = true;
|
|
98
|
+
for (const listener of this.#listeners) {
|
|
99
|
+
listener();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
86
103
|
class PreparedAppIdentityProxy extends AppIdentityProxy {
|
|
87
104
|
#onTargetSet;
|
|
88
105
|
setTargetHandlers(options) {
|
|
@@ -108,9 +125,11 @@ function createPhaseApis(options) {
|
|
|
108
125
|
options.appBasePath
|
|
109
126
|
);
|
|
110
127
|
const identityProxy = new PreparedAppIdentityProxy();
|
|
128
|
+
const appLifecycleApi = new DefaultAppLifecycleApi();
|
|
111
129
|
const phaseApiRegistry = new FrontendApiRegistry();
|
|
112
130
|
phaseApiRegistry.registerAll([
|
|
113
131
|
createApiFactory(appTreeApiRef, appTreeApi),
|
|
132
|
+
createApiFactory(appLifecycleApiRef, appLifecycleApi),
|
|
114
133
|
...options.includeConfigApi ? [createApiFactory(configApiRef, options.config)] : [],
|
|
115
134
|
createApiFactory(routeResolutionApiRef, routeResolutionApi),
|
|
116
135
|
createApiFactory(identityApiRef, identityProxy),
|
|
@@ -125,6 +144,7 @@ function createPhaseApis(options) {
|
|
|
125
144
|
apis,
|
|
126
145
|
routeResolutionApi,
|
|
127
146
|
appTreeApi,
|
|
147
|
+
appLifecycleApi,
|
|
128
148
|
identityApiProxy: identityProxy
|
|
129
149
|
};
|
|
130
150
|
}
|
|
@@ -157,5 +177,5 @@ function setIdentityApiTarget(options) {
|
|
|
157
177
|
});
|
|
158
178
|
}
|
|
159
179
|
|
|
160
|
-
export { AppTreeApiProxy, PreparedAppIdentityProxy, RouteResolutionApiProxy, createPhaseApis, instantiateAndInitializePhaseTree, setIdentityApiTarget };
|
|
180
|
+
export { AppTreeApiProxy, DefaultAppLifecycleApi, PreparedAppIdentityProxy, RouteResolutionApiProxy, createPhaseApis, instantiateAndInitializePhaseTree, setIdentityApiTarget };
|
|
161
181
|
//# sourceMappingURL=phaseApis.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phaseApis.esm.js","sources":["../../src/wiring/phaseApis.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 AnyApiFactory,\n ApiHolder,\n AppTree,\n AppTreeApi,\n appTreeApiRef,\n ConfigApi,\n configApiRef,\n createApiFactory,\n ExternalRouteRef,\n identityApiRef,\n RouteFunc,\n RouteRef,\n RouteResolutionApi,\n routeResolutionApiRef,\n SubRouteRef,\n type AnyRouteRefParams,\n type AppNode,\n type ExtensionFactoryMiddleware,\n type IdentityApi,\n} from '@backstage/frontend-plugin-api';\nimport { matchRoutes } from 'react-router-dom';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { AppIdentityProxy } from '../../../core-app-api/src/apis/implementations/IdentityApi/AppIdentityProxy';\nimport { createRouteAliasResolver } from '../routing/RouteAliasResolver';\nimport { RouteResolver } from '../routing/RouteResolver';\nimport { collectRouteIds } from '../routing/collectRouteIds';\nimport {\n extractRouteInfoFromAppNode,\n type RouteInfo,\n} from '../routing/extractRouteInfoFromAppNode';\nimport { type BackstageRouteObject } from '../routing/types';\nimport { instantiateAppNodeTree } from '../tree/instantiateAppNodeTree';\nimport {\n FrontendApiRegistry,\n FrontendApiResolver,\n} from './FrontendApiRegistry';\nimport { type ExtensionPredicateContext } from './predicates';\nimport { type ErrorCollector } from './createErrorCollector';\n\n// Helps delay callers from reaching out to the API before the app tree has been materialized\nexport class AppTreeApiProxy implements AppTreeApi {\n #routeInfo?: RouteInfo;\n private readonly tree: AppTree;\n private readonly appBasePath: string;\n\n constructor(tree: AppTree, appBasePath: string) {\n this.tree = tree;\n this.appBasePath = appBasePath;\n }\n\n private checkIfInitialized() {\n if (!this.#routeInfo) {\n throw new Error(\n `You can't access the AppTreeApi during initialization of the app tree. Please move occurrences of this out of the initialization of the factory`,\n );\n }\n }\n\n getTree() {\n this.checkIfInitialized();\n\n return { tree: this.tree };\n }\n\n getNodesByRoutePath(routePath: string): { nodes: AppNode[] } {\n this.checkIfInitialized();\n const routeInfo = this.#routeInfo;\n if (!routeInfo) {\n throw new Error(\n `You can't access the AppTreeApi during initialization of the app tree. Please move occurrences of this out of the initialization of the factory`,\n );\n }\n\n let path = routePath;\n if (path.startsWith(this.appBasePath)) {\n path = path.slice(this.appBasePath.length);\n }\n\n const matchedRoutes = matchRoutes(routeInfo.routeObjects, path);\n\n const matchedAppNodes =\n matchedRoutes?.flatMap(routeObj => {\n const appNode = routeObj.route.appNode;\n return appNode ? [appNode] : [];\n }) || [];\n\n return { nodes: matchedAppNodes };\n }\n\n initialize(routeInfo: RouteInfo) {\n this.#routeInfo = routeInfo;\n }\n}\n\n// Helps delay callers from reaching out to the API before the app tree has been materialized\nexport class RouteResolutionApiProxy implements RouteResolutionApi {\n #delegate: RouteResolutionApi | undefined;\n #routeObjects: BackstageRouteObject[] | undefined;\n\n private readonly routeBindings: Map<ExternalRouteRef, RouteRef | SubRouteRef>;\n private readonly appBasePath: string;\n\n constructor(\n routeBindings: Map<ExternalRouteRef, RouteRef | SubRouteRef>,\n appBasePath: string,\n ) {\n this.routeBindings = routeBindings;\n this.appBasePath = appBasePath;\n }\n\n resolve<TParams extends AnyRouteRefParams>(\n anyRouteRef:\n | RouteRef<TParams>\n | SubRouteRef<TParams>\n | ExternalRouteRef<TParams>,\n options?: { sourcePath?: string },\n ): RouteFunc<TParams> | undefined {\n if (!this.#delegate) {\n throw new Error(\n `You can't access the RouteResolver during initialization of the app tree. Please move occurrences of this out of the initialization of the factory`,\n );\n }\n\n return this.#delegate.resolve(anyRouteRef, options);\n }\n\n initialize(\n routeInfo: RouteInfo,\n routeRefsById: Map<string, RouteRef | SubRouteRef>,\n ) {\n this.#delegate = new RouteResolver(\n routeInfo.routePaths,\n routeInfo.routeParents,\n routeInfo.routeObjects,\n this.routeBindings,\n this.appBasePath,\n routeInfo.routeAliasResolver,\n routeRefsById,\n );\n this.#routeObjects = routeInfo.routeObjects;\n\n return routeInfo;\n }\n\n getRouteObjects() {\n return this.#routeObjects;\n }\n}\n\nexport class PreparedAppIdentityProxy extends AppIdentityProxy {\n #onTargetSet?:\n | ((identityApi: Parameters<AppIdentityProxy['setTarget']>[0]) => void)\n | undefined;\n\n setTargetHandlers(options: {\n onTargetSet?(\n identityApi: Parameters<AppIdentityProxy['setTarget']>[0],\n ): void;\n }) {\n this.#onTargetSet = options.onTargetSet;\n }\n\n clearTargetHandlers() {\n this.#onTargetSet = undefined;\n }\n\n override setTarget(\n identityApi: Parameters<AppIdentityProxy['setTarget']>[0],\n targetOptions: Parameters<AppIdentityProxy['setTarget']>[1],\n ) {\n super.setTarget(identityApi, targetOptions);\n\n const onTargetSet = this.#onTargetSet;\n if (!onTargetSet) {\n return;\n }\n\n this.clearTargetHandlers();\n onTargetSet(identityApi);\n }\n}\n\nexport function createPhaseApis(options: {\n tree: AppTree;\n config: ConfigApi;\n appApiRegistry: FrontendApiRegistry;\n fallbackApis?: ApiHolder;\n includeConfigApi: boolean;\n appBasePath: string;\n routeBindings: Map<ExternalRouteRef, RouteRef | SubRouteRef>;\n staticFactories: AnyApiFactory[];\n}) {\n const appTreeApi = new AppTreeApiProxy(options.tree, options.appBasePath);\n const routeResolutionApi = new RouteResolutionApiProxy(\n options.routeBindings,\n options.appBasePath,\n );\n const identityProxy = new PreparedAppIdentityProxy();\n const phaseApiRegistry = new FrontendApiRegistry();\n phaseApiRegistry.registerAll([\n createApiFactory(appTreeApiRef, appTreeApi),\n ...(options.includeConfigApi\n ? [createApiFactory(configApiRef, options.config)]\n : []),\n createApiFactory(routeResolutionApiRef, routeResolutionApi),\n createApiFactory(identityApiRef, identityProxy),\n ...options.staticFactories,\n ]);\n\n const apis = new FrontendApiResolver({\n primaryRegistry: phaseApiRegistry,\n secondaryRegistry: options.appApiRegistry,\n fallbackApis: options.fallbackApis,\n });\n\n return {\n apis,\n routeResolutionApi,\n appTreeApi,\n identityApiProxy: identityProxy,\n };\n}\n\nexport function instantiateAndInitializePhaseTree(options: {\n tree: AppTree;\n apis: ApiHolder;\n collector: ErrorCollector;\n extensionFactoryMiddleware?: ExtensionFactoryMiddleware;\n routeResolutionApi: RouteResolutionApiProxy;\n appTreeApi: AppTreeApiProxy;\n routeRefsById: ReturnType<typeof collectRouteIds>;\n skipChild?(ctx: { node: AppNode; input: string; child: AppNode }): boolean;\n onMissingApi?(ctx: { node: AppNode; apiRefId: string }): void;\n predicateContext?: ExtensionPredicateContext;\n stopAtAttachment?(ctx: { node: AppNode; input: string }): boolean;\n}) {\n instantiateAppNodeTree(\n options.tree.root,\n options.apis,\n options.collector,\n options.extensionFactoryMiddleware,\n {\n ...(options.stopAtAttachment\n ? { stopAtAttachment: options.stopAtAttachment }\n : {}),\n skipChild: options.skipChild,\n onMissingApi: options.onMissingApi,\n predicateContext: options.predicateContext,\n },\n );\n\n const routeInfo = extractRouteInfoFromAppNode(\n options.tree.root,\n createRouteAliasResolver(options.routeRefsById),\n );\n\n options.routeResolutionApi.initialize(\n routeInfo,\n options.routeRefsById.routes,\n );\n options.appTreeApi.initialize(routeInfo);\n}\n\nexport function setIdentityApiTarget(options: {\n identityApiProxy: AppIdentityProxy;\n identityApi: IdentityApi;\n signOutTargetUrl: string;\n}) {\n options.identityApiProxy.setTarget(options.identityApi, {\n signOutTargetUrl: options.signOutTargetUrl,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;AAyDO,MAAM,eAAA,CAAsC;AAAA,EACjD,UAAA;AAAA,EACiB,IAAA;AAAA,EACA,WAAA;AAAA,EAEjB,WAAA,CAAY,MAAe,WAAA,EAAqB;AAC9C,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,WAAA,GAAc,WAAA;AAAA,EACrB;AAAA,EAEQ,kBAAA,GAAqB;AAC3B,IAAA,IAAI,CAAC,KAAK,UAAA,EAAY;AACpB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,+IAAA;AAAA,OACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,OAAA,GAAU;AACR,IAAA,IAAA,CAAK,kBAAA,EAAmB;AAExB,IAAA,OAAO,EAAE,IAAA,EAAM,IAAA,CAAK,IAAA,EAAK;AAAA,EAC3B;AAAA,EAEA,oBAAoB,SAAA,EAAyC;AAC3D,IAAA,IAAA,CAAK,kBAAA,EAAmB;AACxB,IAAA,MAAM,YAAY,IAAA,CAAK,UAAA;AACvB,IAAA,IAAI,CAAC,SAAA,EAAW;AACd,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,+IAAA;AAAA,OACF;AAAA,IACF;AAEA,IAAA,IAAI,IAAA,GAAO,SAAA;AACX,IAAA,IAAI,IAAA,CAAK,UAAA,CAAW,IAAA,CAAK,WAAW,CAAA,EAAG;AACrC,MAAA,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,WAAA,CAAY,MAAM,CAAA;AAAA,IAC3C;AAEA,I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|
|
1
|
+
{"version":3,"file":"phaseApis.esm.js","sources":["../../src/wiring/phaseApis.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 AnyApiFactory,\n ApiHolder,\n AppLifecycleApi,\n appLifecycleApiRef,\n AppTree,\n AppTreeApi,\n appTreeApiRef,\n ConfigApi,\n configApiRef,\n createApiFactory,\n ExternalRouteRef,\n identityApiRef,\n RouteFunc,\n RouteRef,\n RouteResolutionApi,\n routeResolutionApiRef,\n SubRouteRef,\n type AnyRouteRefParams,\n type AppNode,\n type ExtensionFactoryMiddleware,\n type IdentityApi,\n} from '@backstage/frontend-plugin-api';\nimport { matchRoutes } from 'react-router-dom';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { AppIdentityProxy } from '../../../core-app-api/src/apis/implementations/IdentityApi/AppIdentityProxy';\nimport { createRouteAliasResolver } from '../routing/RouteAliasResolver';\nimport { RouteResolver } from '../routing/RouteResolver';\nimport { collectRouteIds } from '../routing/collectRouteIds';\nimport {\n extractRouteInfoFromAppNode,\n type RouteInfo,\n} from '../routing/extractRouteInfoFromAppNode';\nimport { type BackstageRouteObject } from '../routing/types';\nimport { instantiateAppNodeTree } from '../tree/instantiateAppNodeTree';\nimport {\n FrontendApiRegistry,\n FrontendApiResolver,\n} from './FrontendApiRegistry';\nimport { type ExtensionPredicateContext } from './predicates';\nimport { type ErrorCollector } from './createErrorCollector';\n\n// Helps delay callers from reaching out to the API before the app tree has been materialized\nexport class AppTreeApiProxy implements AppTreeApi {\n #routeInfo?: RouteInfo;\n private readonly tree: AppTree;\n private readonly appBasePath: string;\n\n constructor(tree: AppTree, appBasePath: string) {\n this.tree = tree;\n this.appBasePath = appBasePath;\n }\n\n private checkIfInitialized() {\n if (!this.#routeInfo) {\n throw new Error(\n `You can't access the AppTreeApi during initialization of the app tree. Please move occurrences of this out of the initialization of the factory`,\n );\n }\n }\n\n getTree() {\n this.checkIfInitialized();\n\n return { tree: this.tree };\n }\n\n getNodesByRoutePath(routePath: string): { nodes: AppNode[] } {\n this.checkIfInitialized();\n const routeInfo = this.#routeInfo;\n if (!routeInfo) {\n throw new Error(\n `You can't access the AppTreeApi during initialization of the app tree. Please move occurrences of this out of the initialization of the factory`,\n );\n }\n\n let path = routePath;\n if (path.startsWith(this.appBasePath)) {\n path = path.slice(this.appBasePath.length);\n }\n\n const matchedRoutes = matchRoutes(routeInfo.routeObjects, path);\n\n const matchedAppNodes =\n matchedRoutes?.flatMap(routeObj => {\n const appNode = routeObj.route.appNode;\n return appNode ? [appNode] : [];\n }) || [];\n\n return { nodes: matchedAppNodes };\n }\n\n initialize(routeInfo: RouteInfo) {\n this.#routeInfo = routeInfo;\n }\n}\n\n// Helps delay callers from reaching out to the API before the app tree has been materialized\nexport class RouteResolutionApiProxy implements RouteResolutionApi {\n #delegate: RouteResolutionApi | undefined;\n #routeObjects: BackstageRouteObject[] | undefined;\n\n private readonly routeBindings: Map<ExternalRouteRef, RouteRef | SubRouteRef>;\n private readonly appBasePath: string;\n\n constructor(\n routeBindings: Map<ExternalRouteRef, RouteRef | SubRouteRef>,\n appBasePath: string,\n ) {\n this.routeBindings = routeBindings;\n this.appBasePath = appBasePath;\n }\n\n resolve<TParams extends AnyRouteRefParams>(\n anyRouteRef:\n | RouteRef<TParams>\n | SubRouteRef<TParams>\n | ExternalRouteRef<TParams>,\n options?: { sourcePath?: string },\n ): RouteFunc<TParams> | undefined {\n if (!this.#delegate) {\n throw new Error(\n `You can't access the RouteResolver during initialization of the app tree. Please move occurrences of this out of the initialization of the factory`,\n );\n }\n\n return this.#delegate.resolve(anyRouteRef, options);\n }\n\n initialize(\n routeInfo: RouteInfo,\n routeRefsById: Map<string, RouteRef | SubRouteRef>,\n ) {\n this.#delegate = new RouteResolver(\n routeInfo.routePaths,\n routeInfo.routeParents,\n routeInfo.routeObjects,\n this.routeBindings,\n this.appBasePath,\n routeInfo.routeAliasResolver,\n routeRefsById,\n );\n this.#routeObjects = routeInfo.routeObjects;\n\n return routeInfo;\n }\n\n getRouteObjects() {\n return this.#routeObjects;\n }\n}\n\nexport class DefaultAppLifecycleApi implements AppLifecycleApi {\n #finalized = false;\n readonly #listeners = new Set<() => void>();\n\n isFinalized = () => this.#finalized;\n\n subscribe = (listener: () => void) => {\n this.#listeners.add(listener);\n\n return () => {\n this.#listeners.delete(listener);\n };\n };\n\n markFinalized() {\n this.#finalized = true;\n\n for (const listener of this.#listeners) {\n listener();\n }\n }\n}\n\nexport class PreparedAppIdentityProxy extends AppIdentityProxy {\n #onTargetSet?:\n | ((identityApi: Parameters<AppIdentityProxy['setTarget']>[0]) => void)\n | undefined;\n\n setTargetHandlers(options: {\n onTargetSet?(\n identityApi: Parameters<AppIdentityProxy['setTarget']>[0],\n ): void;\n }) {\n this.#onTargetSet = options.onTargetSet;\n }\n\n clearTargetHandlers() {\n this.#onTargetSet = undefined;\n }\n\n override setTarget(\n identityApi: Parameters<AppIdentityProxy['setTarget']>[0],\n targetOptions: Parameters<AppIdentityProxy['setTarget']>[1],\n ) {\n super.setTarget(identityApi, targetOptions);\n\n const onTargetSet = this.#onTargetSet;\n if (!onTargetSet) {\n return;\n }\n\n this.clearTargetHandlers();\n onTargetSet(identityApi);\n }\n}\n\nexport function createPhaseApis(options: {\n tree: AppTree;\n config: ConfigApi;\n appApiRegistry: FrontendApiRegistry;\n fallbackApis?: ApiHolder;\n includeConfigApi: boolean;\n appBasePath: string;\n routeBindings: Map<ExternalRouteRef, RouteRef | SubRouteRef>;\n staticFactories: AnyApiFactory[];\n}) {\n const appTreeApi = new AppTreeApiProxy(options.tree, options.appBasePath);\n const routeResolutionApi = new RouteResolutionApiProxy(\n options.routeBindings,\n options.appBasePath,\n );\n const identityProxy = new PreparedAppIdentityProxy();\n const appLifecycleApi = new DefaultAppLifecycleApi();\n const phaseApiRegistry = new FrontendApiRegistry();\n phaseApiRegistry.registerAll([\n createApiFactory(appTreeApiRef, appTreeApi),\n createApiFactory(appLifecycleApiRef, appLifecycleApi),\n ...(options.includeConfigApi\n ? [createApiFactory(configApiRef, options.config)]\n : []),\n createApiFactory(routeResolutionApiRef, routeResolutionApi),\n createApiFactory(identityApiRef, identityProxy),\n ...options.staticFactories,\n ]);\n\n const apis = new FrontendApiResolver({\n primaryRegistry: phaseApiRegistry,\n secondaryRegistry: options.appApiRegistry,\n fallbackApis: options.fallbackApis,\n });\n\n return {\n apis,\n routeResolutionApi,\n appTreeApi,\n appLifecycleApi,\n identityApiProxy: identityProxy,\n };\n}\n\nexport function instantiateAndInitializePhaseTree(options: {\n tree: AppTree;\n apis: ApiHolder;\n collector: ErrorCollector;\n extensionFactoryMiddleware?: ExtensionFactoryMiddleware;\n routeResolutionApi: RouteResolutionApiProxy;\n appTreeApi: AppTreeApiProxy;\n routeRefsById: ReturnType<typeof collectRouteIds>;\n skipChild?(ctx: { node: AppNode; input: string; child: AppNode }): boolean;\n onMissingApi?(ctx: { node: AppNode; apiRefId: string }): void;\n predicateContext?: ExtensionPredicateContext;\n stopAtAttachment?(ctx: { node: AppNode; input: string }): boolean;\n}) {\n instantiateAppNodeTree(\n options.tree.root,\n options.apis,\n options.collector,\n options.extensionFactoryMiddleware,\n {\n ...(options.stopAtAttachment\n ? { stopAtAttachment: options.stopAtAttachment }\n : {}),\n skipChild: options.skipChild,\n onMissingApi: options.onMissingApi,\n predicateContext: options.predicateContext,\n },\n );\n\n const routeInfo = extractRouteInfoFromAppNode(\n options.tree.root,\n createRouteAliasResolver(options.routeRefsById),\n );\n\n options.routeResolutionApi.initialize(\n routeInfo,\n options.routeRefsById.routes,\n );\n options.appTreeApi.initialize(routeInfo);\n}\n\nexport function setIdentityApiTarget(options: {\n identityApiProxy: AppIdentityProxy;\n identityApi: IdentityApi;\n signOutTargetUrl: string;\n}) {\n options.identityApiProxy.setTarget(options.identityApi, {\n signOutTargetUrl: options.signOutTargetUrl,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;AA2DO,MAAM,eAAA,CAAsC;AAAA,EACjD,UAAA;AAAA,EACiB,IAAA;AAAA,EACA,WAAA;AAAA,EAEjB,WAAA,CAAY,MAAe,WAAA,EAAqB;AAC9C,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,WAAA,GAAc,WAAA;AAAA,EACrB;AAAA,EAEQ,kBAAA,GAAqB;AAC3B,IAAA,IAAI,CAAC,KAAK,UAAA,EAAY;AACpB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,+IAAA;AAAA,OACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,OAAA,GAAU;AACR,IAAA,IAAA,CAAK,kBAAA,EAAmB;AAExB,IAAA,OAAO,EAAE,IAAA,EAAM,IAAA,CAAK,IAAA,EAAK;AAAA,EAC3B;AAAA,EAEA,oBAAoB,SAAA,EAAyC;AAC3D,IAAA,IAAA,CAAK,kBAAA,EAAmB;AACxB,IAAA,MAAM,YAAY,IAAA,CAAK,UAAA;AACvB,IAAA,IAAI,CAAC,SAAA,EAAW;AACd,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,+IAAA;AAAA,OACF;AAAA,IACF;AAEA,IAAA,IAAI,IAAA,GAAO,SAAA;AACX,IAAA,IAAI,IAAA,CAAK,UAAA,CAAW,IAAA,CAAK,WAAW,CAAA,EAAG;AACrC,MAAA,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,WAAA,CAAY,MAAM,CAAA;AAAA,IAC3C;AAEA,IAAA,MAAM,aAAA,GAAgB,WAAA,CAAY,SAAA,CAAU,YAAA,EAAc,IAAI,CAAA;AAE9D,I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,CAAQ,SAAA;AAAA,MACnB,cAAc,OAAA,CAAQ,YAAA;AAAA,MACtB,kBAAkB,OAAA,CAAQ;AAAA;AAC5B,GACF;AAEA,EAAA,MAAM,SAAA,GAAY,2BAAA;AAAA,IAChB,QAAQ,IAAA,CAAK,IAAA;AAAA,IACb,wBAAA,CAAyB,QAAQ,aAAa;AAAA,GAChD;AAEA,EAAA,OAAA,CAAQ,kBAAA,CAAmB,UAAA;AAAA,IACzB,SAAA;AAAA,IACA,QAAQ,aAAA,CAAc;AAAA,GACxB;AACA,EAAA,OAAA,CAAQ,UAAA,CAAW,WAAW,SAAS,CAAA;AACzC;AAEO,SAAS,qBAAqB,OAAA,EAIlC;AACD,EAAA,OAAA,CAAQ,gBAAA,CAAiB,SAAA,CAAU,OAAA,CAAQ,WAAA,EAAa;AAAA,IACtD,kBAAkB,OAAA,CAAQ;AAAA,GAC3B,CAAA;AACH;;"}
|
|
@@ -210,13 +210,15 @@ function prepareSpecializedApp(options) {
|
|
|
210
210
|
providedSessionData
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
+
function setFinalized(finalizedApp) {
|
|
214
|
+
finalized = finalizedApp;
|
|
215
|
+
phase.appLifecycleApi.markFinalized();
|
|
216
|
+
}
|
|
213
217
|
const finalization = createFinalizationController({
|
|
214
218
|
getFinalized() {
|
|
215
219
|
return finalized;
|
|
216
220
|
},
|
|
217
|
-
setFinalized
|
|
218
|
-
finalized = finalizedApp;
|
|
219
|
-
},
|
|
221
|
+
setFinalized,
|
|
220
222
|
finalizeFromSessionState: finalizeWithSessionState,
|
|
221
223
|
finalizeFromBootstrapError: finalizeWithBootstrapError
|
|
222
224
|
});
|
|
@@ -313,8 +315,9 @@ function prepareSpecializedApp(options) {
|
|
|
313
315
|
"prepareSpecializedApp requires waiting for asynchronous finalization before calling finalize()"
|
|
314
316
|
);
|
|
315
317
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
+
const finalizedApp = finalizeWithSessionState(finalizedSessionState);
|
|
319
|
+
setFinalized(finalizedApp);
|
|
320
|
+
return finalizedApp;
|
|
318
321
|
}
|
|
319
322
|
};
|
|
320
323
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareSpecializedApp.esm.js","sources":["../../src/wiring/prepareSpecializedApp.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 { ConfigReader } from '@backstage/config';\nimport { isError } from '@backstage/errors';\nimport {\n AnyApiFactory,\n ApiHolder,\n AppTree,\n ConfigApi,\n coreExtensionData,\n AppNode,\n ExtensionFactoryMiddleware,\n FrontendFeature,\n IdentityApi,\n identityApiRef,\n createExtensionDataRef,\n} from '@backstage/frontend-plugin-api';\nimport {\n createExtensionDataContainer,\n OpaqueFrontendPlugin,\n} from '@internal/frontend';\nimport { OpaqueType } from '@internal/opaque';\nimport { ComponentType, ReactNode } from 'react';\n\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport {\n resolveExtensionDefinition,\n toInternalExtension,\n} from '../../../frontend-plugin-api/src/wiring/resolveExtensionDefinition';\n\nimport { CreateAppRouteBinder } from '../routing';\nimport { resolveRouteBindings } from '../routing/resolveRouteBindings';\nimport { collectRouteIds } from '../routing/collectRouteIds';\nimport { getBasePath } from '../routing/getBasePath';\nimport { Root } from '../extensions/Root';\nimport { resolveAppTree } from '../tree/resolveAppTree';\nimport { resolveAppNodeSpecs } from '../tree/resolveAppNodeSpecs';\nimport { readAppExtensionsConfig } from '../tree/readAppExtensionsConfig';\nimport {\n createPluginInfoAttacher,\n FrontendPluginInfoResolver,\n} from './createPluginInfoAttacher';\nimport {\n AppError,\n createErrorCollector,\n ErrorCollector,\n} from './createErrorCollector';\nimport {\n createPhaseApis,\n instantiateAndInitializePhaseTree,\n setIdentityApiTarget,\n} from './phaseApis';\nimport {\n collectPredicateReferences,\n createPredicateContextLoader,\n EMPTY_PREDICATE_CONTEXT,\n type ExtensionPredicateContext,\n} from './predicates';\nimport { FrontendApiRegistry } from './FrontendApiRegistry';\nimport {\n ApiFactoryEntry,\n collectApiFactoryEntries,\n registerFeatureFlagDeclarationsInHolder,\n syncFinalApiFactories,\n wrapFeatureFlagApiFactory,\n} from './apiFactories';\nimport {\n attachThrowingFinalizationChild,\n BootstrapClassification,\n classifyBootstrapTree,\n clearFinalizationBoundaryInstances,\n createBootstrapApp,\n prepareFinalizedTree,\n} from './treeLifecycle';\n\nfunction deduplicateFeatures(\n allFeatures: FrontendFeature[],\n): FrontendFeature[] {\n // Start by removing duplicates by reference\n const features = Array.from(new Set(allFeatures));\n\n // Plugins are deduplicated by ID, last one wins\n const seenIds = new Set<string>();\n return features\n .reverse()\n .filter(feature => {\n if (!OpaqueFrontendPlugin.isType(feature)) {\n return true;\n }\n if (seenIds.has(feature.id)) {\n return false;\n }\n seenIds.add(feature.id);\n return true;\n })\n .reverse();\n}\n\ntype SignInPageProps = {\n onSignInSuccess(identityApi: IdentityApi): void;\n children?: ReactNode;\n};\n\n/**\n * Result of bootstrapping a prepared specialized app.\n *\n * @public\n */\nexport type BootstrapSpecializedApp = {\n apis: ApiHolder;\n element: JSX.Element;\n tree: AppTree;\n};\n\n/**\n * Result of finalizing a prepared specialized app.\n *\n * @public\n */\nexport type FinalizedSpecializedApp = {\n apis: ApiHolder;\n element: JSX.Element;\n sessionState: SpecializedAppSessionState;\n tree: AppTree;\n errors?: AppError[];\n};\n\ntype SignInRuntime = {\n readyIdentityApi?: IdentityApi;\n requiresSignIn: boolean;\n};\n\ntype FinalizationState = {\n started: boolean;\n promise: Promise<FinalizedSpecializedApp>;\n resolve(app: FinalizedSpecializedApp): void;\n reject(error: unknown): void;\n};\n\ntype FinalizationMode = 'onFinalized' | 'finalize';\n\ntype InternalSpecializedAppSessionState = {\n apis: ApiHolder;\n identityApi?: IdentityApi;\n predicateContext: ExtensionPredicateContext;\n};\n\n/**\n * Opaque reusable session state for specialized apps.\n *\n * @public\n */\nexport type SpecializedAppSessionState = {\n $$type: '@backstage/SpecializedAppSessionState';\n};\n\nconst OpaqueSpecializedAppSessionState = OpaqueType.create<{\n public: SpecializedAppSessionState;\n versions: InternalSpecializedAppSessionState & {\n version: 'v1';\n };\n}>({\n type: '@backstage/SpecializedAppSessionState',\n versions: ['v1'],\n});\n\nconst signInPageComponentDataRef = createExtensionDataRef<\n ComponentType<SignInPageProps>\n>().with({ id: 'core.sign-in-page.component' });\n\n/**\n * Options for {@link prepareSpecializedApp}.\n *\n * @public\n */\nexport type PrepareSpecializedAppOptions = {\n /**\n * The list of features to load.\n */\n features?: FrontendFeature[];\n\n /**\n * The config API implementation to use. For most normal apps, this should be\n * specified.\n *\n * If none is given, a new _empty_ config will be used during startup. In\n * later stages of the app lifecycle, the config API in the API holder will be\n * used.\n */\n config?: ConfigApi;\n\n /**\n * Allows for the binding of plugins' external route refs within the app.\n */\n bindRoutes?(context: { bind: CreateAppRouteBinder }): void;\n\n /**\n * Advanced, more rarely used options.\n */\n advanced?: {\n /**\n * A reusable specialized app session state to use.\n *\n * This can be obtained from either the app passed to\n * {@link PreparedSpecializedApp.onFinalized} or from\n * {@link PreparedSpecializedApp.finalize}, and reused in a future app\n * instance to skip sign-in and session preparation.\n */\n sessionState?: SpecializedAppSessionState;\n\n /**\n * Applies one or more middleware on every extension, as they are added to\n * the application.\n *\n * This is an advanced use case for modifying extension data on the fly as\n * it gets emitted by extensions being instantiated.\n */\n extensionFactoryMiddleware?:\n | ExtensionFactoryMiddleware\n | ExtensionFactoryMiddleware[];\n\n /**\n * Allows for customizing how plugin info is retrieved.\n */\n pluginInfoResolver?: FrontendPluginInfoResolver;\n };\n};\n\n/**\n * Result of {@link prepareSpecializedApp}.\n *\n * @public\n */\nexport type PreparedSpecializedApp = {\n getBootstrapApp(): BootstrapSpecializedApp;\n onFinalized(callback: (app: FinalizedSpecializedApp) => void): () => void;\n finalize(): FinalizedSpecializedApp;\n};\n\n// Internal options type, not exported in the public API\nexport interface CreateSpecializedAppInternalOptions\n extends PrepareSpecializedAppOptions {\n __internal?: {\n apiFactoryOverrides?: AnyApiFactory[];\n };\n}\n\nexport function createSessionStateFromApis(\n apis: ApiHolder,\n): SpecializedAppSessionState {\n return OpaqueSpecializedAppSessionState.createInstance('v1', {\n apis,\n identityApi: apis.get(identityApiRef),\n predicateContext: EMPTY_PREDICATE_CONTEXT,\n });\n}\n\n/**\n * Prepares an app without instantiating the full extension tree.\n *\n * @remarks\n *\n * This is useful for split sign-in flows where the sign-in page should be\n * rendered first, and the full app finalized once an identity has been\n * captured.\n *\n * @public\n */\nexport function prepareSpecializedApp(\n options?: PrepareSpecializedAppOptions,\n): PreparedSpecializedApp {\n const internalOptions = options as CreateSpecializedAppInternalOptions;\n const config = options?.config ?? new ConfigReader({}, 'empty-config');\n const features = deduplicateFeatures(options?.features ?? []).map(\n createPluginInfoAttacher(config, options?.advanced?.pluginInfoResolver),\n );\n\n const collector = createErrorCollector();\n\n const tree = resolveAppTree(\n 'root',\n resolveAppNodeSpecs({\n features,\n builtinExtensions: [\n resolveExtensionDefinition(Root, { namespace: 'root' }),\n ],\n parameters: readAppExtensionsConfig(config),\n forbidden: new Set(['root']),\n collector,\n }),\n collector,\n );\n\n const appBasePath = getBasePath(config);\n const routeRefsById = collectRouteIds(features, collector);\n const routeBindings = resolveRouteBindings(\n options?.bindRoutes,\n config,\n routeRefsById,\n collector,\n );\n\n const mergedExtensionFactoryMiddleware = mergeExtensionFactoryMiddleware(\n options?.advanced?.extensionFactoryMiddleware,\n );\n const providedSessionState = options?.advanced?.sessionState;\n const providedSessionData = providedSessionState\n ? OpaqueSpecializedAppSessionState.toInternal(providedSessionState)\n : undefined;\n const providedApis = providedSessionData?.apis;\n // Bootstrap only renders the parts of the tree that are known to be safe\n // before predicate context and sign-in have been resolved.\n const bootstrapClassification = classifyBootstrapTree({\n tree,\n collector,\n });\n const predicateReferences = collectPredicateReferences(tree.nodes.values());\n const appApiRegistry = new FrontendApiRegistry();\n const internalStaticFactories =\n internalOptions?.__internal?.apiFactoryOverrides ?? [];\n const phaseStaticFactories = [...internalStaticFactories];\n const bootstrapApiFactoryEntries = new Map<string, ApiFactoryEntry>();\n const bootstrapMissingApiAccesses = new Map<\n string,\n { node: AppNode; apiRefId: string }\n >();\n\n if (providedApis) {\n // Reused session state already carries a fully prepared API holder, so the\n // bootstrap path only needs to register feature flag declarations on top.\n registerFeatureFlagDeclarationsInHolder(providedApis, features, collector);\n } else {\n // Bootstrap materializes only the immediately visible API factories. Any\n // predicate-gated API roots are revisited during finalization.\n collectApiFactoryEntries({\n apiNodes: (tree.root.edges.attachments.get('apis') ?? []).filter(\n apiNode => !bootstrapClassification.deferredApiRoots.has(apiNode),\n ),\n collector,\n entries: bootstrapApiFactoryEntries,\n });\n const apiFactories = Array.from(\n bootstrapApiFactoryEntries.values(),\n entry => wrapFeatureFlagApiFactory(entry.factory, features, collector),\n );\n appApiRegistry.registerAll(apiFactories);\n }\n const phase = createPhaseApis({\n tree,\n config,\n appApiRegistry,\n fallbackApis: providedApis,\n includeConfigApi: !providedApis,\n appBasePath,\n routeBindings,\n staticFactories: phaseStaticFactories,\n });\n const predicateContextLoader = createPredicateContextLoader({\n apis: phase.apis,\n predicateReferences,\n });\n\n let finalized: FinalizedSpecializedApp | undefined;\n let bootstrapApp: BootstrapSpecializedApp | undefined;\n const signInRuntime: SignInRuntime = { requiresSignIn: false };\n\n function updateIdentityApiTarget(identityApi?: IdentityApi) {\n if (!identityApi) {\n return;\n }\n\n setIdentityApiTarget({\n identityApiProxy: phase.identityApiProxy,\n identityApi,\n signOutTargetUrl: appBasePath || '/',\n });\n }\n\n function createSessionState(predicateContext: ExtensionPredicateContext) {\n const identityApi =\n signInRuntime.readyIdentityApi ?? providedSessionData?.identityApi;\n // As soon as a real identity is available we swap the phase proxy over so\n // the finalized tree observes the same API instance.\n updateIdentityApiTarget(identityApi);\n const sessionState = OpaqueSpecializedAppSessionState.createInstance('v1', {\n apis: phase.apis,\n identityApi,\n predicateContext,\n });\n return sessionState;\n }\n\n function getSynchronousSessionState() {\n if (providedSessionState) {\n return providedSessionState;\n }\n // The direct finalize() path is intentionally synchronous. If sign-in is\n // still pending we refuse to guess and force the caller to wait.\n if (signInRuntime.requiresSignIn) {\n return undefined;\n }\n\n const predicateContext = predicateContextLoader.getImmediate();\n if (!predicateContext) {\n return undefined;\n }\n\n return createSessionState(predicateContext);\n }\n\n function loadAsyncSessionState() {\n if (providedSessionState) {\n return Promise.resolve(providedSessionState);\n }\n if (signInRuntime.requiresSignIn && !signInRuntime.readyIdentityApi) {\n return Promise.reject(\n new Error(\n 'prepareSpecializedApp requires waiting for the bootstrap app to be ready before calling finalize()',\n ),\n );\n }\n\n // For apps without sign-in we can sometimes finalize immediately from the\n // already available predicate context, skipping the async loader.\n if (!signInRuntime.requiresSignIn) {\n const immediateSessionState = getSynchronousSessionState();\n if (immediateSessionState) {\n return Promise.resolve(immediateSessionState);\n }\n }\n\n return predicateContextLoader.load().then(createSessionState);\n }\n\n function finalizeWithSessionState(\n finalizedSessionState: SpecializedAppSessionState,\n ) {\n return finalizeFromSessionState({\n finalized,\n finalizedSessionState,\n tree,\n collector,\n phase,\n extensionFactoryMiddleware: mergedExtensionFactoryMiddleware,\n routeRefsById,\n appBasePath,\n providedApis,\n features,\n appApiRegistry,\n bootstrapClassification,\n bootstrapApiFactoryEntries,\n bootstrapMissingApiAccesses,\n });\n }\n\n function finalizeWithBootstrapError(\n error: Error,\n finalizedSessionState?: SpecializedAppSessionState,\n ) {\n return finalizeFromBootstrapError({\n finalized,\n error,\n finalizedSessionState,\n tree,\n collector,\n phase,\n extensionFactoryMiddleware: mergedExtensionFactoryMiddleware,\n routeRefsById,\n signInRuntime,\n providedSessionData,\n });\n }\n\n const finalization = createFinalizationController({\n getFinalized() {\n return finalized;\n },\n setFinalized(finalizedApp) {\n finalized = finalizedApp;\n },\n finalizeFromSessionState: finalizeWithSessionState,\n finalizeFromBootstrapError: finalizeWithBootstrapError,\n });\n\n function getBootstrapApp() {\n if (bootstrapApp) {\n return bootstrapApp;\n }\n\n if (!providedSessionState) {\n phase.identityApiProxy.setTargetHandlers({\n onTargetSet(identityApi) {\n signInRuntime.readyIdentityApi = identityApi;\n // Sign-in completion only auto-starts finalization for onFinalized().\n // The direct finalize() path stays explicit and synchronous.\n if (finalization.getMode() === 'onFinalized') {\n finalization.start(loadAsyncSessionState);\n }\n },\n });\n }\n\n const result = createBootstrapApp({\n tree,\n apis: phase.apis,\n collector,\n routeRefsById,\n routeResolutionApi: phase.routeResolutionApi,\n appTreeApi: phase.appTreeApi,\n extensionFactoryMiddleware: mergedExtensionFactoryMiddleware,\n disableSignIn: Boolean(providedSessionState),\n skipBootstrapChild({ child }) {\n return bootstrapClassification.deferredRoots.has(child);\n },\n onMissingApi({ node, apiRefId }) {\n bootstrapMissingApiAccesses.set(`${node.spec.id}:${apiRefId}`, {\n node,\n apiRefId,\n });\n },\n hasSignInPage(signInPageNode) {\n return Boolean(\n signInPageNode?.instance?.getData(signInPageComponentDataRef),\n );\n },\n });\n\n if (result.requiresSignIn) {\n signInRuntime.requiresSignIn = true;\n } else {\n phase.identityApiProxy.clearTargetHandlers();\n }\n\n bootstrapApp = { ...result.bootstrapApp, apis: phase.apis };\n\n return bootstrapApp;\n }\n\n return {\n getBootstrapApp,\n onFinalized(callback) {\n finalization.selectMode('onFinalized');\n // Subscribing to finalization also ensures the bootstrap tree exists,\n // because sign-in may need to capture identity before finalization starts.\n getBootstrapApp();\n\n let subscribed = true;\n\n if (finalized) {\n const finalizedApp = finalized;\n Promise.resolve().then(() => {\n if (subscribed) {\n callback(finalizedApp);\n }\n });\n return () => {\n subscribed = false;\n };\n }\n\n // If sign-in is still in progress we wait for the shared promise created\n // by the sign-in callback. Otherwise we can start finalization right away.\n const finalizedAppPromise =\n signInRuntime.requiresSignIn && !signInRuntime.readyIdentityApi\n ? finalization.getPromise()\n : finalization.start(loadAsyncSessionState);\n finalizedAppPromise\n .then(finalizedApp => {\n if (subscribed) {\n callback(finalizedApp);\n }\n })\n .catch(() => {});\n\n return () => {\n subscribed = false;\n };\n },\n finalize() {\n finalization.selectMode('finalize');\n if (finalized) {\n return finalized;\n }\n if (!providedSessionState) {\n // finalize() still depends on bootstrap classification and sign-in\n // discovery unless a reusable session was supplied up front, so we make\n // sure the bootstrap tree has been prepared first.\n getBootstrapApp();\n }\n\n // Direct finalization never waits for async session preparation. Callers\n // must either provide sessionState during prepareSpecializedApp() or\n // invoke finalize() only when the predicate context is already available\n // synchronously.\n const finalizedSessionState = signInRuntime.requiresSignIn\n ? undefined\n : getSynchronousSessionState();\n if (!finalizedSessionState) {\n if (signInRuntime.requiresSignIn) {\n throw new Error(\n 'prepareSpecializedApp requires waiting for the bootstrap app to be ready before calling finalize()',\n );\n }\n throw new Error(\n 'prepareSpecializedApp requires waiting for asynchronous finalization before calling finalize()',\n );\n }\n\n finalized = finalizeWithSessionState(finalizedSessionState);\n return finalized;\n },\n };\n}\n\n/**\n * Materializes the fully finalized app tree from a prepared session state.\n *\n * This is responsible for switching the identity proxy to the resolved target,\n * synchronizing any deferred API factories, and re-instantiating the parts of\n * the tree that are only valid once predicate context is available.\n */\nfunction finalizeFromSessionState(options: {\n finalized?: FinalizedSpecializedApp;\n finalizedSessionState: SpecializedAppSessionState;\n tree: AppTree;\n collector: ErrorCollector;\n phase: ReturnType<typeof createPhaseApis>;\n extensionFactoryMiddleware?: ExtensionFactoryMiddleware;\n routeRefsById: ReturnType<typeof collectRouteIds>;\n appBasePath: string;\n providedApis?: ApiHolder;\n features: FrontendFeature[];\n appApiRegistry: FrontendApiRegistry;\n bootstrapClassification: BootstrapClassification;\n bootstrapApiFactoryEntries: Map<string, ApiFactoryEntry>;\n bootstrapMissingApiAccesses: Map<string, { node: AppNode; apiRefId: string }>;\n}): FinalizedSpecializedApp {\n if (options.finalized) {\n return options.finalized;\n }\n\n const sessionStateData = OpaqueSpecializedAppSessionState.toInternal(\n options.finalizedSessionState,\n );\n if (sessionStateData.identityApi) {\n // Finalization retargets the identity proxy before any additional nodes are\n // instantiated so the full tree observes the captured identity immediately.\n setIdentityApiTarget({\n identityApiProxy: options.phase.identityApiProxy,\n identityApi: sessionStateData.identityApi,\n signOutTargetUrl: options.appBasePath || '/',\n });\n }\n if (!options.providedApis) {\n // Deferred API roots are synchronized at finalization time, but bootstrap-\n // materialized APIs stay frozen if they were already observed earlier.\n syncFinalApiFactories({\n deferredApiNodes: options.bootstrapClassification.deferredApiRoots,\n appApiRegistry: options.appApiRegistry,\n apiResolver: options.phase.apis,\n collector: options.collector,\n features: options.features,\n bootstrapApiFactoryEntries: options.bootstrapApiFactoryEntries,\n bootstrapMissingApiAccesses: options.bootstrapMissingApiAccesses,\n predicateContext: sessionStateData.predicateContext,\n });\n }\n\n prepareFinalizedTree({\n tree: options.tree,\n });\n // Finalization re-instantiates the boundary subtree so predicate-gated app\n // content can be re-evaluated without disturbing preserved bootstrap nodes.\n clearFinalizationBoundaryInstances(options.tree);\n instantiateAndInitializePhaseTree({\n tree: options.tree,\n apis: options.phase.apis,\n collector: options.collector,\n extensionFactoryMiddleware: options.extensionFactoryMiddleware,\n routeResolutionApi: options.phase.routeResolutionApi,\n appTreeApi: options.phase.appTreeApi,\n routeRefsById: options.routeRefsById,\n predicateContext: sessionStateData.predicateContext,\n });\n\n const element = options.tree.root.instance?.getData(\n coreExtensionData.reactElement,\n );\n if (!element) {\n throw new Error('Expected finalized app tree to expose a root element');\n }\n\n return {\n apis: options.phase.apis,\n element,\n sessionState: options.finalizedSessionState,\n tree: options.tree,\n errors: options.collector.collectErrors(),\n };\n}\n\n/**\n * Builds a finalized app that rethrows a bootstrap-time failure through the\n * normal app root boundary.\n *\n * This keeps the error handling path aligned with normal finalization while\n * preserving any session state that was already resolved before the failure.\n */\nfunction finalizeFromBootstrapError(options: {\n finalized?: FinalizedSpecializedApp;\n error: Error;\n finalizedSessionState?: SpecializedAppSessionState;\n tree: AppTree;\n collector: ErrorCollector;\n phase: ReturnType<typeof createPhaseApis>;\n extensionFactoryMiddleware?: ExtensionFactoryMiddleware;\n routeRefsById: ReturnType<typeof collectRouteIds>;\n signInRuntime?: SignInRuntime;\n providedSessionData?: InternalSpecializedAppSessionState;\n}): FinalizedSpecializedApp {\n if (options.finalized) {\n return options.finalized;\n }\n\n // If finalization fails after session state was already prepared, keep using\n // it so the error app reflects the same identity and API view.\n const finalizedSessionState =\n options.finalizedSessionState ??\n OpaqueSpecializedAppSessionState.createInstance('v1', {\n apis: options.phase.apis,\n identityApi:\n options.signInRuntime?.readyIdentityApi ??\n options.providedSessionData?.identityApi,\n predicateContext: EMPTY_PREDICATE_CONTEXT,\n });\n\n prepareFinalizedTree({\n tree: options.tree,\n });\n clearFinalizationBoundaryInstances(options.tree);\n // The final app reports bootstrap failures through app/root.children so the\n // normal app root boundary renders the error state for us.\n attachThrowingFinalizationChild(options.tree, options.error);\n instantiateAndInitializePhaseTree({\n tree: options.tree,\n apis: options.phase.apis,\n collector: options.collector,\n extensionFactoryMiddleware: options.extensionFactoryMiddleware,\n routeResolutionApi: options.phase.routeResolutionApi,\n appTreeApi: options.phase.appTreeApi,\n routeRefsById: options.routeRefsById,\n });\n\n const element = options.tree.root.instance?.getData(\n coreExtensionData.reactElement,\n );\n if (!element) {\n throw new Error('Expected finalized app tree to expose a root element');\n }\n\n return {\n apis: options.phase.apis,\n element,\n sessionState: finalizedSessionState,\n tree: options.tree,\n };\n}\n\n/**\n * Owns the callback-driven finalization lifecycle for a prepared app.\n *\n * The controller enforces the selected finalization mode, memoizes the shared\n * async finalization promise for `onFinalized()` subscribers, and funnels both\n * successful and failing async finalization through the same resolution path.\n */\nfunction createFinalizationController(options: {\n getFinalized(): FinalizedSpecializedApp | undefined;\n setFinalized(finalizedApp: FinalizedSpecializedApp): void;\n finalizeFromSessionState(\n finalizedSessionState: SpecializedAppSessionState,\n ): FinalizedSpecializedApp;\n finalizeFromBootstrapError(\n error: Error,\n finalizedSessionState?: SpecializedAppSessionState,\n ): FinalizedSpecializedApp;\n}) {\n let finalizationState: FinalizationState | undefined;\n let finalizationMode: FinalizationMode | undefined;\n\n function getState(): FinalizationState {\n if (finalizationState) {\n return finalizationState;\n }\n\n // onFinalized() subscribers all fan into the same promise so that the full\n // finalization flow only ever runs once.\n let resolve: ((app: FinalizedSpecializedApp) => void) | undefined;\n let reject: ((error: unknown) => void) | undefined;\n const promise = new Promise<FinalizedSpecializedApp>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n if (!resolve || !reject) {\n throw new Error('Failed to create finalization state');\n }\n\n finalizationState = {\n started: false,\n promise,\n resolve,\n reject,\n };\n return finalizationState;\n }\n\n return {\n getMode() {\n return finalizationMode;\n },\n getPromise() {\n return getState().promise;\n },\n selectMode(mode: FinalizationMode) {\n if (finalizationMode && finalizationMode !== mode) {\n throw new Error(\n `prepareSpecializedApp only supports using either onFinalized() or finalize(), not both`,\n );\n }\n\n // A prepared app now has one owner: either the callback-driven path or\n // the direct finalize() path, never both.\n finalizationMode = mode;\n },\n start(loader: () => Promise<SpecializedAppSessionState>) {\n const finalized = options.getFinalized();\n if (finalized) {\n return Promise.resolve(finalized);\n }\n\n const state = getState();\n if (state.started) {\n return state.promise;\n }\n state.started = true;\n\n // If loading finishes but final tree materialization fails, we still\n // want to preserve the resolved session state when building the error app.\n let finalizedSessionState: SpecializedAppSessionState | undefined;\n loader()\n .then(sessionState => {\n finalizedSessionState = sessionState;\n const finalizedApp = options.finalizeFromSessionState(sessionState);\n options.setFinalized(finalizedApp);\n state.resolve(finalizedApp);\n })\n .catch(error => {\n try {\n const bootstrapFailure = isError(error)\n ? error\n : new Error(String(error));\n const finalizedApp = options.finalizeFromBootstrapError(\n bootstrapFailure,\n finalizedSessionState,\n );\n options.setFinalized(finalizedApp);\n state.resolve(finalizedApp);\n } catch (finalizationError) {\n finalizationState = undefined;\n state.reject(finalizationError);\n }\n });\n\n return state.promise;\n },\n };\n}\n\n/**\n * Combines one or more extension factory middlewares into a single middleware\n * invocation chain that preserves Backstage's extension data container shape.\n */\nfunction mergeExtensionFactoryMiddleware(\n middlewares?: ExtensionFactoryMiddleware | ExtensionFactoryMiddleware[],\n): ExtensionFactoryMiddleware | undefined {\n if (!middlewares) {\n return undefined;\n }\n if (!Array.isArray(middlewares)) {\n return middlewares;\n }\n if (middlewares.length <= 1) {\n return middlewares[0];\n }\n return middlewares.reduce((prev, next) => {\n if (!prev || !next) {\n return prev ?? next;\n }\n return (orig, ctx) => {\n const internalExt = toInternalExtension(ctx.node.spec.extension);\n if (internalExt.version !== 'v2') {\n return orig();\n }\n return next(ctxOverrides => {\n return createExtensionDataContainer(\n prev(orig, {\n node: ctx.node,\n apis: ctx.apis,\n config: ctxOverrides?.config ?? ctx.config,\n }),\n 'extension factory middleware',\n );\n }, ctx);\n };\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAS,oBACP,WAAA,EACmB;AAEnB,EAAA,MAAM,WAAW,KAAA,CAAM,IAAA,CAAK,IAAI,GAAA,CAAI,WAAW,CAAC,CAAA;AAGhD,EAAA,MAAM,OAAA,uBAAc,GAAA,EAAY;AAChC,EAAA,OAAO,QAAA,CACJ,OAAA,EAAQ,CACR,MAAA,CAAO,CAAA,OAAA,KAAW;AACjB,IAAA,IAAI,CAAC,oBAAA,CAAqB,MAAA,CAAO,OAAO,CAAA,EAAG;AACzC,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA,EAAG;AAC3B,MAAA,OAAO,KAAA;AAAA,IACT;AACA,IAAA,OAAA,CAAQ,GAAA,CAAI,QAAQ,EAAE,CAAA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ACL,KAAK,IAAA,EAAM;AAAA,YACT,MAAM,GAAA,CAAI,IAAA;AAAA,YACV,MAAM,GAAA,CAAI,IAAA;AAAA,YACV,MAAA,EAAQ,YAAA,EAAc,MAAA,IAAU,GAAA,CAAI;AAAA,WACrC,CAAA;AAAA,UACD;AAAA,SACF;AAAA,MACF,GAAG,GAAG,CAAA;AAAA,IACR,CAAA;AAAA,EACF,CAAC,CAAA;AACH;;"}
|
|
1
|
+
{"version":3,"file":"prepareSpecializedApp.esm.js","sources":["../../src/wiring/prepareSpecializedApp.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 { ConfigReader } from '@backstage/config';\nimport { isError } from '@backstage/errors';\nimport {\n AnyApiFactory,\n ApiHolder,\n AppTree,\n ConfigApi,\n coreExtensionData,\n AppNode,\n ExtensionFactoryMiddleware,\n FrontendFeature,\n IdentityApi,\n identityApiRef,\n createExtensionDataRef,\n} from '@backstage/frontend-plugin-api';\nimport {\n createExtensionDataContainer,\n OpaqueFrontendPlugin,\n} from '@internal/frontend';\nimport { OpaqueType } from '@internal/opaque';\nimport { ComponentType, ReactNode } from 'react';\n\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport {\n resolveExtensionDefinition,\n toInternalExtension,\n} from '../../../frontend-plugin-api/src/wiring/resolveExtensionDefinition';\n\nimport { CreateAppRouteBinder } from '../routing';\nimport { resolveRouteBindings } from '../routing/resolveRouteBindings';\nimport { collectRouteIds } from '../routing/collectRouteIds';\nimport { getBasePath } from '../routing/getBasePath';\nimport { Root } from '../extensions/Root';\nimport { resolveAppTree } from '../tree/resolveAppTree';\nimport { resolveAppNodeSpecs } from '../tree/resolveAppNodeSpecs';\nimport { readAppExtensionsConfig } from '../tree/readAppExtensionsConfig';\nimport {\n createPluginInfoAttacher,\n FrontendPluginInfoResolver,\n} from './createPluginInfoAttacher';\nimport {\n AppError,\n createErrorCollector,\n ErrorCollector,\n} from './createErrorCollector';\nimport {\n createPhaseApis,\n instantiateAndInitializePhaseTree,\n setIdentityApiTarget,\n} from './phaseApis';\nimport {\n collectPredicateReferences,\n createPredicateContextLoader,\n EMPTY_PREDICATE_CONTEXT,\n type ExtensionPredicateContext,\n} from './predicates';\nimport { FrontendApiRegistry } from './FrontendApiRegistry';\nimport {\n ApiFactoryEntry,\n collectApiFactoryEntries,\n registerFeatureFlagDeclarationsInHolder,\n syncFinalApiFactories,\n wrapFeatureFlagApiFactory,\n} from './apiFactories';\nimport {\n attachThrowingFinalizationChild,\n BootstrapClassification,\n classifyBootstrapTree,\n clearFinalizationBoundaryInstances,\n createBootstrapApp,\n prepareFinalizedTree,\n} from './treeLifecycle';\n\nfunction deduplicateFeatures(\n allFeatures: FrontendFeature[],\n): FrontendFeature[] {\n // Start by removing duplicates by reference\n const features = Array.from(new Set(allFeatures));\n\n // Plugins are deduplicated by ID, last one wins\n const seenIds = new Set<string>();\n return features\n .reverse()\n .filter(feature => {\n if (!OpaqueFrontendPlugin.isType(feature)) {\n return true;\n }\n if (seenIds.has(feature.id)) {\n return false;\n }\n seenIds.add(feature.id);\n return true;\n })\n .reverse();\n}\n\ntype SignInPageProps = {\n onSignInSuccess(identityApi: IdentityApi): void;\n children?: ReactNode;\n};\n\n/**\n * Result of bootstrapping a prepared specialized app.\n *\n * @public\n */\nexport type BootstrapSpecializedApp = {\n apis: ApiHolder;\n element: JSX.Element;\n tree: AppTree;\n};\n\n/**\n * Result of finalizing a prepared specialized app.\n *\n * @public\n */\nexport type FinalizedSpecializedApp = {\n apis: ApiHolder;\n element: JSX.Element;\n sessionState: SpecializedAppSessionState;\n tree: AppTree;\n errors?: AppError[];\n};\n\ntype SignInRuntime = {\n readyIdentityApi?: IdentityApi;\n requiresSignIn: boolean;\n};\n\ntype FinalizationState = {\n started: boolean;\n promise: Promise<FinalizedSpecializedApp>;\n resolve(app: FinalizedSpecializedApp): void;\n reject(error: unknown): void;\n};\n\ntype FinalizationMode = 'onFinalized' | 'finalize';\n\ntype InternalSpecializedAppSessionState = {\n apis: ApiHolder;\n identityApi?: IdentityApi;\n predicateContext: ExtensionPredicateContext;\n};\n\n/**\n * Opaque reusable session state for specialized apps.\n *\n * @public\n */\nexport type SpecializedAppSessionState = {\n $$type: '@backstage/SpecializedAppSessionState';\n};\n\nconst OpaqueSpecializedAppSessionState = OpaqueType.create<{\n public: SpecializedAppSessionState;\n versions: InternalSpecializedAppSessionState & {\n version: 'v1';\n };\n}>({\n type: '@backstage/SpecializedAppSessionState',\n versions: ['v1'],\n});\n\nconst signInPageComponentDataRef = createExtensionDataRef<\n ComponentType<SignInPageProps>\n>().with({ id: 'core.sign-in-page.component' });\n\n/**\n * Options for {@link prepareSpecializedApp}.\n *\n * @public\n */\nexport type PrepareSpecializedAppOptions = {\n /**\n * The list of features to load.\n */\n features?: FrontendFeature[];\n\n /**\n * The config API implementation to use. For most normal apps, this should be\n * specified.\n *\n * If none is given, a new _empty_ config will be used during startup. In\n * later stages of the app lifecycle, the config API in the API holder will be\n * used.\n */\n config?: ConfigApi;\n\n /**\n * Allows for the binding of plugins' external route refs within the app.\n */\n bindRoutes?(context: { bind: CreateAppRouteBinder }): void;\n\n /**\n * Advanced, more rarely used options.\n */\n advanced?: {\n /**\n * A reusable specialized app session state to use.\n *\n * This can be obtained from either the app passed to\n * {@link PreparedSpecializedApp.onFinalized} or from\n * {@link PreparedSpecializedApp.finalize}, and reused in a future app\n * instance to skip sign-in and session preparation.\n */\n sessionState?: SpecializedAppSessionState;\n\n /**\n * Applies one or more middleware on every extension, as they are added to\n * the application.\n *\n * This is an advanced use case for modifying extension data on the fly as\n * it gets emitted by extensions being instantiated.\n */\n extensionFactoryMiddleware?:\n | ExtensionFactoryMiddleware\n | ExtensionFactoryMiddleware[];\n\n /**\n * Allows for customizing how plugin info is retrieved.\n */\n pluginInfoResolver?: FrontendPluginInfoResolver;\n };\n};\n\n/**\n * Result of {@link prepareSpecializedApp}.\n *\n * @public\n */\nexport type PreparedSpecializedApp = {\n getBootstrapApp(): BootstrapSpecializedApp;\n onFinalized(callback: (app: FinalizedSpecializedApp) => void): () => void;\n finalize(): FinalizedSpecializedApp;\n};\n\n// Internal options type, not exported in the public API\nexport interface CreateSpecializedAppInternalOptions\n extends PrepareSpecializedAppOptions {\n __internal?: {\n apiFactoryOverrides?: AnyApiFactory[];\n };\n}\n\nexport function createSessionStateFromApis(\n apis: ApiHolder,\n): SpecializedAppSessionState {\n return OpaqueSpecializedAppSessionState.createInstance('v1', {\n apis,\n identityApi: apis.get(identityApiRef),\n predicateContext: EMPTY_PREDICATE_CONTEXT,\n });\n}\n\n/**\n * Prepares an app without instantiating the full extension tree.\n *\n * @remarks\n *\n * This is useful for split sign-in flows where the sign-in page should be\n * rendered first, and the full app finalized once an identity has been\n * captured.\n *\n * @public\n */\nexport function prepareSpecializedApp(\n options?: PrepareSpecializedAppOptions,\n): PreparedSpecializedApp {\n const internalOptions = options as CreateSpecializedAppInternalOptions;\n const config = options?.config ?? new ConfigReader({}, 'empty-config');\n const features = deduplicateFeatures(options?.features ?? []).map(\n createPluginInfoAttacher(config, options?.advanced?.pluginInfoResolver),\n );\n\n const collector = createErrorCollector();\n\n const tree = resolveAppTree(\n 'root',\n resolveAppNodeSpecs({\n features,\n builtinExtensions: [\n resolveExtensionDefinition(Root, { namespace: 'root' }),\n ],\n parameters: readAppExtensionsConfig(config),\n forbidden: new Set(['root']),\n collector,\n }),\n collector,\n );\n\n const appBasePath = getBasePath(config);\n const routeRefsById = collectRouteIds(features, collector);\n const routeBindings = resolveRouteBindings(\n options?.bindRoutes,\n config,\n routeRefsById,\n collector,\n );\n\n const mergedExtensionFactoryMiddleware = mergeExtensionFactoryMiddleware(\n options?.advanced?.extensionFactoryMiddleware,\n );\n const providedSessionState = options?.advanced?.sessionState;\n const providedSessionData = providedSessionState\n ? OpaqueSpecializedAppSessionState.toInternal(providedSessionState)\n : undefined;\n const providedApis = providedSessionData?.apis;\n // Bootstrap only renders the parts of the tree that are known to be safe\n // before predicate context and sign-in have been resolved.\n const bootstrapClassification = classifyBootstrapTree({\n tree,\n collector,\n });\n const predicateReferences = collectPredicateReferences(tree.nodes.values());\n const appApiRegistry = new FrontendApiRegistry();\n const internalStaticFactories =\n internalOptions?.__internal?.apiFactoryOverrides ?? [];\n const phaseStaticFactories = [...internalStaticFactories];\n const bootstrapApiFactoryEntries = new Map<string, ApiFactoryEntry>();\n const bootstrapMissingApiAccesses = new Map<\n string,\n { node: AppNode; apiRefId: string }\n >();\n\n if (providedApis) {\n // Reused session state already carries a fully prepared API holder, so the\n // bootstrap path only needs to register feature flag declarations on top.\n registerFeatureFlagDeclarationsInHolder(providedApis, features, collector);\n } else {\n // Bootstrap materializes only the immediately visible API factories. Any\n // predicate-gated API roots are revisited during finalization.\n collectApiFactoryEntries({\n apiNodes: (tree.root.edges.attachments.get('apis') ?? []).filter(\n apiNode => !bootstrapClassification.deferredApiRoots.has(apiNode),\n ),\n collector,\n entries: bootstrapApiFactoryEntries,\n });\n const apiFactories = Array.from(\n bootstrapApiFactoryEntries.values(),\n entry => wrapFeatureFlagApiFactory(entry.factory, features, collector),\n );\n appApiRegistry.registerAll(apiFactories);\n }\n const phase = createPhaseApis({\n tree,\n config,\n appApiRegistry,\n fallbackApis: providedApis,\n includeConfigApi: !providedApis,\n appBasePath,\n routeBindings,\n staticFactories: phaseStaticFactories,\n });\n const predicateContextLoader = createPredicateContextLoader({\n apis: phase.apis,\n predicateReferences,\n });\n\n let finalized: FinalizedSpecializedApp | undefined;\n let bootstrapApp: BootstrapSpecializedApp | undefined;\n const signInRuntime: SignInRuntime = { requiresSignIn: false };\n\n function updateIdentityApiTarget(identityApi?: IdentityApi) {\n if (!identityApi) {\n return;\n }\n\n setIdentityApiTarget({\n identityApiProxy: phase.identityApiProxy,\n identityApi,\n signOutTargetUrl: appBasePath || '/',\n });\n }\n\n function createSessionState(predicateContext: ExtensionPredicateContext) {\n const identityApi =\n signInRuntime.readyIdentityApi ?? providedSessionData?.identityApi;\n // As soon as a real identity is available we swap the phase proxy over so\n // the finalized tree observes the same API instance.\n updateIdentityApiTarget(identityApi);\n const sessionState = OpaqueSpecializedAppSessionState.createInstance('v1', {\n apis: phase.apis,\n identityApi,\n predicateContext,\n });\n return sessionState;\n }\n\n function getSynchronousSessionState() {\n if (providedSessionState) {\n return providedSessionState;\n }\n // The direct finalize() path is intentionally synchronous. If sign-in is\n // still pending we refuse to guess and force the caller to wait.\n if (signInRuntime.requiresSignIn) {\n return undefined;\n }\n\n const predicateContext = predicateContextLoader.getImmediate();\n if (!predicateContext) {\n return undefined;\n }\n\n return createSessionState(predicateContext);\n }\n\n function loadAsyncSessionState() {\n if (providedSessionState) {\n return Promise.resolve(providedSessionState);\n }\n if (signInRuntime.requiresSignIn && !signInRuntime.readyIdentityApi) {\n return Promise.reject(\n new Error(\n 'prepareSpecializedApp requires waiting for the bootstrap app to be ready before calling finalize()',\n ),\n );\n }\n\n // For apps without sign-in we can sometimes finalize immediately from the\n // already available predicate context, skipping the async loader.\n if (!signInRuntime.requiresSignIn) {\n const immediateSessionState = getSynchronousSessionState();\n if (immediateSessionState) {\n return Promise.resolve(immediateSessionState);\n }\n }\n\n return predicateContextLoader.load().then(createSessionState);\n }\n\n function finalizeWithSessionState(\n finalizedSessionState: SpecializedAppSessionState,\n ) {\n return finalizeFromSessionState({\n finalized,\n finalizedSessionState,\n tree,\n collector,\n phase,\n extensionFactoryMiddleware: mergedExtensionFactoryMiddleware,\n routeRefsById,\n appBasePath,\n providedApis,\n features,\n appApiRegistry,\n bootstrapClassification,\n bootstrapApiFactoryEntries,\n bootstrapMissingApiAccesses,\n });\n }\n\n function finalizeWithBootstrapError(\n error: Error,\n finalizedSessionState?: SpecializedAppSessionState,\n ) {\n return finalizeFromBootstrapError({\n finalized,\n error,\n finalizedSessionState,\n tree,\n collector,\n phase,\n extensionFactoryMiddleware: mergedExtensionFactoryMiddleware,\n routeRefsById,\n signInRuntime,\n providedSessionData,\n });\n }\n\n function setFinalized(finalizedApp: FinalizedSpecializedApp) {\n finalized = finalizedApp;\n phase.appLifecycleApi.markFinalized();\n }\n\n const finalization = createFinalizationController({\n getFinalized() {\n return finalized;\n },\n setFinalized,\n finalizeFromSessionState: finalizeWithSessionState,\n finalizeFromBootstrapError: finalizeWithBootstrapError,\n });\n\n function getBootstrapApp() {\n if (bootstrapApp) {\n return bootstrapApp;\n }\n\n if (!providedSessionState) {\n phase.identityApiProxy.setTargetHandlers({\n onTargetSet(identityApi) {\n signInRuntime.readyIdentityApi = identityApi;\n // Sign-in completion only auto-starts finalization for onFinalized().\n // The direct finalize() path stays explicit and synchronous.\n if (finalization.getMode() === 'onFinalized') {\n finalization.start(loadAsyncSessionState);\n }\n },\n });\n }\n\n const result = createBootstrapApp({\n tree,\n apis: phase.apis,\n collector,\n routeRefsById,\n routeResolutionApi: phase.routeResolutionApi,\n appTreeApi: phase.appTreeApi,\n extensionFactoryMiddleware: mergedExtensionFactoryMiddleware,\n disableSignIn: Boolean(providedSessionState),\n skipBootstrapChild({ child }) {\n return bootstrapClassification.deferredRoots.has(child);\n },\n onMissingApi({ node, apiRefId }) {\n bootstrapMissingApiAccesses.set(`${node.spec.id}:${apiRefId}`, {\n node,\n apiRefId,\n });\n },\n hasSignInPage(signInPageNode) {\n return Boolean(\n signInPageNode?.instance?.getData(signInPageComponentDataRef),\n );\n },\n });\n\n if (result.requiresSignIn) {\n signInRuntime.requiresSignIn = true;\n } else {\n phase.identityApiProxy.clearTargetHandlers();\n }\n\n bootstrapApp = { ...result.bootstrapApp, apis: phase.apis };\n\n return bootstrapApp;\n }\n\n return {\n getBootstrapApp,\n onFinalized(callback) {\n finalization.selectMode('onFinalized');\n // Subscribing to finalization also ensures the bootstrap tree exists,\n // because sign-in may need to capture identity before finalization starts.\n getBootstrapApp();\n\n let subscribed = true;\n\n if (finalized) {\n const finalizedApp = finalized;\n Promise.resolve().then(() => {\n if (subscribed) {\n callback(finalizedApp);\n }\n });\n return () => {\n subscribed = false;\n };\n }\n\n // If sign-in is still in progress we wait for the shared promise created\n // by the sign-in callback. Otherwise we can start finalization right away.\n const finalizedAppPromise =\n signInRuntime.requiresSignIn && !signInRuntime.readyIdentityApi\n ? finalization.getPromise()\n : finalization.start(loadAsyncSessionState);\n finalizedAppPromise\n .then(finalizedApp => {\n if (subscribed) {\n callback(finalizedApp);\n }\n })\n .catch(() => {});\n\n return () => {\n subscribed = false;\n };\n },\n finalize() {\n finalization.selectMode('finalize');\n if (finalized) {\n return finalized;\n }\n if (!providedSessionState) {\n // finalize() still depends on bootstrap classification and sign-in\n // discovery unless a reusable session was supplied up front, so we make\n // sure the bootstrap tree has been prepared first.\n getBootstrapApp();\n }\n\n // Direct finalization never waits for async session preparation. Callers\n // must either provide sessionState during prepareSpecializedApp() or\n // invoke finalize() only when the predicate context is already available\n // synchronously.\n const finalizedSessionState = signInRuntime.requiresSignIn\n ? undefined\n : getSynchronousSessionState();\n if (!finalizedSessionState) {\n if (signInRuntime.requiresSignIn) {\n throw new Error(\n 'prepareSpecializedApp requires waiting for the bootstrap app to be ready before calling finalize()',\n );\n }\n throw new Error(\n 'prepareSpecializedApp requires waiting for asynchronous finalization before calling finalize()',\n );\n }\n\n const finalizedApp = finalizeWithSessionState(finalizedSessionState);\n setFinalized(finalizedApp);\n return finalizedApp;\n },\n };\n}\n\n/**\n * Materializes the fully finalized app tree from a prepared session state.\n *\n * This is responsible for switching the identity proxy to the resolved target,\n * synchronizing any deferred API factories, and re-instantiating the parts of\n * the tree that are only valid once predicate context is available.\n */\nfunction finalizeFromSessionState(options: {\n finalized?: FinalizedSpecializedApp;\n finalizedSessionState: SpecializedAppSessionState;\n tree: AppTree;\n collector: ErrorCollector;\n phase: ReturnType<typeof createPhaseApis>;\n extensionFactoryMiddleware?: ExtensionFactoryMiddleware;\n routeRefsById: ReturnType<typeof collectRouteIds>;\n appBasePath: string;\n providedApis?: ApiHolder;\n features: FrontendFeature[];\n appApiRegistry: FrontendApiRegistry;\n bootstrapClassification: BootstrapClassification;\n bootstrapApiFactoryEntries: Map<string, ApiFactoryEntry>;\n bootstrapMissingApiAccesses: Map<string, { node: AppNode; apiRefId: string }>;\n}): FinalizedSpecializedApp {\n if (options.finalized) {\n return options.finalized;\n }\n\n const sessionStateData = OpaqueSpecializedAppSessionState.toInternal(\n options.finalizedSessionState,\n );\n if (sessionStateData.identityApi) {\n // Finalization retargets the identity proxy before any additional nodes are\n // instantiated so the full tree observes the captured identity immediately.\n setIdentityApiTarget({\n identityApiProxy: options.phase.identityApiProxy,\n identityApi: sessionStateData.identityApi,\n signOutTargetUrl: options.appBasePath || '/',\n });\n }\n if (!options.providedApis) {\n // Deferred API roots are synchronized at finalization time, but bootstrap-\n // materialized APIs stay frozen if they were already observed earlier.\n syncFinalApiFactories({\n deferredApiNodes: options.bootstrapClassification.deferredApiRoots,\n appApiRegistry: options.appApiRegistry,\n apiResolver: options.phase.apis,\n collector: options.collector,\n features: options.features,\n bootstrapApiFactoryEntries: options.bootstrapApiFactoryEntries,\n bootstrapMissingApiAccesses: options.bootstrapMissingApiAccesses,\n predicateContext: sessionStateData.predicateContext,\n });\n }\n\n prepareFinalizedTree({\n tree: options.tree,\n });\n // Finalization re-instantiates the boundary subtree so predicate-gated app\n // content can be re-evaluated without disturbing preserved bootstrap nodes.\n clearFinalizationBoundaryInstances(options.tree);\n instantiateAndInitializePhaseTree({\n tree: options.tree,\n apis: options.phase.apis,\n collector: options.collector,\n extensionFactoryMiddleware: options.extensionFactoryMiddleware,\n routeResolutionApi: options.phase.routeResolutionApi,\n appTreeApi: options.phase.appTreeApi,\n routeRefsById: options.routeRefsById,\n predicateContext: sessionStateData.predicateContext,\n });\n\n const element = options.tree.root.instance?.getData(\n coreExtensionData.reactElement,\n );\n if (!element) {\n throw new Error('Expected finalized app tree to expose a root element');\n }\n\n return {\n apis: options.phase.apis,\n element,\n sessionState: options.finalizedSessionState,\n tree: options.tree,\n errors: options.collector.collectErrors(),\n };\n}\n\n/**\n * Builds a finalized app that rethrows a bootstrap-time failure through the\n * normal app root boundary.\n *\n * This keeps the error handling path aligned with normal finalization while\n * preserving any session state that was already resolved before the failure.\n */\nfunction finalizeFromBootstrapError(options: {\n finalized?: FinalizedSpecializedApp;\n error: Error;\n finalizedSessionState?: SpecializedAppSessionState;\n tree: AppTree;\n collector: ErrorCollector;\n phase: ReturnType<typeof createPhaseApis>;\n extensionFactoryMiddleware?: ExtensionFactoryMiddleware;\n routeRefsById: ReturnType<typeof collectRouteIds>;\n signInRuntime?: SignInRuntime;\n providedSessionData?: InternalSpecializedAppSessionState;\n}): FinalizedSpecializedApp {\n if (options.finalized) {\n return options.finalized;\n }\n\n // If finalization fails after session state was already prepared, keep using\n // it so the error app reflects the same identity and API view.\n const finalizedSessionState =\n options.finalizedSessionState ??\n OpaqueSpecializedAppSessionState.createInstance('v1', {\n apis: options.phase.apis,\n identityApi:\n options.signInRuntime?.readyIdentityApi ??\n options.providedSessionData?.identityApi,\n predicateContext: EMPTY_PREDICATE_CONTEXT,\n });\n\n prepareFinalizedTree({\n tree: options.tree,\n });\n clearFinalizationBoundaryInstances(options.tree);\n // The final app reports bootstrap failures through app/root.children so the\n // normal app root boundary renders the error state for us.\n attachThrowingFinalizationChild(options.tree, options.error);\n instantiateAndInitializePhaseTree({\n tree: options.tree,\n apis: options.phase.apis,\n collector: options.collector,\n extensionFactoryMiddleware: options.extensionFactoryMiddleware,\n routeResolutionApi: options.phase.routeResolutionApi,\n appTreeApi: options.phase.appTreeApi,\n routeRefsById: options.routeRefsById,\n });\n\n const element = options.tree.root.instance?.getData(\n coreExtensionData.reactElement,\n );\n if (!element) {\n throw new Error('Expected finalized app tree to expose a root element');\n }\n\n return {\n apis: options.phase.apis,\n element,\n sessionState: finalizedSessionState,\n tree: options.tree,\n };\n}\n\n/**\n * Owns the callback-driven finalization lifecycle for a prepared app.\n *\n * The controller enforces the selected finalization mode, memoizes the shared\n * async finalization promise for `onFinalized()` subscribers, and funnels both\n * successful and failing async finalization through the same resolution path.\n */\nfunction createFinalizationController(options: {\n getFinalized(): FinalizedSpecializedApp | undefined;\n setFinalized(finalizedApp: FinalizedSpecializedApp): void;\n finalizeFromSessionState(\n finalizedSessionState: SpecializedAppSessionState,\n ): FinalizedSpecializedApp;\n finalizeFromBootstrapError(\n error: Error,\n finalizedSessionState?: SpecializedAppSessionState,\n ): FinalizedSpecializedApp;\n}) {\n let finalizationState: FinalizationState | undefined;\n let finalizationMode: FinalizationMode | undefined;\n\n function getState(): FinalizationState {\n if (finalizationState) {\n return finalizationState;\n }\n\n // onFinalized() subscribers all fan into the same promise so that the full\n // finalization flow only ever runs once.\n let resolve: ((app: FinalizedSpecializedApp) => void) | undefined;\n let reject: ((error: unknown) => void) | undefined;\n const promise = new Promise<FinalizedSpecializedApp>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n if (!resolve || !reject) {\n throw new Error('Failed to create finalization state');\n }\n\n finalizationState = {\n started: false,\n promise,\n resolve,\n reject,\n };\n return finalizationState;\n }\n\n return {\n getMode() {\n return finalizationMode;\n },\n getPromise() {\n return getState().promise;\n },\n selectMode(mode: FinalizationMode) {\n if (finalizationMode && finalizationMode !== mode) {\n throw new Error(\n `prepareSpecializedApp only supports using either onFinalized() or finalize(), not both`,\n );\n }\n\n // A prepared app now has one owner: either the callback-driven path or\n // the direct finalize() path, never both.\n finalizationMode = mode;\n },\n start(loader: () => Promise<SpecializedAppSessionState>) {\n const finalized = options.getFinalized();\n if (finalized) {\n return Promise.resolve(finalized);\n }\n\n const state = getState();\n if (state.started) {\n return state.promise;\n }\n state.started = true;\n\n // If loading finishes but final tree materialization fails, we still\n // want to preserve the resolved session state when building the error app.\n let finalizedSessionState: SpecializedAppSessionState | undefined;\n loader()\n .then(sessionState => {\n finalizedSessionState = sessionState;\n const finalizedApp = options.finalizeFromSessionState(sessionState);\n options.setFinalized(finalizedApp);\n state.resolve(finalizedApp);\n })\n .catch(error => {\n try {\n const bootstrapFailure = isError(error)\n ? error\n : new Error(String(error));\n const finalizedApp = options.finalizeFromBootstrapError(\n bootstrapFailure,\n finalizedSessionState,\n );\n options.setFinalized(finalizedApp);\n state.resolve(finalizedApp);\n } catch (finalizationError) {\n finalizationState = undefined;\n state.reject(finalizationError);\n }\n });\n\n return state.promise;\n },\n };\n}\n\n/**\n * Combines one or more extension factory middlewares into a single middleware\n * invocation chain that preserves Backstage's extension data container shape.\n */\nfunction mergeExtensionFactoryMiddleware(\n middlewares?: ExtensionFactoryMiddleware | ExtensionFactoryMiddleware[],\n): ExtensionFactoryMiddleware | undefined {\n if (!middlewares) {\n return undefined;\n }\n if (!Array.isArray(middlewares)) {\n return middlewares;\n }\n if (middlewares.length <= 1) {\n return middlewares[0];\n }\n return middlewares.reduce((prev, next) => {\n if (!prev || !next) {\n return prev ?? next;\n }\n return (orig, ctx) => {\n const internalExt = toInternalExtension(ctx.node.spec.extension);\n if (internalExt.version !== 'v2') {\n return orig();\n }\n return next(ctxOverrides => {\n return createExtensionDataContainer(\n prev(orig, {\n node: ctx.node,\n apis: ctx.apis,\n config: ctxOverrides?.config ?? ctx.config,\n }),\n 'extension factory middleware',\n );\n }, ctx);\n };\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAS,oBACP,WAAA,EACmB;AAEnB,EAAA,MAAM,WAAW,KAAA,CAAM,IAAA,CAAK,IAAI,GAAA,CAAI,WAAW,CAAC,CAAA;AAGhD,EAAA,MAAM,OAAA,uBAAc,GAAA,EAAY;AAChC,EAAA,OAAO,QAAA,CACJ,OAAA,EAAQ,CACR,MAAA,CAAO,CAAA,OAAA,KAAW;AACjB,IAAA,IAAI,CAAC,oBAAA,C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ClB,MAAA,OAAO,IAAA,IAAQ,IAAA;AAAA,IACjB;AACA,IAAA,OAAO,CAAC,MAAM,GAAA,KAAQ;AACpB,MAAA,MAAM,WAAA,GAAc,mBAAA,CAAoB,GAAA,CAAI,IAAA,CAAK,KAAK,SAAS,CAAA;AAC/D,MAAA,IAAI,WAAA,CAAY,YAAY,IAAA,EAAM;AAChC,QAAA,OAAO,IAAA,EAAK;AAAA,MACd;AACA,MAAA,OAAO,KAAK,CAAA,YAAA,KAAgB;AAC1B,QAAA,OAAO,4BAAA;AAAA,UACL,KAAK,IAAA,EAAM;AAAA,YACT,MAAM,GAAA,CAAI,IAAA;AAAA,YACV,MAAM,GAAA,CAAI,IAAA;AAAA,YACV,MAAA,EAAQ,YAAA,EAAc,MAAA,IAAU,GAAA,CAAI;AAAA,WACrC,CAAA;AAAA,UACD;AAAA,SACF;AAAA,MACF,GAAG,GAAG,CAAA;AAAA,IACR,CAAA;AAAA,EACF,CAAC,CAAA;AACH;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/frontend-app-api",
|
|
3
|
-
"version": "0.16.9-next.
|
|
3
|
+
"version": "0.16.9-next.1",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "web-library"
|
|
6
6
|
},
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@backstage/config": "1.3.10-next.0",
|
|
36
|
-
"@backstage/core-app-api": "1.20.6-next.
|
|
36
|
+
"@backstage/core-app-api": "1.20.6-next.1",
|
|
37
37
|
"@backstage/core-plugin-api": "1.12.11-next.0",
|
|
38
38
|
"@backstage/errors": "1.3.2-next.0",
|
|
39
39
|
"@backstage/filter-predicates": "0.1.6-next.0",
|
|
40
40
|
"@backstage/frontend-defaults": "0.5.7-next.0",
|
|
41
|
-
"@backstage/frontend-plugin-api": "0.18.2-next.
|
|
41
|
+
"@backstage/frontend-plugin-api": "0.18.2-next.1",
|
|
42
42
|
"@backstage/types": "1.2.2",
|
|
43
43
|
"@backstage/version-bridge": "1.0.12",
|
|
44
44
|
"lodash": "^4.17.21"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@backstage/cli": "0.36.7-next.0",
|
|
48
48
|
"@backstage/frontend-test-utils": "0.6.5-next.0",
|
|
49
|
-
"@backstage/plugin-app": "0.5.4-next.
|
|
49
|
+
"@backstage/plugin-app": "0.5.4-next.1",
|
|
50
50
|
"@backstage/plugin-permission-common": "0.9.12-next.0",
|
|
51
51
|
"@backstage/test-utils": "1.7.23-next.0",
|
|
52
52
|
"@testing-library/dom": "^10.0.0",
|