From ceaa54178b5028d83d04bba34a79fcc236e8a563 Mon Sep 17 00:00:00 2001 From: Giuseppe Scuglia Date: Fri, 24 Jan 2025 09:32:35 +0100 Subject: [PATCH] chore: update api --- .../generated/@tanstack/react-query.gen.ts | 120 +++++---------- src/api/generated/sdk.gen.ts | 112 +++++--------- src/api/generated/types.gen.ts | 24 +-- src/api/openapi.json | 143 +++++------------- .../__tests__/codegate-status.test.tsx | 8 +- src/hooks/usePromptsData.ts | 6 +- src/hooks/useSse.ts | 2 +- src/mocks/msw/handlers.ts | 4 +- 8 files changed, 136 insertions(+), 283 deletions(-) diff --git a/src/api/generated/@tanstack/react-query.gen.ts b/src/api/generated/@tanstack/react-query.gen.ts index e700ca27..bae9ec57 100644 --- a/src/api/generated/@tanstack/react-query.gen.ts +++ b/src/api/generated/@tanstack/react-query.gen.ts @@ -5,10 +5,6 @@ import { queryOptions, type UseMutationOptions } from "@tanstack/react-query"; import { client, healthCheckHealthGet, - v1GetMessages, - v1GetAlerts, - v1StreamSse, - v1VersionCheck, v1ListWorkspaces, v1CreateWorkspace, v1ListActiveWorkspaces, @@ -22,6 +18,8 @@ import { v1GetWorkspaceCustomInstructions, v1SetWorkspaceCustomInstructions, v1DeleteWorkspaceCustomInstructions, + v1StreamSse, + v1VersionCheck, } from "../sdk.gen"; import type { V1CreateWorkspaceData, @@ -103,82 +101,6 @@ export const healthCheckHealthGetOptions = (options?: OptionsLegacyParser) => { }); }; -export const v1GetMessagesQueryKey = (options?: OptionsLegacyParser) => [ - createQueryKey("v1GetMessages", options), -]; - -export const v1GetMessagesOptions = (options?: OptionsLegacyParser) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await v1GetMessages({ - ...options, - ...queryKey[0], - signal, - throwOnError: true, - }); - return data; - }, - queryKey: v1GetMessagesQueryKey(options), - }); -}; - -export const v1GetAlertsQueryKey = (options?: OptionsLegacyParser) => [ - createQueryKey("v1GetAlerts", options), -]; - -export const v1GetAlertsOptions = (options?: OptionsLegacyParser) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await v1GetAlerts({ - ...options, - ...queryKey[0], - signal, - throwOnError: true, - }); - return data; - }, - queryKey: v1GetAlertsQueryKey(options), - }); -}; - -export const v1StreamSseQueryKey = (options?: OptionsLegacyParser) => [ - createQueryKey("v1StreamSse", options), -]; - -export const v1StreamSseOptions = (options?: OptionsLegacyParser) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await v1StreamSse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true, - }); - return data; - }, - queryKey: v1StreamSseQueryKey(options), - }); -}; - -export const v1VersionCheckQueryKey = (options?: OptionsLegacyParser) => [ - createQueryKey("v1VersionCheck", options), -]; - -export const v1VersionCheckOptions = (options?: OptionsLegacyParser) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await v1VersionCheck({ - ...options, - ...queryKey[0], - signal, - throwOnError: true, - }); - return data; - }, - queryKey: v1VersionCheckQueryKey(options), - }); -}; - export const v1ListWorkspacesQueryKey = (options?: OptionsLegacyParser) => [ createQueryKey("v1ListWorkspaces", options), ]; @@ -507,3 +429,41 @@ export const v1DeleteWorkspaceCustomInstructionsMutation = ( }; return mutationOptions; }; + +export const v1StreamSseQueryKey = (options?: OptionsLegacyParser) => [ + createQueryKey("v1StreamSse", options), +]; + +export const v1StreamSseOptions = (options?: OptionsLegacyParser) => { + return queryOptions({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await v1StreamSse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + }); + return data; + }, + queryKey: v1StreamSseQueryKey(options), + }); +}; + +export const v1VersionCheckQueryKey = (options?: OptionsLegacyParser) => [ + createQueryKey("v1VersionCheck", options), +]; + +export const v1VersionCheckOptions = (options?: OptionsLegacyParser) => { + return queryOptions({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await v1VersionCheck({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + }); + return data; + }, + queryKey: v1VersionCheckQueryKey(options), + }); +}; diff --git a/src/api/generated/sdk.gen.ts b/src/api/generated/sdk.gen.ts index a5915dfd..9d4951ea 100644 --- a/src/api/generated/sdk.gen.ts +++ b/src/api/generated/sdk.gen.ts @@ -8,14 +8,6 @@ import { import type { HealthCheckHealthGetError, HealthCheckHealthGetResponse, - V1GetMessagesError, - V1GetMessagesResponse, - V1GetAlertsError, - V1GetAlertsResponse, - V1StreamSseError, - V1StreamSseResponse, - V1VersionCheckError, - V1VersionCheckResponse, V1ListWorkspacesError, V1ListWorkspacesResponse, V1CreateWorkspaceData, @@ -52,6 +44,10 @@ import type { V1DeleteWorkspaceCustomInstructionsData, V1DeleteWorkspaceCustomInstructionsError, V1DeleteWorkspaceCustomInstructionsResponse, + V1StreamSseError, + V1StreamSseResponse, + V1VersionCheckError, + V1VersionCheckResponse, } from "./types.gen"; export const client = createClient(createConfig()); @@ -72,73 +68,6 @@ export const healthCheckHealthGet = ( }); }; -/** - * Get Messages - * Get all the messages from the database and return them as a list of conversations. - */ -export const v1GetMessages = ( - options?: OptionsLegacyParser, -) => { - return (options?.client ?? client).get< - V1GetMessagesResponse, - V1GetMessagesError, - ThrowOnError - >({ - ...options, - url: "/api/v1/dashboard/messages", - }); -}; - -/** - * Get Alerts - * Get all the messages from the database and return them as a list of conversations. - */ -export const v1GetAlerts = ( - options?: OptionsLegacyParser, -) => { - return (options?.client ?? client).get< - V1GetAlertsResponse, - V1GetAlertsError, - ThrowOnError - >({ - ...options, - url: "/api/v1/dashboard/alerts", - }); -}; - -/** - * Stream Sse - * Send alerts event - */ -export const v1StreamSse = ( - options?: OptionsLegacyParser, -) => { - return (options?.client ?? client).get< - V1StreamSseResponse, - V1StreamSseError, - ThrowOnError - >({ - ...options, - url: "/api/v1/dashboard/alerts_notification", - }); -}; - -/** - * Version Check - */ -export const v1VersionCheck = ( - options?: OptionsLegacyParser, -) => { - return (options?.client ?? client).get< - V1VersionCheckResponse, - V1VersionCheckError, - ThrowOnError - >({ - ...options, - url: "/api/v1/dashboard/version", - }); -}; - /** * List Workspaces * List all workspaces. @@ -375,3 +304,36 @@ export const v1DeleteWorkspaceCustomInstructions = < url: "/api/v1/workspaces/{workspace_name}/custom-instructions", }); }; + +/** + * Stream Sse + * Send alerts event + */ +export const v1StreamSse = ( + options?: OptionsLegacyParser, +) => { + return (options?.client ?? client).get< + V1StreamSseResponse, + V1StreamSseError, + ThrowOnError + >({ + ...options, + url: "/api/v1/alerts_notification", + }); +}; + +/** + * Version Check + */ +export const v1VersionCheck = ( + options?: OptionsLegacyParser, +) => { + return (options?.client ?? client).get< + V1VersionCheckResponse, + V1VersionCheckError, + ThrowOnError + >({ + ...options, + url: "/api/v1/version", + }); +}; diff --git a/src/api/generated/types.gen.ts b/src/api/generated/types.gen.ts index 1cdfb289..03d958eb 100644 --- a/src/api/generated/types.gen.ts +++ b/src/api/generated/types.gen.ts @@ -99,22 +99,6 @@ export type HealthCheckHealthGetResponse = unknown; export type HealthCheckHealthGetError = unknown; -export type V1GetMessagesResponse = Array; - -export type V1GetMessagesError = unknown; - -export type V1GetAlertsResponse = Array; - -export type V1GetAlertsError = unknown; - -export type V1StreamSseResponse = unknown; - -export type V1StreamSseError = unknown; - -export type V1VersionCheckResponse = unknown; - -export type V1VersionCheckError = unknown; - export type V1ListWorkspacesResponse = ListWorkspacesResponse; export type V1ListWorkspacesError = unknown; @@ -226,3 +210,11 @@ export type V1DeleteWorkspaceCustomInstructionsData = { export type V1DeleteWorkspaceCustomInstructionsResponse = void; export type V1DeleteWorkspaceCustomInstructionsError = HTTPValidationError; + +export type V1StreamSseResponse = unknown; + +export type V1StreamSseError = unknown; + +export type V1VersionCheckResponse = unknown; + +export type V1VersionCheckError = unknown; diff --git a/src/api/openapi.json b/src/api/openapi.json index b089262c..b1f5f96f 100644 --- a/src/api/openapi.json +++ b/src/api/openapi.json @@ -25,108 +25,6 @@ } } }, - "/api/v1/dashboard/messages": { - "get": { - "tags": [ - "CodeGate API", - "Dashboard" - ], - "summary": "Get Messages", - "description": "Get all the messages from the database and return them as a list of conversations.", - "operationId": "v1_get_messages", - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "items": { - "$ref": "#/components/schemas/Conversation" - }, - "type": "array", - "title": "Response V1 Get Messages" - } - } - } - } - } - } - }, - "/api/v1/dashboard/alerts": { - "get": { - "tags": [ - "CodeGate API", - "Dashboard" - ], - "summary": "Get Alerts", - "description": "Get all the messages from the database and return them as a list of conversations.", - "operationId": "v1_get_alerts", - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "items": { - "anyOf": [ - { - "$ref": "#/components/schemas/AlertConversation" - }, - { - "type": "null" - } - ] - }, - "type": "array", - "title": "Response V1 Get Alerts" - } - } - } - } - } - } - }, - "/api/v1/dashboard/alerts_notification": { - "get": { - "tags": [ - "CodeGate API", - "Dashboard" - ], - "summary": "Stream Sse", - "description": "Send alerts event", - "operationId": "v1_stream_sse", - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": {} - } - } - } - } - } - }, - "/api/v1/dashboard/version": { - "get": { - "tags": [ - "CodeGate API", - "Dashboard" - ], - "summary": "Version Check", - "operationId": "v1_version_check", - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": {} - } - } - } - } - } - }, "/api/v1/workspaces": { "get": { "tags": [ @@ -632,6 +530,47 @@ } } } + }, + "/api/v1/alerts_notification": { + "get": { + "tags": [ + "CodeGate API", + "Dashboard" + ], + "summary": "Stream Sse", + "description": "Send alerts event", + "operationId": "v1_stream_sse", + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + } + } + } + }, + "/api/v1/version": { + "get": { + "tags": [ + "CodeGate API", + "Dashboard" + ], + "summary": "Version Check", + "operationId": "v1_version_check", + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + } + } + } } }, "components": { diff --git a/src/features/dashboard-codegate-status/components/__tests__/codegate-status.test.tsx b/src/features/dashboard-codegate-status/components/__tests__/codegate-status.test.tsx index d4704b8d..d3e14ee7 100644 --- a/src/features/dashboard-codegate-status/components/__tests__/codegate-status.test.tsx +++ b/src/features/dashboard-codegate-status/components/__tests__/codegate-status.test.tsx @@ -49,7 +49,7 @@ describe("CardCodegateStatus", () => { }); test("renders 'error' state when version check request fails", async () => { - server.use(http.get("*/dashboard/version", () => HttpResponse.error())); + server.use(http.get("*/api/v1/version", () => HttpResponse.error())); const { getByText } = renderComponent(); @@ -63,7 +63,7 @@ describe("CardCodegateStatus", () => { test("renders 'latest version' state", async () => { server.use( - http.get("*/dashboard/version", () => + http.get("*/api/v1/version", () => HttpResponse.json({ current_version: "foo", latest_version: "foo", @@ -85,7 +85,7 @@ describe("CardCodegateStatus", () => { test("renders 'update available' state", async () => { server.use( - http.get("*/dashboard/version", () => + http.get("*/api/v1/version", () => HttpResponse.json({ current_version: "foo", latest_version: "bar", @@ -112,7 +112,7 @@ describe("CardCodegateStatus", () => { test("renders 'version check error' state", async () => { server.use( - http.get("*/dashboard/version", () => + http.get("*/api/v1/version", () => HttpResponse.json({ current_version: "foo", latest_version: "bar", diff --git a/src/hooks/usePromptsData.ts b/src/hooks/usePromptsData.ts index 1ef90e67..c841078e 100644 --- a/src/hooks/usePromptsData.ts +++ b/src/hooks/usePromptsData.ts @@ -1,13 +1,15 @@ import { useQuery } from "@tanstack/react-query"; import { Conversation, - V1GetMessagesResponse, + V1GetWorkspaceMessagesResponse, V1GetWorkspaceMessagesData, } from "@/api/generated"; import { v1GetWorkspaceMessagesOptions } from "@/api/generated/@tanstack/react-query.gen"; import { useActiveWorkspaceName } from "@/features/workspace/hooks/use-active-workspace-name"; -const selectConversations = (data: V1GetMessagesResponse): Conversation[] => { +const selectConversations = ( + data: V1GetWorkspaceMessagesResponse, +): Conversation[] => { return data.filter((prompt) => prompt.question_answers?.every((item) => item.answer && item.question), ); diff --git a/src/hooks/useSse.ts b/src/hooks/useSse.ts index baf753fc..6bd783b9 100644 --- a/src/hooks/useSse.ts +++ b/src/hooks/useSse.ts @@ -12,7 +12,7 @@ export function useSse() { useEffect(() => { const eventSource = new EventSource( - `${BASE_URL}/api/v1/dashboard/alerts_notification`, + `${BASE_URL}/api/v1/alerts_notification`, ); eventSource.onmessage = function (event) { diff --git a/src/mocks/msw/handlers.ts b/src/mocks/msw/handlers.ts index eb865736..fa5f231b 100644 --- a/src/mocks/msw/handlers.ts +++ b/src/mocks/msw/handlers.ts @@ -12,9 +12,7 @@ export const handlers = [ error: null, }), ), - http.get("*/api/v1/dashboard/version", () => - HttpResponse.json({ status: "healthy" }), - ), + http.get("*/api/v1/version", () => HttpResponse.json({ status: "healthy" })), http.get("*/api/v1/workspaces/active", () => HttpResponse.json([ {