From 2096c38db6d605a9e41f05ae6ba5480cfef2a59a Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Tue, 7 Nov 2023 15:26:33 +0100 Subject: [PATCH] fontend-plugin-api: use relative imports Signed-off-by: Vincenzo Scamporlino --- .../index.ts => apis/definitions/AlertApi.ts} | 24 +- .../{ => apis}/definitions/AppLanguageApi.ts | 25 +- .../src/apis/definitions/AppThemeApi.ts | 22 + .../src/{ => apis}/definitions/ConfigApi.ts | 20 +- .../{ => apis}/definitions/DiscoveryApi.ts | 0 .../src/{ => apis}/definitions/ErrorApi.ts | 0 .../{ => apis}/definitions/FeatureFlagsApi.ts | 0 .../src/{ => apis}/definitions/FetchApi.ts | 0 .../src/{ => apis}/definitions/IdentityApi.ts | 0 .../{ => apis}/definitions/OAuthRequestApi.ts | 0 .../src/{ => apis}/definitions/StorageApi.ts | 0 .../src/{ => apis}/definitions/alpha.ts | 0 .../src/apis/definitions/auth.ts | 40 ++ .../src/apis/definitions/index.ts | 19 + .../frontend-plugin-api/src/apis/index.ts | 1 + .../{ => apis}/system/ApiAggregator.test.ts | 0 .../src/{ => apis}/system/ApiAggregator.ts | 0 .../system/ApiFactoryRegistry.test.ts | 0 .../{ => apis}/system/ApiFactoryRegistry.ts | 0 .../{ => apis}/system/ApiProvider.test.tsx | 0 .../src/{ => apis}/system/ApiProvider.tsx | 0 .../src/{ => apis}/system/ApiRef.test.ts | 0 .../src/{ => apis}/system/ApiRef.ts | 0 .../src/{ => apis}/system/ApiRegistry.test.ts | 0 .../src/{ => apis}/system/ApiRegistry.ts | 0 .../src/{ => apis}/system/ApiResolver.test.ts | 0 .../src/{ => apis}/system/ApiResolver.ts | 0 .../src/{ => apis}/system/index.ts | 0 .../src/{ => apis}/system/types.ts | 0 .../src/definitions/AlertApi.ts | 56 --- .../src/definitions/AppThemeApi.ts | 87 ---- .../src/definitions/auth.ts | 452 ------------------ packages/frontend-plugin-api/src/index.ts | 3 +- 33 files changed, 96 insertions(+), 653 deletions(-) rename packages/frontend-plugin-api/src/{definitions/index.ts => apis/definitions/AlertApi.ts} (52%) rename packages/frontend-plugin-api/src/{ => apis}/definitions/AppLanguageApi.ts (56%) create mode 100644 packages/frontend-plugin-api/src/apis/definitions/AppThemeApi.ts rename packages/frontend-plugin-api/src/{ => apis}/definitions/ConfigApi.ts (59%) rename packages/frontend-plugin-api/src/{ => apis}/definitions/DiscoveryApi.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/definitions/ErrorApi.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/definitions/FeatureFlagsApi.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/definitions/FetchApi.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/definitions/IdentityApi.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/definitions/OAuthRequestApi.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/definitions/StorageApi.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/definitions/alpha.ts (100%) create mode 100644 packages/frontend-plugin-api/src/apis/definitions/auth.ts rename packages/frontend-plugin-api/src/{ => apis}/system/ApiAggregator.test.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/ApiAggregator.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/ApiFactoryRegistry.test.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/ApiFactoryRegistry.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/ApiProvider.test.tsx (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/ApiProvider.tsx (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/ApiRef.test.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/ApiRef.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/ApiRegistry.test.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/ApiRegistry.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/ApiResolver.test.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/ApiResolver.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/index.ts (100%) rename packages/frontend-plugin-api/src/{ => apis}/system/types.ts (100%) delete mode 100644 packages/frontend-plugin-api/src/definitions/AlertApi.ts delete mode 100644 packages/frontend-plugin-api/src/definitions/AppThemeApi.ts delete mode 100644 packages/frontend-plugin-api/src/definitions/auth.ts diff --git a/packages/frontend-plugin-api/src/definitions/index.ts b/packages/frontend-plugin-api/src/apis/definitions/AlertApi.ts similarity index 52% rename from packages/frontend-plugin-api/src/definitions/index.ts rename to packages/frontend-plugin-api/src/apis/definitions/AlertApi.ts index cc02442f3d..eb42477f77 100644 --- a/packages/frontend-plugin-api/src/definitions/index.ts +++ b/packages/frontend-plugin-api/src/apis/definitions/AlertApi.ts @@ -14,21 +14,9 @@ * limitations under the License. */ -// This folder contains definitions for all core APIs. -// -// Plugins should rely on these APIs for functionality as much as possible. -// -// If you think some API definition is missing, please open an Issue or send a PR! - -export * from './auth'; - -export * from './AlertApi'; -export * from './AppThemeApi'; -export * from './ConfigApi'; -export * from './DiscoveryApi'; -export * from './ErrorApi'; -export * from './FeatureFlagsApi'; -export * from './FetchApi'; -export * from './IdentityApi'; -export * from './OAuthRequestApi'; -export * from './StorageApi'; +// eslint-disable-next-line @backstage/no-relative-monorepo-imports +export { + type AlertApi, + type AlertMessage, + alertApiRef, +} from '../../../../core-plugin-api'; diff --git a/packages/frontend-plugin-api/src/definitions/AppLanguageApi.ts b/packages/frontend-plugin-api/src/apis/definitions/AppLanguageApi.ts similarity index 56% rename from packages/frontend-plugin-api/src/definitions/AppLanguageApi.ts rename to packages/frontend-plugin-api/src/apis/definitions/AppLanguageApi.ts index 1207e84755..020742f9e4 100644 --- a/packages/frontend-plugin-api/src/definitions/AppLanguageApi.ts +++ b/packages/frontend-plugin-api/src/apis/definitions/AppLanguageApi.ts @@ -14,23 +14,8 @@ * limitations under the License. */ -import { ApiRef, createApiRef } from '@backstage/core-plugin-api'; -import { Observable } from '@backstage/types'; - -/** @alpha */ -export type AppLanguageApi = { - getAvailableLanguages(): { languages: string[] }; - - setLanguage(language?: string): void; - - getLanguage(): { language: string }; - - language$(): Observable<{ language: string }>; -}; - -/** - * @alpha - */ -export const appLanguageApiRef: ApiRef = createApiRef({ - id: 'core.applanguage', -}); +// eslint-disable-next-line @backstage/no-relative-monorepo-imports +export { + type AppLanguageApi, + appLanguageApiRef, +} from '../../../../core-plugin-api/src/alpha'; diff --git a/packages/frontend-plugin-api/src/apis/definitions/AppThemeApi.ts b/packages/frontend-plugin-api/src/apis/definitions/AppThemeApi.ts new file mode 100644 index 0000000000..0764cfa6eb --- /dev/null +++ b/packages/frontend-plugin-api/src/apis/definitions/AppThemeApi.ts @@ -0,0 +1,22 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// eslint-disable-next-line @backstage/no-relative-monorepo-imports +export { + type AppTheme, + type AppThemeApi, + appThemeApiRef, +} from '../../../../core-plugin-api'; diff --git a/packages/frontend-plugin-api/src/definitions/ConfigApi.ts b/packages/frontend-plugin-api/src/apis/definitions/ConfigApi.ts similarity index 59% rename from packages/frontend-plugin-api/src/definitions/ConfigApi.ts rename to packages/frontend-plugin-api/src/apis/definitions/ConfigApi.ts index d3bada9e46..dc28ff2980 100644 --- a/packages/frontend-plugin-api/src/definitions/ConfigApi.ts +++ b/packages/frontend-plugin-api/src/apis/definitions/ConfigApi.ts @@ -13,22 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ApiRef, createApiRef } from '../system'; -import { Config } from '@backstage/config'; -/** - * The Config API is used to provide a mechanism to access the - * runtime configuration of the system. - * - * @public - */ -export type ConfigApi = Config; - -/** - * The {@link ApiRef} of {@link ConfigApi}. - * - * @public - */ -export const configApiRef: ApiRef = createApiRef({ - id: 'core.config', -}); +// eslint-disable-next-line @backstage/no-relative-monorepo-imports +export { type ConfigApi, configApiRef } from '../../../../core-plugin-api'; diff --git a/packages/frontend-plugin-api/src/definitions/DiscoveryApi.ts b/packages/frontend-plugin-api/src/apis/definitions/DiscoveryApi.ts similarity index 100% rename from packages/frontend-plugin-api/src/definitions/DiscoveryApi.ts rename to packages/frontend-plugin-api/src/apis/definitions/DiscoveryApi.ts diff --git a/packages/frontend-plugin-api/src/definitions/ErrorApi.ts b/packages/frontend-plugin-api/src/apis/definitions/ErrorApi.ts similarity index 100% rename from packages/frontend-plugin-api/src/definitions/ErrorApi.ts rename to packages/frontend-plugin-api/src/apis/definitions/ErrorApi.ts diff --git a/packages/frontend-plugin-api/src/definitions/FeatureFlagsApi.ts b/packages/frontend-plugin-api/src/apis/definitions/FeatureFlagsApi.ts similarity index 100% rename from packages/frontend-plugin-api/src/definitions/FeatureFlagsApi.ts rename to packages/frontend-plugin-api/src/apis/definitions/FeatureFlagsApi.ts diff --git a/packages/frontend-plugin-api/src/definitions/FetchApi.ts b/packages/frontend-plugin-api/src/apis/definitions/FetchApi.ts similarity index 100% rename from packages/frontend-plugin-api/src/definitions/FetchApi.ts rename to packages/frontend-plugin-api/src/apis/definitions/FetchApi.ts diff --git a/packages/frontend-plugin-api/src/definitions/IdentityApi.ts b/packages/frontend-plugin-api/src/apis/definitions/IdentityApi.ts similarity index 100% rename from packages/frontend-plugin-api/src/definitions/IdentityApi.ts rename to packages/frontend-plugin-api/src/apis/definitions/IdentityApi.ts diff --git a/packages/frontend-plugin-api/src/definitions/OAuthRequestApi.ts b/packages/frontend-plugin-api/src/apis/definitions/OAuthRequestApi.ts similarity index 100% rename from packages/frontend-plugin-api/src/definitions/OAuthRequestApi.ts rename to packages/frontend-plugin-api/src/apis/definitions/OAuthRequestApi.ts diff --git a/packages/frontend-plugin-api/src/definitions/StorageApi.ts b/packages/frontend-plugin-api/src/apis/definitions/StorageApi.ts similarity index 100% rename from packages/frontend-plugin-api/src/definitions/StorageApi.ts rename to packages/frontend-plugin-api/src/apis/definitions/StorageApi.ts diff --git a/packages/frontend-plugin-api/src/definitions/alpha.ts b/packages/frontend-plugin-api/src/apis/definitions/alpha.ts similarity index 100% rename from packages/frontend-plugin-api/src/definitions/alpha.ts rename to packages/frontend-plugin-api/src/apis/definitions/alpha.ts diff --git a/packages/frontend-plugin-api/src/apis/definitions/auth.ts b/packages/frontend-plugin-api/src/apis/definitions/auth.ts new file mode 100644 index 0000000000..60ce40c6ad --- /dev/null +++ b/packages/frontend-plugin-api/src/apis/definitions/auth.ts @@ -0,0 +1,40 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// eslint-disable-next-line @backstage/no-relative-monorepo-imports +export { + type BackstageIdentityApi, + type BackstageIdentityResponse, + type BackstageUserIdentity, + type AuthProviderInfo, + type AuthRequestOptions, + type OAuthScope, + type OAuthApi, + type OpenIdConnectApi, + type ProfileInfoApi, + type ProfileInfo, + type SessionApi, + SessionState, + atlassianAuthApiRef, + bitbucketAuthApiRef, + bitbucketServerAuthApiRef, + githubAuthApiRef, + gitlabAuthApiRef, + googleAuthApiRef, + oktaAuthApiRef, + microsoftAuthApiRef, + oneloginAuthApiRef, +} from '../../../../core-plugin-api'; diff --git a/packages/frontend-plugin-api/src/apis/definitions/index.ts b/packages/frontend-plugin-api/src/apis/definitions/index.ts index 8facdca2ca..420942cb19 100644 --- a/packages/frontend-plugin-api/src/apis/definitions/index.ts +++ b/packages/frontend-plugin-api/src/apis/definitions/index.ts @@ -23,3 +23,22 @@ export { type AppTree, type AppTreeApi, } from './AppTreeApi'; + +// This folder contains definitions for all core APIs. +// +// Plugins should rely on these APIs for functionality as much as possible. +// +// If you think some API definition is missing, please open an Issue or send a PR! + +export * from './auth'; + +export * from './AlertApi'; +export * from './AppThemeApi'; +export * from './ConfigApi'; +export * from './DiscoveryApi'; +export * from './ErrorApi'; +export * from './FeatureFlagsApi'; +export * from './FetchApi'; +export * from './IdentityApi'; +export * from './OAuthRequestApi'; +export * from './StorageApi'; diff --git a/packages/frontend-plugin-api/src/apis/index.ts b/packages/frontend-plugin-api/src/apis/index.ts index 5a012c0553..5def6cb0f9 100644 --- a/packages/frontend-plugin-api/src/apis/index.ts +++ b/packages/frontend-plugin-api/src/apis/index.ts @@ -15,3 +15,4 @@ */ export * from './definitions'; +export * from './system'; diff --git a/packages/frontend-plugin-api/src/system/ApiAggregator.test.ts b/packages/frontend-plugin-api/src/apis/system/ApiAggregator.test.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiAggregator.test.ts rename to packages/frontend-plugin-api/src/apis/system/ApiAggregator.test.ts diff --git a/packages/frontend-plugin-api/src/system/ApiAggregator.ts b/packages/frontend-plugin-api/src/apis/system/ApiAggregator.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiAggregator.ts rename to packages/frontend-plugin-api/src/apis/system/ApiAggregator.ts diff --git a/packages/frontend-plugin-api/src/system/ApiFactoryRegistry.test.ts b/packages/frontend-plugin-api/src/apis/system/ApiFactoryRegistry.test.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiFactoryRegistry.test.ts rename to packages/frontend-plugin-api/src/apis/system/ApiFactoryRegistry.test.ts diff --git a/packages/frontend-plugin-api/src/system/ApiFactoryRegistry.ts b/packages/frontend-plugin-api/src/apis/system/ApiFactoryRegistry.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiFactoryRegistry.ts rename to packages/frontend-plugin-api/src/apis/system/ApiFactoryRegistry.ts diff --git a/packages/frontend-plugin-api/src/system/ApiProvider.test.tsx b/packages/frontend-plugin-api/src/apis/system/ApiProvider.test.tsx similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiProvider.test.tsx rename to packages/frontend-plugin-api/src/apis/system/ApiProvider.test.tsx diff --git a/packages/frontend-plugin-api/src/system/ApiProvider.tsx b/packages/frontend-plugin-api/src/apis/system/ApiProvider.tsx similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiProvider.tsx rename to packages/frontend-plugin-api/src/apis/system/ApiProvider.tsx diff --git a/packages/frontend-plugin-api/src/system/ApiRef.test.ts b/packages/frontend-plugin-api/src/apis/system/ApiRef.test.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiRef.test.ts rename to packages/frontend-plugin-api/src/apis/system/ApiRef.test.ts diff --git a/packages/frontend-plugin-api/src/system/ApiRef.ts b/packages/frontend-plugin-api/src/apis/system/ApiRef.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiRef.ts rename to packages/frontend-plugin-api/src/apis/system/ApiRef.ts diff --git a/packages/frontend-plugin-api/src/system/ApiRegistry.test.ts b/packages/frontend-plugin-api/src/apis/system/ApiRegistry.test.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiRegistry.test.ts rename to packages/frontend-plugin-api/src/apis/system/ApiRegistry.test.ts diff --git a/packages/frontend-plugin-api/src/system/ApiRegistry.ts b/packages/frontend-plugin-api/src/apis/system/ApiRegistry.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiRegistry.ts rename to packages/frontend-plugin-api/src/apis/system/ApiRegistry.ts diff --git a/packages/frontend-plugin-api/src/system/ApiResolver.test.ts b/packages/frontend-plugin-api/src/apis/system/ApiResolver.test.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiResolver.test.ts rename to packages/frontend-plugin-api/src/apis/system/ApiResolver.test.ts diff --git a/packages/frontend-plugin-api/src/system/ApiResolver.ts b/packages/frontend-plugin-api/src/apis/system/ApiResolver.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/ApiResolver.ts rename to packages/frontend-plugin-api/src/apis/system/ApiResolver.ts diff --git a/packages/frontend-plugin-api/src/system/index.ts b/packages/frontend-plugin-api/src/apis/system/index.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/index.ts rename to packages/frontend-plugin-api/src/apis/system/index.ts diff --git a/packages/frontend-plugin-api/src/system/types.ts b/packages/frontend-plugin-api/src/apis/system/types.ts similarity index 100% rename from packages/frontend-plugin-api/src/system/types.ts rename to packages/frontend-plugin-api/src/apis/system/types.ts diff --git a/packages/frontend-plugin-api/src/definitions/AlertApi.ts b/packages/frontend-plugin-api/src/definitions/AlertApi.ts deleted file mode 100644 index afdcb6a617..0000000000 --- a/packages/frontend-plugin-api/src/definitions/AlertApi.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { createApiRef, ApiRef } from '../system'; -import { Observable } from '@backstage/types'; - -/** - * Message handled by the {@link AlertApi}. - * - * @public - */ -export type AlertMessage = { - message: string; - // Severity will default to success since that is what material ui defaults the value to. - severity?: 'success' | 'info' | 'warning' | 'error'; - display?: 'permanent' | 'transient'; -}; - -/** - * The alert API is used to report alerts to the app, and display them to the user. - * - * @public - */ -export type AlertApi = { - /** - * Post an alert for handling by the application. - */ - post(alert: AlertMessage): void; - - /** - * Observe alerts posted by other parts of the application. - */ - alert$(): Observable; -}; - -/** - * The {@link ApiRef} of {@link AlertApi}. - * - * @public - */ -export const alertApiRef: ApiRef = createApiRef({ - id: 'core.alert', -}); diff --git a/packages/frontend-plugin-api/src/definitions/AppThemeApi.ts b/packages/frontend-plugin-api/src/definitions/AppThemeApi.ts deleted file mode 100644 index e771fad597..0000000000 --- a/packages/frontend-plugin-api/src/definitions/AppThemeApi.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { ReactNode } from 'react'; -import { ApiRef, createApiRef } from '../system'; -import { Observable } from '@backstage/types'; - -/** - * Describes a theme provided by the app. - * - * @public - */ -export type AppTheme = { - /** - * ID used to remember theme selections. - */ - id: string; - - /** - * Title of the theme - */ - title: string; - - /** - * Theme variant - */ - variant: 'light' | 'dark'; - - /** - * An Icon for the theme mode setting. - */ - icon?: React.ReactElement; - - Provider(props: { children: ReactNode }): JSX.Element | null; -}; - -/** - * The AppThemeApi gives access to the current app theme, and allows switching - * to other options that have been registered as a part of the App. - * - * @public - */ -export type AppThemeApi = { - /** - * Get a list of available themes. - */ - getInstalledThemes(): AppTheme[]; - - /** - * Observe the currently selected theme. A value of undefined means no specific theme has been selected. - */ - activeThemeId$(): Observable; - - /** - * Get the current theme ID. Returns undefined if no specific theme is selected. - */ - getActiveThemeId(): string | undefined; - - /** - * Set a specific theme to use in the app, overriding the default theme selection. - * - * Clear the selection by passing in undefined. - */ - setActiveThemeId(themeId?: string): void; -}; - -/** - * The {@link ApiRef} of {@link AppThemeApi}. - * - * @public - */ -export const appThemeApiRef: ApiRef = createApiRef({ - id: 'core.apptheme', -}); diff --git a/packages/frontend-plugin-api/src/definitions/auth.ts b/packages/frontend-plugin-api/src/definitions/auth.ts deleted file mode 100644 index 5ed873a566..0000000000 --- a/packages/frontend-plugin-api/src/definitions/auth.ts +++ /dev/null @@ -1,452 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { ApiRef, createApiRef } from '../system'; -import { IconComponent } from '../icons/types'; -import { Observable } from '@backstage/types'; - -/** - * This file contains declarations for common interfaces of auth-related APIs. - * The declarations should be used to signal which type of authentication and - * authorization methods each separate auth provider supports. - * - * For example, a Google OAuth provider that supports OAuth 2 and OpenID Connect, - * would be declared as follows: - * - * const googleAuthApiRef = createApiRef({ ... }) - */ - -/** - * Information about the auth provider. - * - * @remarks - * - * This information is used both to connect the correct auth provider in the backend, as - * well as displaying the provider to the user. - * - * @public - */ -export type AuthProviderInfo = { - /** - * The ID of the auth provider. This should match with ID of the provider in the `@backstage/auth-backend`. - */ - id: string; - - /** - * Title for the auth provider, for example "GitHub" - */ - title: string; - - /** - * Icon for the auth provider. - */ - icon: IconComponent; -}; - -/** - * An array of scopes, or a scope string formatted according to the - * auth provider, which is typically a space separated list. - * - * @remarks - * - * See the documentation for each auth provider for the list of scopes - * supported by each provider. - * - * @public - */ -export type OAuthScope = string | string[]; - -/** - * Configuration of an authentication request. - * - * @public - */ -export type AuthRequestOptions = { - /** - * If this is set to true, the user will not be prompted to log in, - * and an empty response will be returned if there is no existing session. - * - * This can be used to perform a check whether the user is logged in, or if you don't - * want to force a user to be logged in, but provide functionality if they already are. - * - * @defaultValue false - */ - optional?: boolean; - - /** - * If this is set to true, the request will bypass the regular oauth login modal - * and open the login popup directly. - * - * The method must be called synchronously from a user action for this to work in all browsers. - * - * @defaultValue false - */ - instantPopup?: boolean; -}; - -/** - * This API provides access to OAuth 2 credentials. It lets you request access tokens, - * which can be used to act on behalf of the user when talking to APIs. - * - * @public - */ -export type OAuthApi = { - /** - * Requests an OAuth 2 Access Token, optionally with a set of scopes. The access token allows - * you to make requests on behalf of the user, and the copes may grant you broader access, depending - * on the auth provider. - * - * Each auth provider has separate handling of scope, so you need to look at the documentation - * for each one to know what scope you need to request. - * - * This method is cheap and should be called each time an access token is used. Do not for example - * store the access token in React component state, as that could cause the token to expire. Instead - * fetch a new access token for each request. - * - * Be sure to include all required scopes when requesting an access token. When testing your implementation - * it is best to log out the Backstage session and then visit your plugin page directly, as - * you might already have some required scopes in your existing session. Not requesting the correct - * scopes can lead to 403 or other authorization errors, which can be tricky to debug. - * - * If the user has not yet granted access to the provider and the set of requested scopes, the user - * will be prompted to log in. The returned promise will not resolve until the user has - * successfully logged in. The returned promise can be rejected, but only if the user rejects the login request. - */ - getAccessToken( - scope?: OAuthScope, - options?: AuthRequestOptions, - ): Promise; -}; - -/** - * This API provides access to OpenID Connect credentials. It lets you request ID tokens, - * which can be passed to backend services to prove the user's identity. - * - * @public - */ -export type OpenIdConnectApi = { - /** - * Requests an OpenID Connect ID Token. - * - * This method is cheap and should be called each time an ID token is used. Do not for example - * store the id token in React component state, as that could cause the token to expire. Instead - * fetch a new id token for each request. - * - * If the user has not yet logged in to Google inside Backstage, the user will be prompted - * to log in. The returned promise will not resolve until the user has successfully logged in. - * The returned promise can be rejected, but only if the user rejects the login request. - */ - getIdToken(options?: AuthRequestOptions): Promise; -}; - -/** - * This API provides access to profile information of the user from an auth provider. - * - * @public - */ -export type ProfileInfoApi = { - /** - * Get profile information for the user as supplied by this auth provider. - * - * If the optional flag is not set, a session is guaranteed to be returned, while if - * the optional flag is set, the session may be undefined. See {@link AuthRequestOptions} for more details. - */ - getProfile(options?: AuthRequestOptions): Promise; -}; - -/** - * This API provides access to the user's identity within Backstage. - * - * @remarks - * - * An auth provider that implements this interface can be used to sign-in to backstage. It is - * not intended to be used directly from a plugin, but instead serves as a connection between - * this authentication method and the app's {@link IdentityApi} - * - * @public - */ -export type BackstageIdentityApi = { - /** - * Get the user's identity within Backstage. This should normally not be called directly, - * use the {@link IdentityApi} instead. - * - * If the optional flag is not set, a session is guaranteed to be returned, while if - * the optional flag is set, the session may be undefined. See {@link AuthRequestOptions} for more details. - */ - getBackstageIdentity( - options?: AuthRequestOptions, - ): Promise; -}; - -/** - * User identity information within Backstage. - * - * @public - */ -export type BackstageUserIdentity = { - /** - * The type of identity that this structure represents. In the frontend app - * this will currently always be 'user'. - */ - type: 'user'; - - /** - * The entityRef of the user in the catalog. - * For example User:default/sandra - */ - userEntityRef: string; - - /** - * The user and group entities that the user claims ownership through - */ - ownershipEntityRefs: string[]; -}; - -/** - * Token and Identity response, with the users claims in the Identity. - * - * @public - */ -export type BackstageIdentityResponse = { - /** - * The token used to authenticate the user within Backstage. - */ - token: string; - - /** - * The time at which the token expires. If not set, it can be assumed that the token does not expire. - */ - expiresAt?: Date; - - /** - * Identity information derived from the token. - */ - identity: BackstageUserIdentity; -}; - -/** - * Profile information of the user. - * - * @public - */ -export type ProfileInfo = { - /** - * Email ID. - */ - email?: string; - - /** - * Display name that can be presented to the user. - */ - displayName?: string; - - /** - * URL to an avatar image of the user. - */ - picture?: string; -}; - -/** - * Session state values passed to subscribers of the SessionApi. - * - * @public - */ -export enum SessionState { - /** - * User signed in. - */ - SignedIn = 'SignedIn', - /** - * User not signed in. - */ - SignedOut = 'SignedOut', -} - -/** - * The SessionApi provides basic controls for any auth provider that is tied to a persistent session. - * - * @public - */ -export type SessionApi = { - /** - * Sign in with a minimum set of permissions. - */ - signIn(): Promise; - - /** - * Sign out from the current session. This will reload the page. - */ - signOut(): Promise; - - /** - * Observe the current state of the auth session. Emits the current state on subscription. - */ - sessionState$(): Observable; -}; - -/** - * Provides authentication towards Google APIs and identities. - * - * @public - * @remarks - * - * See {@link https://developers.google.com/identity/protocols/googlescopes} for a full list of supported scopes. - * - * Note that the ID token payload is only guaranteed to contain the user's numerical Google ID, - * email and expiration information. Do not rely on any other fields, as they might not be present. - */ -export const googleAuthApiRef: ApiRef< - OAuthApi & - OpenIdConnectApi & - ProfileInfoApi & - BackstageIdentityApi & - SessionApi -> = createApiRef({ - id: 'core.auth.google', -}); - -/** - * Provides authentication towards GitHub APIs. - * - * @public - * @remarks - * - * See {@link https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/} - * for a full list of supported scopes. - */ -export const githubAuthApiRef: ApiRef< - OAuthApi & ProfileInfoApi & BackstageIdentityApi & SessionApi -> = createApiRef({ - id: 'core.auth.github', -}); - -/** - * Provides authentication towards Okta APIs. - * - * @public - * @remarks - * - * See {@link https://developer.okta.com/docs/guides/implement-oauth-for-okta/scopes/} - * for a full list of supported scopes. - */ -export const oktaAuthApiRef: ApiRef< - OAuthApi & - OpenIdConnectApi & - ProfileInfoApi & - BackstageIdentityApi & - SessionApi -> = createApiRef({ - id: 'core.auth.okta', -}); - -/** - * Provides authentication towards GitLab APIs. - * - * @public - * @remarks - * - * See {@link https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#limiting-scopes-of-a-personal-access-token} - * for a full list of supported scopes. - */ -export const gitlabAuthApiRef: ApiRef< - OAuthApi & - OpenIdConnectApi & - ProfileInfoApi & - BackstageIdentityApi & - SessionApi -> = createApiRef({ - id: 'core.auth.gitlab', -}); - -/** - * Provides authentication towards Microsoft APIs and identities. - * - * @public - * @remarks - * - * For more info and a full list of supported scopes, see: - * - {@link https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent} - * - {@link https://docs.microsoft.com/en-us/graph/permissions-reference} - */ -export const microsoftAuthApiRef: ApiRef< - OAuthApi & - OpenIdConnectApi & - ProfileInfoApi & - BackstageIdentityApi & - SessionApi -> = createApiRef({ - id: 'core.auth.microsoft', -}); - -/** - * Provides authentication towards OneLogin APIs. - * - * @public - */ -export const oneloginAuthApiRef: ApiRef< - OAuthApi & - OpenIdConnectApi & - ProfileInfoApi & - BackstageIdentityApi & - SessionApi -> = createApiRef({ - id: 'core.auth.onelogin', -}); - -/** - * Provides authentication towards Bitbucket APIs. - * - * @public - * @remarks - * - * See {@link https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/} - * for a full list of supported scopes. - */ -export const bitbucketAuthApiRef: ApiRef< - OAuthApi & ProfileInfoApi & BackstageIdentityApi & SessionApi -> = createApiRef({ - id: 'core.auth.bitbucket', -}); - -/** - * Provides authentication towards Bitbucket Server APIs. - * - * @public - * @remarks - * - * See {@link https://confluence.atlassian.com/bitbucketserver/bitbucket-oauth-2-0-provider-api-1108483661.html#BitbucketOAuth2.0providerAPI-scopes} - * for a full list of supported scopes. - */ -export const bitbucketServerAuthApiRef: ApiRef< - OAuthApi & ProfileInfoApi & BackstageIdentityApi & SessionApi -> = createApiRef({ - id: 'core.auth.bitbucket-server', -}); - -/** - * Provides authentication towards Atlassian APIs. - * - * @public - * @remarks - * - * See {@link https://developer.atlassian.com/cloud/jira/platform/scopes-for-connect-and-oauth-2-3LO-apps/} - * for a full list of supported scopes. - */ -export const atlassianAuthApiRef: ApiRef< - OAuthApi & ProfileInfoApi & BackstageIdentityApi & SessionApi -> = createApiRef({ - id: 'core.auth.atlassian', -}); diff --git a/packages/frontend-plugin-api/src/index.ts b/packages/frontend-plugin-api/src/index.ts index f3656a0dc3..3248e79945 100644 --- a/packages/frontend-plugin-api/src/index.ts +++ b/packages/frontend-plugin-api/src/index.ts @@ -22,10 +22,9 @@ export * from './apis'; export * from './components'; -export * from './definitions'; export * from './extensions'; export * from './icons'; export * from './routing'; export * from './schema'; -export * from './system'; +export * from './apis/system'; export * from './wiring';