mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 12:38:36 +00:00
Convert all SecurityClient API calls to hooks except auth
This commit is contained in:
@@ -8,7 +8,7 @@ const encKeyKeys = {
|
||||
getUserWorkspaceKey: (workspaceID: string) => ["workspace-key-pair", { workspaceID }] as const
|
||||
};
|
||||
|
||||
const fetchUserWsKey = async (workspaceID: string) => {
|
||||
export const fetchUserWsKey = async (workspaceID: string) => {
|
||||
const { data } = await apiRequest.get<{ latestKey: UserWsKeyPair }>(
|
||||
`/api/v1/key/${workspaceID}/latest`
|
||||
);
|
||||
@@ -24,8 +24,23 @@ export const useGetUserWsKey = (workspaceID: string) =>
|
||||
});
|
||||
|
||||
// mutations
|
||||
export const uploadWsKey = async ({
|
||||
workspaceId,
|
||||
userId,
|
||||
encryptedKey,
|
||||
nonce
|
||||
}: UploadWsKeyDTO) => {
|
||||
return apiRequest.post(`/api/v1/key/${workspaceId}`, { key: { userId, encryptedKey, nonce } })
|
||||
}
|
||||
|
||||
export const useUploadWsKey = () =>
|
||||
useMutation<{}, {}, UploadWsKeyDTO>({
|
||||
mutationFn: ({ encryptedKey, nonce, userId, workspaceId }) =>
|
||||
apiRequest.post(`/api/v1/key/${workspaceId}`, { key: { userId, encryptedKey, nonce } })
|
||||
mutationFn: async ({ encryptedKey, nonce, userId, workspaceId }) => {
|
||||
return uploadWsKey({
|
||||
workspaceId,
|
||||
userId,
|
||||
encryptedKey,
|
||||
nonce
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -27,12 +27,16 @@ const organizationKeys = {
|
||||
getOrgLicenses: (orgId: string) => [{ orgId }, "organization-licenses"] as const
|
||||
};
|
||||
|
||||
export const fetchOrganizations = async () => {
|
||||
const { data: { organizations } } = await apiRequest.get<{ organizations: Organization[] }>("/api/v1/organization");
|
||||
return organizations;
|
||||
}
|
||||
|
||||
export const useGetOrganizations = () => {
|
||||
return useQuery({
|
||||
queryKey: organizationKeys.getUserOrganizations,
|
||||
queryFn: async () => {
|
||||
const { data: { organizations } } = await apiRequest.get<{ organizations: Organization[] }>("/api/v1/organization");
|
||||
return organizations;
|
||||
return fetchOrganizations();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -42,7 +46,6 @@ export const useRenameOrg = () => {
|
||||
|
||||
return useMutation<{}, {}, RenameOrgDTO>({
|
||||
mutationFn: ({ newOrgName, orgId }) => {
|
||||
console.log("useRenameOrg");
|
||||
return apiRequest.patch(`/api/v1/organization/${orgId}/name`, { name: newOrgName });
|
||||
},
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -7,6 +7,7 @@ export {
|
||||
useDeleteOrgMembership,
|
||||
useGetMyAPIKeys,
|
||||
useGetMyIp,
|
||||
useGetMyOrganizationProjects,
|
||||
useGetMySessions,
|
||||
useGetOrgUsers,
|
||||
useGetUser,
|
||||
|
||||
@@ -29,6 +29,7 @@ const userKeys = {
|
||||
myIp: ["ip"] as const,
|
||||
myAPIKeys: ["api-keys"] as const,
|
||||
mySessions: ["sessions"] as const,
|
||||
myOrganizationProjects: (orgId: string) => [{ orgId }, "organization-projects"] as const
|
||||
};
|
||||
|
||||
export const fetchUserDetails = async () => {
|
||||
@@ -147,7 +148,9 @@ export const useAddUserToOrg = () => {
|
||||
}
|
||||
|
||||
return useMutation<Response, {}, AddUserToOrgDTO>({
|
||||
mutationFn: (dto) => apiRequest.post("/api/v1/invite-org/signup", dto),
|
||||
mutationFn: (dto) => {
|
||||
return apiRequest.post("/api/v1/invite-org/signup", dto);
|
||||
},
|
||||
onSuccess: (_, { organizationId }) => {
|
||||
queryClient.invalidateQueries(userKeys.getOrgUsers(organizationId));
|
||||
}
|
||||
@@ -329,4 +332,22 @@ export const useUpdateMfaEnabled = () => {
|
||||
queryClient.invalidateQueries(userKeys.getUser);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const fetchMyOrganizationProjects = async (orgId: string) => {
|
||||
const { data: { workspaces } } = await apiRequest.get(
|
||||
`/api/v1/organization/${orgId}/my-workspaces`
|
||||
);
|
||||
|
||||
return workspaces;
|
||||
}
|
||||
|
||||
export const useGetMyOrganizationProjects = (orgId: string) => {
|
||||
return useQuery({
|
||||
queryKey: userKeys.myOrganizationProjects(orgId),
|
||||
queryFn: async () => {
|
||||
return fetchMyOrganizationProjects(orgId);
|
||||
},
|
||||
enabled: true
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user