@backstage/core-app-api 0.2.1 → 0.3.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,26 @@
1
1
  # @backstage/core-app-api
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a195284c7b: Updated `WebStorageApi` to reflect the `StorageApi` changes in `@backstage/core-plugin-api`.
8
+ - b3605da81c: - Removed deprecated definition `createApp` from `@backstage/core-app-api` which has been replaced by `@backstage/app-defaults#createApp`
9
+ - Removed deprecated type `BackstagePluginWithAnyOutput`
10
+ - Removed deprecated constructors for `GithubAuth`, `OAuth2`, and `SamlAuth` as the `create` method should be used instead
11
+ - 68f8b10ccd: - Removed deprecation configuration option `theme` from `AppTheme` of the `AppThemeApi`
12
+ - Removed reference to `theme` in the `app-defaults` default `AppTheme`
13
+ - Removed logic in `AppThemeProvider` that creates `ThemeProvider` from `appTheme.theme`
14
+
15
+ ### Patch Changes
16
+
17
+ - 7927005152: Add `FetchApi` and related `fetchApiRef` which implement fetch, with an added Backstage token header when available.
18
+ - 518ddc00bc: Schema-validate local storage cached session info on load
19
+ - Updated dependencies
20
+ - @backstage/app-defaults@0.1.3
21
+ - @backstage/core-plugin-api@0.4.0
22
+ - @backstage/core-components@0.8.2
23
+
3
24
  ## 0.2.1
4
25
 
5
26
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import { ReactNode, PropsWithChildren, ComponentType } from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { ApiHolder, ApiRef, ApiFactory, AnyApiRef, ProfileInfo, BackstageIdentity, SessionState, OAuthRequestApi, DiscoveryApi, AuthProviderInfo, OAuthApi, SessionApi, AuthRequestOptions, gitlabAuthApiRef, googleAuthApiRef, OpenIdConnectApi, ProfileInfoApi, BackstageIdentityApi, oktaAuthApiRef, auth0AuthApiRef, microsoftAuthApiRef, oneloginAuthApiRef, bitbucketAuthApiRef, atlassianAuthApiRef, AlertApi, AlertMessage, AnalyticsApi, AnalyticsEvent, AppThemeApi, AppTheme, ErrorApi, ErrorApiError, ErrorApiErrorContext, FeatureFlagsApi, FeatureFlag, FeatureFlagsSaveOptions, OAuthRequesterOptions, OAuthRequester, PendingOAuthRequest, StorageApi, StorageValueChange, IdentityApi, BackstagePlugin, IconComponent, ExternalRouteRef, PluginOutput, AnyApiFactory, RouteRef, SubRouteRef } from '@backstage/core-plugin-api';
3
+ import { ApiHolder, ApiRef, ApiFactory, AnyApiRef, ProfileInfo, BackstageIdentity, OAuthRequestApi, DiscoveryApi, AuthProviderInfo, OAuthApi, SessionApi, SessionState, AuthRequestOptions, gitlabAuthApiRef, googleAuthApiRef, OpenIdConnectApi, ProfileInfoApi, BackstageIdentityApi, oktaAuthApiRef, auth0AuthApiRef, microsoftAuthApiRef, oneloginAuthApiRef, bitbucketAuthApiRef, atlassianAuthApiRef, AlertApi, AlertMessage, AnalyticsApi, AnalyticsEvent, AppThemeApi, AppTheme, ErrorApi, ErrorApiError, ErrorApiErrorContext, FeatureFlagsApi, FeatureFlag, FeatureFlagsSaveOptions, FetchApi, IdentityApi, OAuthRequesterOptions, OAuthRequester, PendingOAuthRequest, StorageApi, StorageValueSnapshot, BackstagePlugin, IconComponent, ExternalRouteRef, AnyApiFactory, PluginOutput, RouteRef, SubRouteRef } from '@backstage/core-plugin-api';
4
4
  import * as _backstage_types from '@backstage/types';
