From f669a99228bbdd00a92895064a35464f02c8a94a Mon Sep 17 00:00:00 2001 From: Laurent Nguyen Date: Wed, 29 May 2024 16:03:51 +0200 Subject: [PATCH] Separate Fabric-specific message types (#1848) * Update message de->fabric to v3 * Reinstate get authorization token path which doesn't get called every 5 minutes anymore * Remove obsolete comment * Add missing types * Fix format * Fix build issue * Revert "Reinstate get authorization token path which doesn't get called every 5 minutes anymore" This reverts commit a3f3511043201c8824989df04fd2ad813b88bd9e. * Keep 3 old fabric message types enums for compatibility with the portal * Re-add warning comment about not changing existing message type enums --------- Co-authored-by: Laurent Nguyen --- src/Common/CosmosClient.ts | 4 +-- src/Common/MessageHandler.ts | 3 ++- src/Contracts/DataExplorerMessagesContract.ts | 27 +++++-------------- src/Contracts/FabricMessageTypes.ts | 13 +++++++++ src/Contracts/FabricMessagesContract.ts | 2 +- src/Contracts/MessageTypes.ts | 14 ++++------ src/Platform/Fabric/FabricUtil.ts | 4 +-- src/hooks/useKnockoutExplorer.ts | 3 ++- 8 files changed, 33 insertions(+), 37 deletions(-) create mode 100644 src/Contracts/FabricMessageTypes.ts diff --git a/src/Common/CosmosClient.ts b/src/Common/CosmosClient.ts index f75c47454..c24680f4b 100644 --- a/src/Common/CosmosClient.ts +++ b/src/Common/CosmosClient.ts @@ -1,6 +1,6 @@ import * as Cosmos from "@azure/cosmos"; import { getAuthorizationTokenUsingResourceTokens } from "Common/getAuthorizationTokenUsingResourceTokens"; -import { AuthorizationToken } from "Contracts/MessageTypes"; +import { AuthorizationToken } from "Contracts/FabricMessageTypes"; import { checkDatabaseResourceTokensValidity } from "Platform/Fabric/FabricUtil"; import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility"; import { AuthType } from "../AuthType"; @@ -59,7 +59,7 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => { /* ************** TODO: Uncomment this code if we need to support these operations ************** // User master tokens const authorizationToken = await sendCachedDataMessage( - MessageTypes.GetAuthorizationToken, + FabricMessageTypes.GetAuthorizationToken, [requestInfo], userContext.fabricContext.connectionId, ); diff --git a/src/Common/MessageHandler.ts b/src/Common/MessageHandler.ts index 0d8304d95..378c58b5f 100644 --- a/src/Common/MessageHandler.ts +++ b/src/Common/MessageHandler.ts @@ -1,3 +1,4 @@ +import { FabricMessageTypes } from "Contracts/FabricMessageTypes"; import Q from "q"; import * as _ from "underscore"; import { MessageTypes } from "../Contracts/ExplorerContracts"; @@ -36,7 +37,7 @@ export function handleCachedDataMessage(message: any): void { * @returns */ export function sendCachedDataMessage( - messageType: MessageTypes, + messageType: MessageTypes | FabricMessageTypes, params: Object[], scope?: string, timeoutInMs?: number, diff --git a/src/Contracts/DataExplorerMessagesContract.ts b/src/Contracts/DataExplorerMessagesContract.ts index e47e4c384..a38940120 100644 --- a/src/Contracts/DataExplorerMessagesContract.ts +++ b/src/Contracts/DataExplorerMessagesContract.ts @@ -1,37 +1,22 @@ -import { MessageTypes } from "./MessageTypes"; +import { FabricMessageTypes } from "./FabricMessageTypes"; // This is the current version of these messages -export const DATA_EXPLORER_RPC_VERSION = "2"; +export const DATA_EXPLORER_RPC_VERSION = "3"; // Data Explorer to Fabric - -// TODO Remove when upgrading to Fabric v2 -export type DataExploreMessageV1 = - | "ready" +export type DataExploreMessageV3 = | { - type: MessageTypes.GetAuthorizationToken; - id: string; - params: GetCosmosTokenMessageOptions[]; - } - | { - type: MessageTypes.GetAllResourceTokens; - id: string; - }; -// ----------------------------- - -export type DataExploreMessageV2 = - | { - type: MessageTypes.Ready; + type: FabricMessageTypes.Ready; id: string; params: [string]; // version } | { - type: MessageTypes.GetAuthorizationToken; + type: FabricMessageTypes.GetAuthorizationToken; id: string; params: GetCosmosTokenMessageOptions[]; } | { - type: MessageTypes.GetAllResourceTokens; + type: FabricMessageTypes.GetAllResourceTokens; id: string; }; diff --git a/src/Contracts/FabricMessageTypes.ts b/src/Contracts/FabricMessageTypes.ts new file mode 100644 index 000000000..aa374472d --- /dev/null +++ b/src/Contracts/FabricMessageTypes.ts @@ -0,0 +1,13 @@ +/** + * Data Explorer -> Fabric communication. + */ +export enum FabricMessageTypes { + GetAuthorizationToken = "GetAuthorizationToken", + GetAllResourceTokens = "GetAllResourceTokens", + Ready = "Ready", +} + +export interface AuthorizationToken { + XDate: string; + PrimaryReadWriteToken: string; +} diff --git a/src/Contracts/FabricMessagesContract.ts b/src/Contracts/FabricMessagesContract.ts index b381fd845..dcf5a5a50 100644 --- a/src/Contracts/FabricMessagesContract.ts +++ b/src/Contracts/FabricMessagesContract.ts @@ -1,4 +1,4 @@ -import { AuthorizationToken } from "./MessageTypes"; +import { AuthorizationToken } from "Contracts/FabricMessageTypes"; // This is the version of these messages export const FABRIC_RPC_VERSION = "2"; diff --git a/src/Contracts/MessageTypes.ts b/src/Contracts/MessageTypes.ts index a19b69e5f..4550d2a53 100644 --- a/src/Contracts/MessageTypes.ts +++ b/src/Contracts/MessageTypes.ts @@ -1,12 +1,13 @@ /** * Messaging types used with Data Explorer <-> Portal communication, - * Hosted <-> Explorer communication and Data Explorer -> Fabric communication. + * Hosted <-> Explorer communication * * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * WARNING: !!!!!!! YOU CAN ONLY ADD NEW TYPES TO THE END OF THIS ENUM !!!!!!! * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * * Enum are integers, so inserting or deleting a type will break the communication. + * */ export enum MessageTypes { TelemetryInfo, @@ -43,14 +44,9 @@ export enum MessageTypes { DisplayNPSSurvey, OpenVCoreMongoNetworkingBlade, OpenVCoreMongoConnectionStringsBlade, - GetAuthorizationToken, // Data Explorer -> Fabric - GetAllResourceTokens, // Data Explorer -> Fabric - Ready, // Data Explorer -> Fabric + GetAuthorizationToken, // unused. Can be removed if the portal uses the same list of enums. + GetAllResourceTokens, // unused. Can be removed if the portal uses the same list of enums. + Ready, // unused. Can be removed if the portal uses the same list of enums. OpenCESCVAFeedbackBlade, ActivateTab, } - -export interface AuthorizationToken { - XDate: string; - PrimaryReadWriteToken: string; -} diff --git a/src/Platform/Fabric/FabricUtil.ts b/src/Platform/Fabric/FabricUtil.ts index 6c6d2ef9c..26ba859ff 100644 --- a/src/Platform/Fabric/FabricUtil.ts +++ b/src/Platform/Fabric/FabricUtil.ts @@ -1,6 +1,6 @@ import { sendCachedDataMessage } from "Common/MessageHandler"; +import { FabricMessageTypes } from "Contracts/FabricMessageTypes"; import { FabricDatabaseConnectionInfo } from "Contracts/FabricMessagesContract"; -import { MessageTypes } from "Contracts/MessageTypes"; import { updateUserContext, userContext } from "UserContext"; import { logConsoleError } from "Utils/NotificationConsoleUtils"; @@ -19,7 +19,7 @@ const requestDatabaseResourceTokens = async (): Promise => { lastRequestTimestamp = Date.now(); try { const fabricDatabaseConnectionInfo = await sendCachedDataMessage( - MessageTypes.GetAllResourceTokens, + FabricMessageTypes.GetAllResourceTokens, [], userContext.fabricContext.connectionId, ); diff --git a/src/hooks/useKnockoutExplorer.ts b/src/hooks/useKnockoutExplorer.ts index 4e80b3476..3a6061acd 100644 --- a/src/hooks/useKnockoutExplorer.ts +++ b/src/hooks/useKnockoutExplorer.ts @@ -1,5 +1,6 @@ import { createUri } from "Common/UrlUtility"; import { DATA_EXPLORER_RPC_VERSION } from "Contracts/DataExplorerMessagesContract"; +import { FabricMessageTypes } from "Contracts/FabricMessageTypes"; import { FABRIC_RPC_VERSION, FabricMessageV2 } from "Contracts/FabricMessagesContract"; import Explorer from "Explorer/Explorer"; import { useSelectedNode } from "Explorer/useSelectedNode"; @@ -156,7 +157,7 @@ async function configureFabric(): Promise { ); sendMessage({ - type: MessageTypes.Ready, + type: FabricMessageTypes.Ready, id: "ready", params: [DATA_EXPLORER_RPC_VERSION], });