@backstage/frontend-plugin-api 0.3.0 → 0.4.0-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 CHANGED
@@ -1,5 +1,36 @@
1
1
  # @backstage/frontend-plugin-api
2
2
 
3
+ ## 0.4.0-next.1
4
+
5
+ ### Minor Changes
6
+
7
+ - a5a04739e1: The extension `factory` function now longer receives `id` or `source`, but instead now provides the extension's `AppNode` as `node`. The `ExtensionBoundary` component has also been updated to receive a `node` prop rather than `id` and `source`.
8
+
9
+ ### Patch Changes
10
+
11
+ - 5eb6b8a7bc: Added the nav logo extension for customization of sidebar logo
12
+ - 1f12fb762c: Create factories for overriding default core components extensions.
13
+ - 59709286b3: Add feature flags to plugins and extension overrides.
14
+ - e539735435: Added `createSignInPageExtension`.
15
+ - f27ee7d937: Migrate analytics api and context files.
16
+ - Updated dependencies
17
+ - @backstage/core-components@0.13.9-next.1
18
+ - @backstage/core-plugin-api@1.8.1-next.1
19
+ - @backstage/config@1.1.1
20
+ - @backstage/types@1.1.1
21
+ - @backstage/version-bridge@1.0.7
22
+
23
+ ## 0.3.1-next.0
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies
28
+ - @backstage/core-plugin-api@1.8.1-next.0
29
+ - @backstage/core-components@0.13.9-next.0
30
+ - @backstage/config@1.1.1
31
+ - @backstage/types@1.1.1
32
+ - @backstage/version-bridge@1.0.7
33
+
3
34
  ## 0.3.0
4
35
 
5
36
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -1,10 +1,54 @@
1
1
  /// <reference types="react" />
2
+ import React, { ReactNode, ComponentType, PropsWithChildren, JSX as JSX$1 } from 'react';
2
3
  import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
3
- import { IconComponent, AnyApiFactory, AppTheme, AnyApiRef } from '@backstage/core-plugin-api';
4
+ import { BackstagePlugin as BackstagePlugin$1, IconComponent as IconComponent$1, AnyApiFactory, AppTheme, ApiRef, AnyApiRef, SignInPageProps } from '@backstage/core-plugin-api';
5
+ export { AlertApi, AlertMessage, AnyApiFactory, AnyApiRef, ApiFactory, ApiHolder, ApiRef, ApiRefConfig, AppTheme, AppThemeApi, AuthProviderInfo, AuthRequestOptions, BackstageIdentityApi, BackstageIdentityResponse, BackstageUserIdentity, ConfigApi, DiscoveryApi, ErrorApi, ErrorApiError, ErrorApiErrorContext, FeatureFlag, FeatureFlagState, FeatureFlagsApi, FeatureFlagsSaveOptions, FetchApi, IdentityApi, OAuthApi, OAuthRequestApi, OAuthRequester, OAuthRequesterOptions, OAuthScope, OpenIdConnectApi, PendingOAuthRequest, ProfileInfo, ProfileInfoApi, SessionApi, SessionState, StorageApi, StorageValueSnapshot, TypesToApiRefs, alertApiRef, appThemeApiRef, atlassianAuthApiRef, bitbucketAuthApiRef, bitbucketServerAuthApiRef, configApiRef, createApiFactory, createApiRef, discoveryApiRef, errorApiRef, featureFlagsApiRef, fetchApiRef, githubAuthApiRef, gitlabAuthApiRef, googleAuthApiRef, identityApiRef, microsoftAuthApiRef, oauthRequestApiRef, oktaAuthApiRef, oneloginAuthApiRef, storageApiRef, useApi, useApiHolder, withApis } from '@backstage/core-plugin-api';
4
6
  import { JsonObject } from '@backstage/types';
5
- import React, { JSX as JSX$1, ReactNode } from 'react';
6
7
  import { z, ZodSchema, ZodTypeDef } from 'zod';
7
8
 