5
- import { Observable } from '@backstage/types';
6
- import { AppConfig } from '@backstage/config';
5
+ import { Observable, JsonValue } from '@backstage/types';
6
+ import { Config, AppConfig } from '@backstage/config';
7
7
  export { ConfigReader } from '@backstage/config';
8
- import { createApp as createApp$1 } from '@backstage/app-defaults';
9
8
 
10
9
  /**
11
10
  * Prop types for the ApiProvider component.
@@ -146,22 +145,6 @@ declare type GithubSession = {
146
145
  backstageIdentity: BackstageIdentity;
147
146
  };
148
147
 
149
- declare type GetSessionOptions = {
150
- optional?: boolean;
151
- instantPopup?: boolean;
152
- scopes?: Set<string>;
153
- };
154
- /**
155
- * A sessions manager keeps track of the current session and makes sure that
156
- * multiple simultaneous requests for sessions with different scope are handled
157
- * in a correct way.
158
- */
159
- declare type SessionManager<T> = {
160
- getSession(options: GetSessionOptions): Promise<T | undefined>;
161
- removeSession(): Promise<void>;
162
- sessionState$(): Observable<SessionState>;
163
- };
164
-
165
148
  /**
166
149
  * Create options for OAuth APIs.
167
150
  * @public
@@ -188,10 +171,7 @@ declare type AuthApiCreateOptions = {
188
171
  declare class GithubAuth implements OAuthApi, SessionApi {
189
172
  private readonly sessionManager;
190
173
  static create(options: OAuthApiCreateOptions): GithubAuth;
191
- /**
192
- * @deprecated will be made private in the future. Use create method instead.
193
- */
194
- constructor(sessionManager: SessionManager<GithubSession>);
174
+ private constructor();
195
175
  signIn(): Promise<void>;
196
176
  signOut(): Promise<void>;
197
177
  sessionState$(): Observable<SessionState>;
@@ -219,22 +199,6 @@ declare class GoogleAuth {
219
199
  static create(options: OAuthApiCreateOptions): typeof googleAuthApiRef.T;
220
200
  }
221
201
 
222
- /**
223
- * Session information for generic OAuth2 auth.
224
- *
225
- * @public
226
- */
227
- declare type OAuth2Session = {
228
- providerInfo: {
229
- idToken: string;
230
- accessToken: string;
231
- scopes: Set<string>;
232
- expiresAt: Date;
233
- };
234
- profile: ProfileInfo;
235
- backstageIdentity: BackstageIdentity;
236
- };
237
-
238
202
  /**
239
203
  * OAuth2 create options.
240
204
  * @public
@@ -251,13 +215,7 @@ declare class OAuth2 implements OAuthApi, OpenIdConnectApi, ProfileInfoApi, Back
251
215
  static create(options: OAuth2CreateOptions): OAuth2;
252
216
  private readonly sessionManager;
253
217
  private readonly scopeTransform;
254
- /**
255
- * @deprecated will be made private in the future. Use create method instead.
256
- */
257
- constructor(options: {
258
- sessionManager: SessionManager<OAuth2Session>;
259
- scopeTransform: (scopes: string[]) => string[];
260
- });
218
+ private constructor();
261
219
  signIn(): Promise<void>;
262
220
  signOut(): Promise<void>;
263
221
  sessionState$(): Observable<SessionState>;
@@ -269,24 +227,29 @@ declare class OAuth2 implements OAuthApi, OpenIdConnectApi, ProfileInfoApi, Back
269
227
  }
270
228
 
271
229
  /**
272
- * Implements the OAuth flow to Okta products.
230
+ * Session information for generic OAuth2 auth.
273
231
  *
274
232
  * @public
275
233
  */
276
- declare class OktaAuth {
277
- static create(options: OAuthApiCreateOptions): typeof oktaAuthApiRef.T;
278
- }
234
+ declare type OAuth2Session = {
235
+ providerInfo: {
236
+ idToken: string;
237
+ accessToken: string;
238
+ scopes: Set<string>;
239
+ expiresAt: Date;
240
+ };
241
+ profile: ProfileInfo;
242
+ backstageIdentity: BackstageIdentity;
243
+ };
279
244
 
