diff --git a/src/common/utils/url.ts b/src/common/utils/url.ts index 62d1c436..119afc89 100644 --- a/src/common/utils/url.ts +++ b/src/common/utils/url.ts @@ -12,11 +12,7 @@ export function getProjectId(url?: string) { } function getVersionAndSpecification(url?: string) { -<<<<<<<< HEAD:src/common/UrlUtils.ts - const project = getProjectId(url)?.replace('-openapi', ''); -======== const project = getProjectId(url) ->>>>>>>> develop:src/common/utils/url.ts if (url && project) { const versionAndSpecification = url.substring(project.length + 2)// remove first slash let specification: string | undefined = undefined; diff --git a/src/features/auth/data/Auth0OAuthTokenRepository.ts b/src/features/auth/data/Auth0OAuthTokenRepository.ts deleted file mode 100644 index 635b8546..00000000 --- a/src/features/auth/data/Auth0OAuthTokenRepository.ts +++ /dev/null @@ -1,133 +0,0 @@ -import { ManagementClient } from "auth0" -import { getSession } from "@auth0/nextjs-auth0" -import IOAuthTokenRepository, { IOAuthToken } from "../domain/IOAuthTokenRepository" - -type Auth0UserAppMetadataAuthToken = { - readonly access_token: string - readonly refresh_token: string - readonly access_token_expires_at: string - readonly refresh_token_expires_at: string -} - -type Auth0UserIdentity = { - readonly connection: string - readonly access_token: string - readonly refresh_token: string -} - -type Auth0User = { - readonly user_id: string - readonly identities: Auth0UserIdentity[] - readonly app_metadata?: {[key: string]: any} -} - -interface Auth0OAuthIdentityProviderConfig { - readonly domain: string - readonly clientId: string - readonly clientSecret: string - readonly connection: string -} - -export default class Auth0OAuthTokenRepository implements IOAuthTokenRepository { - private readonly managementClient: ManagementClient - private readonly connection: string - - constructor(config: Auth0OAuthIdentityProviderConfig) { - this.connection = config.connection - this.managementClient = new ManagementClient({ - domain: config.domain, - clientId: config.clientId, - clientSecret: config.clientSecret - }) - } - - async getOAuthToken(): Promise { - const user = await this.getUser() - const metadataAuthToken = this.getAuthTokenFromMetadata(user) - if (!metadataAuthToken) { - return this.getDefaultAuth0AuthToken(user) - } - const accessTokenExpiryDate = new Date(metadataAuthToken.access_token_expires_at) - const refreshTokenExpiryDate = new Date(metadataAuthToken.refresh_token_expires_at) - const now = new Date() - if (refreshTokenExpiryDate.getTime() <= now.getTime()) { - return this.getDefaultAuth0AuthToken(user) - } - return { - accessToken: metadataAuthToken.access_token, - refreshToken: metadataAuthToken.refresh_token, - accessTokenExpiryDate: accessTokenExpiryDate, - refreshTokenExpiryDate: refreshTokenExpiryDate - } - } - - async storeOAuthToken(token: IOAuthToken): Promise { - const user = await this.getUser() - const authTokenKey = this.getAuthTokenMetadataKey(this.connection) - const appMetadataToken: Auth0UserAppMetadataAuthToken = { - access_token: token.accessToken, - refresh_token: token.refreshToken, - access_token_expires_at: token.accessTokenExpiryDate.toISOString(), - refresh_token_expires_at: token.refreshTokenExpiryDate.toISOString() - } - const appMetadata: any = {} - appMetadata[authTokenKey] = appMetadataToken - await this.managementClient.users.update({ id: user.user_id }, { - app_metadata: appMetadata - }) - } - - private async getDefaultAuth0AuthToken(user: Auth0User) { - const identity = this.getIdentity(user) - if (!identity) { - throw new Error("User have no identities") - } - return { - accessToken: identity.access_token, - refreshToken: identity.refresh_token, - accessTokenExpiryDate: new Date(new Date().getTime() - 30 * 60 * 1000), - refreshTokenExpiryDate: new Date(new Date().getTime() + 30 * 60 * 1000) - } - } - - private getIdentity(user: Auth0User): Auth0UserIdentity | undefined { - if (!user.identities) { - return undefined - } - return user.identities.find(e => { - return e.connection.toLowerCase() === this.connection.toLowerCase() - }) - } - - private getAuthTokenFromMetadata(user: Auth0User): Auth0UserAppMetadataAuthToken | undefined { - if (!user.app_metadata) { - return undefined - } - const authTokenKey = this.getAuthTokenMetadataKey(this.connection) - const authToken = user.app_metadata[authTokenKey] - if ( - authToken.access_token && authToken.access_token.length > 0 && - authToken.refresh_token && authToken.refresh_token.length > 0 && - authToken.access_token_expires_at && authToken.access_token_expires_at.length > 0 && - authToken.refresh_token_expires_at && authToken.refresh_token_expires_at.length > 0 - ) { - return authToken - } else { - return undefined - } - } - - private getAuthTokenMetadataKey(connection: string): string { - return `authToken[${connection.toLowerCase()}]` - } - - private async getUser(): Promise { - const session = await getSession() - const user = session?.user - if (!user) { - throw new Error("User is not authenticated") - } - const userResponse = await this.managementClient.users.get({ id: user.sub }) - return userResponse.data - } -} diff --git a/src/features/auth/domain/IUserDataOAuthTokenRepository.ts b/src/features/auth/domain/IUserDataOAuthTokenRepository.ts index ddee24f3..3c70aa51 100644 --- a/src/features/auth/domain/IUserDataOAuthTokenRepository.ts +++ b/src/features/auth/domain/IUserDataOAuthTokenRepository.ts @@ -1,6 +1,6 @@ import OAuthToken from "./OAuthToken" -export default interface IOAuthTokenRepository { +export default interface IUserDataOAuthTokenRepository { getOAuthToken(userId: string): Promise storeOAuthToken(userId: string, token: OAuthToken): Promise deleteOAuthToken(userId: string): Promise diff --git a/src/features/projects/data/IGitHubOrganizationNameProvider.ts b/src/features/projects/data/IGitHubOrganizationNameProvider.ts deleted file mode 100644 index e1da61d3..00000000 --- a/src/features/projects/data/IGitHubOrganizationNameProvider.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default interface IGitHubOrganizationNameProvider { - getOrganizationName(): Promise -} diff --git a/src/features/projects/view/ProjectsPage.tsx b/src/features/projects/view/ProjectsPage.tsx deleted file mode 100644 index b0177af0..00000000 --- a/src/features/projects/view/ProjectsPage.tsx +++ /dev/null @@ -1,65 +0,0 @@ -"use client" - -import { useRouter } from "next/navigation" -import SidebarContainer from "@/common/SidebarContainer" -import ProjectList from "./ProjectList" -import ProjectsPageSecondaryContent from "./ProjectsPageSecondaryContent" -import ProjectsPageTrailingToolbarItem from "./ProjectsPageTrailingToolbarItem" -import useProjects from "../data/useProjects" -import { getProjectPageState } from "../domain/ProjectPageState" -import projectNavigator from "../domain/projectNavigator" - -interface ProjectsPageProps { - readonly projectId?: string - readonly versionId?: string - readonly specificationId?: string -} - -export default function ProjectsPage( - { projectId, versionId, specificationId }: ProjectsPageProps -) { - const router = useRouter() - const { projects, error, isLoading } = useProjects() - const stateContainer = getProjectPageState({ - isLoading, - error, - projects, - selectedProjectId: projectId, - selectedVersionId: versionId, - selectedSpecificationId: specificationId - }) - // Ensure the URL reflects the current selection of project, version, and specification. - if (stateContainer.selection) { - const candidateSelection = { projectId, versionId, specificationId } - projectNavigator.navigateToCurrentSelection( - candidateSelection, - stateContainer.selection, - router - ) - } - return ( - - } - secondary={ - - } - toolbarTrailing={ - { - projectNavigator.navigateToVersion(stateContainer.selection!, versionId, router) - }} - onSelectSpecification={(specificationId: string) => { - projectNavigator.navigateToSpecification(stateContainer.selection!, specificationId, router) - }} - /> - } - /> - ) -} diff --git a/src/features/settings/data/SettingsStore.ts b/src/features/settings/data/SettingsStore.ts deleted file mode 100644 index c7f8c561..00000000 --- a/src/features/settings/data/SettingsStore.ts +++ /dev/null @@ -1,36 +0,0 @@ -import DocumentationVisualizer from "../domain/DocumentationVisualizer" -import ISettingsStore from "../domain/ISettingsStore" -import SettingsChangedEvent from "@/common/events/SettingsChangedEvent" -import { publish } from "@/common/events/utils" - -const LOCAL_STORAGE_SETTINGS_KEY = "settings" - -export default class SettingsStore implements ISettingsStore { - get documentationVisualizer(): DocumentationVisualizer { - return getSettings().documentationVisualizer - } - - set documentationVisualizer(documentationVisualizer: DocumentationVisualizer) { - setSettings({ ...getSettings(), documentationVisualizer }) - } -} - -interface ISettings { - documentationVisualizer: DocumentationVisualizer -} - -function getSettings(): ISettings { - const savedSettings = window.localStorage.getItem(LOCAL_STORAGE_SETTINGS_KEY) - return savedSettings ? JSON.parse(savedSettings) : getDefaultSettings() -} - -function setSettings(settings: ISettings) { - window.localStorage.setItem(LOCAL_STORAGE_SETTINGS_KEY, JSON.stringify(settings)) - publish(new SettingsChangedEvent()) -} - -function getDefaultSettings(): ISettings { - return { - documentationVisualizer: DocumentationVisualizer.SWAGGER - } -} diff --git a/src/features/settings/domain/ISettingsStore.ts b/src/features/settings/domain/ISettingsStore.ts deleted file mode 100644 index 3d68d3a8..00000000 --- a/src/features/settings/domain/ISettingsStore.ts +++ /dev/null @@ -1,5 +0,0 @@ -import DocumentationVisualizer from "./DocumentationVisualizer" - -export default interface ISettingsStore { - documentationVisualizer: DocumentationVisualizer -}