@backstage/frontend-plugin-api 0.18.0-next.0 → 0.18.1-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @backstage/frontend-plugin-api
2
2
 
3
+ ## 0.18.1-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 024c0ef: Updated internal type imports to avoid circular declaration chunks in package builds.
8
+ - Updated dependencies
9
+ - @backstage/filter-predicates@0.1.5-next.0
10
+
11
+ ## 0.18.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 907793c: **BREAKING**: Removed the deprecated `config.schema` option for extensions and extension blueprints. Use the top-level `configSchema` option with Standard Schema-compatible schema values, such as Zod v4.
16
+
17
+ ### Patch Changes
18
+
19
+ - e156f1e: Added support for using a `SubRouteRef` as the parent of another `SubRouteRef`. Child paths are combined with ancestor paths at creation, and nested sub-routes inherit parameters from their complete ancestor chain.
20
+
3
21
  ## 0.18.0-next.0
4
22
 
5
23
  ### Minor Changes
package/dist/alpha.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { b as AnyRouteRefParams, d as ApiHolder, e as ApiRef, f as AppNode, g as AppNodeEdges, h as AppNodeInstance, i as AppNodeSpec, j as AppTree, C as ConfigurableExtensionDataRef, E as Extension, p as ExtensionAttachTo, q as ExtensionBlueprint, r as ExtensionBlueprintDefineParams, s as ExtensionBlueprintParameters, t as ExtensionBlueprintParams, u as ExtensionDataContainer, v as ExtensionDataRef, w as ExtensionDataValue, x as ExtensionDefinition, y as ExtensionDefinitionAttachTo, z as ExtensionDefinitionParameters, D as ExtensionInput, F as ExternalRouteRef, J as FrontendPlugin, K as FrontendPluginInfo, N as IconElement, O as OverridableExtensionDefinition, R as PluginWrapperApi, S as PluginWrapperBlueprint, T as PluginWrapperDefinition, U as PortableSchema, V as RouteRef, W as SubRouteRef, $ as createExtensionBlueprintParams, a7 as pluginWrapperApiRef } from './types/alpha.d-CUDLigYe.js';
1
+ export { b as AnyRouteRefParams, d as ApiHolder, e as ApiRef, f as AppNode, g as AppNodeEdges, h as AppNodeInstance, i as AppNodeSpec, j as AppTree, C as ConfigurableExtensionDataRef, E as Extension, p as ExtensionAttachTo, q as ExtensionBlueprint, r as ExtensionBlueprintDefineParams, s as ExtensionBlueprintParameters, t as ExtensionBlueprintParams, u as ExtensionDataContainer, v as ExtensionDataRef, w as ExtensionDataValue, x as ExtensionDefinition, y as ExtensionDefinitionAttachTo, z as ExtensionDefinitionParameters, D as ExtensionInput, F as ExternalRouteRef, J as FrontendPlugin, K as FrontendPluginInfo, N as IconElement, O as OverridableExtensionDefinition, R as PluginWrapperApi, S as PluginWrapperBlueprint, T as PluginWrapperDefinition, U as PortableSchema, V as RouteRef, W as SubRouteRef, $ as createExtensionBlueprintParams, a7 as pluginWrapperApiRef } from './types/alpha.d-gY8B1WFX.js';
2
2
  export { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import '@backstage/frontend-plugin-api';
4
4
  import 'react';
@@ -1 +1 @@
1
- {"version":3,"file":"AppNodeProvider.esm.js","sources":["../../src/components/AppNodeProvider.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 createVersionedContext,\n createVersionedValueMap,\n useVersionedContext,\n} from '@backstage/version-bridge';\nimport { AppNode } from '../apis';\nimport { ReactNode } from 'react';\n\nconst CONTEXT_KEY = 'app-node-context';\n\ntype AppNodeContextV1 = {\n node?: AppNode;\n};\n\ntype AppNodeContextMap = {\n 1: AppNodeContextV1;\n};\n\nconst AppNodeContext = createVersionedContext<AppNodeContextMap>(CONTEXT_KEY);\n\n/** @internal */\nexport function AppNodeProvider({\n node,\n children,\n}: {\n node: AppNode;\n children: ReactNode;\n}) {\n const versionedValue = createVersionedValueMap({ 1: { node } });\n\n return <AppNodeContext.Provider value={versionedValue} children={children} />;\n}\n\n/**\n * React hook providing access to the current {@link AppNode}.\n *\n * @public\n * @remarks\n *\n * This hook will return the {@link AppNode} for the closest extension. This\n * relies on the extension using the {@link (ExtensionBoundary:function)} component in its\n * implementation, which is included by default for all common blueprints.\n *\n * If the current component is not inside an {@link (ExtensionBoundary:function)}, it will\n * return `undefined`.\n */\nexport function useAppNode(): AppNode | undefined {\n const versionedContext = useVersionedContext<AppNodeContextMap>(CONTEXT_KEY);\n if (!versionedContext) {\n return undefined;\n }\n\n const context = versionedContext.atVersion(1);\n if (!context) {\n throw new Error('AppNodeContext v1 not available');\n }\n return context.node;\n}\n"],"names":[],"mappings":";;;AAwBA,MAAM,WAAA,GAAc,kBAAA;AAUpB,MAAM,cAAA,GAAiB,uBAA0C,WAAW,CAAA;AAGrE,SAAS,eAAA,CAAgB;AAAA,EAC9B,IAAA;AAAA,EACA;AACF,CAAA,EAGG;AACD,EAAA,MAAM,iBAAiB,uBAAA,CAAwB,EAAE,GAAG,EAAE,IAAA,IAAQ,CAAA;AAE9D,EAAA,2BAAQ,cAAA,CAAe,QAAA,EAAf,EAAwB,KAAA,EAAO,gBAAgB,QAAA,EAAoB,CAAA;AAC7E;AAeO,SAAS,UAAA,GAAkC;AAChD,EAAA,MAAM,gBAAA,GAAmB,oBAAuC,WAAW,CAAA;AAC3E,EAAA,IAAI,CAAC,gBAAA,EAAkB;AACrB,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,OAAA,GAAU,gBAAA,CAAiB,SAAA,CAAU,CAAC,CAAA;AAC5C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,EACnD;AACA,EAAA,OAAO,OAAA,CAAQ,IAAA;AACjB;;;;"}
1
+ {"version":3,"file":"AppNodeProvider.esm.js","sources":["../../src/components/AppNodeProvider.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 createVersionedContext,\n createVersionedValueMap,\n useVersionedContext,\n} from '@backstage/version-bridge';\nimport type { AppNode } from '../apis/definitions/AppTreeApi';\nimport { ReactNode } from 'react';\n\nconst CONTEXT_KEY = 'app-node-context';\n\ntype AppNodeContextV1 = {\n node?: AppNode;\n};\n\ntype AppNodeContextMap = {\n 1: AppNodeContextV1;\n};\n\nconst AppNodeContext = createVersionedContext<AppNodeContextMap>(CONTEXT_KEY);\n\n/** @internal */\nexport function AppNodeProvider({\n node,\n children,\n}: {\n node: AppNode;\n children: ReactNode;\n}) {\n const versionedValue = createVersionedValueMap({ 1: { node } });\n\n return <AppNodeContext.Provider value={versionedValue} children={children} />;\n}\n\n/**\n * React hook providing access to the current {@link AppNode}.\n *\n * @public\n * @remarks\n *\n * This hook will return the {@link AppNode} for the closest extension. This\n * relies on the extension using the {@link (ExtensionBoundary:function)} component in its\n * implementation, which is included by default for all common blueprints.\n *\n * If the current component is not inside an {@link (ExtensionBoundary:function)}, it will\n * return `undefined`.\n */\nexport function useAppNode(): AppNode | undefined {\n const versionedContext = useVersionedContext<AppNodeContextMap>(CONTEXT_KEY);\n if (!versionedContext) {\n return undefined;\n }\n\n const context = versionedContext.atVersion(1);\n if (!context) {\n throw new Error('AppNodeContext v1 not available');\n }\n return context.node;\n}\n"],"names":[],"mappings":";;;AAwBA,MAAM,WAAA,GAAc,kBAAA;AAUpB,MAAM,cAAA,GAAiB,uBAA0C,WAAW,CAAA;AAGrE,SAAS,eAAA,CAAgB;AAAA,EAC9B,IAAA;AAAA,EACA;AACF,CAAA,EAGG;AACD,EAAA,MAAM,iBAAiB,uBAAA,CAAwB,EAAE,GAAG,EAAE,IAAA,IAAQ,CAAA;AAE9D,EAAA,2BAAQ,cAAA,CAAe,QAAA,EAAf,EAAwB,KAAA,EAAO,gBAAgB,QAAA,EAAoB,CAAA;AAC7E;AAeO,SAAS,UAAA,GAAkC;AAChD,EAAA,MAAM,gBAAA,GAAmB,oBAAuC,WAAW,CAAA;AAC3E,EAAA,IAAI,CAAC,gBAAA,EAAkB;AACrB,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,OAAA,GAAU,gBAAA,CAAiB,SAAA,CAAU,CAAC,CAAA;AAC5C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,EACnD;AACA,EAAA,OAAO,OAAA,CAAQ,IAAA;AACjB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExtensionBoundary.esm.js","sources":["../../src/components/ExtensionBoundary.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 PropsWithChildren,\n ReactNode,\n Suspense,\n useEffect,\n useMemo,\n lazy as reactLazy,\n} from 'react';\nimport { AnalyticsContext, useAnalytics } from '../analytics';\nimport { ErrorDisplayBoundary } from './ErrorDisplayBoundary';\nimport { ErrorApiBoundary } from './ErrorApiBoundary';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { routableExtensionRenderedEvent } from '../../../core-plugin-api/src/analytics/Tracker';\nimport { AppNode, ErrorApi, errorApiRef, useApi } from '../apis';\nimport {\n PluginWrapperApi,\n pluginWrapperApiRef,\n} from '../apis/definitions/PluginWrapperApi';\nimport { coreExtensionData } from '../wiring';\nimport { AppNodeProvider } from './AppNodeProvider';\nimport { Progress } from './DefaultSwappableComponents';\n\nfunction useOptionalErrorApi(): ErrorApi | undefined {\n try {\n return useApi(errorApiRef);\n } catch {\n return undefined;\n }\n}\n\nfunction useOptionalPluginWrapperApi(): PluginWrapperApi | undefined {\n try {\n return useApi(pluginWrapperApiRef);\n } catch {\n return undefined;\n }\n}\ntype RouteTrackerProps = PropsWithChildren<{\n enabled?: boolean;\n}>;\n\nconst RouteTracker = (props: RouteTrackerProps) => {\n const { enabled, children } = props;\n const analytics = useAnalytics();\n\n // This event, never exposed to end-users of the analytics API,\n // helps inform which extension metadata gets associated with a\n // navigation event when the route navigated to is a gathered\n // mountpoint.\n useEffect(() => {\n if (enabled) {\n analytics.captureEvent(routableExtensionRenderedEvent, '');\n }\n }, [analytics, enabled]);\n\n return <>{children}</>;\n};\n\n/** @public */\nexport interface ExtensionBoundaryProps {\n errorPresentation?: 'error-api' | 'error-display';\n node: AppNode;\n children: ReactNode;\n}\n\n/** @public */\nexport function ExtensionBoundary(props: ExtensionBoundaryProps) {\n const { node, children } = props;\n\n const errorApi = useOptionalErrorApi();\n\n const hasRoutePathOutput = Boolean(\n node.instance?.getData(coreExtensionData.routePath),\n );\n\n const plugin = node.spec.plugin;\n const pluginId = plugin.pluginId ?? 'app';\n\n const pluginWrapperApi = useOptionalPluginWrapperApi();\n\n const PluginWrapper = useMemo(() => {\n return pluginWrapperApi?.getPluginWrapper(pluginId);\n }, [pluginWrapperApi, pluginId]);\n\n // Skipping \"routeRef\" attribute in the new system, the extension \"id\" should provide more insight\n const attributes = {\n extensionId: node.spec.id,\n pluginId,\n };\n\n let content = (\n <AnalyticsContext attributes={attributes}>\n <RouteTracker enabled={hasRoutePathOutput}>{children}</RouteTracker>\n </AnalyticsContext>\n );\n\n if (PluginWrapper) {\n content = <PluginWrapper>{content}</PluginWrapper>;\n }\n\n if (props.errorPresentation === 'error-api') {\n content = (\n <ErrorApiBoundary node={node} errorApi={errorApi}>\n {content}\n </ErrorApiBoundary>\n );\n } else {\n content = (\n <ErrorDisplayBoundary plugin={plugin}>{content}</ErrorDisplayBoundary>\n );\n }\n\n return (\n <AppNodeProvider node={node}>\n <Suspense fallback={<Progress />}>{content}</Suspense>\n </AppNodeProvider>\n );\n}\n\n/** @public */\nexport namespace ExtensionBoundary {\n export function lazy(\n appNode: AppNode,\n loader: () => Promise<JSX.Element>,\n ): JSX.Element {\n const ExtensionComponent = reactLazy(() =>\n loader().then(element => ({ default: () => element })),\n );\n return (\n <ExtensionBoundary node={appNode}>\n <ExtensionComponent />\n </ExtensionBoundary>\n );\n }\n\n export function lazyComponent<TProps extends {}>(\n appNode: AppNode,\n loader: () => Promise<(props: TProps) => JSX.Element>,\n ): (props: TProps) => JSX.Element {\n const ExtensionComponent = reactLazy(() =>\n loader().then(Component => ({ default: Component })),\n ) as unknown as React.ComponentType<TProps>;\n\n return (props: TProps) => (\n <ExtensionBoundary node={appNode}>\n <ExtensionComponent {...props} />\n </ExtensionBoundary>\n );\n }\n}\n"],"names":["ExtensionBoundary","lazy","reactLazy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAS,mBAAA,GAA4C;AACnD,EAAA,IAAI;AACF,IAAA,OAAO,OAAO,WAAW,CAAA;AAAA,EAC3B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAEA,SAAS,2BAAA,GAA4D;AACnE,EAAA,IAAI;AACF,IAAA,OAAO,OAAO,mBAAmB,CAAA;AAAA,EACnC,CAAA,CAAA,MAAQ;AACN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,kBAAAA,EAAA,EAAkB,IAAA,EAAM,OAAA,EACvB,QAAA,kBAAA,GAAA,CAAC,kBAAA,EAAA,EAAoB,GAAG,KAAA,EAAO,CAAA,EACjC,CAAA;AAAA,EAEJ;AAbO,EAAAA,kBAAAA,CAAS,aAAA,GAAA,aAAA;AAAA,CAAA,EAfD,iBAAA,KAAA,iBAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"ExtensionBoundary.esm.js","sources":["../../src/components/ExtensionBoundary.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 PropsWithChildren,\n ReactNode,\n Suspense,\n useEffect,\n useMemo,\n lazy as reactLazy,\n} from 'react';\nimport { AnalyticsContext, useAnalytics } from '../analytics';\nimport { ErrorDisplayBoundary } from './ErrorDisplayBoundary';\nimport { ErrorApiBoundary } from './ErrorApiBoundary';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { routableExtensionRenderedEvent } from '../../../core-plugin-api/src/analytics/Tracker';\nimport { ErrorApi, errorApiRef, useApi } from '../apis';\nimport type { AppNode } from '../apis/definitions/AppTreeApi';\nimport {\n PluginWrapperApi,\n pluginWrapperApiRef,\n} from '../apis/definitions/PluginWrapperApi';\nimport { coreExtensionData } from '../wiring';\nimport { AppNodeProvider } from './AppNodeProvider';\nimport { Progress } from './DefaultSwappableComponents';\n\nfunction useOptionalErrorApi(): ErrorApi | undefined {\n try {\n return useApi(errorApiRef);\n } catch {\n return undefined;\n }\n}\n\nfunction useOptionalPluginWrapperApi(): PluginWrapperApi | undefined {\n try {\n return useApi(pluginWrapperApiRef);\n } catch {\n return undefined;\n }\n}\ntype RouteTrackerProps = PropsWithChildren<{\n enabled?: boolean;\n}>;\n\nconst RouteTracker = (props: RouteTrackerProps) => {\n const { enabled, children } = props;\n const analytics = useAnalytics();\n\n // This event, never exposed to end-users of the analytics API,\n // helps inform which extension metadata gets associated with a\n // navigation event when the route navigated to is a gathered\n // mountpoint.\n useEffect(() => {\n if (enabled) {\n analytics.captureEvent(routableExtensionRenderedEvent, '');\n }\n }, [analytics, enabled]);\n\n return <>{children}</>;\n};\n\n/** @public */\nexport interface ExtensionBoundaryProps {\n errorPresentation?: 'error-api' | 'error-display';\n node: AppNode;\n children: ReactNode;\n}\n\n/** @public */\nexport function ExtensionBoundary(props: ExtensionBoundaryProps) {\n const { node, children } = props;\n\n const errorApi = useOptionalErrorApi();\n\n const hasRoutePathOutput = Boolean(\n node.instance?.getData(coreExtensionData.routePath),\n );\n\n const plugin = node.spec.plugin;\n const pluginId = plugin.pluginId ?? 'app';\n\n const pluginWrapperApi = useOptionalPluginWrapperApi();\n\n const PluginWrapper = useMemo(() => {\n return pluginWrapperApi?.getPluginWrapper(pluginId);\n }, [pluginWrapperApi, pluginId]);\n\n // Skipping \"routeRef\" attribute in the new system, the extension \"id\" should provide more insight\n const attributes = {\n extensionId: node.spec.id,\n pluginId,\n };\n\n let content = (\n <AnalyticsContext attributes={attributes}>\n <RouteTracker enabled={hasRoutePathOutput}>{children}</RouteTracker>\n </AnalyticsContext>\n );\n\n if (PluginWrapper) {\n content = <PluginWrapper>{content}</PluginWrapper>;\n }\n\n if (props.errorPresentation === 'error-api') {\n content = (\n <ErrorApiBoundary node={node} errorApi={errorApi}>\n {content}\n </ErrorApiBoundary>\n );\n } else {\n content = (\n <ErrorDisplayBoundary plugin={plugin}>{content}</ErrorDisplayBoundary>\n );\n }\n\n return (\n <AppNodeProvider node={node}>\n <Suspense fallback={<Progress />}>{content}</Suspense>\n </AppNodeProvider>\n );\n}\n\n/** @public */\nexport namespace ExtensionBoundary {\n export function lazy(\n appNode: AppNode,\n loader: () => Promise<JSX.Element>,\n ): JSX.Element {\n const ExtensionComponent = reactLazy(() =>\n loader().then(element => ({ default: () => element })),\n );\n return (\n <ExtensionBoundary node={appNode}>\n <ExtensionComponent />\n </ExtensionBoundary>\n );\n }\n\n export function lazyComponent<TProps extends {}>(\n appNode: AppNode,\n loader: () => Promise<(props: TProps) => JSX.Element>,\n ): (props: TProps) => JSX.Element {\n const ExtensionComponent = reactLazy(() =>\n loader().then(Component => ({ default: Component })),\n ) as unknown as React.ComponentType<TProps>;\n\n return (props: TProps) => (\n <ExtensionBoundary node={appNode}>\n <ExtensionComponent {...props} />\n </ExtensionBoundary>\n );\n }\n}\n"],"names":["ExtensionBoundary","lazy","reactLazy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAS,mBAAA,GAA4C;AACnD,EAAA,IAAI;AACF,IAAA,OAAO,OAAO,WAAW,CAAA;AAAA,EAC3B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAEA,SAAS,2BAAA,GAA4D;AACnE,EAAA,IAAI;AACF,IAAA,OAAO,OAAO,mBAAmB,CAAA;AAAA,EACnC,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAKA,MAAM,YAAA,GAAe,CAAC,KAAA,KAA6B;AACjD,EAAA,MAAM,EAAE,OAAA,EAAS,QAAA,EAAS,GAAI,KAAA;AAC9B,EAAA,MAAM,YAAY,YAAA,EAAa;AAM/B,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,SAAA,CAAU,YAAA,CAAa,gCAAgC,EAAE,CAAA;AAAA,IAC3D;AAAA,EACF,CAAA,EAAG,CAAC,SAAA,EAAW,OAAO,CAAC,CAAA;AAEvB,EAAA,uCAAU,QAAA,EAAS,CAAA;AACrB,CAAA;AAUO,SAAS,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,uBACE,GAAA,CAAC,eAAA,EAAA,EAAgB,IAAA,EACf,QAAA,kBAAA,GAAA,CAAC,QAAA,EAAA,EAAS,0BAAU,GAAA,CAAC,QAAA,EAAA,EAAS,CAAA,EAAK,QAAA,EAAA,OAAA,EAAQ,CAAA,EAC7C,CAAA;AAEJ;AAAA,CAGO,CAAUA,kBAAAA,KAAV;AACE,EAAA,SAASC,MAAA,CACd,SACA,MAAA,EACa;AACb,IAAA,MAAM,kBAAA,GAAqBC,IAAA;AAAA,MAAU,MACnC,QAAO,CAAE,IAAA,CAAK,cAAY,EAAE,OAAA,EAAS,MAAM,OAAA,EAAQ,CAAE;AAAA,KACvD;AACA,IAAA,2BACGF,kBAAAA,EAAA,EAAkB,MAAM,OAAA,EACvB,QAAA,kBAAA,GAAA,CAAC,sBAAmB,CAAA,EACtB,CAAA;AAAA,EAEJ;AAZO,EAAAA,kBAAAA,CAAS,IAAA,GAAAC,MAAA;AAcT,EAAA,SAAS,aAAA,CACd,SACA,MAAA,EACgC;AAChC,IAAA,MAAM,kBAAA,GAAqBC,IAAA;AAAA,MAAU,MACnC,QAAO,CAAE,IAAA,CAAK,gBAAc,EAAE,OAAA,EAAS,WAAU,CAAE;AAAA,KACrD;AAEA,IAAA,OAAO,CAAC,KAAA,qBACN,GAAA,CAACF,kBAAAA,EAAA,EAAkB,IAAA,EAAM,OAAA,EACvB,QAAA,kBAAA,GAAA,CAAC,kBAAA,EAAA,EAAoB,GAAG,KAAA,EAAO,CAAA,EACjC,CAAA;AAAA,EAEJ;AAbO,EAAAA,kBAAAA,CAAS,aAAA,GAAA,aAAA;AAAA,CAAA,EAfD,iBAAA,KAAA,iBAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { ReactNode, JSX as JSX$1, ComponentType, PropsWithChildren } from 'react';
4
4
  import * as _backstage_frontend_plugin_api from '@backstage/frontend-plugin-api';
5
- import { N as IconElement, V as RouteRef, b as AnyRouteRefParams, W as SubRouteRef, F as ExternalRouteRef, H as FrontendFeature, M as IconComponent, f as AppNode, J as FrontendPlugin, e as ApiRef, d as ApiHolder, X as TypesToApiRefs, c as ApiFactory, A as AnyApiFactory } from './types/alpha.d-CUDLigYe.js';
6
- export { a as AnyApiRef, g as AppNodeEdges, h as AppNodeInstance, i as AppNodeSpec, j as AppTree, k as AppTreeApi, C as ConfigurableExtensionDataRef, l as CreateExtensionBlueprintOptions, m as CreateExtensionOptions, n as CreateFrontendModuleOptions, o as CreateFrontendPluginOptions, E as Extension, p as ExtensionAttachTo, q as ExtensionBlueprint, r as ExtensionBlueprintDefineParams, s as ExtensionBlueprintParameters, t as ExtensionBlueprintParams, u as ExtensionDataContainer, v as ExtensionDataRef, w as ExtensionDataValue, x as ExtensionDefinition, y as ExtensionDefinitionAttachTo, z as ExtensionDefinitionParameters, B as ExtensionFactoryMiddleware, D as ExtensionInput, G as FeatureFlagConfig, I as FrontendModule, K as FrontendPluginInfo, L as FrontendPluginInfoOptions, O as OverridableExtensionDefinition, P as OverridableFrontendPlugin, Q as PluginOptions, R as PluginWrapperApi, S as PluginWrapperBlueprint, T as PluginWrapperDefinition, U as PortableSchema, Y as appTreeApiRef, Z as createExtension, _ as createExtensionBlueprint, $ as createExtensionBlueprintParams, a0 as createExtensionDataRef, a1 as createExtensionInput, a2 as createExternalRouteRef, a3 as createFrontendModule, a4 as createFrontendPlugin, a5 as createRouteRef, a6 as createSubRouteRef, a7 as pluginWrapperApiRef } from './types/alpha.d-CUDLigYe.js';
5
+ import { N as IconElement, V as RouteRef, b as AnyRouteRefParams, W as SubRouteRef, F as ExternalRouteRef, H as FrontendFeature, M as IconComponent, f as AppNode, J as FrontendPlugin, e as ApiRef, d as ApiHolder, X as TypesToApiRefs, c as ApiFactory, A as AnyApiFactory } from './types/alpha.d-gY8B1WFX.js';
6
+ export { a as AnyApiRef, g as AppNodeEdges, h as AppNodeInstance, i as AppNodeSpec, j as AppTree, k as AppTreeApi, C as ConfigurableExtensionDataRef, l as CreateExtensionBlueprintOptions, m as CreateExtensionOptions, n as CreateFrontendModuleOptions, o as CreateFrontendPluginOptions, E as Extension, p as ExtensionAttachTo, q as ExtensionBlueprint, r as ExtensionBlueprintDefineParams, s as ExtensionBlueprintParameters, t as ExtensionBlueprintParams, u as ExtensionDataContainer, v as ExtensionDataRef, w as ExtensionDataValue, x as ExtensionDefinition, y as ExtensionDefinitionAttachTo, z as ExtensionDefinitionParameters, B as ExtensionFactoryMiddleware, D as ExtensionInput, G as FeatureFlagConfig, I as FrontendModule, K as FrontendPluginInfo, L as FrontendPluginInfoOptions, O as OverridableExtensionDefinition, P as OverridableFrontendPlugin, Q as PluginOptions, R as PluginWrapperApi, S as PluginWrapperBlueprint, T as PluginWrapperDefinition, U as PortableSchema, Y as appTreeApiRef, Z as createExtension, _ as createExtensionBlueprint, $ as createExtensionBlueprintParams, a0 as createExtensionDataRef, a1 as createExtensionInput, a2 as createExternalRouteRef, a3 as createFrontendModule, a4 as createFrontendPlugin, a5 as createRouteRef, a6 as createSubRouteRef, a7 as pluginWrapperApiRef } from './types/alpha.d-gY8B1WFX.js';
7
7
  import { Observable, JsonValue, Expand, ExpandRecursive } from '@backstage/types';
8
8
  import { Config } from '@backstage/config';
9
9
  export { StandardSchemaV1 } from '@standard-schema/spec';
@@ -1,13 +1,15 @@
1
- import { OpaqueRouteRef } from '../frontend-internal/src/routing/OpaqueRouteRef.esm.js';
2
1
  import { OpaqueSubRouteRef } from '../frontend-internal/src/routing/OpaqueSubRouteRef.esm.js';
2
+ import { OpaqueRouteRef } from '../frontend-internal/src/routing/OpaqueRouteRef.esm.js';
3
3
  import '../frontend-internal/src/routing/OpaqueExternalRouteRef.esm.js';
4
4
 
5
5
  const PARAM_PATTERN = /^\w+$/;
6
6
  function createSubRouteRef(config) {
7
7
  const { path, parent } = config;
8
- const internalParent = OpaqueRouteRef.toInternal(parent);
9
- const parentParams = internalParent.getParams();
10
- const parentDescription = internalParent.getDescription();
8
+ const subRouteParent = OpaqueSubRouteRef.isType(parent) ? OpaqueSubRouteRef.toInternal(parent) : void 0;
9
+ const parentRef = subRouteParent?.getParent() ?? parent;
10
+ const internalParent = OpaqueRouteRef.toInternal(parentRef);
11
+ const parentParams = subRouteParent?.getParams() ?? internalParent.getParams();
12
+ const subPath = subRouteParent ? `${subRouteParent.path}${path}` : path;
11
13
  const pathParams = path.split("/").filter((p) => p.startsWith(":")).map((p) => p.substring(1));
12
14
  const params = [...parentParams, ...pathParams];
13
15
  if (parentParams.some((p) => pathParams.includes(p))) {
@@ -28,18 +30,18 @@ function createSubRouteRef(config) {
28
30
  }
29
31
  return OpaqueSubRouteRef.createInstance("v1", {
30
32
  T: void 0,
31
- path,
33
+ path: subPath,
32
34
  getParams() {
33
35
  return params;
34
36
  },
35
37
  getParent() {
36
- return parent;
38
+ return parentRef;
37
39
  },
38
40
  getDescription() {
39
- return `at ${path} with parent ${parentDescription}`;
41
+ return `at ${subPath} with parent ${internalParent.getDescription()}`;
40
42
  },
41
43
  toString() {
42
- return `subRouteRef{path='${path}',parent=${parent}}`;
44
+ return `subRouteRef{path='${subPath}',parent=${parentRef}}`;
43
45
  }
44
46
  });
45
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SubRouteRef.esm.js","sources":["../../src/routing/SubRouteRef.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 { OpaqueRouteRef, OpaqueSubRouteRef } from '@internal/frontend';\nimport { RouteRef } from './RouteRef';\nimport { AnyRouteRefParams } from './types';\n\n// Should match the pattern in react-router\nconst PARAM_PATTERN = /^\\w+$/;\n\n/**\n * Descriptor of a route relative to an absolute {@link RouteRef}.\n *\n * @remarks\n *\n * See {@link https://backstage.io/docs/plugins/composability#routing-system}.\n *\n * @public\n */\nexport interface SubRouteRef<\n TParams extends AnyRouteRefParams = AnyRouteRefParams,\n> {\n readonly $$type: '@backstage/SubRouteRef';\n\n readonly T: TParams;\n\n readonly path: string;\n}\n\n/** @internal */\nexport interface InternalSubRouteRef<\n TParams extends AnyRouteRefParams = AnyRouteRefParams,\n> extends SubRouteRef<TParams> {\n readonly version: 'v1';\n\n getParams(): string[];\n getParent(): RouteRef;\n getDescription(): string;\n}\n\n/**\n * Used in {@link PathParams} type declaration.\n * @ignore\n */\ntype ParamPart<S extends string> = S extends `:${infer Param}` ? Param : never;\n\n/**\n * Used in {@link PathParams} type declaration.\n * @ignore\n */\ntype ParamNames<S extends string> = S extends `${infer Part}/${infer Rest}`\n ? ParamPart<Part> | ParamNames<Rest>\n : ParamPart<S>;\n/**\n * This utility type helps us infer a Param object type from a string path\n * For example, `/foo/:bar/:baz` inferred to `{ bar: string, baz: string }`\n * @ignore\n */\ntype PathParams<S extends string> = { [name in ParamNames<S>]: string };\n\n/**\n * Merges a param object type with an optional params type into a params object.\n * @ignore\n */\ntype MergeParams<\n P1 extends { [param in string]: string },\n P2 extends AnyRouteRefParams,\n> = (P1[keyof P1] extends never ? {} : P1) & (P2 extends undefined ? {} : P2);\n\n/**\n * Convert empty params to undefined.\n * @ignore\n */\ntype TrimEmptyParams<Params extends { [param in string]: string }> =\n keyof Params extends never ? undefined : Params;\n\n/**\n * Creates a SubRouteRef type given the desired parameters and parent route parameters.\n * The parameters types are merged together while ensuring that there is no overlap between the two.\n *\n * @ignore\n */\ntype MakeSubRouteRef<\n Params extends { [param in string]: string },\n ParentParams extends AnyRouteRefParams,\n> = keyof Params & keyof ParentParams extends never\n ? SubRouteRef<TrimEmptyParams<MergeParams<Params, ParentParams>>>\n : never;\n\n/**\n * Create a {@link SubRouteRef} from a route descriptor.\n *\n * @param config - Description of the route reference to be created.\n * @public\n */\nexport function createSubRouteRef<\n Path extends string,\n ParentParams extends AnyRouteRefParams = never,\n>(config: {\n path: Path;\n parent: RouteRef<ParentParams>;\n}): MakeSubRouteRef<PathParams<Path>, ParentParams> {\n const { path, parent } = config;\n type Params = PathParams<Path>;\n\n const internalParent = OpaqueRouteRef.toInternal(parent);\n const parentParams = internalParent.getParams();\n const parentDescription = internalParent.getDescription();\n\n // Collect runtime parameters from the path, e.g. ['bar', 'baz'] from '/foo/:bar/:baz'\n const pathParams = path\n .split('/')\n .filter(p => p.startsWith(':'))\n .map(p => p.substring(1));\n const params = [...parentParams, ...pathParams];\n\n if (parentParams.some(p => pathParams.includes(p as string))) {\n throw new Error(\n 'SubRouteRef may not have params that overlap with its parent',\n );\n }\n if (!path.startsWith('/')) {\n throw new Error(`SubRouteRef path must start with '/', got '${path}'`);\n }\n if (path.endsWith('/')) {\n throw new Error(`SubRouteRef path must not end with '/', got '${path}'`);\n }\n for (const param of pathParams) {\n if (!PARAM_PATTERN.test(param)) {\n throw new Error(`SubRouteRef path has invalid param, got '${param}'`);\n }\n }\n\n return OpaqueSubRouteRef.createInstance('v1', {\n T: undefined as unknown as TrimEmptyParams<\n MergeParams<Params, ParentParams>\n >,\n path,\n getParams() {\n return params;\n },\n getParent() {\n return parent;\n },\n getDescription() {\n return `at ${path} with parent ${parentDescription}`;\n },\n toString() {\n return `subRouteRef{path='${path}',parent=${parent}}`;\n },\n });\n}\n"],"names":[],"mappings":";;;;AAqBA,MAAM,aAAA,GAAgB,OAAA;AAuFf,SAAS,kBAGd,MAAA,EAGkD;AAClD,EAAA,MAAM,EAAE,IAAA,EAAM,MAAA,EAAO,GAAI,MAAA;AAGzB,EAAA,MAAM,cAAA,GAAiB,cAAA,CAAe,UAAA,CAAW,MAAM,CAAA;AACvD,EAAA,MAAM,YAAA,GAAe,eAAe,SAAA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AO,MAAA;AAAA,IACT,CAAA;AAAA,IACA,cAAA,GAAiB;AACf,MAAA,OAAO,CAAA,GAAA,EAAM,IAAI,CAAA,aAAA,EAAgB,iBAAiB,CAAA,CAAA;AAAA,IACpD,CAAA;AAAA,IACA,QAAA,GAAW;AACT,MAAA,OAAO,CAAA,kBAAA,EAAqB,IAAI,CAAA,SAAA,EAAY,MAAM,CAAA,CAAA,CAAA;AAAA,IACpD;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"SubRouteRef.esm.js","sources":["../../src/routing/SubRouteRef.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 { OpaqueRouteRef, OpaqueSubRouteRef } from '@internal/frontend';\nimport { RouteRef } from './RouteRef';\nimport { AnyRouteRefParams } from './types';\n\n// Should match the pattern in react-router\nconst PARAM_PATTERN = /^\\w+$/;\n\n/**\n * Descriptor of a route relative to a {@link RouteRef} or another sub-route.\n *\n * @remarks\n *\n * See {@link https://backstage.io/docs/plugins/composability#routing-system}.\n *\n * @public\n */\nexport interface SubRouteRef<\n TParams extends AnyRouteRefParams = AnyRouteRefParams,\n> {\n readonly $$type: '@backstage/SubRouteRef';\n\n readonly T: TParams;\n\n readonly path: string;\n}\n\n/** @internal */\nexport interface InternalSubRouteRef<\n TParams extends AnyRouteRefParams = AnyRouteRefParams,\n> extends SubRouteRef<TParams> {\n readonly version: 'v1';\n\n getParams(): string[];\n getParent(): RouteRef;\n getDescription(): string;\n}\n\n/**\n * Used in {@link PathParams} type declaration.\n * @ignore\n */\ntype ParamPart<S extends string> = S extends `:${infer Param}` ? Param : never;\n\n/**\n * Used in {@link PathParams} type declaration.\n * @ignore\n */\ntype ParamNames<S extends string> = S extends `${infer Part}/${infer Rest}`\n ? ParamPart<Part> | ParamNames<Rest>\n : ParamPart<S>;\n/**\n * This utility type helps us infer a Param object type from a string path\n * For example, `/foo/:bar/:baz` inferred to `{ bar: string, baz: string }`\n * @ignore\n */\ntype PathParams<S extends string> = { [name in ParamNames<S>]: string };\n\n/**\n * Merges a param object type with an optional params type into a params object.\n * @ignore\n */\ntype MergeParams<\n P1 extends { [param in string]: string },\n P2 extends AnyRouteRefParams,\n> = (P1[keyof P1] extends never ? {} : P1) & (P2 extends undefined ? {} : P2);\n\n/**\n * Convert empty params to undefined.\n * @ignore\n */\ntype TrimEmptyParams<Params extends { [param in string]: string }> =\n keyof Params extends never ? undefined : Params;\n\n/**\n * Creates a SubRouteRef type given the desired parameters and parent route parameters.\n * The parameters types are merged together while ensuring that there is no overlap between the two.\n *\n * @ignore\n */\ntype MakeSubRouteRef<\n Params extends { [param in string]: string },\n ParentParams extends AnyRouteRefParams,\n> = keyof Params & keyof ParentParams extends never\n ? SubRouteRef<TrimEmptyParams<MergeParams<Params, ParentParams>>>\n : never;\n\n/**\n * Create a {@link SubRouteRef} from a route descriptor.\n *\n * @param config - Description of the route reference to be created.\n * @public\n */\nexport function createSubRouteRef<\n Path extends string,\n ParentParams extends AnyRouteRefParams = never,\n>(config: {\n path: Path;\n parent: RouteRef<ParentParams> | SubRouteRef<ParentParams>;\n}): MakeSubRouteRef<PathParams<Path>, ParentParams> {\n const { path, parent } = config;\n type Params = PathParams<Path>;\n\n const subRouteParent = OpaqueSubRouteRef.isType(parent)\n ? OpaqueSubRouteRef.toInternal(parent)\n : undefined;\n const parentRef = subRouteParent?.getParent() ?? (parent as RouteRef);\n const internalParent = OpaqueRouteRef.toInternal(parentRef);\n const parentParams =\n subRouteParent?.getParams() ?? internalParent.getParams();\n const subPath = subRouteParent ? `${subRouteParent.path}${path}` : path;\n\n // Collect runtime parameters from the path, e.g. ['bar', 'baz'] from '/foo/:bar/:baz'\n const pathParams = path\n .split('/')\n .filter(p => p.startsWith(':'))\n .map(p => p.substring(1));\n const params = [...parentParams, ...pathParams];\n\n if (parentParams.some(p => pathParams.includes(p as string))) {\n throw new Error(\n 'SubRouteRef may not have params that overlap with its parent',\n );\n }\n if (!path.startsWith('/')) {\n throw new Error(`SubRouteRef path must start with '/', got '${path}'`);\n }\n if (path.endsWith('/')) {\n throw new Error(`SubRouteRef path must not end with '/', got '${path}'`);\n }\n for (const param of pathParams) {\n if (!PARAM_PATTERN.test(param)) {\n throw new Error(`SubRouteRef path has invalid param, got '${param}'`);\n }\n }\n\n return OpaqueSubRouteRef.createInstance('v1', {\n T: undefined as unknown as TrimEmptyParams<\n MergeParams<Params, ParentParams>\n >,\n path: subPath,\n getParams() {\n return params;\n },\n getParent() {\n return parentRef;\n },\n getDescription() {\n return `at ${subPath} with parent ${internalParent.getDescription()}`;\n },\n toString() {\n return `subRouteRef{path='${subPath}',parent=${parentRef}}`;\n },\n });\n}\n"],"names":[],"mappings":";;;;AAqBA,MAAM,aAAA,GAAgB,OAAA;AAuFf,SAAS,kBAGd,MAAA,EAGkD;AAClD,EAAA,MAAM,EAAE,IAAA,EAAM,MAAA,EAAO,GAAI,MAAA;AAGzB,EAAA,MAAM,cAAA,GAAiB,kBAAkB,MAAA,CAAO,MAAM,IAClD,iBAAA,CAAkB,UAAA,CAAW,MAAM,CAAA,GACnC,MAAA;AACJ,EAAA,MAAM,SAAA,GAAY,cAAA,EAAgB,SAAA,EAAU,IAAM,MAAA;AAClD,EAAA,MAAM,cAAA,GAAiB,cAAA,CAAe,UAAA,CAAW,SAAS,CAAA;AAC1D,EAAA,MAAM,YAAA,GACJ,cAAA,EAAgB,SAAA,EAAU,IAAK,eAAe,SAAA,EAAU;AAC1D,EAAA,MAAM,UAAU,cAAA,GAAiB,CAAA,EAAG,eAAe,IAAI,CAAA,EAAG,IAAI,CAAA,CA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,IACA,cAAA,GAAiB;AACf,MAAA,OAAO,CAAA,GAAA,EAAM,OAAO,CAAA,aAAA,EAAgB,cAAA,CAAe,gBAAgB,CAAA,CAAA;AAAA,IACrE,CAAA;AAAA,IACA,QAAA,GAAW;AACT,MAAA,OAAO,CAAA,kBAAA,EAAqB,OAAO,CAAA,SAAA,EAAY,SAAS,CAAA,CAAA,CAAA;AAAA,IAC1D;AAAA,GACD,CAAA;AACH;;;;"}
@@ -344,7 +344,7 @@ type ExtensionArrayToMap<T extends ExtensionDefinition[], TId extends string, TO
344
344
  type MakeSortedExtensionsMap<UExtensions extends ExtensionDefinition, TId extends string> = ExtensionArrayToMap<SortExtensions<UnionToArray<UExtensions>>, TId>;
345
345
 
346
346
  /**
347
- * Descriptor of a route relative to an absolute {@link RouteRef}.
347
+ * Descriptor of a route relative to a {@link RouteRef} or another sub-route.
348
348
  *
349
349
  * @remarks
350
350
  *
@@ -406,7 +406,7 @@ type MakeSubRouteRef<Params extends {
406
406
  */
407
407
  declare function createSubRouteRef<Path extends string, ParentParams extends AnyRouteRefParams = never>(config: {
408
408
  path: Path;
409
- parent: RouteRef<ParentParams>;
409
+ parent: RouteRef<ParentParams> | SubRouteRef<ParentParams>;
410
410
  }): MakeSubRouteRef<PathParams<Path>, ParentParams>;
411
411
 
412
412
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/frontend-plugin-api",
3
- "version": "0.18.0-next.0",
3
+ "version": "0.18.1-next.0",
4
4
  "backstage": {
5
5
  "role": "web-library"
6
6
  },
@@ -54,16 +54,17 @@
54
54
  "dependencies": {
55
55
  "@backstage/config": "1.3.8",
56
56
  "@backstage/errors": "1.3.1",
57
- "@backstage/filter-predicates": "0.1.4",
57
+ "@backstage/filter-predicates": "0.1.5-next.0",
58
58
  "@backstage/types": "1.2.2",
59
59
  "@backstage/version-bridge": "1.0.12",
60
60
  "@standard-schema/spec": "^1.1.0"
61
61
  },
62
62
  "devDependencies": {
63
- "@backstage/cli": "0.36.5-next.1",
64
- "@backstage/frontend-app-api": "0.16.7-next.1",
65
- "@backstage/frontend-test-utils": "0.6.3-next.1",
66
- "@backstage/test-utils": "1.7.21-next.1",
63
+ "@backstage/cli": "0.36.6-next.0",
64
+ "@backstage/frontend-app-api": "0.16.8-next.1",
65
+ "@backstage/frontend-test-utils": "0.6.4-next.1",
66
+ "@backstage/test-utils": "1.7.22-next.1",
67
+ "@testing-library/dom": "^10.0.0",
67
68
  "@testing-library/jest-dom": "^6.0.0",
68
69
  "@testing-library/react": "^16.0.0",
69
70
  "@types/react": "^18.0.0",