280
245
  /**
281
- * Session information for SAML auth.
246
+ * Implements the OAuth flow to Okta products.
282
247
  *
283
248
  * @public
284
249
  */
285
- declare type SamlSession = {
286
- userId: string;
287
- profile: ProfileInfo;
288
- backstageIdentity: BackstageIdentity;
289
- };
250
+ declare class OktaAuth {
251
+ static create(options: OAuthApiCreateOptions): typeof oktaAuthApiRef.T;
252
+ }
290
253
 
291
254
  /**
292
255
  * Implements a general SAML based auth flow.
@@ -297,16 +260,24 @@ declare class SamlAuth implements ProfileInfoApi, BackstageIdentityApi, SessionA
297
260
  private readonly sessionManager;
298
261
  static create(options: AuthApiCreateOptions): SamlAuth;
299
262
  sessionState$(): Observable<SessionState>;
300
- /**
301
- * @deprecated will be made private in the future. Use create method instead.
302
- */
303
- constructor(sessionManager: SessionManager<SamlSession>);
263
+ private constructor();
304
264
  signIn(): Promise<void>;
305
265
  signOut(): Promise<void>;
306
266
  getBackstageIdentity(options?: AuthRequestOptions): Promise<BackstageIdentity | undefined>;
307
267
  getProfile(options?: AuthRequestOptions): Promise<ProfileInfo | undefined>;
308
268
  }
309
269
 
270
+ /**
271
+ * Session information for SAML auth.
272
+ *
273
+ * @public
274
+ */
275
+ declare type SamlSession = {
276
+ userId: string;
277
+ profile: ProfileInfo;
278
+ backstageIdentity: BackstageIdentity;
279
+ };
280
+
310
281
  /**
311
282
  * Implements the OAuth flow to Auth0 products.
312
283
  *
@@ -511,6 +482,87 @@ declare class LocalStorageFeatureFlags implements FeatureFlagsApi {
511
482
  private load;
512
483
  }
513
484
 
485
+ /**
486
+ * A middleware that modifies the behavior of an ongoing fetch.
487
+ *
488
+ * @public
489
+ */
490
+ interface FetchMiddleware {
491
+ /**
492
+ * Applies this middleware to an inner implementation.
493
+ *
494
+ * @param next - The next, inner, implementation, that this middleware shall
495
+ * call out to as part of the request cycle.
496
+ */
497
+ apply(next: typeof fetch): typeof fetch;
498
+ }
499
+
500
+ /**
501
+ * Builds a fetch API, based on the builtin fetch wrapped by a set of optional
502
+ * middleware implementations that add behaviors.
503
+ *
504
+ * @remarks
505
+ *
506
+ * The middleware are applied in reverse order, i.e. the last one will be
507
+ * "closest" to the base implementation. Passing in `[M1, M2, M3]` effectively
508
+ * leads to `M1(M2(M3(baseImplementation)))`.
509
+ *
510
+ * @public
511
+ */
512
+ declare function createFetchApi(options: {
513
+ baseImplementation?: typeof fetch | undefined;
514
+ middleware?: FetchMiddleware | FetchMiddleware[] | undefined;
515
+ }): FetchApi;
516
+
517
+ /**
518
+ * A collection of common middlewares for the FetchApi.
519
+ *
520
+ * @public
521
+ */
522
+ declare class FetchMiddlewares {
523
+ /**
524
+ * Handles translation from `plugin://` URLs to concrete http(s) URLs based on
525
+ * the discovery API.
526
+ *
527
+ * @remarks
528
+ *
529
+ * If the request is for `plugin://catalog/entities?filter=x=y`, the discovery
530
+ * API will be queried for `'catalog'`. If it returned
531
+ * `https://backstage.example.net/api/catalog`, the resulting query would be
532
+ * `https://backstage.example.net/api/catalog/entities?filter=x=y`.
533
+ *
534
+ * If the incoming URL protocol was not `plugin`, the request is just passed
535
+ * through verbatim to the underlying implementation.
536
+ */
537
+ static resolvePluginProtocol(options: {
538
+ discoveryApi: DiscoveryApi;
539
+ }): FetchMiddleware;
540
+ /**
541
+ * Injects a Backstage token header when the user is signed in.
542
+ *
543
+ * @remarks
544
+ *
545
+ * Per default, an `Authorization: Bearer <token>` is generated. This can be
546
+ * customized using the `header` option.
547
+ *
548
+ * The header injection only happens on allowlisted URLs. Per default, if the
549
+ * `config` option is passed in, the `backend.baseUrl` is allowlisted, unless
550
+ * the `urlPrefixAllowlist` option is passed in, in which case it takes
551
+ * precedence. If you pass in neither config nor an allowlist, the middleware
552
+ * will have no effect.
553
+ */
554
+ static injectIdentityAuth(options: {
555
+ identityApi: IdentityApi;
556
+ config?: Config;
557
+ urlPrefixAllowlist?: string[];
558
+ header?: {
559
+ name: string;
560
+ value: (backstageToken: string) => string;
561
+ };
562
+ }): FetchMiddleware;
563
+ private constructor();
564
+ }
565
+
514
566
  /**
515
567
  * The OAuthRequestManager is an implementation of the OAuthRequestApi.
516
568
  *
@@ -543,10 +595,11 @@ declare class WebStorage implements StorageApi {
543
595
  namespace?: string;
544
596
  }): WebStorage;
545
597
  get<T>(key: string): T | undefined;
598
+ snapshot<T extends JsonValue>(key: string): StorageValueSnapshot<T>;
546
599
  forBucket(name: string): WebStorage;
547
600
  set<T>(key: string, data: T): Promise<void>;
548
601
  remove(key: string): Promise<void>;
549
- observe$<T>(key: string): Observable<StorageValueChange<T>>;
602
+ observe$<T>(key: string): Observable<StorageValueSnapshot<T>>;
550
603
  private getKeyName;
551
604
  private notifyChanges;
552
605
  private subscribers;
@@ -694,7 +747,7 @@ declare type TargetRouteMap<ExternalRoutes extends {
694
747
  };
695
748
  /**
696
749
  * A function that can bind from external routes of a given plugin, to concrete
697
- * routes of other plugins. See {@link createApp}.
750
+ * routes of other plugins. See {@link createSpecializedApp}.
698
751
  *
699
752
  * @public
700
753
  */
