@backstage/core-app-api 1.7.0 → 1.7.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,16 @@
1
1
  # @backstage/core-app-api
2
2
 
3
+ ## 1.7.1-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 42d817e76ab: Added `FrontendHostDiscovery` for config driven discovery implementation
8
+ - Updated dependencies
9
+ - @backstage/core-plugin-api@1.5.1
10
+ - @backstage/config@1.0.7
11
+ - @backstage/types@1.0.2
12
+ - @backstage/version-bridge@1.0.4
13
+
3
14
  ## 1.7.0
4
15
 
5
16
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -411,6 +411,43 @@ declare class UrlPatternDiscovery implements DiscoveryApi {
411
411
  getBaseUrl(pluginId: string): Promise<string>;
412
412
  }
413
413
 
414
+ /**
415
+ * FrontendHostDiscovery is a config driven DiscoveryApi implementation.
416
+ * It uses the app-config to determine the url for a plugin.
417
+ *
418
+ * @public
419
+ */
420
+ declare class FrontendHostDiscovery implements DiscoveryApi {
421
+ private readonly endpoints;
422
+ private readonly defaultEndpoint;
423
+ /**
424
+ * Creates a new FrontendHostDiscovery discovery instance by reading
425
+ * the external target URL from the `discovery.endpoints` config section.
426
+ *
427
+ * eg.
428
+ * ```yaml
429
+ * discovery:
430
+ * endpoints:
431
+ * - target: https://internal.example.com/internal-catalog
432
+ * plugins: [catalog]
433
+ * - target: https://internal.example.com/secure/api/{{pluginId}}
434
+ * plugins: [auth, permissions]
435
+ * - target:
436
+ * internal: https://internal.example.com/search
437
+ * external: https://example.com/search
438
+ * plugins: [search]
439
+ * ```
440
+ *
441
+ * If a plugin is not declared in the config, the discovery will fall back to using the baseUrl with
442
+ * the provided `pathPattern` appended. The default path pattern is `"/api/{{ pluginId }}"`.
443
+ */
444
+ static fromConfig(config: Config, options?: {
445
+ pathPattern?: string;
446
+ }): FrontendHostDiscovery;
447
+ private constructor();
448
+ getBaseUrl(pluginId: string): Promise<string>;
449
+ }
450
+
414
451
  /**
415
452
  * Decorates an ErrorApi by also forwarding error messages
416
453
  * to the alertApi with an 'error' severity.
@@ -1004,4 +1041,4 @@ type FeatureFlaggedProps = {
1004
1041
  */
1005
1042
  declare const FeatureFlagged: (props: FeatureFlaggedProps) => JSX.Element;
1006
1043
 
1007
- export { AlertApiForwarder, ApiFactoryHolder, ApiFactoryRegistry, ApiFactoryScope, ApiProvider, ApiProviderProps, ApiResolver, AppComponents, AppConfigLoader, AppContext, AppIcons, AppOptions, AppRouteBinder, AppRouter, AppRouterProps, AppThemeSelector, AtlassianAuth, AuthApiCreateOptions, BackstageApp, BitbucketAuth, BitbucketServerAuth, BitbucketServerSession, BitbucketSession, BootErrorPageProps, ErrorAlerter, ErrorApiForwarder, ErrorBoundaryFallbackProps, FeatureFlagged, FeatureFlaggedProps, FetchMiddleware, FetchMiddlewares, FlatRoutes, FlatRoutesProps, GithubAuth, GitlabAuth, GoogleAuth, LocalStorageFeatureFlags, MicrosoftAuth, MultipleAnalyticsApi, NoOpAnalyticsApi, OAuth2, OAuth2CreateOptions, OAuth2Session, OAuthApiCreateOptions, OAuthRequestManager, OktaAuth, OneLoginAuth, OneLoginAuthCreateOptions, SamlAuth, SignInPageProps, UnhandledErrorForwarder, UrlPatternDiscovery, WebStorage, createFetchApi, createSpecializedApp, defaultConfigLoader };
1044
+ export { AlertApiForwarder, ApiFactoryHolder, ApiFactoryRegistry, ApiFactoryScope, ApiProvider, ApiProviderProps, ApiResolver, AppComponents, AppConfigLoader, AppContext, AppIcons, AppOptions, AppRouteBinder, AppRouter, AppRouterProps, AppThemeSelector, AtlassianAuth, AuthApiCreateOptions, BackstageApp, BitbucketAuth, BitbucketServerAuth, BitbucketServerSession, BitbucketSession, BootErrorPageProps, ErrorAlerter, ErrorApiForwarder, ErrorBoundaryFallbackProps, FeatureFlagged, FeatureFlaggedProps, FetchMiddleware, FetchMiddlewares, FlatRoutes, FlatRoutesProps, FrontendHostDiscovery, GithubAuth, GitlabAuth, GoogleAuth, LocalStorageFeatureFlags, MicrosoftAuth, MultipleAnalyticsApi, NoOpAnalyticsApi, OAuth2, OAuth2CreateOptions, OAuth2Session, OAuthApiCreateOptions, OAuthRequestManager, OktaAuth, OneLoginAuth, OneLoginAuthCreateOptions, SamlAuth, SignInPageProps, UnhandledErrorForwarder, UrlPatternDiscovery, WebStorage, createFetchApi, createSpecializedApp, defaultConfigLoader };
package/dist/index.esm.js CHANGED
@@ -1476,7 +1476,56 @@ class UrlPatternDiscovery {
1476
1476
  return new UrlPatternDiscovery(parts);
1477
1477
  }
