From adc28d8082ec64e8447c63f09625ed5083416dd5 Mon Sep 17 00:00:00 2001 From: Asier Isayas Date: Wed, 19 Aug 2026 15:37:51 -0700 Subject: [PATCH] Move the Portal Backend client to Common The module is a plain service client with no dependency on the hosted platform, and CosmosClient and MetricEvents already hand roll their own Portal Backend calls, so Common is where a shared client belongs. --- .../PortalBackendClient.ts} | 6 +++--- src/HostedExplorer.test.tsx | 4 ++-- src/HostedExplorer.tsx | 2 +- src/Platform/Hosted/Components/ConnectExplorer.tsx | 5 +---- tsconfig.strict.json | 2 +- 5 files changed, 8 insertions(+), 11 deletions(-) rename src/{Platform/Hosted/PortalBackendConnectionStringClient.ts => Common/PortalBackendClient.ts} (90%) diff --git a/src/Platform/Hosted/PortalBackendConnectionStringClient.ts b/src/Common/PortalBackendClient.ts similarity index 90% rename from src/Platform/Hosted/PortalBackendConnectionStringClient.ts rename to src/Common/PortalBackendClient.ts index 9822aa852..e2e13afa3 100644 --- a/src/Platform/Hosted/PortalBackendConnectionStringClient.ts +++ b/src/Common/PortalBackendClient.ts @@ -1,6 +1,6 @@ -import { HttpHeaders } from "../../Common/Constants"; -import { configContext } from "../../ConfigContext"; -import { AccessInputMetadata } from "../../Contracts/DataModels"; +import { configContext } from "../ConfigContext"; +import { AccessInputMetadata } from "../Contracts/DataModels"; +import { HttpHeaders } from "./Constants"; export async function fetchAccessData(portalToken: string): Promise { const headers = new Headers(); diff --git a/src/HostedExplorer.test.tsx b/src/HostedExplorer.test.tsx index 0db2e45ce..dda571e4f 100644 --- a/src/HostedExplorer.test.tsx +++ b/src/HostedExplorer.test.tsx @@ -1,6 +1,6 @@ jest.mock("./hooks/useAADAuth"); jest.mock("./hooks/useConfig"); -jest.mock("./Platform/Hosted/PortalBackendConnectionStringClient"); +jest.mock("./Common/PortalBackendClient"); jest.mock("./Platform/Hosted/Components/ConnectExplorer"); jest.mock("./Shared/appInsights"); jest.mock("./Platform/Hosted/Components/AccountSwitcher", () => ({ @@ -25,11 +25,11 @@ jest.mock("./Platform/Hosted/Components/AadAuthorizationFailure", () => ({ import "@testing-library/jest-dom"; import { act, render } from "@testing-library/react"; import React from "react"; +import { fetchAccessData, fetchEncryptedToken } from "./Common/PortalBackendClient"; import { useAADAuth } from "./hooks/useAADAuth"; import { useConfig } from "./hooks/useConfig"; import { App } from "./HostedExplorer"; import { ConnectExplorer } from "./Platform/Hosted/Components/ConnectExplorer"; -import { fetchAccessData, fetchEncryptedToken } from "./Platform/Hosted/PortalBackendConnectionStringClient"; const mockFetchEncryptedToken = fetchEncryptedToken as jest.MockedFunction; diff --git a/src/HostedExplorer.tsx b/src/HostedExplorer.tsx index c468fc3ac..938f5ae95 100644 --- a/src/HostedExplorer.tsx +++ b/src/HostedExplorer.tsx @@ -8,6 +8,7 @@ import ChevronRight from "../images/chevron-right.svg"; import "../less/hostedexplorer.less"; import { AuthType } from "./AuthType"; import { logError } from "./Common/Logger"; +import { fetchAccessData, fetchEncryptedToken } from "./Common/PortalBackendClient"; import { AccessInputMetadata, DatabaseAccount } from "./Contracts/DataModels"; import "./Explorer/Menus/NavBar/MeControlComponent.less"; import { HostedExplorerChildFrame } from "./HostedExplorerChildFrame"; @@ -24,7 +25,6 @@ import { extractMasterKeyFromDirectLoginConnectionString, isDirectConnectionStringLoginApi, } from "./Platform/Hosted/HostedUtils"; -import { fetchAccessData, fetchEncryptedToken } from "./Platform/Hosted/PortalBackendConnectionStringClient"; import "./Shared/appInsights"; import { allowedHostedExplorerEndpoints } from "./Utils/EndpointUtils"; import { useAADAuth } from "./hooks/useAADAuth"; diff --git a/src/Platform/Hosted/Components/ConnectExplorer.tsx b/src/Platform/Hosted/Components/ConnectExplorer.tsx index de77ac8a9..135eafbb7 100644 --- a/src/Platform/Hosted/Components/ConnectExplorer.tsx +++ b/src/Platform/Hosted/Components/ConnectExplorer.tsx @@ -5,14 +5,11 @@ import * as React from "react"; import ConnectImage from "../../../../images/HdeConnectCosmosDB.svg"; import ErrorImage from "../../../../images/error.svg"; import { AuthType } from "../../../AuthType"; +import { fetchEncryptedToken, isAccountRestrictedForConnectionStringLogin } from "../../../Common/PortalBackendClient"; import { AccessInputMetadata } from "../../../Contracts/DataModels"; import { parseConnectionString } from "../Helpers/ConnectionStringParser"; import { isResourceTokenConnectionString } from "../Helpers/ResourceTokenUtils"; import { isDirectConnectionStringLoginApi } from "../HostedUtils"; -import { - fetchEncryptedToken, - isAccountRestrictedForConnectionStringLogin, -} from "../PortalBackendConnectionStringClient"; interface Props { connectionString: string; diff --git a/tsconfig.strict.json b/tsconfig.strict.json index ac9418213..947b073e5 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -25,6 +25,7 @@ "./src/Common/ObjectCache.ts", "./src/Common/OfferUtility.test.ts", "./src/Common/OfferUtility.ts", + "./src/Common/PortalBackendClient.ts", "./src/Common/Splitter.ts", "./src/Common/ThemeUtility.ts", "./src/Common/UrlUtility.ts", @@ -66,7 +67,6 @@ "./src/Platform/Hosted/Components/MeControl.test.tsx", "./src/Platform/Hosted/Components/MeControl.tsx", "./src/Platform/Hosted/Components/SignInButton.tsx", - "./src/Platform/Hosted/PortalBackendConnectionStringClient.ts", "./src/Platform/Hosted/HostedUtils.test.ts", "./src/Platform/Hosted/HostedUtils.ts", "./src/Platform/Hosted/extractFeatures.test.ts",