mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-12 02:29:09 +00:00
91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import { apiRequest } from "@app/config/request";
|
|
|
|
import {
|
|
GetIdentityAuthTemplatesDTO,
|
|
GetTemplateUsagesDTO,
|
|
IdentityAuthTemplate,
|
|
MachineAuthTemplateUsage
|
|
} from "./types";
|
|
|
|
export const identityAuthTemplatesKeys = {
|
|
all: ["identity-auth-templates"] as const,
|
|
getTemplates: (dto: GetIdentityAuthTemplatesDTO) =>
|
|
[...identityAuthTemplatesKeys.all, "list", dto] as const,
|
|
getTemplate: (templateId: string) =>
|
|
[...identityAuthTemplatesKeys.all, "single", templateId] as const,
|
|
getTemplatesByOrgId: (authMethod: string) =>
|
|
[...identityAuthTemplatesKeys.all, "list", authMethod] as const,
|
|
getTemplateUsages: (templateId: string) =>
|
|
[...identityAuthTemplatesKeys.all, "usages", templateId] as const
|
|
};
|
|
|
|
export const useGetIdentityAuthTemplates = (dto: GetIdentityAuthTemplatesDTO) => {
|
|
return useQuery({
|
|
queryKey: identityAuthTemplatesKeys.getTemplates(dto),
|
|
queryFn: async () => {
|
|
const { data } = await apiRequest.get<{
|
|
templates: IdentityAuthTemplate[];
|
|
totalCount: number;
|
|
}>("/api/v1/identities/templates/search", {
|
|
params: {
|
|
organizationId: dto.organizationId,
|
|
limit: dto.limit || 50,
|
|
offset: dto.offset || 0
|
|
}
|
|
});
|
|
return data;
|
|
},
|
|
enabled: Boolean(dto.organizationId)
|
|
});
|
|
};
|
|
|
|
export const useGetIdentityAuthTemplate = (templateId: string, organizationId: string) => {
|
|
return useQuery({
|
|
queryKey: identityAuthTemplatesKeys.getTemplate(templateId),
|
|
queryFn: async () => {
|
|
const { data } = await apiRequest.get<{ template: IdentityAuthTemplate }>(
|
|
`/api/v1/identities/templates/${templateId}`,
|
|
{
|
|
params: { organizationId }
|
|
}
|
|
);
|
|
return data.template;
|
|
},
|
|
enabled: Boolean(templateId) && Boolean(organizationId)
|
|
});
|
|
};
|
|
|
|
export const useGetIdentityAuthTemplatesByOrgId = (authMethod: string) => {
|
|
return useQuery({
|
|
queryKey: identityAuthTemplatesKeys.getTemplatesByOrgId(authMethod),
|
|
queryFn: async () => {
|
|
const { data } = await apiRequest.get<IdentityAuthTemplate[]>(
|
|
"/api/v1/identities/templates",
|
|
{
|
|
params: { authMethod }
|
|
}
|
|
);
|
|
return data;
|
|
},
|
|
enabled: Boolean(authMethod)
|
|
});
|
|
};
|
|
|
|
export const useGetTemplateUsages = (dto: GetTemplateUsagesDTO) => {
|
|
return useQuery({
|
|
queryKey: identityAuthTemplatesKeys.getTemplateUsages(dto.templateId),
|
|
queryFn: async () => {
|
|
const { data } = await apiRequest.get<MachineAuthTemplateUsage[]>(
|
|
`/api/v1/identities/templates/${dto.templateId}/usage`,
|
|
{
|
|
params: { organizationId: dto.organizationId }
|
|
}
|
|
);
|
|
return data;
|
|
},
|
|
enabled: Boolean(dto.templateId) && Boolean(dto.organizationId)
|
|
});
|
|
};
|