From 63f7d4d6cd79d38b45a32bda3e6f10b6727ab9e4 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 11 Mar 2021 11:09:47 +0100 Subject: [PATCH] app-api: remove api definitions and import them from plugin-api instead Co-authored-by: Juan Lulkin Signed-off-by: Patrik Oldsberg --- .../app-api/src/apis/definitions/AlertApi.ts | 44 --- .../src/apis/definitions/AppThemeApi.ts | 83 ----- .../app-api/src/apis/definitions/ConfigApi.ts | 28 -- .../src/apis/definitions/DiscoveryApi.ts | 47 --- .../app-api/src/apis/definitions/ErrorApi.ts | 68 ---- .../src/apis/definitions/FeatureFlagsApi.ts | 86 ----- .../src/apis/definitions/IdentityApi.ts | 56 --- .../src/apis/definitions/OAuthRequestApi.ts | 133 ------- .../src/apis/definitions/StorageApi.ts | 71 ---- packages/app-api/src/apis/definitions/auth.ts | 347 ------------------ .../app-api/src/apis/definitions/index.ts | 33 -- .../AlertApi/AlertApiForwarder.ts | 2 +- .../AppThemeApi/AppThemeSelector.test.ts | 2 +- .../AppThemeApi/AppThemeSelector.ts | 2 +- .../DiscoveryApi/UrlPatternDiscovery.ts | 2 +- .../implementations/ErrorApi/ErrorAlerter.ts | 2 +- .../ErrorApi/ErrorApiForwarder.ts | 2 +- .../LocalStorageFeatureFlags.test.tsx | 2 +- .../LocalStorageFeatureFlags.tsx | 2 +- .../OAuthRequestApi/MockOAuthApi.ts | 2 +- .../OAuthRequestApi/OAuthRequestManager.ts | 2 +- .../StorageApi/WebStorage.test.ts | 4 +- .../implementations/StorageApi/WebStorage.ts | 8 +- .../implementations/auth/auth0/Auth0Auth.ts | 2 +- .../implementations/auth/github/GithubAuth.ts | 2 +- .../apis/implementations/auth/github/types.ts | 3 +- .../implementations/auth/gitlab/GitlabAuth.ts | 2 +- .../implementations/auth/google/GoogleAuth.ts | 2 +- .../auth/microsoft/MicrosoftAuth.ts | 2 +- .../implementations/auth/oauth2/OAuth2.ts | 2 +- .../apis/implementations/auth/oauth2/types.ts | 2 +- .../implementations/auth/okta/OktaAuth.ts | 2 +- .../auth/onelogin/OneLoginAuth.ts | 4 +- .../implementations/auth/saml/SamlAuth.ts | 2 +- .../apis/implementations/auth/saml/types.ts | 2 +- .../src/apis/implementations/auth/types.ts | 6 +- packages/app-api/src/apis/index.ts | 1 - packages/app-api/src/app/App.tsx | 10 +- packages/app-api/src/app/AppIdentity.ts | 2 +- packages/app-api/src/app/AppThemeProvider.tsx | 2 +- packages/app-api/src/app/defaultApis.ts | 23 +- packages/app-api/src/app/types.ts | 3 +- packages/app-api/src/index.test.ts | 10 +- .../lib/AuthConnector/DefaultAuthConnector.ts | 4 +- .../lib/AuthConnector/DirectAuthConnector.ts | 2 +- .../RefreshingAuthSessionManager.test.ts | 2 +- .../AuthSessionManager/SessionStateTracker.ts | 2 +- .../src/lib/AuthSessionManager/types.ts | 2 +- 48 files changed, 66 insertions(+), 1058 deletions(-) delete mode 100644 packages/app-api/src/apis/definitions/AlertApi.ts delete mode 100644 packages/app-api/src/apis/definitions/AppThemeApi.ts delete mode 100644 packages/app-api/src/apis/definitions/ConfigApi.ts delete mode 100644 packages/app-api/src/apis/definitions/DiscoveryApi.ts delete mode 100644 packages/app-api/src/apis/definitions/ErrorApi.ts delete mode 100644 packages/app-api/src/apis/definitions/FeatureFlagsApi.ts delete mode 100644 packages/app-api/src/apis/definitions/IdentityApi.ts delete mode 100644 packages/app-api/src/apis/definitions/OAuthRequestApi.ts delete mode 100644 packages/app-api/src/apis/definitions/StorageApi.ts delete mode 100644 packages/app-api/src/apis/definitions/auth.ts delete mode 100644 packages/app-api/src/apis/definitions/index.ts diff --git a/packages/app-api/src/apis/definitions/AlertApi.ts b/packages/app-api/src/apis/definitions/AlertApi.ts deleted file mode 100644 index 91641ac35b..0000000000 --- a/packages/app-api/src/apis/definitions/AlertApi.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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 '../../types'; - -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'; -}; - -/** - * The alert API is used to report alerts to the app, and display them to the user. - */ - -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; -}; - -export const alertApiRef: ApiRef = createApiRef({ - id: 'core.alert', - description: 'Used to report alerts and forward them to the app', -}); diff --git a/packages/app-api/src/apis/definitions/AppThemeApi.ts b/packages/app-api/src/apis/definitions/AppThemeApi.ts deleted file mode 100644 index 515e8df082..0000000000 --- a/packages/app-api/src/apis/definitions/AppThemeApi.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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 { BackstageTheme } from '@backstage/theme'; -import { Observable } from '../../types'; -import { SvgIconProps } from '@material-ui/core'; - -/** - * Describes a theme provided by the app. - */ -export type AppTheme = { - /** - * ID used to remember theme selections. - */ - id: string; - - /** - * Title of the theme - */ - title: string; - - /** - * Theme variant - */ - variant: 'light' | 'dark'; - - /** - * The specialized MaterialUI theme instance. - */ - theme: BackstageTheme; - - /** - * An Icon for the theme mode setting. - */ - icon?: React.ReactElement; -}; - -/** - * 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. - */ -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; -}; - -export const appThemeApiRef: ApiRef = createApiRef({ - id: 'core.apptheme', - description: 'API Used to configure the app theme, and enumerate options', -}); diff --git a/packages/app-api/src/apis/definitions/ConfigApi.ts b/packages/app-api/src/apis/definitions/ConfigApi.ts deleted file mode 100644 index 459a361cf7..0000000000 --- a/packages/app-api/src/apis/definitions/ConfigApi.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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 { Config } from '@backstage/config'; - -/** - * The Config API is used to provide a mechanism to access the - * runtime configuration of the system. - */ -export type ConfigApi = Config; - -export const configApiRef: ApiRef = createApiRef({ - id: 'core.config', - description: 'Used to access runtime configuration', -}); diff --git a/packages/app-api/src/apis/definitions/DiscoveryApi.ts b/packages/app-api/src/apis/definitions/DiscoveryApi.ts deleted file mode 100644 index f62a97b61a..0000000000 --- a/packages/app-api/src/apis/definitions/DiscoveryApi.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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'; - -/** - * The discovery API is used to provide a mechanism for plugins to - * discover the endpoint to use to talk to their backend counterpart. - * - * The purpose of the discovery API is to allow for many different deployment - * setups and routing methods through a central configuration, instead - * of letting each individual plugin manage that configuration. - * - * Implementations of the discovery API can be a simple as a URL pattern - * using the pluginId, but could also have overrides for individual plugins, - * or query a separate discovery service. - */ -export type DiscoveryApi = { - /** - * Returns the HTTP base backend URL for a given plugin, without a trailing slash. - * - * This method must always be called just before making a request, as opposed to - * fetching the URL when constructing an API client. That is to ensure that more - * flexible routing patterns can be supported. - * - * For example, asking for the URL for `auth` may return something - * like `https://backstage.example.com/api/auth` - */ - getBaseUrl(pluginId: string): Promise; -}; - -export const discoveryApiRef: ApiRef = createApiRef({ - id: 'core.discovery', - description: 'Provides service discovery of backend plugins', -}); diff --git a/packages/app-api/src/apis/definitions/ErrorApi.ts b/packages/app-api/src/apis/definitions/ErrorApi.ts deleted file mode 100644 index 6205f8e058..0000000000 --- a/packages/app-api/src/apis/definitions/ErrorApi.ts +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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 { Observable } from '../../types'; - -/** - * Mirrors the JavaScript Error class, for the purpose of - * providing documentation and optional fields. - */ -type Error = { - name: string; - message: string; - stack?: string; -}; - -/** - * Provides additional information about an error that was posted to the application. - */ -export type ErrorContext = { - // If set to true, this error should not be displayed to the user. Defaults to false. - hidden?: boolean; -}; - -/** - * The error API is used to report errors to the app, and display them to the user. - * - * Plugins can use this API as a method of displaying errors to the user, but also - * to report errors for collection by error reporting services. - * - * If an error can be displayed inline, e.g. as feedback in a form, that should be - * preferred over relying on this API to display the error. The main use of this API - * for displaying errors should be for asynchronous errors, such as a failing background process. - * - * Even if an error is displayed inline, it should still be reported through this API - * if it would be useful to collect or log it for debugging purposes, but with - * the hidden flag set. For example, an error arising from form field validation - * should probably not be reported, while a failed REST call would be useful to report. - */ -export type ErrorApi = { - /** - * Post an error for handling by the application. - */ - post(error: Error, context?: ErrorContext): void; - - /** - * Observe errors posted by other parts of the application. - */ - error$(): Observable<{ error: Error; context?: ErrorContext }>; -}; - -export const errorApiRef: ApiRef = createApiRef({ - id: 'core.error', - description: 'Used to report errors and forward them to the app', -}); diff --git a/packages/app-api/src/apis/definitions/FeatureFlagsApi.ts b/packages/app-api/src/apis/definitions/FeatureFlagsApi.ts deleted file mode 100644 index 243af562b1..0000000000 --- a/packages/app-api/src/apis/definitions/FeatureFlagsApi.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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'; - -/** - * The feature flags API is used to toggle functionality to users across plugins and Backstage. - * - * Plugins can use this API to register feature flags that they have available - * for users to enable/disable, and this API will centralize the current user's - * state of which feature flags they would like to enable. - * - * This is ideal for Backstage plugins, as well as your own App, to trial incomplete - * or unstable upcoming features. Although there will be a common interface for users - * to enable and disable feature flags, this API acts as another way to enable/disable. - */ - -export type FeatureFlag = { - name: string; - pluginId: string; -}; - -export enum FeatureFlagState { - None = 0, - Active = 1, -} - -/** - * Options to use when saving feature flags. - */ -export type FeatureFlagsSaveOptions = { - /** - * The new feature flag states to save. - */ - states: Record; - - /** - * Whether the saves states should be merged into the existing ones, or replace them. - * - * Defaults to false. - */ - merge?: boolean; -}; - -export type UserFlags = {}; - -export interface FeatureFlagsApi { - /** - * Registers a new feature flag. Once a feature flag has been registered it - * can be toggled by users, and read back to enable or disable features. - */ - registerFlag(flag: FeatureFlag): void; - - /** - * Get a list of all registered flags. - */ - getRegisteredFlags(): FeatureFlag[]; - - /** - * Whether the feature flag with the given name is currently activated for the user. - */ - isActive(name: string): boolean; - - /** - * Save the user's choice of feature flag states. - */ - save(options: FeatureFlagsSaveOptions): void; -} - -export const featureFlagsApiRef: ApiRef = createApiRef({ - id: 'core.featureflags', - description: 'Used to toggle functionality in features across Backstage', -}); diff --git a/packages/app-api/src/apis/definitions/IdentityApi.ts b/packages/app-api/src/apis/definitions/IdentityApi.ts deleted file mode 100644 index 2d29709b02..0000000000 --- a/packages/app-api/src/apis/definitions/IdentityApi.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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 { ProfileInfo } from './auth'; - -/** - * The Identity API used to identify and get information about the signed in user. - */ -export type IdentityApi = { - /** - * The ID of the signed in user. This ID is not meant to be presented to the user, but used - * as an opaque string to pass on to backends or use in frontend logic. - * - * TODO: The intention of the user ID is to be able to tie the user to an identity - * that is known by the catalog and/or identity backend. It should for example - * be possible to fetch all owned components using this ID. - */ - getUserId(): string; - - // TODO: getProfile(): Promise - We want this to be async when added, but needs more work. - /** - * The profile of the signed in user. - */ - getProfile(): ProfileInfo; - - /** - * An OpenID Connect ID Token which proves the identity of the signed in user. - * - * The ID token will be undefined if the signed in user does not have a verified - * identity, such as a demo user or mocked user for e2e tests. - */ - getIdToken(): Promise; - - /** - * Sign out the current user - */ - signOut(): Promise; -}; - -export const identityApiRef: ApiRef = createApiRef({ - id: 'core.identity', - description: 'Provides access to the identity of the signed in user', -}); diff --git a/packages/app-api/src/apis/definitions/OAuthRequestApi.ts b/packages/app-api/src/apis/definitions/OAuthRequestApi.ts deleted file mode 100644 index 316a9be778..0000000000 --- a/packages/app-api/src/apis/definitions/OAuthRequestApi.ts +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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 { IconComponent } from '@backstage/plugin-api'; -import { Observable } from '../../types'; -import { ApiRef, createApiRef } from '../system'; - -/** - * Information about the auth provider that we're requesting a login towards. - * - * This should be shown to the user so that they can be informed about what login is being requested - * before a popup is shown. - */ -export type AuthProvider = { - /** - * Title for the auth provider, for example "GitHub" - */ - title: string; - - /** - * Icon for the auth provider. - */ - icon: IconComponent; -}; - -/** - * Describes how to handle auth requests. Both how to show them to the user, and what to do when - * the user accesses the auth request. - */ -export type AuthRequesterOptions = { - /** - * Information about the auth provider, which will be forwarded to auth requests. - */ - provider: AuthProvider; - - /** - * Implementation of the auth flow, which will be called synchronously when - * trigger() is called on an auth requests. - */ - onAuthRequest(scopes: Set): Promise; -}; - -/** - * Function used to trigger new auth requests for a set of scopes. - * - * The returned promise will resolve to the same value returned by the onAuthRequest in the - * AuthRequesterOptions. Or rejected, if the request is rejected. - * - * This function can be called multiple times before the promise resolves. All calls - * will be merged into one request, and the scopes forwarded to the onAuthRequest will be the - * union of all requested scopes. - */ -export type AuthRequester = ( - scopes: Set, -) => Promise; - -/** - * An pending auth request for a single auth provider. The request will remain in this pending - * state until either reject() or trigger() is called. - * - * Any new requests for the same provider are merged into the existing pending request, meaning - * there will only ever be a single pending request for a given provider. - */ -export type PendingAuthRequest = { - /** - * Information about the auth provider, as given in the AuthRequesterOptions - */ - provider: AuthProvider; - - /** - * Rejects the request, causing all pending AuthRequester calls to fail with "RejectedError". - */ - reject: () => void; - - /** - * Trigger the auth request to continue the auth flow, by for example showing a popup. - * - * Synchronously calls onAuthRequest with all scope currently in the request. - */ - trigger(): Promise; -}; - -/** - * Provides helpers for implemented OAuth login flows within Backstage. - */ -export type OAuthRequestApi = { - /** - * A utility for showing login popups or similar things, and merging together multiple requests for - * different scopes into one request that includes all scopes. - * - * The passed in options provide information about the login provider, and how to handle auth requests. - * - * The returned AuthRequester function is used to request login with new scopes. These requests - * are merged together and forwarded to the auth handler, as soon as a consumer of auth requests - * triggers an auth flow. - * - * See AuthRequesterOptions, AuthRequester, and handleAuthRequests for more info. - */ - createAuthRequester( - options: AuthRequesterOptions, - ): AuthRequester; - - /** - * Observers pending auth requests. The returned observable will emit all - * current active auth request, at most one for each created auth requester. - * - * Each request has its own info about the login provider, forwarded from the auth requester options. - * - * Depending on user interaction, the request should either be rejected, or used to trigger the auth handler. - * If the request is rejected, all pending AuthRequester calls will fail with a "RejectedError". - * If a auth is triggered, and the auth handler resolves successfully, then all currently pending - * AuthRequester calls will resolve to the value returned by the onAuthRequest call. - */ - authRequest$(): Observable; -}; - -export const oauthRequestApiRef: ApiRef = createApiRef({ - id: 'core.oauthrequest', - description: 'An API for implementing unified OAuth flows in Backstage', -}); diff --git a/packages/app-api/src/apis/definitions/StorageApi.ts b/packages/app-api/src/apis/definitions/StorageApi.ts deleted file mode 100644 index 2482af6d63..0000000000 --- a/packages/app-api/src/apis/definitions/StorageApi.ts +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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 { Observable } from '../../types'; -import { ErrorApi } from './ErrorApi'; - -export type StorageValueChange = { - key: string; - newValue?: T; -}; - -export type CreateStorageApiOptions = { - errorApi: ErrorApi; - namespace?: string; -}; - -export interface StorageApi { - /** - * Create a bucket to store data in. - * @param {String} name Namespace for the storage to be stored under, - * will inherit previous namespaces too - */ - forBucket(name: string): StorageApi; - - /** - * Get the current value for persistent data, use observe$ to be notified of updates. - * - * @param {String} key Unique key associated with the data. - * @return {Object} data The data that should is stored. - */ - get(key: string): T | undefined; - - /** - * Remove persistent data. - * - * @param {String} key Unique key associated with the data. - */ - remove(key: string): Promise; - - /** - * Save persistent data, and emit messages to anyone that is using observe$ for this key - * - * @param {String} key Unique key associated with the data. - */ - set(key: string, data: any): Promise; - - /** - * Observe changes on a particular key in the bucket - * @param {String} key Unique key associated with the data - */ - observe$(key: string): Observable>; -} - -export const storageApiRef: ApiRef = createApiRef({ - id: 'core.storage', - description: 'Provides the ability to store data which is unique to the user', -}); diff --git a/packages/app-api/src/apis/definitions/auth.ts b/packages/app-api/src/apis/definitions/auth.ts deleted file mode 100644 index 30b07887ad..0000000000 --- a/packages/app-api/src/apis/definitions/auth.ts +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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 { Observable } from '../../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({ ... }) - */ - -/** - * An array of scopes, or a scope string formatted according to the - * auth provider, which is typically a space separated list. - * - * See the documentation for each auth provider for the list of scopes - * supported by each provider. - */ -export type OAuthScope = string | string[]; - -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. - * - * @default 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. - * - * @default 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. - */ -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. - */ -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. - */ -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 @AuthRequestOptions for more details. - */ - getProfile(options?: AuthRequestOptions): Promise; -}; - -/** - * This API provides access to the user's identity within Backstage. - * - * 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 @IdentityApi - */ -export type BackstageIdentityApi = { - /** - * Get the user's identity within Backstage. This should normally not be called directly, - * use the @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 @AuthRequestOptions for more details. - */ - getBackstageIdentity( - options?: AuthRequestOptions, - ): Promise; -}; - -export type BackstageIdentity = { - /** - * The backstage user ID. - */ - id: string; - - /** - * An ID token that can be used to authenticate the user within Backstage. - */ - idToken: string; -}; - -/** - * Profile information of the user. - */ -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. - */ -export enum SessionState { - SignedIn = 'SignedIn', - SignedOut = 'SignedOut', -} - -/** - * The SessionApi provides basic controls for any auth provider that is tied to a persistent session. - */ -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. - * - * See 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', - description: 'Provides authentication towards Google APIs and identities', -}); - -/** - * Provides authentication towards GitHub APIs. - * - * See 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', - description: 'Provides authentication towards GitHub APIs', -}); - -/** - * Provides authentication towards Okta APIs. - * - * See 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', - description: 'Provides authentication towards Okta APIs', -}); - -/** - * Provides authentication towards GitLab APIs. - * - * See 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 & ProfileInfoApi & BackstageIdentityApi & SessionApi -> = createApiRef({ - id: 'core.auth.gitlab', - description: 'Provides authentication towards GitLab APIs', -}); - -/** - * Provides authentication towards Auth0 APIs. - * - * See https://auth0.com/docs/scopes/current/oidc-scopes - * for a full list of supported scopes. - */ -export const auth0AuthApiRef: ApiRef< - OpenIdConnectApi & ProfileInfoApi & BackstageIdentityApi & SessionApi -> = createApiRef({ - id: 'core.auth.auth0', - description: 'Provides authentication towards Auth0 APIs', -}); - -/** - * Provides authentication towards Microsoft APIs and identities. - * - * For more info and a full list of supported scopes, see: - * - https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent - * - https://docs.microsoft.com/en-us/graph/permissions-reference - */ -export const microsoftAuthApiRef: ApiRef< - OAuthApi & - OpenIdConnectApi & - ProfileInfoApi & - BackstageIdentityApi & - SessionApi -> = createApiRef({ - id: 'core.auth.microsoft', - description: 'Provides authentication towards Microsoft APIs and identities', -}); - -/** - * Provides authentication for custom identity providers. - */ -export const oauth2ApiRef: ApiRef< - OAuthApi & - OpenIdConnectApi & - ProfileInfoApi & - BackstageIdentityApi & - SessionApi -> = createApiRef({ - id: 'core.auth.oauth2', - description: 'Example of how to use oauth2 custom provider', -}); - -/** - * Provides authentication for custom OpenID Connect identity providers. - */ -export const oidcAuthApiRef: ApiRef< - OAuthApi & - OpenIdConnectApi & - ProfileInfoApi & - BackstageIdentityApi & - SessionApi -> = createApiRef({ - id: 'core.auth.oidc', - description: 'Example of how to use oidc custom provider', -}); - -/** - * Provides authentication for saml based identity providers - */ -export const samlAuthApiRef: ApiRef< - ProfileInfoApi & BackstageIdentityApi & SessionApi -> = createApiRef({ - id: 'core.auth.saml', - description: 'Example of how to use SAML custom provider', -}); - -export const oneloginAuthApiRef: ApiRef< - OAuthApi & - OpenIdConnectApi & - ProfileInfoApi & - BackstageIdentityApi & - SessionApi -> = createApiRef({ - id: 'core.auth.onelogin', - description: 'Provides authentication towards OneLogin APIs and identities', -}); diff --git a/packages/app-api/src/apis/definitions/index.ts b/packages/app-api/src/apis/definitions/index.ts deleted file mode 100644 index e29d1022c4..0000000000 --- a/packages/app-api/src/apis/definitions/index.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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. - */ - -// 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 './IdentityApi'; -export * from './OAuthRequestApi'; -export * from './StorageApi'; diff --git a/packages/app-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts b/packages/app-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts index 91a606059d..322afe71c5 100644 --- a/packages/app-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts +++ b/packages/app-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { AlertApi, AlertMessage } from '../..'; +import { AlertApi, AlertMessage } from '@backstage/plugin-api'; import { PublishSubject } from '../../../lib'; import { Observable } from '../../../types'; diff --git a/packages/app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.test.ts b/packages/app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.test.ts index 0c23fe5219..80789ff7a6 100644 --- a/packages/app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.test.ts +++ b/packages/app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { AppTheme } from '../../definitions'; +import { AppTheme } from '@backstage/plugin-api'; import { AppThemeSelector } from './AppThemeSelector'; describe('AppThemeSelector', () => { diff --git a/packages/app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts b/packages/app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts index 43b52a254b..eb00382601 100644 --- a/packages/app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts +++ b/packages/app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { AppThemeApi, AppTheme } from '../../definitions'; +import { AppThemeApi, AppTheme } from '@backstage/plugin-api'; import { BehaviorSubject } from '../../../lib'; import { Observable } from '../../../types'; diff --git a/packages/app-api/src/apis/implementations/DiscoveryApi/UrlPatternDiscovery.ts b/packages/app-api/src/apis/implementations/DiscoveryApi/UrlPatternDiscovery.ts index ca48784584..db9cbfccd5 100644 --- a/packages/app-api/src/apis/implementations/DiscoveryApi/UrlPatternDiscovery.ts +++ b/packages/app-api/src/apis/implementations/DiscoveryApi/UrlPatternDiscovery.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { DiscoveryApi } from '../../definitions/DiscoveryApi'; +import { DiscoveryApi } from '@backstage/plugin-api'; /** * UrlPatternDiscovery is a lightweight DiscoveryApi implementation. diff --git a/packages/app-api/src/apis/implementations/ErrorApi/ErrorAlerter.ts b/packages/app-api/src/apis/implementations/ErrorApi/ErrorAlerter.ts index 162b28f334..5bbf6e123a 100644 --- a/packages/app-api/src/apis/implementations/ErrorApi/ErrorAlerter.ts +++ b/packages/app-api/src/apis/implementations/ErrorApi/ErrorAlerter.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ErrorApi, ErrorContext, AlertApi } from '../..'; +import { ErrorApi, ErrorContext, AlertApi } from '@backstage/plugin-api'; /** * Decorates an ErrorApi by also forwarding error messages diff --git a/packages/app-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts b/packages/app-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts index 2ebf9db7a8..a9841bb660 100644 --- a/packages/app-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts +++ b/packages/app-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ErrorApi, ErrorContext } from '../..'; +import { ErrorApi, ErrorContext } from '@backstage/plugin-api'; import { PublishSubject } from '../../../lib'; import { Observable } from '../../../types'; diff --git a/packages/app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.test.tsx b/packages/app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.test.tsx index 2902e399c9..590a3b5ce2 100644 --- a/packages/app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.test.tsx +++ b/packages/app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.test.tsx @@ -15,7 +15,7 @@ */ import { LocalStorageFeatureFlags } from './LocalStorageFeatureFlags'; -import { FeatureFlagState, FeatureFlagsApi } from '../../definitions'; +import { FeatureFlagState, FeatureFlagsApi } from '@backstage/plugin-api'; describe('FeatureFlags', () => { beforeEach(() => { diff --git a/packages/app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.tsx b/packages/app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.tsx index 00b3eff906..582e85bed9 100644 --- a/packages/app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.tsx +++ b/packages/app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.tsx @@ -19,7 +19,7 @@ import { FeatureFlagsApi, FeatureFlag, FeatureFlagsSaveOptions, -} from '../../definitions'; +} from '@backstage/plugin-api'; export function validateFlagName(name: string): void { if (name.length < 3) { diff --git a/packages/app-api/src/apis/implementations/OAuthRequestApi/MockOAuthApi.ts b/packages/app-api/src/apis/implementations/OAuthRequestApi/MockOAuthApi.ts index 523f713f45..ff440ffd51 100644 --- a/packages/app-api/src/apis/implementations/OAuthRequestApi/MockOAuthApi.ts +++ b/packages/app-api/src/apis/implementations/OAuthRequestApi/MockOAuthApi.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { OAuthRequestApi, AuthRequesterOptions } from '../../definitions'; +import { OAuthRequestApi, AuthRequesterOptions } from '@backstage/plugin-api'; import { OAuthRequestManager } from './OAuthRequestManager'; export default class MockOAuthApi implements OAuthRequestApi { diff --git a/packages/app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts b/packages/app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts index 23e9e1ddc4..d643b1d060 100644 --- a/packages/app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts +++ b/packages/app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts @@ -19,7 +19,7 @@ import { PendingAuthRequest, AuthRequester, AuthRequesterOptions, -} from '../../definitions'; +} from '@backstage/plugin-api'; import { OAuthPendingRequests, PendingRequest } from './OAuthPendingRequests'; import { BehaviorSubject } from '../../../lib'; import { Observable } from '../../../types'; diff --git a/packages/app-api/src/apis/implementations/StorageApi/WebStorage.test.ts b/packages/app-api/src/apis/implementations/StorageApi/WebStorage.test.ts index 81140ffcc9..73257fd746 100644 --- a/packages/app-api/src/apis/implementations/StorageApi/WebStorage.test.ts +++ b/packages/app-api/src/apis/implementations/StorageApi/WebStorage.test.ts @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { WebStorage } from './WebStorage'; -import { CreateStorageApiOptions, StorageApi } from '../../definitions'; +import { CreateStorageApiOptions, WebStorage } from './WebStorage'; +import { StorageApi } from '@backstage/plugin-api'; describe('WebStorage Storage API', () => { const mockErrorApi = { post: jest.fn(), error$: jest.fn() }; diff --git a/packages/app-api/src/apis/implementations/StorageApi/WebStorage.ts b/packages/app-api/src/apis/implementations/StorageApi/WebStorage.ts index b9b01cd20b..d9bea8d5ee 100644 --- a/packages/app-api/src/apis/implementations/StorageApi/WebStorage.ts +++ b/packages/app-api/src/apis/implementations/StorageApi/WebStorage.ts @@ -17,13 +17,17 @@ import { StorageApi, StorageValueChange, ErrorApi, - CreateStorageApiOptions, -} from '../../definitions'; +} from '@backstage/plugin-api'; import { Observable } from '../../../types'; import ObservableImpl from 'zen-observable'; const buckets = new Map(); +export type CreateStorageApiOptions = { + errorApi: ErrorApi; + namespace?: string; +}; + export class WebStorage implements StorageApi { constructor( private readonly namespace: string, diff --git a/packages/app-api/src/apis/implementations/auth/auth0/Auth0Auth.ts b/packages/app-api/src/apis/implementations/auth/auth0/Auth0Auth.ts index b41e705726..bfb244caee 100644 --- a/packages/app-api/src/apis/implementations/auth/auth0/Auth0Auth.ts +++ b/packages/app-api/src/apis/implementations/auth/auth0/Auth0Auth.ts @@ -15,7 +15,7 @@ */ import Auth0Icon from '@material-ui/icons/AcUnit'; -import { auth0AuthApiRef } from '../../../definitions/auth'; +import { auth0AuthApiRef } from '@backstage/plugin-api'; import { OAuth2 } from '../oauth2'; import { OAuthApiCreateOptions } from '../types'; diff --git a/packages/app-api/src/apis/implementations/auth/github/GithubAuth.ts b/packages/app-api/src/apis/implementations/auth/github/GithubAuth.ts index a7c945a907..810cd7dc44 100644 --- a/packages/app-api/src/apis/implementations/auth/github/GithubAuth.ts +++ b/packages/app-api/src/apis/implementations/auth/github/GithubAuth.ts @@ -24,7 +24,7 @@ import { ProfileInfo, BackstageIdentity, AuthRequestOptions, -} from '../../../definitions/auth'; +} from '@backstage/plugin-api'; import { SessionManager } from '../../../../lib/AuthSessionManager/types'; import { AuthSessionStore, diff --git a/packages/app-api/src/apis/implementations/auth/github/types.ts b/packages/app-api/src/apis/implementations/auth/github/types.ts index 54c427423c..1360f01100 100644 --- a/packages/app-api/src/apis/implementations/auth/github/types.ts +++ b/packages/app-api/src/apis/implementations/auth/github/types.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { ProfileInfo } from '../../..'; -import { BackstageIdentity } from '../../../definitions'; +import { ProfileInfo, BackstageIdentity } from '@backstage/plugin-api'; export type GithubSession = { providerInfo: { diff --git a/packages/app-api/src/apis/implementations/auth/gitlab/GitlabAuth.ts b/packages/app-api/src/apis/implementations/auth/gitlab/GitlabAuth.ts index 3f4bc814e3..72dadc5cb2 100644 --- a/packages/app-api/src/apis/implementations/auth/gitlab/GitlabAuth.ts +++ b/packages/app-api/src/apis/implementations/auth/gitlab/GitlabAuth.ts @@ -15,7 +15,7 @@ */ import GitlabIcon from '@material-ui/icons/AcUnit'; -import { gitlabAuthApiRef } from '../../../definitions/auth'; +import { gitlabAuthApiRef } from '@backstage/plugin-api'; import { OAuth2 } from '../oauth2'; import { OAuthApiCreateOptions } from '../types'; diff --git a/packages/app-api/src/apis/implementations/auth/google/GoogleAuth.ts b/packages/app-api/src/apis/implementations/auth/google/GoogleAuth.ts index fbc902cdd8..0d305cbe70 100644 --- a/packages/app-api/src/apis/implementations/auth/google/GoogleAuth.ts +++ b/packages/app-api/src/apis/implementations/auth/google/GoogleAuth.ts @@ -15,7 +15,7 @@ */ import GoogleIcon from '@material-ui/icons/AcUnit'; -import { googleAuthApiRef } from '../../../definitions/auth'; +import { googleAuthApiRef } from '@backstage/plugin-api'; import { OAuth2 } from '../oauth2'; import { OAuthApiCreateOptions } from '../types'; diff --git a/packages/app-api/src/apis/implementations/auth/microsoft/MicrosoftAuth.ts b/packages/app-api/src/apis/implementations/auth/microsoft/MicrosoftAuth.ts index 3e2711db3b..7851294e80 100644 --- a/packages/app-api/src/apis/implementations/auth/microsoft/MicrosoftAuth.ts +++ b/packages/app-api/src/apis/implementations/auth/microsoft/MicrosoftAuth.ts @@ -15,7 +15,7 @@ */ import MicrosoftIcon from '@material-ui/icons/AcUnit'; -import { microsoftAuthApiRef } from '../../../definitions/auth'; +import { microsoftAuthApiRef } from '@backstage/plugin-api'; import { OAuth2 } from '../oauth2'; import { OAuthApiCreateOptions } from '../types'; diff --git a/packages/app-api/src/apis/implementations/auth/oauth2/OAuth2.ts b/packages/app-api/src/apis/implementations/auth/oauth2/OAuth2.ts index 73ad3dcf14..68e31b3356 100644 --- a/packages/app-api/src/apis/implementations/auth/oauth2/OAuth2.ts +++ b/packages/app-api/src/apis/implementations/auth/oauth2/OAuth2.ts @@ -29,7 +29,7 @@ import { SessionState, SessionApi, BackstageIdentityApi, -} from '../../../definitions/auth'; +} from '@backstage/plugin-api'; import { OAuth2Session } from './types'; import { OAuthApiCreateOptions } from '../types'; diff --git a/packages/app-api/src/apis/implementations/auth/oauth2/types.ts b/packages/app-api/src/apis/implementations/auth/oauth2/types.ts index 0e9c6f124d..8ab6eaf1af 100644 --- a/packages/app-api/src/apis/implementations/auth/oauth2/types.ts +++ b/packages/app-api/src/apis/implementations/auth/oauth2/types.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ProfileInfo, BackstageIdentity } from '../../../definitions'; +import { ProfileInfo, BackstageIdentity } from '@backstage/plugin-api'; export type OAuth2Session = { providerInfo: { diff --git a/packages/app-api/src/apis/implementations/auth/okta/OktaAuth.ts b/packages/app-api/src/apis/implementations/auth/okta/OktaAuth.ts index 2df908e9fb..dba63c9b06 100644 --- a/packages/app-api/src/apis/implementations/auth/okta/OktaAuth.ts +++ b/packages/app-api/src/apis/implementations/auth/okta/OktaAuth.ts @@ -15,7 +15,7 @@ */ import OktaIcon from '@material-ui/icons/AcUnit'; -import { oktaAuthApiRef } from '../../../definitions/auth'; +import { oktaAuthApiRef } from '@backstage/plugin-api'; import { OAuth2 } from '../oauth2'; import { OAuthApiCreateOptions } from '../types'; diff --git a/packages/app-api/src/apis/implementations/auth/onelogin/OneLoginAuth.ts b/packages/app-api/src/apis/implementations/auth/onelogin/OneLoginAuth.ts index ff5c7c1990..f3ebb0a6f8 100644 --- a/packages/app-api/src/apis/implementations/auth/onelogin/OneLoginAuth.ts +++ b/packages/app-api/src/apis/implementations/auth/onelogin/OneLoginAuth.ts @@ -15,12 +15,12 @@ */ import OneLoginIcon from '@material-ui/icons/AcUnit'; -import { oneloginAuthApiRef } from '../../../definitions/auth'; import { + oneloginAuthApiRef, OAuthRequestApi, AuthProvider, DiscoveryApi, -} from '../../../definitions'; +} from '@backstage/plugin-api'; import { OAuth2 } from '../oauth2'; type CreateOptions = { diff --git a/packages/app-api/src/apis/implementations/auth/saml/SamlAuth.ts b/packages/app-api/src/apis/implementations/auth/saml/SamlAuth.ts index af97ad8f36..74c25200e9 100644 --- a/packages/app-api/src/apis/implementations/auth/saml/SamlAuth.ts +++ b/packages/app-api/src/apis/implementations/auth/saml/SamlAuth.ts @@ -26,7 +26,7 @@ import { ProfileInfoApi, BackstageIdentityApi, SessionApi, -} from '../../../definitions/auth'; +} from '@backstage/plugin-api'; import { SamlSession } from './types'; import { AuthSessionStore, diff --git a/packages/app-api/src/apis/implementations/auth/saml/types.ts b/packages/app-api/src/apis/implementations/auth/saml/types.ts index 296f70b0ea..49debe2e97 100644 --- a/packages/app-api/src/apis/implementations/auth/saml/types.ts +++ b/packages/app-api/src/apis/implementations/auth/saml/types.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ProfileInfo, BackstageIdentity } from '../../../definitions'; +import { ProfileInfo, BackstageIdentity } from '@backstage/plugin-api'; export type SamlSession = { userId: string; diff --git a/packages/app-api/src/apis/implementations/auth/types.ts b/packages/app-api/src/apis/implementations/auth/types.ts index db3b718d25..cf13d550fb 100644 --- a/packages/app-api/src/apis/implementations/auth/types.ts +++ b/packages/app-api/src/apis/implementations/auth/types.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { AuthProvider, DiscoveryApi, OAuthRequestApi } from '../../definitions'; +import { + AuthProvider, + DiscoveryApi, + OAuthRequestApi, +} from '@backstage/plugin-api'; export type OAuthApiCreateOptions = AuthApiCreateOptions & { oauthRequestApi: OAuthRequestApi; diff --git a/packages/app-api/src/apis/index.ts b/packages/app-api/src/apis/index.ts index 03569f9570..5652dadf79 100644 --- a/packages/app-api/src/apis/index.ts +++ b/packages/app-api/src/apis/index.ts @@ -15,5 +15,4 @@ */ export * from './system'; -export * from './definitions'; export * from './implementations'; diff --git a/packages/app-api/src/app/App.tsx b/packages/app-api/src/app/App.tsx index 743e39772b..7aaac06623 100644 --- a/packages/app-api/src/app/App.tsx +++ b/packages/app-api/src/app/App.tsx @@ -23,26 +23,26 @@ import React, { } from 'react'; import { Navigate, Route, Routes } from 'react-router-dom'; import { useAsync } from 'react-use'; -import { IconComponent } from '@backstage/plugin-api'; import { AnyApiFactory, ApiHolder, ApiProvider, ApiRegistry, - AppTheme, - appThemeApiRef, AppThemeSelector, - configApiRef, ConfigReader, LocalStorageFeatureFlags, useApi, } from '../apis'; import { + IconComponent, + AppTheme, + appThemeApiRef, + configApiRef, AppThemeApi, ConfigApi, featureFlagsApiRef, identityApiRef, -} from '../apis/definitions'; +} from '@backstage/plugin-api'; import { ApiFactoryRegistry, ApiResolver } from '../apis/system'; import { childDiscoverer, diff --git a/packages/app-api/src/app/AppIdentity.ts b/packages/app-api/src/app/AppIdentity.ts index d3e5fe567a..b247530064 100644 --- a/packages/app-api/src/app/AppIdentity.ts +++ b/packages/app-api/src/app/AppIdentity.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { IdentityApi, ProfileInfo } from '../apis'; +import { IdentityApi, ProfileInfo } from '@backstage/plugin-api'; import { SignInResult } from './types'; /** diff --git a/packages/app-api/src/app/AppThemeProvider.tsx b/packages/app-api/src/app/AppThemeProvider.tsx index 993de23a7a..86746d7c09 100644 --- a/packages/app-api/src/app/AppThemeProvider.tsx +++ b/packages/app-api/src/app/AppThemeProvider.tsx @@ -16,7 +16,7 @@ import React, { useMemo, useEffect, useState, PropsWithChildren } from 'react'; import { ThemeProvider, CssBaseline } from '@material-ui/core'; -import { useApi, appThemeApiRef, AppTheme } from '../apis'; +import { useApi, appThemeApiRef, AppTheme } from '@backstage/plugin-api'; import { useObservable } from 'react-use'; // This tries to find the most accurate match, but also falls back to less diff --git a/packages/app-api/src/app/defaultApis.ts b/packages/app-api/src/app/defaultApis.ts index c8b153a158..40c2c68ca0 100644 --- a/packages/app-api/src/app/defaultApis.ts +++ b/packages/app-api/src/app/defaultApis.ts @@ -15,12 +15,9 @@ */ import { - alertApiRef, - errorApiRef, AlertApiForwarder, ErrorApiForwarder, ErrorAlerter, - discoveryApiRef, GoogleAuth, GithubAuth, OAuth2, @@ -28,8 +25,19 @@ import { GitlabAuth, Auth0Auth, MicrosoftAuth, - oauthRequestApiRef, OAuthRequestManager, + WebStorage, + createApiFactory, + UrlPatternDiscovery, + SamlAuth, + OneLoginAuth, +} from '../apis'; + +import { + alertApiRef, + errorApiRef, + discoveryApiRef, + oauthRequestApiRef, googleAuthApiRef, githubAuthApiRef, oauth2ApiRef, @@ -38,16 +46,11 @@ import { auth0AuthApiRef, microsoftAuthApiRef, storageApiRef, - WebStorage, - createApiFactory, configApiRef, - UrlPatternDiscovery, samlAuthApiRef, - SamlAuth, oneloginAuthApiRef, - OneLoginAuth, oidcAuthApiRef, -} from '../apis'; +} from '@backstage/plugin-api'; import OAuth2Icon from '@material-ui/icons/AcUnit'; diff --git a/packages/app-api/src/app/types.ts b/packages/app-api/src/app/types.ts index 8498834640..c309eb8f8a 100644 --- a/packages/app-api/src/app/types.ts +++ b/packages/app-api/src/app/types.ts @@ -18,9 +18,8 @@ import { ComponentType } from 'react'; import { AnyExternalRoutes, BackstagePlugin } from '../plugin/types'; import { ExternalRouteRef, RouteRef } from '../routing'; import { AnyApiFactory } from '../apis'; -import { AppTheme, ProfileInfo } from '../apis/definitions'; +import { AppTheme, ProfileInfo, IconComponent } from '@backstage/plugin-api'; import { AppConfig } from '@backstage/config'; -import { IconComponent } from '@backstage/plugin-api'; import { SubRouteRef } from '../routing/types'; import { AppIcons } from './icons'; diff --git a/packages/app-api/src/index.test.ts b/packages/app-api/src/index.test.ts index 26a8f2a2f3..0ba9ad13f0 100644 --- a/packages/app-api/src/index.test.ts +++ b/packages/app-api/src/index.test.ts @@ -23,9 +23,9 @@ describe('index', () => { createApp: expect.any(Function), ApiProvider: expect.any(Function), // TODO(Rugvip): Figure out if we need these - // ApiFactoryRegistry: expect.any(Function), - // ApiResolver: expect.any(Function), - // ApiRegistry: expect.any(Function), + ApiFactoryRegistry: expect.any(Function), + ApiResolver: expect.any(Function), + ApiRegistry: expect.any(Function), // Components FlatRoutes: expect.any(Function), @@ -49,10 +49,6 @@ describe('index', () => { SamlAuth: expect.any(Function), UrlPatternDiscovery: expect.any(Function), WebStorage: expect.any(Function), - - // Enums - SessionState: expect.any(Object), - FeatureFlagState: { 0: 'None', 1: 'Active', Active: 1, None: 0 }, }); }); }); diff --git a/packages/app-api/src/lib/AuthConnector/DefaultAuthConnector.ts b/packages/app-api/src/lib/AuthConnector/DefaultAuthConnector.ts index 1c7e92daa8..072b617de8 100644 --- a/packages/app-api/src/lib/AuthConnector/DefaultAuthConnector.ts +++ b/packages/app-api/src/lib/AuthConnector/DefaultAuthConnector.ts @@ -14,12 +14,12 @@ * limitations under the License. */ -import { AuthRequester } from '../../apis'; import { + AuthRequester, OAuthRequestApi, AuthProvider, DiscoveryApi, -} from '../../apis/definitions'; +} from '@backstage/plugin-api'; import { showLoginPopup } from '../loginPopup'; import { AuthConnector, CreateSessionOptions } from './types'; diff --git a/packages/app-api/src/lib/AuthConnector/DirectAuthConnector.ts b/packages/app-api/src/lib/AuthConnector/DirectAuthConnector.ts index e7764fcbaa..85d53caa71 100644 --- a/packages/app-api/src/lib/AuthConnector/DirectAuthConnector.ts +++ b/packages/app-api/src/lib/AuthConnector/DirectAuthConnector.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { AuthProvider, DiscoveryApi } from '../../apis/definitions'; +import { AuthProvider, DiscoveryApi } from '@backstage/plugin-api'; import { showLoginPopup } from '../loginPopup'; type Options = { diff --git a/packages/app-api/src/lib/AuthSessionManager/RefreshingAuthSessionManager.test.ts b/packages/app-api/src/lib/AuthSessionManager/RefreshingAuthSessionManager.test.ts index 9e22e4cd69..8c21e59dd8 100644 --- a/packages/app-api/src/lib/AuthSessionManager/RefreshingAuthSessionManager.test.ts +++ b/packages/app-api/src/lib/AuthSessionManager/RefreshingAuthSessionManager.test.ts @@ -15,7 +15,7 @@ */ import { RefreshingAuthSessionManager } from './RefreshingAuthSessionManager'; -import { SessionState } from '../../apis'; +import { SessionState } from '@backstage/plugin-api'; const defaultOptions = { sessionScopes: (session: { scopes: Set }) => session.scopes, diff --git a/packages/app-api/src/lib/AuthSessionManager/SessionStateTracker.ts b/packages/app-api/src/lib/AuthSessionManager/SessionStateTracker.ts index c4260bb31d..390d6c7599 100644 --- a/packages/app-api/src/lib/AuthSessionManager/SessionStateTracker.ts +++ b/packages/app-api/src/lib/AuthSessionManager/SessionStateTracker.ts @@ -15,7 +15,7 @@ */ import { BehaviorSubject } from '..'; -import { SessionState } from '../../apis'; +import { SessionState } from '@backstage/plugin-api'; import { Observable } from '../../types'; export class SessionStateTracker { diff --git a/packages/app-api/src/lib/AuthSessionManager/types.ts b/packages/app-api/src/lib/AuthSessionManager/types.ts index f57afd6760..8c614843e0 100644 --- a/packages/app-api/src/lib/AuthSessionManager/types.ts +++ b/packages/app-api/src/lib/AuthSessionManager/types.ts @@ -15,7 +15,7 @@ */ import { Observable } from '../../types'; -import { SessionState } from '../../apis'; +import { SessionState } from '@backstage/plugin-api'; export type GetSessionOptions = { optional?: boolean;