mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 15:27:27 +00:00
feat(integration-page): updated components and api hooks
This commit is contained in:
@@ -13,6 +13,7 @@ type Props = {
|
|||||||
onChange?: (isOpen: boolean) => void;
|
onChange?: (isOpen: boolean) => void;
|
||||||
deleteKey: string;
|
deleteKey: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
subTitle?: string;
|
||||||
onDeleteApproved: () => Promise<void>;
|
onDeleteApproved: () => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -22,7 +23,8 @@ export const DeleteActionModal = ({
|
|||||||
onChange,
|
onChange,
|
||||||
deleteKey,
|
deleteKey,
|
||||||
onDeleteApproved,
|
onDeleteApproved,
|
||||||
title
|
title,
|
||||||
|
subTitle = 'This action is irreversible!'
|
||||||
}: Props): JSX.Element => {
|
}: Props): JSX.Element => {
|
||||||
const [inputData, setInputData] = useState("");
|
const [inputData, setInputData] = useState("");
|
||||||
const [isLoading, setIsLoading] = useToggle();
|
const [isLoading, setIsLoading] = useToggle();
|
||||||
@@ -52,7 +54,7 @@ export const DeleteActionModal = ({
|
|||||||
>
|
>
|
||||||
<ModalContent
|
<ModalContent
|
||||||
title={title}
|
title={title}
|
||||||
subTitle="This action is irreversible!"
|
subTitle={subTitle}
|
||||||
footerContent={
|
footerContent={
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export {
|
export {
|
||||||
useGetAuthToken,
|
useGetAuthToken,
|
||||||
useGetCommonPasswords,
|
useGetCommonPasswords,
|
||||||
useRevokeAllSessions,
|
useRevokeAllSessions,
|
||||||
useSendMfaToken,
|
useSendMfaToken,
|
||||||
useVerifyMfaToken} from "./queries"
|
useVerifyMfaToken
|
||||||
|
} from "./queries";
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export { useGetWorkspaceBot, useUpdateBotActiveStatus } from './queries';
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import { apiRequest } from '@app/config/request';
|
||||||
|
|
||||||
|
import { TBot, TSetBotActiveStatusDto } from './types';
|
||||||
|
|
||||||
|
const queryKeys = {
|
||||||
|
getBot: (workspaceId: string) => [{ workspaceId }, 'bot'] as const
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchWorkspaceBot = async (workspaceId: string) => {
|
||||||
|
const { data } = await apiRequest.get<{ bot: TBot }>(`/api/v1/bot/${workspaceId}`);
|
||||||
|
return data.bot;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetWorkspaceBot = (workspaceId: string) =>
|
||||||
|
useQuery({
|
||||||
|
queryKey: queryKeys.getBot(workspaceId),
|
||||||
|
queryFn: () => fetchWorkspaceBot(workspaceId),
|
||||||
|
enabled: Boolean(workspaceId)
|
||||||
|
});
|
||||||
|
|
||||||
|
// mutation
|
||||||
|
|
||||||
|
export const useUpdateBotActiveStatus = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation<{}, {}, TSetBotActiveStatusDto>({
|
||||||
|
mutationFn: ({ botId, isActive, botKey }) =>
|
||||||
|
apiRequest.patch(`/api/v1/bot/${botId}/active`, {
|
||||||
|
isActive,
|
||||||
|
botKey
|
||||||
|
}),
|
||||||
|
onSuccess: (_, { workspaceId }) => {
|
||||||
|
queryClient.invalidateQueries(queryKeys.getBot(workspaceId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
export type TBot = {
|
||||||
|
_id: string;
|
||||||
|
name: string;
|
||||||
|
workspace: string;
|
||||||
|
isActive: boolean;
|
||||||
|
publicKey: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
__v: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TSetBotActiveStatusDto = {
|
||||||
|
workspaceId: string;
|
||||||
|
botId: string;
|
||||||
|
isActive: boolean;
|
||||||
|
botKey?: {
|
||||||
|
encryptedKey: string;
|
||||||
|
nonce: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
export * from "./auth";
|
export * from "./auth";
|
||||||
|
export * from "./bots";
|
||||||
export * from "./incidentContacts";
|
export * from "./incidentContacts";
|
||||||
|
export * from "./integrationAuth";
|
||||||
|
export * from "./integrations";
|
||||||
export * from "./keys";
|
export * from "./keys";
|
||||||
export * from "./organization";
|
export * from "./organization";
|
||||||
export * from "./secretFolders";
|
export * from "./secretFolders";
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
export {
|
export {
|
||||||
useGetIntegrationAuthApps,
|
useDeleteIntegrationAuth,
|
||||||
useGetIntegrationAuthById,
|
useGetIntegrationAuthApps,
|
||||||
useGetIntegrationAuthRailwayEnvironments,
|
useGetIntegrationAuthById,
|
||||||
useGetIntegrationAuthRailwayServices,
|
useGetIntegrationAuthRailwayEnvironments,
|
||||||
useGetIntegrationAuthTeams,
|
useGetIntegrationAuthRailwayServices,
|
||||||
useGetIntegrationAuthVercelBranches} from "./queries";
|
useGetIntegrationAuthTeams,
|
||||||
|
useGetIntegrationAuthVercelBranches
|
||||||
|
} from "./queries";
|
||||||
|
|||||||
@@ -1,204 +1,237 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
import { apiRequest } from "@app/config/request";
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
import {
|
import { workspaceKeys } from "../workspace/queries";
|
||||||
App,
|
import { App, Environment, IntegrationAuth, Service, Team } from "./types";
|
||||||
Environment,
|
|
||||||
IntegrationAuth,
|
|
||||||
Service,
|
|
||||||
Team
|
|
||||||
} from "./types";
|
|
||||||
|
|
||||||
const integrationAuthKeys = {
|
const integrationAuthKeys = {
|
||||||
getIntegrationAuthById: (integrationAuthId: string) => [{ integrationAuthId }, "integrationAuth"] as const,
|
getIntegrationAuthById: (integrationAuthId: string) =>
|
||||||
getIntegrationAuthApps: (integrationAuthId: string, teamId?: string) => [{ integrationAuthId, teamId }, "integrationAuthApps"] as const,
|
[{ integrationAuthId }, "integrationAuth"] as const,
|
||||||
getIntegrationAuthTeams: (integrationAuthId: string) => [{ integrationAuthId }, "integrationAuthTeams"] as const,
|
getIntegrationAuthApps: (integrationAuthId: string, teamId?: string) =>
|
||||||
getIntegrationAuthVercelBranches: ({
|
[{ integrationAuthId, teamId }, "integrationAuthApps"] as const,
|
||||||
integrationAuthId,
|
getIntegrationAuthTeams: (integrationAuthId: string) =>
|
||||||
appId,
|
[{ integrationAuthId }, "integrationAuthTeams"] as const,
|
||||||
}: {
|
getIntegrationAuthVercelBranches: ({
|
||||||
integrationAuthId: string;
|
|
||||||
appId: string;
|
|
||||||
}) => [{ integrationAuthId, appId }, "integrationAuthVercelBranches"] as const,
|
|
||||||
getIntegrationAuthRailwayEnvironments: ({
|
|
||||||
integrationAuthId,
|
|
||||||
appId
|
|
||||||
}: {
|
|
||||||
integrationAuthId: string;
|
|
||||||
appId: string;
|
|
||||||
}) => [{ integrationAuthId, appId }, "integrationAuthRailwayEnvironments"] as const,
|
|
||||||
getIntegrationAuthRailwayServices: ({
|
|
||||||
integrationAuthId,
|
|
||||||
appId
|
|
||||||
}: {
|
|
||||||
integrationAuthId: string;
|
|
||||||
appId: string;
|
|
||||||
}) => [{ integrationAuthId, appId }, "integrationAuthRailwayServices"] as const
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetchIntegrationAuthById = async (integrationAuthId: string) => {
|
|
||||||
const { data } = await apiRequest.get<{ integrationAuth: IntegrationAuth }>(`/api/v1/integration-auth/${integrationAuthId}`);
|
|
||||||
return data.integrationAuth;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetchIntegrationAuthApps = async ({
|
|
||||||
integrationAuthId,
|
|
||||||
teamId
|
|
||||||
}: {
|
|
||||||
integrationAuthId: string;
|
|
||||||
teamId?: string;
|
|
||||||
}) => {
|
|
||||||
const searchParams = new URLSearchParams(teamId ? { teamId } : undefined);
|
|
||||||
const { data } = await apiRequest.get<{ apps: App[] }>(
|
|
||||||
`/api/v1/integration-auth/${integrationAuthId}/apps`,
|
|
||||||
{ params: searchParams }
|
|
||||||
);
|
|
||||||
return data.apps;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetchIntegrationAuthTeams = async (integrationAuthId: string) => {
|
|
||||||
const { data } = await apiRequest.get<{ teams: Team[] }>(`/api/v1/integration-auth/${integrationAuthId}/teams`);
|
|
||||||
return data.teams;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetchIntegrationAuthVercelBranches = async ({
|
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
appId
|
appId
|
||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
appId: string;
|
appId: string;
|
||||||
|
}) => [{ integrationAuthId, appId }, "integrationAuthVercelBranches"] as const,
|
||||||
|
getIntegrationAuthRailwayEnvironments: ({
|
||||||
|
integrationAuthId,
|
||||||
|
appId
|
||||||
|
}: {
|
||||||
|
integrationAuthId: string;
|
||||||
|
appId: string;
|
||||||
|
}) => [{ integrationAuthId, appId }, "integrationAuthRailwayEnvironments"] as const,
|
||||||
|
getIntegrationAuthRailwayServices: ({
|
||||||
|
integrationAuthId,
|
||||||
|
appId
|
||||||
|
}: {
|
||||||
|
integrationAuthId: string;
|
||||||
|
appId: string;
|
||||||
|
}) => [{ integrationAuthId, appId }, "integrationAuthRailwayServices"] as const
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchIntegrationAuthById = async (integrationAuthId: string) => {
|
||||||
|
const { data } = await apiRequest.get<{ integrationAuth: IntegrationAuth }>(
|
||||||
|
`/api/v1/integration-auth/${integrationAuthId}`
|
||||||
|
);
|
||||||
|
return data.integrationAuth;
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchIntegrationAuthApps = async ({
|
||||||
|
integrationAuthId,
|
||||||
|
teamId
|
||||||
|
}: {
|
||||||
|
integrationAuthId: string;
|
||||||
|
teamId?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const { data: { branches } } = await apiRequest.get<{ branches: string[] }>(`/api/v1/integration-auth/${integrationAuthId}/vercel/branches`, {
|
const searchParams = new URLSearchParams(teamId ? { teamId } : undefined);
|
||||||
params: {
|
const { data } = await apiRequest.get<{ apps: App[] }>(
|
||||||
appId
|
`/api/v1/integration-auth/${integrationAuthId}/apps`,
|
||||||
}
|
{ params: searchParams }
|
||||||
});
|
);
|
||||||
|
return data.apps;
|
||||||
return branches;
|
};
|
||||||
|
|
||||||
|
const fetchIntegrationAuthTeams = async (integrationAuthId: string) => {
|
||||||
|
const { data } = await apiRequest.get<{ teams: Team[] }>(
|
||||||
|
`/api/v1/integration-auth/${integrationAuthId}/teams`
|
||||||
|
);
|
||||||
|
return data.teams;
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchIntegrationAuthVercelBranches = async ({
|
||||||
|
integrationAuthId,
|
||||||
|
appId
|
||||||
|
}: {
|
||||||
|
integrationAuthId: string;
|
||||||
|
appId: string;
|
||||||
|
}) => {
|
||||||
|
const {
|
||||||
|
data: { branches }
|
||||||
|
} = await apiRequest.get<{ branches: string[] }>(
|
||||||
|
`/api/v1/integration-auth/${integrationAuthId}/vercel/branches`,
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
appId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return branches;
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchIntegrationAuthRailwayEnvironments = async ({
|
const fetchIntegrationAuthRailwayEnvironments = async ({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
appId
|
appId
|
||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
appId: string;
|
appId: string;
|
||||||
}) => {
|
}) => {
|
||||||
const { data: { environments } } = await apiRequest.get<{ environments: Environment[] }>(`/api/v1/integration-auth/${integrationAuthId}/railway/environments`, {
|
const {
|
||||||
params: {
|
data: { environments }
|
||||||
appId
|
} = await apiRequest.get<{ environments: Environment[] }>(
|
||||||
}
|
`/api/v1/integration-auth/${integrationAuthId}/railway/environments`,
|
||||||
});
|
{
|
||||||
|
params: {
|
||||||
return environments;
|
appId
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return environments;
|
||||||
|
};
|
||||||
|
|
||||||
const fetchIntegrationAuthRailwayServices = async ({
|
const fetchIntegrationAuthRailwayServices = async ({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
appId
|
appId
|
||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
appId: string;
|
appId: string;
|
||||||
}) => {
|
}) => {
|
||||||
const { data: { services } } = await apiRequest.get<{ services: Service[] }>(`/api/v1/integration-auth/${integrationAuthId}/railway/services`, {
|
const {
|
||||||
params: {
|
data: { services }
|
||||||
appId
|
} = await apiRequest.get<{ services: Service[] }>(
|
||||||
}
|
`/api/v1/integration-auth/${integrationAuthId}/railway/services`,
|
||||||
});
|
{
|
||||||
|
params: {
|
||||||
return services;
|
appId
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return services;
|
||||||
|
};
|
||||||
|
|
||||||
export const useGetIntegrationAuthById = (integrationAuthId: string) => {
|
export const useGetIntegrationAuthById = (integrationAuthId: string) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: integrationAuthKeys.getIntegrationAuthById(integrationAuthId),
|
queryKey: integrationAuthKeys.getIntegrationAuthById(integrationAuthId),
|
||||||
queryFn: () => fetchIntegrationAuthById(integrationAuthId),
|
queryFn: () => fetchIntegrationAuthById(integrationAuthId),
|
||||||
enabled: true
|
enabled: true
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export const useGetIntegrationAuthApps = ({
|
export const useGetIntegrationAuthApps = ({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
teamId
|
teamId
|
||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
teamId?: string;
|
teamId?: string;
|
||||||
}) => {
|
}) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: integrationAuthKeys.getIntegrationAuthApps(integrationAuthId, teamId),
|
queryKey: integrationAuthKeys.getIntegrationAuthApps(integrationAuthId, teamId),
|
||||||
queryFn: () => fetchIntegrationAuthApps({
|
queryFn: () =>
|
||||||
integrationAuthId,
|
fetchIntegrationAuthApps({
|
||||||
teamId
|
integrationAuthId,
|
||||||
}),
|
teamId
|
||||||
enabled: true
|
}),
|
||||||
});
|
enabled: true
|
||||||
}
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const useGetIntegrationAuthTeams = (integrationAuthId: string) => {
|
export const useGetIntegrationAuthTeams = (integrationAuthId: string) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: integrationAuthKeys.getIntegrationAuthTeams(integrationAuthId),
|
queryKey: integrationAuthKeys.getIntegrationAuthTeams(integrationAuthId),
|
||||||
queryFn: () => fetchIntegrationAuthTeams(integrationAuthId),
|
queryFn: () => fetchIntegrationAuthTeams(integrationAuthId),
|
||||||
enabled: true
|
enabled: true
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export const useGetIntegrationAuthVercelBranches = ({
|
export const useGetIntegrationAuthVercelBranches = ({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
appId,
|
appId
|
||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
appId: string;
|
appId: string;
|
||||||
}) => {
|
}) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: integrationAuthKeys.getIntegrationAuthVercelBranches({
|
queryKey: integrationAuthKeys.getIntegrationAuthVercelBranches({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
appId,
|
appId
|
||||||
}),
|
}),
|
||||||
queryFn: () => fetchIntegrationAuthVercelBranches({
|
queryFn: () =>
|
||||||
integrationAuthId,
|
fetchIntegrationAuthVercelBranches({
|
||||||
appId,
|
integrationAuthId,
|
||||||
}),
|
appId
|
||||||
enabled: true
|
}),
|
||||||
});
|
enabled: true
|
||||||
}
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const useGetIntegrationAuthRailwayEnvironments = ({
|
export const useGetIntegrationAuthRailwayEnvironments = ({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
appId
|
appId
|
||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
appId: string;
|
appId: string;
|
||||||
}) => {
|
}) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: integrationAuthKeys.getIntegrationAuthRailwayEnvironments({
|
queryKey: integrationAuthKeys.getIntegrationAuthRailwayEnvironments({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
appId,
|
appId
|
||||||
}),
|
}),
|
||||||
queryFn: () => fetchIntegrationAuthRailwayEnvironments({
|
queryFn: () =>
|
||||||
integrationAuthId,
|
fetchIntegrationAuthRailwayEnvironments({
|
||||||
appId,
|
integrationAuthId,
|
||||||
}),
|
appId
|
||||||
enabled: true
|
}),
|
||||||
});
|
enabled: true
|
||||||
}
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const useGetIntegrationAuthRailwayServices = ({
|
export const useGetIntegrationAuthRailwayServices = ({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
appId
|
appId
|
||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
appId: string;
|
appId: string;
|
||||||
}) => {
|
}) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: integrationAuthKeys.getIntegrationAuthRailwayServices({
|
queryKey: integrationAuthKeys.getIntegrationAuthRailwayServices({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
appId,
|
appId
|
||||||
}),
|
}),
|
||||||
queryFn: () => fetchIntegrationAuthRailwayServices({
|
queryFn: () =>
|
||||||
integrationAuthId,
|
fetchIntegrationAuthRailwayServices({
|
||||||
appId,
|
integrationAuthId,
|
||||||
}),
|
appId
|
||||||
enabled: true
|
}),
|
||||||
});
|
enabled: true
|
||||||
}
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDeleteIntegrationAuth = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation<{}, {}, { id: string; workspaceId: string }>({
|
||||||
|
mutationFn: ({ id }) => apiRequest.delete(`/api/v1/integration-auth/${id}`),
|
||||||
|
onSuccess: (_, { workspaceId }) => {
|
||||||
|
queryClient.invalidateQueries(workspaceKeys.getWorkspaceAuthorization(workspaceId));
|
||||||
|
queryClient.invalidateQueries(workspaceKeys.getWorkspaceIntegrations(workspaceId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,28 +1,31 @@
|
|||||||
export type IntegrationAuth = {
|
export type IntegrationAuth = {
|
||||||
_id: string;
|
_id: string;
|
||||||
workspace: string;
|
integration: string;
|
||||||
integration: string;
|
workspace: string;
|
||||||
teamId?: string;
|
__v: number;
|
||||||
accountId?: string;
|
createdAt: string;
|
||||||
}
|
updatedAt: string;
|
||||||
|
algorithm: string;
|
||||||
|
keyEncoding: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type App = {
|
export type App = {
|
||||||
name: string;
|
name: string;
|
||||||
appId?: string;
|
appId?: string;
|
||||||
owner?: string;
|
owner?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type Team = {
|
export type Team = {
|
||||||
name: string;
|
name: string;
|
||||||
teamId: string;
|
teamId: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type Environment = {
|
export type Environment = {
|
||||||
name: string;
|
name: string;
|
||||||
environmentId: string;
|
environmentId: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type Service = {
|
export type Service = {
|
||||||
name: string;
|
name: string;
|
||||||
serviceId: string;
|
serviceId: string;
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export { useDeleteIntegration,useGetCloudIntegrations } from './queries';
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import { apiRequest } from '@app/config/request';
|
||||||
|
|
||||||
|
import { workspaceKeys } from '../workspace/queries';
|
||||||
|
import { TCloudIntegration } from './types';
|
||||||
|
|
||||||
|
export const integrationQueryKeys = {
|
||||||
|
getIntegrations: () => ['integrations'] as const
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchIntegrations = async () => {
|
||||||
|
const { data } = await apiRequest.get<{ integrationOptions: TCloudIntegration[] }>(
|
||||||
|
'/api/v1/integration-auth/integration-options'
|
||||||
|
);
|
||||||
|
|
||||||
|
return data.integrationOptions;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetCloudIntegrations = () =>
|
||||||
|
useQuery({
|
||||||
|
queryKey: integrationQueryKeys.getIntegrations(),
|
||||||
|
queryFn: () => fetchIntegrations()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useDeleteIntegration = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation<{}, {}, { id: string; workspaceId: string }>({
|
||||||
|
mutationFn: ({ id }) => apiRequest.delete(`/api/v1/integration/${id}`),
|
||||||
|
onSuccess: (_, { workspaceId }) => {
|
||||||
|
queryClient.invalidateQueries(workspaceKeys.getWorkspaceIntegrations(workspaceId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
export type TCloudIntegration = {
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
image: string;
|
||||||
|
isAvailable: boolean;
|
||||||
|
type: string;
|
||||||
|
clientId: string;
|
||||||
|
docsLink: string;
|
||||||
|
clientSlug: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TIntegration = {
|
||||||
|
_id: string;
|
||||||
|
workspace: string;
|
||||||
|
environment: string;
|
||||||
|
isActive: boolean;
|
||||||
|
url: any;
|
||||||
|
app: string;
|
||||||
|
appId: string;
|
||||||
|
targetEnvironment: string;
|
||||||
|
targetEnvironmentId: string;
|
||||||
|
targetService: string;
|
||||||
|
targetServiceId: string;
|
||||||
|
owner: string;
|
||||||
|
path: string;
|
||||||
|
region: string;
|
||||||
|
integration: string;
|
||||||
|
integrationAuth: string;
|
||||||
|
secretPath: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
__v: number;
|
||||||
|
};
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
export type { GetAuthTokenAPI } from "./auth/types";
|
export type { GetAuthTokenAPI } from "./auth/types";
|
||||||
export type { IncidentContact } from "./incidentContacts/types";
|
export type { IncidentContact } from "./incidentContacts/types";
|
||||||
|
export type { IntegrationAuth } from "./integrationAuth/types";
|
||||||
|
export type { TCloudIntegration, TIntegration } from "./integrations/types";
|
||||||
export type { UserWsKeyPair } from "./keys/types";
|
export type { UserWsKeyPair } from "./keys/types";
|
||||||
export type { Organization } from "./organization/types";
|
export type { Organization } from "./organization/types";
|
||||||
export type { CreateServiceTokenDTO, ServiceToken } from "./serviceTokens/types";
|
export type { CreateServiceTokenDTO, ServiceToken } from "./serviceTokens/types";
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ export {
|
|||||||
useGetUserWorkspaceMemberships,
|
useGetUserWorkspaceMemberships,
|
||||||
useGetUserWorkspaces,
|
useGetUserWorkspaces,
|
||||||
useGetUserWsEnvironments,
|
useGetUserWsEnvironments,
|
||||||
|
useGetWorkspaceAuthorizations,
|
||||||
useGetWorkspaceById,
|
useGetWorkspaceById,
|
||||||
useGetWorkspaceIndexStatus,
|
useGetWorkspaceIndexStatus,
|
||||||
|
useGetWorkspaceIntegrations,
|
||||||
useGetWorkspaceSecrets,
|
useGetWorkspaceSecrets,
|
||||||
useNameWorkspaceSecrets,
|
useNameWorkspaceSecrets,
|
||||||
useRenameWorkspace,
|
useRenameWorkspace,
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|||||||
|
|
||||||
import { apiRequest } from "@app/config/request";
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
import {
|
import { IntegrationAuth } from "../integrationAuth/types";
|
||||||
EncryptedSecret
|
import { TIntegration } from "../integrations/types";
|
||||||
} from "../secrets/types";
|
import { EncryptedSecret } from "../secrets/types";
|
||||||
import {
|
import {
|
||||||
CreateEnvironmentDTO,
|
CreateEnvironmentDTO,
|
||||||
CreateWorkspaceDTO,
|
CreateWorkspaceDTO,
|
||||||
@@ -19,11 +19,14 @@ import {
|
|||||||
WorkspaceEnv
|
WorkspaceEnv
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
const workspaceKeys = {
|
export const workspaceKeys = {
|
||||||
getWorkspaceById: (workspaceId: string) => [{ workspaceId }, "workspace"] as const,
|
getWorkspaceById: (workspaceId: string) => [{ workspaceId }, "workspace"] as const,
|
||||||
getWorkspaceSecrets: (workspaceId: string) => [{ workspaceId }, "workspace-secrets"] as const,
|
getWorkspaceSecrets: (workspaceId: string) => [{ workspaceId }, "workspace-secrets"] as const,
|
||||||
getWorkspaceIndexStatus: (workspaceId: string) => [{ workspaceId}, "workspace-index-status"] as const,
|
getWorkspaceIndexStatus: (workspaceId: string) =>
|
||||||
|
[{ workspaceId }, "workspace-index-status"] as const,
|
||||||
getWorkspaceMemberships: (orgId: string) => [{ orgId }, "workspace-memberships"],
|
getWorkspaceMemberships: (orgId: string) => [{ orgId }, "workspace-memberships"],
|
||||||
|
getWorkspaceAuthorization: (workspaceId: string) => [{ workspaceId }, "workspace-authorizations"],
|
||||||
|
getWorkspaceIntegrations: (workspaceId: string) => [{ workspaceId }, "workspace-integrations"],
|
||||||
getAllUserWorkspace: ["workspaces"] as const,
|
getAllUserWorkspace: ["workspaces"] as const,
|
||||||
getUserWsEnvironments: (workspaceId: string) => ["workspace-env", { workspaceId }] as const
|
getUserWsEnvironments: (workspaceId: string) => ["workspace-env", { workspaceId }] as const
|
||||||
};
|
};
|
||||||
@@ -42,15 +45,17 @@ const fetchWorkspaceIndexStatus = async (workspaceId: string) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
};
|
||||||
|
|
||||||
const fetchWorkspaceSecrets = async (workspaceId: string) => {
|
const fetchWorkspaceSecrets = async (workspaceId: string) => {
|
||||||
const { data: { secrets } } = await apiRequest.get<{ secrets: EncryptedSecret[] }>(
|
const {
|
||||||
|
data: { secrets }
|
||||||
|
} = await apiRequest.get<{ secrets: EncryptedSecret[] }>(
|
||||||
`/api/v3/workspaces/${workspaceId}/secrets`
|
`/api/v3/workspaces/${workspaceId}/secrets`
|
||||||
);
|
);
|
||||||
|
|
||||||
return secrets;
|
return secrets;
|
||||||
}
|
};
|
||||||
|
|
||||||
const fetchUserWorkspaces = async () => {
|
const fetchUserWorkspaces = async () => {
|
||||||
const { data } = await apiRequest.get<{ workspaces: Workspace[] }>("/api/v1/workspace");
|
const { data } = await apiRequest.get<{ workspaces: Workspace[] }>("/api/v1/workspace");
|
||||||
@@ -63,15 +68,15 @@ export const useGetWorkspaceIndexStatus = (workspaceId: string) => {
|
|||||||
queryFn: () => fetchWorkspaceIndexStatus(workspaceId),
|
queryFn: () => fetchWorkspaceIndexStatus(workspaceId),
|
||||||
enabled: true
|
enabled: true
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export const useGetWorkspaceSecrets = (workspaceId: string) => {
|
export const useGetWorkspaceSecrets = (workspaceId: string) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: workspaceKeys.getWorkspaceSecrets(workspaceId),
|
queryKey: workspaceKeys.getWorkspaceSecrets(workspaceId),
|
||||||
queryFn: () => fetchWorkspaceSecrets(workspaceId),
|
queryFn: () => fetchWorkspaceSecrets(workspaceId),
|
||||||
enabled: true
|
enabled: true
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export const useGetWorkspaceById = (workspaceId: string) => {
|
export const useGetWorkspaceById = (workspaceId: string) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
@@ -126,7 +131,39 @@ export const useNameWorkspaceSecrets = () => {
|
|||||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceIndexStatus(variables.workspaceId));
|
queryClient.invalidateQueries(workspaceKeys.getWorkspaceIndexStatus(variables.workspaceId));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const fetchWorkspaceAuthorization = async (workspaceId: string) => {
|
||||||
|
const { data } = await apiRequest.get<{ authorizations: IntegrationAuth[] }>(
|
||||||
|
`/api/v1/workspace/${workspaceId}/authorizations`
|
||||||
|
);
|
||||||
|
return data.authorizations;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetWorkspaceAuthorizations = <TData = IntegrationAuth[],>(
|
||||||
|
workspaceId: string,
|
||||||
|
select?: (data: IntegrationAuth[]) => TData
|
||||||
|
) =>
|
||||||
|
useQuery({
|
||||||
|
queryKey: workspaceKeys.getWorkspaceAuthorization(workspaceId),
|
||||||
|
queryFn: () => fetchWorkspaceAuthorization(workspaceId),
|
||||||
|
enabled: Boolean(workspaceId),
|
||||||
|
select
|
||||||
|
});
|
||||||
|
|
||||||
|
const fetchWorkspaceIntegrations = async (workspaceId: string) => {
|
||||||
|
const { data } = await apiRequest.get<{ integrations: TIntegration[] }>(
|
||||||
|
`/api/v1/workspace/${workspaceId}/integrations`
|
||||||
|
);
|
||||||
|
return data.integrations;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetWorkspaceIntegrations = (workspaceId: string) =>
|
||||||
|
useQuery({
|
||||||
|
queryKey: workspaceKeys.getWorkspaceIntegrations(workspaceId),
|
||||||
|
queryFn: () => fetchWorkspaceIntegrations(workspaceId),
|
||||||
|
enabled: Boolean(workspaceId)
|
||||||
|
});
|
||||||
|
|
||||||
// mutation
|
// mutation
|
||||||
export const useCreateWorkspace = () => {
|
export const useCreateWorkspace = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user