mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 13:22:08 +00:00
Merge pull request #3338 from Infisical/feat/vercelSecretSyncIntegration
Add secret sync vercel integration
This commit is contained in:
+3
@@ -11,6 +11,7 @@ import { DatabricksSyncFields } from "./DatabricksSyncFields";
|
||||
import { GcpSyncFields } from "./GcpSyncFields";
|
||||
import { GitHubSyncFields } from "./GitHubSyncFields";
|
||||
import { HumanitecSyncFields } from "./HumanitecSyncFields";
|
||||
import { VercelSyncFields } from "./VercelSyncFields";
|
||||
|
||||
export const SecretSyncDestinationFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm>();
|
||||
@@ -34,6 +35,8 @@ export const SecretSyncDestinationFields = () => {
|
||||
return <DatabricksSyncFields />;
|
||||
case SecretSync.Humanitec:
|
||||
return <HumanitecSyncFields />;
|
||||
case SecretSync.Vercel:
|
||||
return <VercelSyncFields />;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Config Field: ${destination}`);
|
||||
}
|
||||
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
import { useMemo } from "react";
|
||||
import { Controller, useFormContext, useWatch } from "react-hook-form";
|
||||
import { SingleValue } from "react-select";
|
||||
import { faCircleInfo } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
|
||||
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
|
||||
import { FilterableSelect, FormControl, Tooltip } from "@app/components/v2";
|
||||
import {
|
||||
TVercelConnectionApp,
|
||||
useVercelConnectionListOrganizations
|
||||
} from "@app/hooks/api/appConnections/vercel";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
import { TSecretSyncForm } from "../schemas";
|
||||
|
||||
const vercelEnvironments = [
|
||||
{ name: "Development", slug: "development" },
|
||||
{ name: "Preview", slug: "preview" },
|
||||
{ name: "Production", slug: "production" }
|
||||
];
|
||||
|
||||
export const VercelSyncFields = () => {
|
||||
const { control, watch, setValue } = useFormContext<
|
||||
TSecretSyncForm & { destination: SecretSync.Vercel }
|
||||
>();
|
||||
|
||||
const connectionId = useWatch({ name: "connection.id", control });
|
||||
const currentApp = watch("destinationConfig.app");
|
||||
const currentEnv = watch("destinationConfig.env");
|
||||
|
||||
const { data: projects, isLoading: isProjectsLoading } = useVercelConnectionListOrganizations(
|
||||
connectionId,
|
||||
{
|
||||
enabled: Boolean(connectionId)
|
||||
}
|
||||
);
|
||||
|
||||
const selectedProject = projects
|
||||
?.find((project) => project.apps.some((app) => app.id === currentApp))
|
||||
?.apps.find((app) => app.id === currentApp);
|
||||
|
||||
const allApps =
|
||||
projects?.flatMap((project) =>
|
||||
project.apps.map((app) => ({ ...app, project: project.name, projectId: project.id }))
|
||||
) || [];
|
||||
|
||||
const environmentOptions = useMemo(() => {
|
||||
return vercelEnvironments
|
||||
.map((env) => ({
|
||||
key: env.slug,
|
||||
type: env.slug,
|
||||
name: env.name
|
||||
}))
|
||||
.concat(
|
||||
selectedProject?.envs?.map((env) => ({
|
||||
key: env.id,
|
||||
type: env.type,
|
||||
name: env.slug
|
||||
})) || []
|
||||
);
|
||||
}, [currentApp]);
|
||||
|
||||
const previewBranchOptions =
|
||||
selectedProject?.previewBranches?.map((branch) => ({
|
||||
id: branch,
|
||||
name: branch
|
||||
})) || [];
|
||||
|
||||
const isPreviewEnvironment = currentEnv === "preview";
|
||||
|
||||
return (
|
||||
<>
|
||||
<SecretSyncConnectionField
|
||||
onChange={() => {
|
||||
setValue("destinationConfig.app", "");
|
||||
setValue("destinationConfig.appName", "");
|
||||
setValue("destinationConfig.env", "production");
|
||||
setValue("destinationConfig.branch", "");
|
||||
}}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="destinationConfig.app"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
label="Vercel App"
|
||||
helperText={
|
||||
<Tooltip
|
||||
className="max-w-md"
|
||||
content="Ensure the project exists and the API token scope for this connection includes the desired project."
|
||||
>
|
||||
<div>
|
||||
<span>Don't see the project you're looking for?</span>{" "}
|
||||
<FontAwesomeIcon icon={faCircleInfo} className="text-mineshaft-400" />
|
||||
</div>
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isProjectsLoading && Boolean(connectionId)}
|
||||
isDisabled={!connectionId}
|
||||
value={allApps.find((app) => app.id === value) ?? null}
|
||||
onChange={(option) => {
|
||||
const appId = (option as SingleValue<TVercelConnectionApp>)?.id ?? null;
|
||||
onChange(appId);
|
||||
setValue("destinationConfig.branch", "");
|
||||
setValue(
|
||||
"destinationConfig.teamId",
|
||||
(option as SingleValue<TVercelConnectionApp>)?.projectId || ""
|
||||
);
|
||||
setValue(
|
||||
"destinationConfig.appName",
|
||||
(option as SingleValue<TVercelConnectionApp>)?.name || ""
|
||||
);
|
||||
}}
|
||||
options={allApps}
|
||||
placeholder="Select a project..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id.toString()}
|
||||
groupBy="project"
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="destinationConfig.env"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
label="Vercel App Environment"
|
||||
>
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isDisabled={!connectionId || !currentApp}
|
||||
value={
|
||||
value
|
||||
? {
|
||||
key: environmentOptions.find((env) => env.key === value)?.key,
|
||||
type: environmentOptions.find((env) => env.key === value)?.type,
|
||||
name: environmentOptions.find((env) => env.key === value)?.name
|
||||
}
|
||||
: null
|
||||
}
|
||||
onChange={(option) => {
|
||||
const envKey = (option as any)?.key ?? null;
|
||||
onChange(envKey);
|
||||
|
||||
setValue("destinationConfig.branch", "");
|
||||
}}
|
||||
options={environmentOptions}
|
||||
placeholder="Select an environment..."
|
||||
getOptionLabel={(option) => option.name || option.key || ""}
|
||||
getOptionValue={(option) => option.key || ""}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
{isPreviewEnvironment && (
|
||||
<Controller
|
||||
name="destinationConfig.branch"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
label="Vercel Preview Branch (Optional)"
|
||||
>
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isProjectsLoading && Boolean(connectionId) && Boolean(currentApp)}
|
||||
isDisabled={!connectionId || !currentApp}
|
||||
value={previewBranchOptions.find((branch) => branch.id === value) ?? null}
|
||||
onChange={(option) => onChange((option as SingleValue<{ id: string }>)?.id || "")}
|
||||
options={previewBranchOptions}
|
||||
placeholder="Select a branch..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option?.id || ""}
|
||||
isClearable
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
+1
@@ -39,6 +39,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
|
||||
case SecretSync.AzureAppConfiguration:
|
||||
case SecretSync.Databricks:
|
||||
case SecretSync.Humanitec:
|
||||
case SecretSync.Vercel:
|
||||
AdditionalSyncOptionsFieldsComponent = null;
|
||||
break;
|
||||
default:
|
||||
|
||||
+4
@@ -21,6 +21,7 @@ import { DatabricksSyncReviewFields } from "./DatabricksSyncReviewFields";
|
||||
import { GcpSyncReviewFields } from "./GcpSyncReviewFields";
|
||||
import { GitHubSyncReviewFields } from "./GitHubSyncReviewFields";
|
||||
import { HumanitecSyncReviewFields } from "./HumanitecSyncReviewFields";
|
||||
import { VercelSyncReviewFields } from "./VercelSyncReviewFields";
|
||||
|
||||
export const SecretSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm>();
|
||||
@@ -72,6 +73,9 @@ export const SecretSyncReviewFields = () => {
|
||||
case SecretSync.Humanitec:
|
||||
DestinationFieldsComponent = <HumanitecSyncReviewFields />;
|
||||
break;
|
||||
case SecretSync.Vercel:
|
||||
DestinationFieldsComponent = <VercelSyncReviewFields />;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Review Fields: ${destination}`);
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { useFormContext } from "react-hook-form";
|
||||
|
||||
import { TSecretSyncForm } from "@app/components/secret-syncs/forms/schemas";
|
||||
import { GenericFieldLabel } from "@app/components/v2";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
import { VercelEnvironmentType } from "@app/hooks/api/secretSyncs/types/vercel-sync";
|
||||
|
||||
export const VercelSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm & { destination: SecretSync.Vercel }>();
|
||||
const envId = watch("destinationConfig.env");
|
||||
const branchId = watch("destinationConfig.branch");
|
||||
const appName = watch("destinationConfig.appName");
|
||||
|
||||
return (
|
||||
<>
|
||||
<GenericFieldLabel label="Vercel App">{appName}</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Environment">{envId}</GenericFieldLabel>
|
||||
{envId === VercelEnvironmentType.Preview && branchId && (
|
||||
<GenericFieldLabel label="Preview Branch">{branchId}</GenericFieldLabel>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -9,6 +9,7 @@ import { AzureAppConfigurationSyncDestinationSchema } from "./azure-app-configur
|
||||
import { AzureKeyVaultSyncDestinationSchema } from "./azure-key-vault-sync-destination-schema";
|
||||
import { GcpSyncDestinationSchema } from "./gcp-sync-destination-schema";
|
||||
import { HumanitecSyncDestinationSchema } from "./humanitec-sync-destination-schema";
|
||||
import { VercelSyncDestinationSchema } from "./vercel-sync-destination-schema";
|
||||
|
||||
const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
AwsParameterStoreSyncDestinationSchema,
|
||||
@@ -18,7 +19,8 @@ const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
AzureKeyVaultSyncDestinationSchema,
|
||||
AzureAppConfigurationSyncDestinationSchema,
|
||||
DatabricksSyncDestinationSchema,
|
||||
HumanitecSyncDestinationSchema
|
||||
HumanitecSyncDestinationSchema,
|
||||
VercelSyncDestinationSchema
|
||||
]);
|
||||
|
||||
export const SecretSyncFormSchema = SecretSyncUnionSchema;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { BaseSecretSyncSchema } from "@app/components/secret-syncs/forms/schemas/base-secret-sync-schema";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
import { VercelEnvironmentType } from "@app/hooks/api/secretSyncs/types/vercel-sync";
|
||||
|
||||
export const VercelSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
||||
z.object({
|
||||
destination: z.literal(SecretSync.Vercel),
|
||||
destinationConfig: z.object({
|
||||
app: z.string().trim().min(1, "Project required"),
|
||||
appName: z.string().trim().min(1, "Project required"),
|
||||
env: z.nativeEnum(VercelEnvironmentType).or(z.string()),
|
||||
branch: z.string().trim().optional(),
|
||||
teamId: z.string().trim()
|
||||
})
|
||||
})
|
||||
);
|
||||
Reference in New Issue
Block a user