Skip to content

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

Merge branch 'main' into org-name-constraint

Scott Wilson7415bb93b8af
diff --cc frontend/src/hooks/api/reactQuery.tsx
index 63007a4edc,cd86229763..922b500b6a
--- a/frontend/src/hooks/api/reactQuery.tsx
+++ b/frontend/src/hooks/api/reactQuery.tsx
@@@ -18,147 -18,268 +18,143 @@@ export const SIGNUP_TEMP_TOKEN_CACHE_KE
export const MFA_TEMP_TOKEN_CACHE_KEY = ["infisical__mfa-temp-token"];
export const AUTH_TOKEN_CACHE_KEY = ["infisical__auth-token"];
- const camelCaseToSpaces = (input: string) => {
- return input.replace(/([a-z])([A-Z])/g, "$1 $2");
- };
-export const queryClient = new QueryClient({
- mutationCache: new MutationCache({
- onError: (error) => {
- if (axios.isAxiosError(error)) {
- const serverResponse = error.response?.data as TApiErrors;
- if (serverResponse?.error === ApiErrorTypes.ValidationError) {
- createNotification(
- {
- title: "Validation Error",
- type: "error",
- text: "Please check the input and try again.",
- callToAction: (
- <Modal>
- <ModalTrigger asChild>
- <Button variant="outline_bg" size="xs">
- Show more
- </Button>
- </ModalTrigger>
- <ModalContent title="Validation Error Details">
- <TableContainer>
- <Table>
- <THead>
- <Tr>
- <Th>Field</Th>
- <Th>Issue</Th>
- </Tr>
- </THead>
- <TBody>
- {serverResponse.message?.map(({ message, path }) => (
- <Tr key={path.join(".")}>
- <Td>{path.join(".")}</Td>
- <Td>{message.toLowerCase()}</Td>
- </Tr>
- ))}
- </TBody>
- </Table>
- </TableContainer>
- </ModalContent>
- </Modal>
- ),
- copyActions: [
- {
- value: serverResponse.reqId,
- name: "Request ID",
- label: `Request ID: ${serverResponse.reqId}`
- }
- ]
- },
- { closeOnClick: false }
- );
- return;
- }
- if (serverResponse?.error === ApiErrorTypes.PermissionBoundaryError) {
- createNotification(
- {
- title: "Forbidden Access",
- type: "error",
- text: `${serverResponse.message}.`,
- callToAction: serverResponse?.details?.missingPermissions?.length ? (
- <Modal>
- <ModalTrigger asChild>
- <Button variant="outline_bg" size="xs">
- Show more
- </Button>
- </ModalTrigger>
- <ModalContent title="Missing Permission">
- <div className="flex flex-col gap-2">
- {serverResponse.details?.missingPermissions?.map((el, index) => {
- const hasConditions = Boolean(Object.keys(el.conditions || {}).length);
- return (
- <div
- key={`Forbidden-error-details-${index + 1}`}
- className="rounded-md border border-gray-600 p-4"
- >
- <div>
- You are not authorized to perform the <b>{el.action}</b> action on the{" "}
- <b>{el.subject}</b> resource.{" "}
- {hasConditions &&
- "Your permission does not allow access to the following conditions:"}
- </div>
- {hasConditions && (
- <ul className="flex list-disc flex-col gap-1 pl-5 pt-2 text-sm">
- {Object.keys(el.conditions || {}).flatMap((field, fieldIndex) => {
- const operators = (
- el.conditions as Record<
- string,
- | string
- | { [K in PermissionConditionOperators]: string | string[] }
- >
- )[field];
-
- const formattedFieldName = camelCaseToSpaces(field).toLowerCase();
- if (typeof operators === "string") {
- return (
- <li
- key={`Forbidden-error-details-${index + 1}-${
- fieldIndex + 1
- }`}
- >
- <span className="font-bold capitalize">
- {formattedFieldName}
- </span>{" "}
- <span className="text-mineshaft-200">equal to</span>{" "}
- <span className="text-yellow-600">{operators}</span>
- </li>
- );
- }
--
- return Object.keys(operators).map((operator, operatorIndex) => (
- <li
- key={`Forbidden-error-details-${index + 1}-${
- fieldIndex + 1
- }-${operatorIndex + 1}`}
- >
- <span className="font-bold capitalize">
- {formattedFieldName}
- </span>{" "}
- <span className="text-mineshaft-200">
- {
- formatedConditionsOperatorNames[
- operator as PermissionConditionOperators
- ]
- }
- </span>{" "}
- <span className="text-yellow-600">
- {operators[
- operator as PermissionConditionOperators
- ].toString()}
- </span>
- </li>
- ));
- })}
- </ul>
- )}
- </div>
- );
- })}
- </div>
- </ModalContent>
- </Modal>
- ) : undefined,
- copyActions: [
- {
- value: serverResponse.reqId,
- name: "Request ID",
- label: `Request ID: ${serverResponse.reqId}`
- }
- ]
- },
- { closeOnClick: false }
- );
- return;
- }
- if (serverResponse?.error === ApiErrorTypes.ForbiddenError) {
- createNotification(
+export const onRequestError = (error: unknown) => {
+ if (axios.isAxiosError(error)) {
+ const serverResponse = error.response?.data as TApiErrors;
+ if (serverResponse?.error === ApiErrorTypes.ValidationError) {
+ createNotification(
+ {
+ title: "Validation Error",
+ type: "error",
+ text: "Please check the input and try again.",
+ callToAction: (
+ <Modal>
+ <ModalTrigger asChild>
+ <Button variant="outline_bg" size="xs">
+ Show more
+ </Button>
+ </ModalTrigger>
+ <ModalContent title="Validation Error Details">
+ <TableContainer>
+ <Table>
+ <THead>
+ <Tr>
+ <Th>Field</Th>
+ <Th>Issue</Th>
+ </Tr>
+ </THead>
+ <TBody>
+ {serverResponse.message?.map(({ message, path }) => (
+ <Tr key={path.join(".")}>
+ <Td>{path.join(".")}</Td>
+ <Td>{message.toLowerCase()}</Td>
+ </Tr>
+ ))}
+ </TBody>
+ </Table>
+ </TableContainer>
+ </ModalContent>
+ </Modal>
+ ),
+ copyActions: [
{
- title: "Forbidden Access",
- type: "error",
- text: `${serverResponse.message}.`,
- callToAction: serverResponse?.details?.length ? (
- <Modal>
- <ModalTrigger asChild>
- <Button variant="outline_bg" size="xs">
- Show more
- </Button>
- </ModalTrigger>
- <ModalContent
- title="Validation Rules"
- subTitle="Please review the allowed rules below."
- >
- <div className="flex flex-col gap-2">
- {serverResponse.details?.map((el, index) => {
- const hasConditions = Boolean(Object.keys(el.conditions || {}).length);
- return (
- <div
- key={`Forbidden-error-details-${index + 1}`}
- className="rounded-md border border-gray-600 p-4"
- >
- <div>
- {el.inverted ? "Cannot" : "Can"}{" "}
- <span className="text-yellow-600">
- {el.action.toString().replaceAll(",", ", ")}
- </span>{" "}
- {el.subject.toString()} {hasConditions && "with conditions:"}
- </div>
- {hasConditions && (
- <ul className="flex list-disc flex-col gap-1 pl-5 pt-2 text-sm">
- {Object.keys(el.conditions || {}).flatMap((field, fieldIndex) => {
- const operators = (
- el.conditions as Record<
- string,
- | string
- | { [K in PermissionConditionOperators]: string | string[] }
- >
- )[field];
+ value: serverResponse.reqId,
+ name: "Request ID",
+ label: `Request ID: ${serverResponse.reqId}`
+ }
+ ]
+ },
+ { closeOnClick: false }
+ );
+ return;
+ }
+ if (serverResponse?.error === ApiErrorTypes.ForbiddenError) {
+ createNotification(
+ {
+ title: "Forbidden Access",
+ type: "error",
+ text: `${serverResponse.message}.`,
+ callToAction: serverResponse?.details?.length ? (
+ <Modal>
+ <ModalTrigger asChild>
+ <Button variant="outline_bg" size="xs">
+ Show more
+ </Button>
+ </ModalTrigger>
+ <ModalContent
+ title="Validation Rules"
+ subTitle="Please review the allowed rules below."
+ >
+ <div className="flex flex-col gap-2">
+ {serverResponse.details?.map((el, index) => {
+ const hasConditions = Boolean(Object.keys(el.conditions || {}).length);
+ return (
+ <div
+ key={`Forbidden-error-details-${index + 1}`}
+ className="rounded-md border border-gray-600 p-4"
+ >
+ <div>
+ {el.inverted ? "Cannot" : "Can"}{" "}
+ <span className="text-yellow-600">
+ {el.action.toString().replaceAll(",", ", ")}
+ </span>{" "}
+ {el.subject.toString()} {hasConditions && "with conditions:"}
+ </div>
+ {hasConditions && (
+ <ul className="flex list-disc flex-col gap-1 pl-5 pt-2 text-sm">
+ {Object.keys(el.conditions || {}).flatMap((field, fieldIndex) => {
+ const operators = (
+ el.conditions as Record<
+ string,
+ | string
+ | { [K in PermissionConditionOperators]: string | string[] }
+ >
+ )[field];
- const formattedFieldName = camelCaseToSpaces(field).toLowerCase();
- if (typeof operators === "string") {
- return (
- <li
- key={`Forbidden-error-details-${index + 1}-${
- fieldIndex + 1
- }`}
- >
- <span className="font-bold capitalize">
- {formattedFieldName}
- </span>{" "}
- <span className="text-mineshaft-200">equal to</span>{" "}
- <span className="text-yellow-600">{operators}</span>
- </li>
- );
- }
+ const formattedFieldName = camelCaseToSpaces(field).toLowerCase();
+ if (typeof operators === "string") {
+ return (
+ <li
+ key={`Forbidden-error-details-${index + 1}-${fieldIndex + 1}`}
+ >
+ <span className="font-bold capitalize">
+ {formattedFieldName}
+ </span>{" "}
+ <span className="text-mineshaft-200">equal to</span>{" "}
+ <span className="text-yellow-600">{operators}</span>
+ </li>
+ );
+ }
- return Object.keys(operators).map((operator, operatorIndex) => (
- <li
- key={`Forbidden-error-details-${index + 1}-${
- fieldIndex + 1
- }-${operatorIndex + 1}`}
- >
- <span className="font-bold capitalize">
- {formattedFieldName}
- </span>{" "}
- <span className="text-mineshaft-200">
- {
- formatedConditionsOperatorNames[
- operator as PermissionConditionOperators
- ]
- }
- </span>{" "}
- <span className="text-yellow-600">
- {operators[
- operator as PermissionConditionOperators
- ].toString()}
- </span>
- </li>
- ));
- })}
- </ul>
- )}
- </div>
- );
- })}
- </div>
- </ModalContent>
- </Modal>
- ) : undefined,
- copyActions: [
- {
- value: serverResponse.reqId,
- name: "Request ID",
- label: `Request ID: ${serverResponse.reqId}`
- }
- ]
- },
- { closeOnClick: false }
- );
- return;
- }
- createNotification({
- title: "Bad Request",
- type: "error",
- text: `${serverResponse.message}${serverResponse.message?.endsWith(".") ? "" : "."}`,
+ return Object.keys(operators).map((operator, operatorIndex) => (
+ <li
+ key={`Forbidden-error-details-${index + 1}-${
+ fieldIndex + 1
+ }-${operatorIndex + 1}`}
+ >
+ <span className="font-bold capitalize">{formattedFieldName}</span>{" "}
+ <span className="text-mineshaft-200">
+ {
+ formatedConditionsOperatorNames[
+ operator as PermissionConditionOperators
+ ]
+ }
+ </span>{" "}
+ <span className="text-yellow-600">
+ {operators[operator as PermissionConditionOperators].toString()}
+ </span>
+ </li>
+ ));
+ })}
+ </ul>
+ )}
+ </div>
+ );
+ })}
+ </div>
+ </ModalContent>
+ </Modal>
+ ) : undefined,
copyActions: [
{
value: serverResponse.reqId,