Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

6.5 KB
Raw Blame
import type { CaStatus } from "../ca";
import { WorkflowIntegrationPlatform } from "../workflowIntegrations/types";
import { ProjectType, TListProjectIdentitiesDTO, TSearchProjectsDTO } from "./types";

export const projectKeys = {
  allProjectQueries: () => ["projects"] as const,
  getProjectById: (projectId: string) =>
    [...projectKeys.allProjectQueries(), { projectId }] as const,
  getProjectSecrets: (projectId: string) => [{ projectId }, "project-secrets"] as const,
  getProjectIndexStatus: (projectId: string) => [{ projectId }, "project-index-status"] as const,
  getProjectUpgradeStatus: (projectId: string) => [{ projectId }, "project-upgrade-status"],
  getProjectMemberships: (orgId: string) => [{ orgId }, "project-memberships"],
  getProjectAuthorization: (projectId: string) => [{ projectId }, "project-authorizations"],
  getProjectIntegrations: (projectId: string) => [{ projectId }, "project-integrations"],
  getAllUserProjects: () => [...projectKeys.allProjectQueries()] as const,
  getAccessibleProjectsWithSubOrgs: (orgId: string) =>
    [...projectKeys.getAllUserProjects(), "with-sub-orgs", { orgId }] as const,
  getMyPendingProjectAccessRequests: () =>
    [...projectKeys.allProjectQueries(), "my-pending-access-requests"] as const,
  getDeletedProjects: (type?: ProjectType) =>
    [...projectKeys.allProjectQueries(), "deleted", { type }] as const,
  getProjectAuditLogs: (projectId: string) => [{ projectId }, "project-audit-logs"] as const,
  getProjectUsers: (
    projectId: string,
    includeGroupMembers: boolean = false,
    roles: string[] = []
  ) => [{ projectId, includeGroupMembers, roles }, "project-users"] as const,
  getAvailableProjectUsers: (projectId: string) =>
    [{ projectId }, "project-available-users"] as const,
  getProjectUserDetails: (projectId: string, membershipId: string) =>
    [{ projectId, membershipId }, "project-user-details"] as const,
  // the flag is a trailing element so two-argument calls prefix-match both variants
  getMembershipPermissionAudit: (
    projectId: string,
    membershipId: string,
    includeFolderPermissions?: boolean
  ) =>
    [
      { projectId, membershipId },
      "membership-permission-audit",
      ...(includeFolderPermissions !== undefined ? [{ includeFolderPermissions }] : [])
    ] as const,
  getIdentityPermissionAudit: (
    projectId: string,
    identityId: string,
    includeFolderPermissions?: boolean
  ) =>
    [
      { projectId, identityId },
      "identity-permission-audit",
      ...(includeFolderPermissions !== undefined ? [{ includeFolderPermissions }] : [])
    ] as const,
  getProjectIdentityMemberships: (projectId: string) =>
    [{ projectId }, "project-identity-memberships"] as const,
  getProjectIdentityMembershipDetails: (projectId: string, identityId: string) =>
    [{ projectId, identityId }, "project-identity-membership-details"] as const,
  getProjectIdentityMembershipDetailsV2: (projectId: string, identityId: string) =>
    [{ projectId, identityId }, "project-identity-membership-details"] as const,
  // allows invalidation using above key without knowing params
  getProjectIdentityMembershipsWithParams: ({ projectId, ...params }: TListProjectIdentitiesDTO) =>
    [...projectKeys.getProjectIdentityMemberships(projectId), params] as const,
  searchProject: (dto: TSearchProjectsDTO) =>
    [...projectKeys.allProjectQueries(), "search-projects", dto] as const,
  getProjectGroupMemberships: (projectId: string) => [{ projectId }, "project-groups"] as const,
  getProjectGroupMembershipDetails: (projectId: string, groupId: string) =>
    [{ projectId, groupId }, "project-group-membership-details"] as const,
  getProjectCas: ({ projectId }: { projectId: string }) => [{ projectId }, "project-cas"] as const,
  specificProjectCas: ({ projectId, status }: { projectId: string; status?: CaStatus }) =>
    [...projectKeys.getProjectCas({ projectId }), { status }] as const,
  allProjectCertificates: () => ["project-certificates"] as const,
  forProjectCertificates: (projectId: string) =>
    [...projectKeys.allProjectCertificates(), projectId] as const,
  specificProjectCertificates: ({
    projectId,
    offset,
    limit,
    friendlyName,
    commonName,
    forPkiSync,
    search,
    status,
    includeDeleted,
    profileIds,
    fromDate,
    toDate,
    metadataFilter,
    extendedKeyUsage,
    keyAlgorithm,
    signatureAlgorithm,
    keySizes,
    caIds,
    enrollmentTypes,
    source,
    notAfterFrom,
    notAfterTo,
    notBeforeFrom,
    notBeforeTo,
    applicationId,
    applicationIds,
    sortBy,
    sortOrder
  }: {
    projectId: string;
    offset: number;
    limit: number;
    friendlyName?: string;
    commonName?: string;
    forPkiSync?: boolean;
    search?: string;
    status?: string | string[];
    includeDeleted?: boolean;
    profileIds?: string[];
    fromDate?: Date;
    toDate?: Date;
    metadataFilter?: Array<{ key: string; value?: string }>;
    extendedKeyUsage?: string;
    keyAlgorithm?: string | string[];
    signatureAlgorithm?: string;
    keySizes?: number[];
    caIds?: string[];
    enrollmentTypes?: string[];
    source?: string | string[];
    notAfterFrom?: Date;
    notAfterTo?: Date;
    notBeforeFrom?: Date;
    notBeforeTo?: Date;
    applicationId?: string;
    applicationIds?: string[];
    sortBy?: string;
    sortOrder?: "asc" | "desc";
  }) =>
    [
      ...projectKeys.forProjectCertificates(projectId),
      {
        offset,
        limit,
        friendlyName,
        commonName,
        forPkiSync,
        search,
        status,
        includeDeleted,
        profileIds,
        fromDate,
        toDate,
        metadataFilter,
        extendedKeyUsage,
        keyAlgorithm,
        signatureAlgorithm,
        keySizes,
        caIds,
        enrollmentTypes,
        source,
        notAfterFrom,
        notAfterTo,
        notBeforeFrom,
        notBeforeTo,
        applicationId,
        applicationIds,
        sortBy,
        sortOrder
      }
    ] as const,
  getProjectPkiAlerts: (projectId: string) => [{ projectId }, "project-pki-alerts"] as const,
  getProjectPkiSubscribers: (projectId: string) =>
    [{ projectId }, "project-pki-subscribers"] as const,
  getProjectPkiCollections: (projectId: string) =>
    [{ projectId }, "project-pki-collections"] as const,
  getProjectCertificateTemplates: (projectId: string) =>
    [{ projectId }, "project-certificate-templates"] as const,
  getProjectWorkflowIntegrationConfig: (
    projectId: string,
    integration: WorkflowIntegrationPlatform
  ) => [{ projectId, integration }, "project-workflow-integration-config"] as const
};