1478
1478
  async getBaseUrl(pluginId) {
1479
- return this.parts.join(pluginId);
1479
+ return this.parts.join(encodeURIComponent(pluginId));
1480
+ }
1481
+ }
1482
+
1483
+ class FrontendHostDiscovery {
1484
+ constructor(endpoints, defaultEndpoint) {
1485
+ this.endpoints = endpoints;
1486
+ this.defaultEndpoint = defaultEndpoint;
1487
+ }
1488
+ /**
1489
+ * Creates a new FrontendHostDiscovery discovery instance by reading
1490
+ * the external target URL from the `discovery.endpoints` config section.
1491
+ *
1492
+ * eg.
1493
+ * ```yaml
1494
+ * discovery:
1495
+ * endpoints:
1496
+ * - target: https://internal.example.com/internal-catalog
1497
+ * plugins: [catalog]
1498
+ * - target: https://internal.example.com/secure/api/{{pluginId}}
1499
+ * plugins: [auth, permissions]
1500
+ * - target:
1501
+ * internal: https://internal.example.com/search
1502
+ * external: https://example.com/search
1503
+ * plugins: [search]
1504
+ * ```
1505
+ *
1506
+ * If a plugin is not declared in the config, the discovery will fall back to using the baseUrl with
1507
+ * the provided `pathPattern` appended. The default path pattern is `"/api/{{ pluginId }}"`.
1508
+ */
1509
+ static fromConfig(config, options) {
1510
+ var _a, _b;
1511
+ const path = (_a = options == null ? void 0 : options.pathPattern) != null ? _a : "/api/{{ pluginId }}";
1512
+ const baseUrl = config.getString("backend.baseUrl");
1513
+ const endpoints = (_b = config.getOptionalConfigArray("discovery.endpoints")) == null ? void 0 : _b.flatMap((e) => {
1514
+ const target = typeof e.get("target") === "object" ? e.getString("target.external") : e.getString("target");
1515
+ const discovery = UrlPatternDiscovery.compile(target);
1516
+ return e.getStringArray("plugins").map((pluginId) => [pluginId, discovery]);
1517
+ });
1518
+ return new FrontendHostDiscovery(
1519
+ new Map(endpoints),
1520
+ UrlPatternDiscovery.compile(`${baseUrl}${path}`)
1521
+ );
1522
+ }
1523
+ async getBaseUrl(pluginId) {
1524
+ const endpoint = this.endpoints.get(pluginId);
1525
+ if (endpoint) {
1526
+ return endpoint.getBaseUrl(pluginId);
1527
+ }
1528
+ return this.defaultEndpoint.getBaseUrl(pluginId);
1480
1529
  }
1481
1530
  }
1482
1531
 
@@ -3263,5 +3312,5 @@ const FlatRoutes = (props) => {
3263
3312
  return useRoutes(withNotFound);
3264
3313
  };
3265
3314
 
3266
- export { AlertApiForwarder, ApiFactoryRegistry, ApiProvider, ApiResolver, AppRouter, AppThemeSelector, AtlassianAuth, BitbucketAuth, BitbucketServerAuth, ErrorAlerter, ErrorApiForwarder, FeatureFlagged, FetchMiddlewares, FlatRoutes, GithubAuth, GitlabAuth, GoogleAuth, LocalStorageFeatureFlags, MicrosoftAuth, MultipleAnalyticsApi, NoOpAnalyticsApi, OAuth2, OAuthRequestManager, OktaAuth, OneLoginAuth, SamlAuth, UnhandledErrorForwarder, UrlPatternDiscovery, WebStorage, createFetchApi, createSpecializedApp, defaultConfigLoader };
3315
+ export { AlertApiForwarder, ApiFactoryRegistry, ApiProvider, ApiResolver, AppRouter, AppThemeSelector, AtlassianAuth, BitbucketAuth, BitbucketServerAuth, ErrorAlerter, ErrorApiForwarder, FeatureFlagged, FetchMiddlewares, FlatRoutes, FrontendHostDiscovery, GithubAuth, GitlabAuth, GoogleAuth, LocalStorageFeatureFlags, MicrosoftAuth, MultipleAnalyticsApi, NoOpAnalyticsApi, OAuth2, OAuthRequestManager, OktaAuth, OneLoginAuth, SamlAuth, UnhandledErrorForwarder, UrlPatternDiscovery, WebStorage, createFetchApi, createSpecializedApp, defaultConfigLoader };
3267
3316
  //# sourceMappingURL=index.esm.js.map