9
+ /**
10
+ * Common analytics context attributes.
11
+ *
12
+ * @public
13
+ */
14
+ type CommonAnalyticsContext = {
15
+ /**
16
+ * The nearest known parent plugin where the event was captured.
17
+ */
18
+ pluginId: string;
19
+ /**
20
+ * The nearest known parent extension where the event was captured.
21
+ */
22
+ /**
23
+ * The nearest known parent extension where the event was captured.
24
+ */
25
+ extensionId: string;
26
+ };
27
+ /**
28
+ * Analytics context envelope.
29
+ *
30
+ * @public
31
+ */
32
+ type AnalyticsContextValue = CommonAnalyticsContext & {
33
+ [param in string]: string | boolean | number | undefined;
34
+ };
35
+
36
+ /**
37
+ * Provides components in the child react tree an Analytics Context, ensuring
38
+ * all analytics events captured within the context have relevant attributes.
39
+ *
40
+ * @remarks
41
+ *
42
+ * Analytics contexts are additive, meaning the context ultimately emitted with
43
+ * an event is the combination of all contexts in the parent tree.
44
+ *
45
+ * @public
46
+ */
47
+ declare const AnalyticsContext: (options: {
48
+ attributes: Partial<AnalyticsContextValue>;
49
+ children: ReactNode;
50
+ }) => React.JSX.Element;
51
+
8
52
  /**
9
53
  * Catch-all type for route params.
10
54
  *
@@ -216,13 +260,63 @@ interface ConfigurableExtensionDataRef<TData, TConfig extends {
216
260
  /** @public */
217
261
  declare function createExtensionDataRef<TData>(id: string): ConfigurableExtensionDataRef<TData>;
218
262
 
263
+ /**
264
+ * Utility type to expand type aliases into their equivalent type.
265
+ * @ignore
266
+ */
267
+ type Expand<T> = T extends infer O ? {
268
+ [K in keyof O]: O[K];
269
+ } : never;
270
+ /** @public */
271
+ type CoreProgressComponent = ComponentType<PropsWithChildren<{}>>;
272
+ /** @public */
273
+ type CoreBootErrorPageComponent = ComponentType<PropsWithChildren<{
274
+ step: 'load-config' | 'load-chunk';
275
+ error: Error;
276
+ }>>;
277
+ /** @public */
278
+ type CoreNotFoundErrorPageComponent = ComponentType<PropsWithChildren<{}>>;
279
+ /** @public */
280
+ type CoreErrorBoundaryFallbackComponent = ComponentType<PropsWithChildren<{
281
+ plugin?: BackstagePlugin$1;
282
+ error: Error;
283
+ resetError: () => void;
284
+ }>>;
285
+
286
+ /** @public */
287
+ type ComponentRef<T> = {
288
+ id: string;
289
+ T: T;
290
+ };
291
+ /** @public */
292
+ declare const coreComponentsRefs: {
293
+ progress: ComponentRef<CoreProgressComponent>;
294
+ bootErrorPage: ComponentRef<CoreBootErrorPageComponent>;
295
+ notFoundErrorPage: ComponentRef<CoreNotFoundErrorPageComponent>;
296
+ errorBoundaryFallback: ComponentRef<CoreErrorBoundaryFallbackComponent>;
297
+ };
298
+
299
+ /** @public */
300
+ interface ExtensionBoundaryProps {
301
+ node: AppNode;
302
+ routable?: boolean;
303
+ children: ReactNode;
304
+ }
305
+ /** @public */
306
+ declare function ExtensionBoundary(props: ExtensionBoundaryProps): React.JSX.Element;
307
+
219
308
  /** @public */
220
309
  type NavTarget = {
221
310
  title: string;
222
- icon: IconComponent;
311
+ icon: IconComponent$1;
223
312
  routeRef: RouteRef<undefined>;
224
313
  };
225
314
  /** @public */
