mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 18:41:21 +00:00
feat(infisical-pg): connected project api changes with frontend
This commit is contained in:
@@ -1,123 +1,123 @@
|
||||
import { TRole } from "../roles/types";
|
||||
import { TOrgRole, TProjectRole } from "../roles/types";
|
||||
import { IdentityAuthMethod } from "./enums";
|
||||
|
||||
export type IdentityTrustedIp = {
|
||||
id: string;
|
||||
ipAddress: string;
|
||||
type: "ipv4" | "ipv6";
|
||||
prefix?: number;
|
||||
}
|
||||
id: string;
|
||||
ipAddress: string;
|
||||
type: "ipv4" | "ipv6";
|
||||
prefix?: number;
|
||||
};
|
||||
|
||||
export type Identity = {
|
||||
id: string;
|
||||
name: string;
|
||||
authMethod?: IdentityAuthMethod;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
id: string;
|
||||
name: string;
|
||||
authMethod?: IdentityAuthMethod;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type IdentityMembershipOrg = {
|
||||
id: string;
|
||||
identity: Identity;
|
||||
organization: string;
|
||||
role: "admin" | "member" | "viewer" | "no-access" | "custom";
|
||||
customRole?: TRole<string>;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
id: string;
|
||||
identity: Identity;
|
||||
organization: string;
|
||||
role: "admin" | "member" | "viewer" | "no-access" | "custom";
|
||||
customRole?: TOrgRole;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type IdentityMembership = {
|
||||
id: string;
|
||||
identity: Identity;
|
||||
organization: string;
|
||||
role: "admin" | "member" | "viewer" | "no-access" | "custom";
|
||||
customRole?: TRole<string>;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
id: string;
|
||||
identity: Identity;
|
||||
organization: string;
|
||||
role: "admin" | "member" | "viewer" | "no-access" | "custom";
|
||||
customRole?: TProjectRole;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type CreateIdentityDTO = {
|
||||
name: string;
|
||||
organizationId: string;
|
||||
role?: string;
|
||||
}
|
||||
name: string;
|
||||
organizationId: string;
|
||||
role?: string;
|
||||
};
|
||||
|
||||
export type UpdateIdentityDTO = {
|
||||
identityId: string;
|
||||
name?: string;
|
||||
role?: string;
|
||||
organizationId: string;
|
||||
}
|
||||
identityId: string;
|
||||
name?: string;
|
||||
role?: string;
|
||||
organizationId: string;
|
||||
};
|
||||
|
||||
export type DeleteIdentityDTO = {
|
||||
identityId: string;
|
||||
organizationId: string;
|
||||
}
|
||||
identityId: string;
|
||||
organizationId: string;
|
||||
};
|
||||
|
||||
export type IdentityUniversalAuth = {
|
||||
identityId: string;
|
||||
clientId: string;
|
||||
clientSecretTrustedIps: IdentityTrustedIp[];
|
||||
accessTokenTTL: number;
|
||||
accessTokenMaxTTL: number;
|
||||
accessTokenNumUsesLimit: number;
|
||||
accessTokenTrustedIps: IdentityTrustedIp[];
|
||||
}
|
||||
identityId: string;
|
||||
clientId: string;
|
||||
clientSecretTrustedIps: IdentityTrustedIp[];
|
||||
accessTokenTTL: number;
|
||||
accessTokenMaxTTL: number;
|
||||
accessTokenNumUsesLimit: number;
|
||||
accessTokenTrustedIps: IdentityTrustedIp[];
|
||||
};
|
||||
|
||||
export type AddIdentityUniversalAuthDTO = {
|
||||
organizationId: string;
|
||||
identityId: string;
|
||||
clientSecretTrustedIps: {
|
||||
ipAddress: string;
|
||||
}[];
|
||||
accessTokenTTL: number;
|
||||
accessTokenMaxTTL: number;
|
||||
accessTokenNumUsesLimit: number;
|
||||
accessTokenTrustedIps: {
|
||||
ipAddress: string;
|
||||
}[];
|
||||
}
|
||||
organizationId: string;
|
||||
identityId: string;
|
||||
clientSecretTrustedIps: {
|
||||
ipAddress: string;
|
||||
}[];
|
||||
accessTokenTTL: number;
|
||||
accessTokenMaxTTL: number;
|
||||
accessTokenNumUsesLimit: number;
|
||||
accessTokenTrustedIps: {
|
||||
ipAddress: string;
|
||||
}[];
|
||||
};
|
||||
|
||||
export type UpdateIdentityUniversalAuthDTO = {
|
||||
organizationId: string;
|
||||
identityId: string;
|
||||
clientSecretTrustedIps?: {
|
||||
ipAddress: string;
|
||||
}[];
|
||||
accessTokenTTL?: number;
|
||||
accessTokenMaxTTL?: number;
|
||||
accessTokenNumUsesLimit?: number;
|
||||
accessTokenTrustedIps?: {
|
||||
ipAddress: string;
|
||||
}[];
|
||||
}
|
||||
organizationId: string;
|
||||
identityId: string;
|
||||
clientSecretTrustedIps?: {
|
||||
ipAddress: string;
|
||||
}[];
|
||||
accessTokenTTL?: number;
|
||||
accessTokenMaxTTL?: number;
|
||||
accessTokenNumUsesLimit?: number;
|
||||
accessTokenTrustedIps?: {
|
||||
ipAddress: string;
|
||||
}[];
|
||||
};
|
||||
|
||||
export type CreateIdentityUniversalAuthClientSecretDTO = {
|
||||
identityId: string;
|
||||
description?: string;
|
||||
ttl?: number;
|
||||
numUsesLimit?: number;
|
||||
}
|
||||
identityId: string;
|
||||
description?: string;
|
||||
ttl?: number;
|
||||
numUsesLimit?: number;
|
||||
};
|
||||
|
||||
export type ClientSecretData = {
|
||||
id: string;
|
||||
identityUniversalAuth: string;
|
||||
isClientSecretRevoked: boolean;
|
||||
description: string;
|
||||
clientSecretPrefix: string;
|
||||
clientSecretNumUses: number;
|
||||
clientSecretNumUsesLimit: number;
|
||||
clientSecretTTL: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
id: string;
|
||||
identityUniversalAuth: string;
|
||||
isClientSecretRevoked: boolean;
|
||||
description: string;
|
||||
clientSecretPrefix: string;
|
||||
clientSecretNumUses: number;
|
||||
clientSecretNumUsesLimit: number;
|
||||
clientSecretTTL: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type CreateIdentityUniversalAuthClientSecretRes = {
|
||||
clientSecret: string;
|
||||
clientSecretData: ClientSecretData;
|
||||
}
|
||||
clientSecret: string;
|
||||
clientSecretData: ClientSecretData;
|
||||
};
|
||||
|
||||
export type DeleteIdentityUniversalAuthClientSecretDTO = {
|
||||
identityId: string;
|
||||
clientSecretId: string;
|
||||
}
|
||||
identityId: string;
|
||||
clientSecretId: string;
|
||||
};
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
export {
|
||||
useCreateOrgRole,
|
||||
useCreateRole,
|
||||
useCreateProjectRole,
|
||||
useDeleteOrgRole,
|
||||
useDeleteRole,
|
||||
useDeleteProjectRole,
|
||||
useUpdateOrgRole,
|
||||
useUpdateRole
|
||||
useUpdateProjectRole
|
||||
} from "./mutation";
|
||||
export {
|
||||
useGetOrgRoles,
|
||||
useGetRoles,
|
||||
useGetProjectRoles,
|
||||
useGetUserOrgPermissions,
|
||||
useGetUserProjectPermissions
|
||||
} from "./queries";
|
||||
|
||||
@@ -6,45 +6,53 @@ import { apiRequest } from "@app/config/request";
|
||||
import { roleQueryKeys } from "./queries";
|
||||
import {
|
||||
TCreateOrgRoleDTO,
|
||||
TCreateRoleDTO,
|
||||
TCreateProjectRoleDTO,
|
||||
TDeleteOrgRoleDTO,
|
||||
TDeleteRoleDTO,
|
||||
TDeleteProjectRoleDTO,
|
||||
TUpdateOrgRoleDTO,
|
||||
TUpdateRoleDTO
|
||||
TUpdateProjectRoleDTO
|
||||
} from "./types";
|
||||
|
||||
export const useCreateRole = <T extends string | undefined>() => {
|
||||
export const useCreateProjectRole = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (dto: TCreateRoleDTO<T>) => apiRequest.post("/api/v1/roles", dto),
|
||||
onSuccess: (_, { orgId, workspaceId }) => {
|
||||
queryClient.invalidateQueries(roleQueryKeys.getRoles({ orgId, workspaceId }));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateRole = <T extends string | undefined>() => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ id, ...dto }: TUpdateRoleDTO<T>) => apiRequest.patch(`/api/v1/roles/${id}`, dto),
|
||||
onSuccess: (_, { orgId, workspaceId }) => {
|
||||
queryClient.invalidateQueries(roleQueryKeys.getRoles({ orgId, workspaceId }));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteRole = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ orgId, id }: TDeleteRoleDTO) =>
|
||||
apiRequest.delete(`/api/v1/roles/${id}`, {
|
||||
data: { orgId }
|
||||
mutationFn: ({ projectId, permissions, ...dto }: TCreateProjectRoleDTO) =>
|
||||
apiRequest.post(`/api/ee/v1/workspace/${projectId}/roles`, {
|
||||
...dto,
|
||||
permissions: permissions.length ? packRules(permissions) : []
|
||||
}),
|
||||
onSuccess: (_, { orgId, workspaceId }) => {
|
||||
queryClient.invalidateQueries(roleQueryKeys.getRoles({ orgId, workspaceId }));
|
||||
onSuccess: (_, { projectId }) => {
|
||||
queryClient.invalidateQueries(roleQueryKeys.getProjectRoles(projectId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateProjectRole = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ id, projectId, permissions, ...dto }: TUpdateProjectRoleDTO) =>
|
||||
apiRequest.patch(`/api/ee/v1/workspace/${projectId}/roles/${id}`, {
|
||||
...dto,
|
||||
permissions: permissions?.length ? packRules(permissions) : []
|
||||
}),
|
||||
onSuccess: (_, { projectId }) => {
|
||||
queryClient.invalidateQueries(roleQueryKeys.getProjectRoles(projectId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteProjectRole = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ projectId, id }: TDeleteProjectRoleDTO) =>
|
||||
apiRequest.delete(`/api/ee/v1/workspace/${projectId}/roles/${id}`, {
|
||||
data: { projectId }
|
||||
}),
|
||||
onSuccess: (_, { projectId }) => {
|
||||
queryClient.invalidateQueries(roleQueryKeys.getProjectRoles(projectId));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -71,7 +79,7 @@ export const useUpdateOrgRole = () => {
|
||||
mutationFn: ({ id, orgId, permissions, ...dto }: TUpdateOrgRoleDTO) =>
|
||||
apiRequest.patch(`/api/ee/v1/organization/${orgId}/roles/${id}`, {
|
||||
...dto,
|
||||
permissions: permissions?.length ? packRules(permissions) : undefined
|
||||
permissions: permissions?.length ? packRules(permissions) : []
|
||||
}),
|
||||
onSuccess: (_, { orgId }) => {
|
||||
queryClient.invalidateQueries(roleQueryKeys.getOrgRoles(orgId));
|
||||
|
||||
@@ -10,12 +10,11 @@ import { ProjectPermissionSet } from "@app/context/ProjectPermissionContext/type
|
||||
|
||||
import { OrgUser } from "../users/types";
|
||||
import {
|
||||
TGetRolesDTO,
|
||||
TGetUserOrgPermissionsDTO,
|
||||
TGetUserProjectPermissionDTO,
|
||||
TOrgRole,
|
||||
TPermission,
|
||||
TRole
|
||||
TProjectRole
|
||||
} from "./types";
|
||||
|
||||
const $glob: FieldInstruction<string> = {
|
||||
@@ -37,7 +36,7 @@ const glob: JsInterpreter<FieldCondition<string>> = (node, object, context) => {
|
||||
const conditionsMatcher = buildMongoQueryMatcher({ $glob }, { glob });
|
||||
|
||||
export const roleQueryKeys = {
|
||||
getRoles: ({ orgId, workspaceId }: TGetRolesDTO) => ["roles", { orgId, workspaceId }] as const,
|
||||
getProjectRoles: (projectId: string) => ["roles", { projectId }] as const,
|
||||
getOrgRoles: (orgId: string) => ["org-roles", { orgId }] as const,
|
||||
getUserOrgPermissions: ({ orgId }: TGetUserOrgPermissionsDTO) =>
|
||||
["user-permissions", { orgId }] as const,
|
||||
@@ -45,25 +44,21 @@ export const roleQueryKeys = {
|
||||
["user-project-permissions", { workspaceId }] as const
|
||||
};
|
||||
|
||||
const getRoles = async ({ orgId, workspaceId }: TGetRolesDTO) => {
|
||||
const { data } = await apiRequest.get<{ data: { roles: TRole<typeof workspaceId>[] } }>(
|
||||
"/api/v1/roles",
|
||||
{
|
||||
params: {
|
||||
workspaceId,
|
||||
orgId
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return data.data.roles;
|
||||
const getProjectRoles = async (projectId: string) => {
|
||||
const { data } = await apiRequest.get<{
|
||||
data: { roles: Array<Omit<TProjectRole, "permissions"> & { permissions: unknown }> };
|
||||
}>(`/api/ee/v1/workspace/${projectId}/roles`);
|
||||
return data.data.roles.map(({ permissions, ...el }) => ({
|
||||
...el,
|
||||
permissions: unpackRules(permissions as PackRule<TPermission>[])
|
||||
}));
|
||||
};
|
||||
|
||||
export const useGetRoles = ({ orgId, workspaceId }: TGetRolesDTO) =>
|
||||
export const useGetProjectRoles = (projectId: string) =>
|
||||
useQuery({
|
||||
queryKey: roleQueryKeys.getRoles({ orgId, workspaceId }),
|
||||
queryFn: () => getRoles({ orgId, workspaceId }),
|
||||
enabled: Boolean(orgId)
|
||||
queryKey: roleQueryKeys.getProjectRoles(projectId),
|
||||
queryFn: () => getProjectRoles(projectId),
|
||||
enabled: Boolean(projectId)
|
||||
});
|
||||
|
||||
const getOrgRoles = async (orgId: string) => {
|
||||
@@ -109,7 +104,7 @@ export const useGetUserOrgPermissions = ({ orgId }: TGetUserOrgPermissionsDTO) =
|
||||
const getUserProjectPermissions = async ({ workspaceId }: TGetUserProjectPermissionDTO) => {
|
||||
const { data } = await apiRequest.get<{
|
||||
data: { permissions: PackRule<RawRuleOf<MongoAbility<OrgPermissionSet>>>[] };
|
||||
}>(`/api/v1/roles/workspace/${workspaceId}/permissions`, {});
|
||||
}>(`/api/ee/v1/workspace/${workspaceId}/permissions`, {});
|
||||
|
||||
return data.data.permissions;
|
||||
};
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
export type TGetRolesDTO = {
|
||||
orgId: string;
|
||||
export type TGetProjectRolesDTO = {
|
||||
workspaceId?: string;
|
||||
};
|
||||
|
||||
// @depreciated
|
||||
export type TRole<T extends string | undefined> = {
|
||||
id: string;
|
||||
organization: string;
|
||||
workspace: T;
|
||||
name: string;
|
||||
description: string;
|
||||
export type TProjectRole = {
|
||||
slug: string;
|
||||
permissions: T extends string ? TProjectPermission[] : TPermission[];
|
||||
name: string;
|
||||
projectId: string;
|
||||
id: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
description?: string;
|
||||
permissions: TPermission[];
|
||||
};
|
||||
|
||||
export type TOrgRole = {
|
||||
@@ -36,28 +33,7 @@ export type TPermission = {
|
||||
export type TProjectPermission = {
|
||||
conditions?: Record<string, any>;
|
||||
action: string;
|
||||
subject: string;
|
||||
};
|
||||
|
||||
export type TCreateRoleDTO<T extends string | undefined> = {
|
||||
orgId: string;
|
||||
workspaceId?: T;
|
||||
name: string;
|
||||
description?: string;
|
||||
slug: string;
|
||||
permissions: T extends string ? TProjectPermission[] : TPermission[];
|
||||
};
|
||||
|
||||
export type TUpdateRoleDTO<T extends string | undefined> = {
|
||||
orgId: string;
|
||||
id: string;
|
||||
workspaceId?: T;
|
||||
} & Partial<Omit<TCreateRoleDTO<T>, "orgId" | "workspaceId">>;
|
||||
|
||||
export type TDeleteRoleDTO = {
|
||||
orgId: string;
|
||||
id: string;
|
||||
workspaceId?: string;
|
||||
subject: [string];
|
||||
};
|
||||
|
||||
export type TGetUserOrgPermissionsDTO = {
|
||||
@@ -85,3 +61,21 @@ export type TDeleteOrgRoleDTO = {
|
||||
orgId: string;
|
||||
id: string;
|
||||
};
|
||||
|
||||
export type TCreateProjectRoleDTO = {
|
||||
projectId: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
slug: string;
|
||||
permissions: TPermission[];
|
||||
};
|
||||
|
||||
export type TUpdateProjectRoleDTO = {
|
||||
projectId: string;
|
||||
id: string;
|
||||
} & Partial<Omit<TCreateOrgRoleDTO, "orgId">>;
|
||||
|
||||
export type TDeleteProjectRoleDTO = {
|
||||
projectId: string;
|
||||
id: string;
|
||||
};
|
||||
|
||||
@@ -196,7 +196,7 @@ export const useToggleAutoCapitalization = () => {
|
||||
|
||||
return useMutation<{}, {}, ToggleAutoCapitalizationDTO>({
|
||||
mutationFn: ({ workspaceID, state }) =>
|
||||
apiRequest.patch(`/api/v2/workspace/${workspaceID}/auto-capitalization`, {
|
||||
apiRequest.post(`/api/v1/workspace/${workspaceID}/auto-capitalization`, {
|
||||
autoCapitalization: state
|
||||
}),
|
||||
onSuccess: () => {
|
||||
@@ -245,7 +245,7 @@ export const useReorderWsEnvironment = () => {
|
||||
otherEnvironmentSlug,
|
||||
otherEnvironmentName
|
||||
}) => {
|
||||
return apiRequest.patch(`/api/v2/workspace/${workspaceId}/environments`, {
|
||||
return apiRequest.patch(`/api/v1/workspace/${workspaceId}/environments`, {
|
||||
environmentSlug,
|
||||
environmentName,
|
||||
otherEnvironmentSlug,
|
||||
@@ -263,7 +263,7 @@ export const useUpdateWsEnvironment = () => {
|
||||
|
||||
return useMutation<{}, {}, UpdateEnvironmentDTO>({
|
||||
mutationFn: ({ workspaceId, id, name, slug }) => {
|
||||
return apiRequest.put(`/api/v2/workspace/${workspaceId}/environments/${id}`, {
|
||||
return apiRequest.patch(`/api/v1/workspace/${workspaceId}/environments/${id}`, {
|
||||
name,
|
||||
slug
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ export type Workspace = {
|
||||
__v: number;
|
||||
id: string;
|
||||
name: string;
|
||||
organization: string;
|
||||
orgId: string;
|
||||
autoCapitalization: boolean;
|
||||
environments: WorkspaceEnv[];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user