@@ -702,28 +755,7 @@ declare type AppRouteBinder = <ExternalRoutes extends {
702
755
  [name: string]: ExternalRouteRef;
703
756
  }>(externalRoutes: ExternalRoutes, targetRoutes: PartialKeys<TargetRouteMap<ExternalRoutes>, KeysWithType<ExternalRoutes, ExternalRouteRef<any, true>>>) => void;
704
757
  /**
705
- * Internal helper type that represents a plugin with any type of output.
706
- *
707
- * @public
708
- * @remarks
709
- * @deprecated Will be removed
710
- *
711
- * The `type: string` type is there to handle output from newer or older plugin
712
- * API versions that might not be supported by this version of the app API, but
713
- * we don't want to break at the type checking level. We only use this more
714
- * permissive type for the `createApp` options, as we otherwise want to stick
715
- * to using the type for the outputs that we know about in this version of the
716
- * app api.
717
- *
718
- * TODO(freben): This should be marked internal but that's not supported by the api report generation tools yet
719
- */
720
- declare type BackstagePluginWithAnyOutput = Omit<BackstagePlugin<any, any>, 'output'> & {
721
- output(): (PluginOutput | {
722
- type: string;
723
- })[];
724
- };
725
- /**
726
- * The options accepted by {@link createApp}.
758
+ * The options accepted by {@link createSpecializedApp}.
727
759
  *
728
760
  * @public
729
761
  */
@@ -823,7 +855,7 @@ declare type AppOptions = {
823
855
  }): void;
824
856
  };
825
857
  /**
826
- * The public API of the output of {@link createApp}.
858
+ * The public API of the output of {@link createSpecializedApp}.
827
859
  *
828
860
  * @public
829
861
  */