315
+ type LogoElements = {
316
+ logoIcon?: JSX$1.Element;
317
+ logoFull?: JSX$1.Element;
318
+ };
319
+ /** @public */
226
320
  declare const coreExtensionData: {
227
321
  reactElement: ConfigurableExtensionDataRef<JSX$1.Element, {}>;
228
322
  routePath: ConfigurableExtensionDataRef<string, {}>;
@@ -230,6 +324,11 @@ declare const coreExtensionData: {
230
324
  routeRef: ConfigurableExtensionDataRef<RouteRef<AnyRouteRefParams>, {}>;
231
325
  navTarget: ConfigurableExtensionDataRef<NavTarget, {}>;
232
326
  theme: ConfigurableExtensionDataRef<AppTheme, {}>;
327
+ logoElements: ConfigurableExtensionDataRef<LogoElements, {}>;
328
+ component: ConfigurableExtensionDataRef<{
329
+ ref: ComponentRef<ComponentType<any>>;
330
+ impl: ComponentType<any>;
331
+ }, {}>;
233
332
  };
234
333
 
235
334
  /** @public */
@@ -241,14 +340,6 @@ type PortableSchema<TOutput> = {
241
340
  /** @public */
242
341
  declare function createSchemaFromZod<TOutput, TInput>(schemaCreator: (zImpl: typeof z) => ZodSchema<TOutput, ZodTypeDef, TInput>): PortableSchema<TOutput>;
243
342
 
244
- /**
245
- * Utility type to expand type aliases into their equivalent type.
246
- * @ignore
247
- */
248
- type Expand<T> = T extends infer O ? {
249
- [K in keyof O]: O[K];
250
- } : never;
251
-
252
343
  /** @public */
253
344
  interface ExtensionInput<TExtensionData extends AnyExtensionDataMap, TConfig extends {
254
345
  singleton: boolean;
@@ -267,32 +358,6 @@ declare function createExtensionInput<TExtensionData extends AnyExtensionDataMap
267
358
  optional: TConfig['optional'] extends true ? true : false;
268
359
  }>;
269
360
 
270
- /** @public */
271
- type AnyRoutes = {
272
- [name in string]: RouteRef;
273
- };
274
- /** @public */
275
- type AnyExternalRoutes = {
276
- [name in string]: ExternalRouteRef;
277
- };
278
- /** @public */
279
- interface PluginOptions<Routes extends AnyRoutes, ExternalRoutes extends AnyExternalRoutes> {
280
- id: string;
281
- routes?: Routes;
282
- externalRoutes?: ExternalRoutes;
283
- extensions?: Extension<unknown>[];
284
- }
285
- /** @public */
286
- interface BackstagePlugin<Routes extends AnyRoutes = AnyRoutes, ExternalRoutes extends AnyExternalRoutes = AnyExternalRoutes> {
287
- $$type: '@backstage/BackstagePlugin';
288
- id: string;
289
- extensions: Extension<unknown>[];
290
- routes: Routes;
291
- externalRoutes: ExternalRoutes;
292
- }
293
- /** @public */
294
- declare function createPlugin<Routes extends AnyRoutes = {}, ExternalRoutes extends AnyExternalRoutes = {}>(options: PluginOptions<Routes, ExternalRoutes>): BackstagePlugin<Routes, ExternalRoutes>;
295
-
296
361
  /** @public */
297
362
  type AnyExtensionDataMap = {
298
363
  [name in string]: ExtensionDataRef<unknown, {
@@ -340,7 +405,7 @@ interface CreateExtensionOptions<TOutput extends AnyExtensionDataMap, TInputs ex
340
405
  output: TOutput;
341
406
  configSchema?: PortableSchema<TConfig>;
342
407
  factory(options: {
343
- source?: BackstagePlugin;
408
+ node: AppNode;
344
409
  config: TConfig;
345
410
  inputs: Expand<ExtensionInputValues<TInputs>>;
346
411
  }): Expand<ExtensionDataValues<TOutput>>;
@@ -358,7 +423,7 @@ interface Extension<TConfig> {
358
423
  output: AnyExtensionDataMap;
359
424
  configSchema?: PortableSchema<TConfig>;
360
425
  factory(options: {
361
- source?: BackstagePlugin;
426
+ node: AppNode;
362
427
  config: TConfig;
363
428
  inputs: Record<string, undefined | Record<string, unknown> | Array<Record<string, unknown>>>;
364
429
  }): ExtensionDataValues<any>;
@@ -366,13 +431,50 @@ interface Extension<TConfig> {
366
431
  /** @public */
367
432
  declare function createExtension<TOutput extends AnyExtensionDataMap, TInputs extends AnyExtensionInputMap, TConfig = never>(options: CreateExtensionOptions<TOutput, TInputs, TConfig>): Extension<TConfig>;
368
433
 
434
+ /**
435
+ * Feature flag configuration.
436
+ *
437
+ * @public
438
+ */
439
+ type FeatureFlagConfig = {
440
+ /** Feature flag name */
441
+ name: string;
442
+ };
443
+
444
+ /** @public */
445
+ type AnyRoutes = {
446
+ [name in string]: RouteRef;
447
+ };
448
+ /** @public */
449
+ type AnyExternalRoutes = {
450
+ [name in string]: ExternalRouteRef;
451
+ };
452
+ /** @public */
453
+ interface PluginOptions<Routes extends AnyRoutes, ExternalRoutes extends AnyExternalRoutes> {
454
+ id: string;
455
+ routes?: Routes;
456
+ externalRoutes?: ExternalRoutes;
457
+ extensions?: Extension<unknown>[];
458
+ featureFlags?: FeatureFlagConfig[];
459
+ }
460
+ /** @public */
461
+ interface BackstagePlugin<Routes extends AnyRoutes = AnyRoutes, ExternalRoutes extends AnyExternalRoutes = AnyExternalRoutes> {
462
+ readonly $$type: '@backstage/BackstagePlugin';
463
+ readonly id: string;
464
+ readonly routes: Routes;
465
+ readonly externalRoutes: ExternalRoutes;
466
+ }
467
+ /** @public */
468
+ declare function createPlugin<Routes extends AnyRoutes = {}, ExternalRoutes extends AnyExternalRoutes = {}>(options: PluginOptions<Routes, ExternalRoutes>): BackstagePlugin<Routes, ExternalRoutes>;
469
+
369
470
  /** @public */
370
471
  interface ExtensionOverridesOptions {
371
472
  extensions: Extension<unknown>[];
473
+ featureFlags?: FeatureFlagConfig[];
372
474
  }
373
475
  /** @public */
374
476
  interface ExtensionOverrides {
375
- $$type: '@backstage/ExtensionOverrides';
477
+ readonly $$type: '@backstage/ExtensionOverrides';
376
478
  }
377
479
  /** @public */
378
480
  declare function createExtensionOverrides(options: ExtensionOverridesOptions): ExtensionOverrides;
@@ -475,15 +577,126 @@ interface AppTreeApi {
475
577
  */
476
578
  declare const appTreeApiRef: _backstage_core_plugin_api.ApiRef<AppTreeApi>;
477
579
 
478
- /** @public */
479
- interface ExtensionBoundaryProps {
480
- id: string;
481
- source?: BackstagePlugin;
482
- routable?: boolean;
483
- children: ReactNode;
580
+ /**
581
+ * API for looking up components based on component refs.
582
+ *
583
+ * @public
584
+ */
585
+ interface ComponentsApi {
586
+ getComponent<T>(ref: ComponentRef<T>): T;
484
587
  }
485
- /** @public */
486
- declare function ExtensionBoundary(props: ExtensionBoundaryProps): React.JSX.Element;
588
+ /**
589
+ * The `ApiRef` of {@link ComponentsApi}.
590
+ *
591
+ * @public
592
+ */
593
+ declare const componentsApiRef: _backstage_core_plugin_api.ApiRef<ComponentsApi>;
594
+
595
+ /**
596
+ * Represents an event worth tracking in an analytics system that could inform
597
+ * how users of a Backstage instance are using its features.
598
+ *
599
+ * @public
600
+ */
601
+ type AnalyticsEvent = {
602
+ /**
603
+ * A string that identifies the event being tracked by the type of action the
604
+ * event represents. Be careful not to encode extra metadata in this string
605
+ * that should instead be placed in the Analytics Context or attributes.
606
+ * Examples include:
607
+ *
608
+ * - view
609
+ * - click
610
+ * - filter
611
+ * - search
612
+ * - hover
613
+ * - scroll
614
+ */
615
+ action: string;
616
+ /**
617
+ * A string that uniquely identifies the object that the action is being
618
+ * taken on. Examples include:
619
+ *
620
+ * - The path of the page viewed
621
+ * - The url of the link clicked
622
+ * - The value that was filtered by
623
+ * - The text that was searched for
624
+ */
625
+ subject: string;
626
+ /**
627
+ * An optional numeric value relevant to the event that could be aggregated
628
+ * by analytics tools. Examples include:
629
+ *
630
+ * - The index or position of the clicked element in an ordered list
631
+ * - The percentage of an element that has been scrolled through
632
+ * - The amount of time that has elapsed since a fixed point
633
+ * - A satisfaction score on a fixed scale
634
+ */
635
+ value?: number;
636
+ /**
637
+ * Optional, additional attributes (representing dimensions or metrics)
638
+ * specific to the event that could be forwarded on to analytics systems.
639
+ */
640
+ attributes?: AnalyticsEventAttributes;
641
+ /**
642
+ * Contextual metadata relating to where the event was captured and by whom.
643
+ * This could include information about the route, plugin, or extension in
644
+ * which an event was captured.
645
+ */
646
+ context: AnalyticsContextValue;
647
+ };
648
+ /**
649
+ * A structure allowing other arbitrary metadata to be provided by analytics
650
+ * event emitters.
651
+ *
652
+ * @public
653
+ */
654
+ type AnalyticsEventAttributes = {
655
+ [attribute in string]: string | boolean | number;
656
+ };
657
+ /**
658
+ * Represents a tracker with methods that can be called to track events in a
659
+ * configured analytics service.
660
+ *
661
+ * @public
662
+ */
663
+ type AnalyticsTracker = {
664
+ captureEvent: (action: string, subject: string, options?: {
665
+ value?: number;
666
+ attributes?: AnalyticsEventAttributes;
667
+ }) => void;
668
+ };
669
+ /**
670
+ * The Analytics API is used to track user behavior in a Backstage instance.
671
+ *
672
+ * @remarks
673
+ *
674
+ * To instrument your App or Plugin, retrieve an analytics tracker using the
675
+ * useAnalytics() hook. This will return a pre-configured AnalyticsTracker
676
+ * with relevant methods for instrumentation.
677
+ *
678
+ * @public
679
+ */
680
+ type AnalyticsApi = {
681
+ /**
682
+ * Primary event handler responsible for compiling and forwarding events to
683
+ * an analytics system.
684
+ */
685
+ captureEvent(event: AnalyticsEvent): void;
686
+ };
687
+ /**
688
+ * The API reference of {@link AnalyticsApi}.
689
+ *
690
+ * @public
691
+ */
692
+ declare const analyticsApiRef: ApiRef<AnalyticsApi>;
693
+
694
+ /**
695
+ * Gets a pre-configured analytics tracker.
696
+ *
697
+ * @public
698
+ */
699
+ declare function useAnalytics(): AnalyticsTracker;
487
700
 
488
701
  /** @public */
489
702
  declare function createApiExtension<TConfig extends {}, TInputs extends AnyExtensionInputMap>(options: ({
@@ -533,12 +746,72 @@ declare function createNavItemExtension(options: {
533
746
  id: string;
534
747
  routeRef: RouteRef<undefined>;
535
748
  title: string;
536
- icon: IconComponent;
749
+ icon: IconComponent$1;
537
750
  }): Extension<{
538
751
  title: string;
539
752
  }>;
540
753
 
754
+ /**
755
+ *
756
+ * @public
757
+ */
758
+ declare function createSignInPageExtension<TConfig extends {}, TInputs extends AnyExtensionInputMap>(options: {
759
+ id: string;
760
+ attachTo?: {
761
+ id: string;
762
+ input: string;
763
+ };
764
+ configSchema?: PortableSchema<TConfig>;
765
+ disabled?: boolean;
766
+ inputs?: TInputs;
767
+ loader: (options: {
768
+ config: TConfig;
769
+ inputs: Expand<ExtensionInputValues<TInputs>>;
770
+ }) => Promise<ComponentType<SignInPageProps>>;
771
+ }): Extension<TConfig>;
772
+
541
773
  /** @public */
542
774
  declare function createThemeExtension(theme: AppTheme): Extension<never>;
543
775
 
544
- export { AnyExtensionDataMap, AnyExtensionInputMap, AnyExternalRoutes, AnyRouteRefParams, AnyRoutes, AppNode, AppNodeEdges, AppNodeInstance, AppNodeSpec, AppTree, AppTreeApi, BackstagePlugin, ConfigurableExtensionDataRef, CreateExtensionOptions, Extension, ExtensionBoundary, ExtensionBoundaryProps, ExtensionDataRef, ExtensionDataValues, ExtensionInput, ExtensionInputValues, ExtensionOverrides, ExtensionOverridesOptions, ExternalRouteRef, NavTarget, PluginOptions, PortableSchema, RouteFunc, RouteRef, SubRouteRef, appTreeApiRef, coreExtensionData, createApiExtension, createExtension, createExtensionDataRef, createExtensionInput, createExtensionOverrides, createExternalRouteRef, createNavItemExtension, createPageExtension, createPlugin, createRouteRef, createSchemaFromZod, createSubRouteRef, createThemeExtension, useRouteRef, useRouteRefParams };
776
+ /** @public */
777
+ declare function createComponentExtension<TRef extends ComponentRef<any>, TConfig extends {}, TInputs extends AnyExtensionInputMap>(options: {
778
+ ref: TRef;
779
+ disabled?: boolean;
780
+ inputs?: TInputs;
781
+ configSchema?: PortableSchema<TConfig>;
782
+ component: {
783
+ lazy: (values: {
784
+ config: TConfig;
785
+ inputs: Expand<ExtensionInputValues<TInputs>>;
786
+ }) => Promise<TRef['T']>;
787
+ } | {
788
+ sync: (values: {
789
+ config: TConfig;
790
+ inputs: Expand<ExtensionInputValues<TInputs>>;
791
+ }) => TRef['T'];
792
+ };
793
+ }): Extension<TConfig>;
794
+
795
+ /**
796
+ * IconComponent is the common icon type used throughout Backstage when
797
+ * working with and rendering generic icons, including the app system icons.
798
+ *
799
+ * @remarks
800
+ *
801
+ * The type is based on SvgIcon from Material UI, but both do not what the plugin-api
802
+ * package to have a dependency on Material UI, nor do we want the props to be as broad
803
+ * as the SvgIconProps interface.
804
+ *
805
+ * If you have the need to forward additional props from SvgIconProps, you can
806
+ * open an issue or submit a PR to the main Backstage repo. When doing so please
807
+ * also describe your use-case and reasoning of the addition.
808
+ *
809
+ * @public
810
+ */
811
+ type IconComponent = ComponentType<{
812
+ fontSize?: 'large' | 'small' | 'default' | 'inherit';
813
+ } | {
814
+ fontSize?: 'medium' | 'large' | 'small' | 'inherit';
815
+ }>;
816
+
817
+ export { AnalyticsApi, AnalyticsContext, AnalyticsContextValue, AnalyticsEvent, AnalyticsEventAttributes, AnalyticsTracker, AnyExtensionDataMap, AnyExtensionInputMap, AnyExternalRoutes, AnyRouteRefParams, AnyRoutes, AppNode, AppNodeEdges, AppNodeInstance, AppNodeSpec, AppTree, AppTreeApi, BackstagePlugin, CommonAnalyticsContext, ComponentRef, ComponentsApi, ConfigurableExtensionDataRef, CoreBootErrorPageComponent, CoreErrorBoundaryFallbackComponent, CoreNotFoundErrorPageComponent, CoreProgressComponent, CreateExtensionOptions, Extension, ExtensionBoundary, ExtensionBoundaryProps, ExtensionDataRef, ExtensionDataValues, ExtensionInput, ExtensionInputValues, ExtensionOverrides, ExtensionOverridesOptions, ExternalRouteRef, FeatureFlagConfig, IconComponent, LogoElements, NavTarget, PluginOptions, PortableSchema, RouteFunc, RouteRef, SubRouteRef, analyticsApiRef, appTreeApiRef, componentsApiRef, coreComponentsRefs, coreExtensionData, createApiExtension, createComponentExtension, createExtension, createExtensionDataRef, createExtensionInput, createExtensionOverrides, createExternalRouteRef, createNavItemExtension, createPageExtension, createPlugin, createRouteRef, createSchemaFromZod, createSignInPageExtension, createSubRouteRef, createThemeExtension, useAnalytics, useRouteRef, useRouteRefParams };