@@ -868,21 +900,19 @@ declare type AppContext = {
868
900
  getComponents(): AppComponents;
869
901
  };
870
902
 
871
- /**
872
- * Creates a new Backstage App.
873
- *
874
- * @deprecated Use {@link @backstage/app-defaults#createApp} from `@backstage/app-defaults` instead
875
- * @param options - A set of options for creating the app
876
- * @public
877
- */
878
- declare function createApp(options?: Parameters<typeof createApp$1>[0]): BackstageApp & AppContext;
879
-
880
903
  /**
881
904
  * Creates a new Backstage App where the full set of options are required.
882
905
  *
883
906
  * @public
884
907
  * @param options - A set of options for creating the app
885
908
  * @returns
909
+ * @remarks
910
+ *
911
+ * You will most likely want to use {@link @backstage/app-defaults#createApp},
912
+ * however, this low-level API allows you to provide a full set of options,
913
+ * including your own `components`, `icons`, `defaultApis`, and `themes`. This
914
+ * is particularly useful if you are not using `@backstage/core-components` or
915
+ * MUI, as it allows you to avoid those dependencies completely.
886
916
  */
887
917
  declare function createSpecializedApp(options: AppOptions): BackstageApp;
888
918
 
@@ -941,4 +971,4 @@ declare type FeatureFlaggedProps = {
941
971
  */
942
972
  declare const FeatureFlagged: (props: FeatureFlaggedProps) => JSX.Element;
943
973
 
944
- export { AlertApiForwarder, ApiFactoryHolder, ApiFactoryRegistry, ApiFactoryScope, ApiProvider, ApiProviderProps, ApiRegistry, ApiResolver, AppComponents, AppConfigLoader, AppContext, AppIcons, AppOptions, AppRouteBinder, AppThemeSelector, AtlassianAuth, Auth0Auth, AuthApiCreateOptions, BackstageApp, BackstagePluginWithAnyOutput, BitbucketAuth, BitbucketSession, BootErrorPageProps, ErrorAlerter, ErrorApiForwarder, ErrorBoundaryFallbackProps, FeatureFlagged, FeatureFlaggedProps, FlatRoutes, FlatRoutesProps, GithubAuth, GithubSession, GitlabAuth, GoogleAuth, LocalStorageFeatureFlags, MicrosoftAuth, NoOpAnalyticsApi, OAuth2, OAuth2CreateOptions, OAuth2Session, OAuthApiCreateOptions, OAuthRequestManager, OktaAuth, OneLoginAuth, OneLoginAuthCreateOptions, SamlAuth, SamlSession, SignInPageProps, SignInResult, UnhandledErrorForwarder, UrlPatternDiscovery, WebStorage, createApp, createSpecializedApp, defaultConfigLoader };
974
+ export { AlertApiForwarder, ApiFactoryHolder, ApiFactoryRegistry, ApiFactoryScope, ApiProvider, ApiProviderProps, ApiRegistry, ApiResolver, AppComponents, AppConfigLoader, AppContext, AppIcons, AppOptions, AppRouteBinder, AppThemeSelector, AtlassianAuth, Auth0Auth, AuthApiCreateOptions, BackstageApp, BitbucketAuth, BitbucketSession, BootErrorPageProps, ErrorAlerter, ErrorApiForwarder, ErrorBoundaryFallbackProps, FeatureFlagged, FeatureFlaggedProps, FetchMiddleware, FetchMiddlewares, FlatRoutes, FlatRoutesProps, GithubAuth, GithubSession, GitlabAuth, GoogleAuth, LocalStorageFeatureFlags, MicrosoftAuth, NoOpAnalyticsApi, OAuth2, OAuth2CreateOptions, OAuth2Session, OAuthApiCreateOptions, OAuthRequestManager, OktaAuth, OneLoginAuth, OneLoginAuthCreateOptions, SamlAuth, SamlSession, SignInPageProps, SignInResult, UnhandledErrorForwarder, UrlPatternDiscovery, WebStorage, createFetchApi, createSpecializedApp, defaultConfigLoader };