Skip to content

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

feat(secret-sync): vercel team scope support

Daniel Hougaarda0bedb1b0176
diff --git a/backend/src/db/migrations/20260407010004_migrate-vercel-secret-syncs-to-new-destination-schema-format.ts b/backend/src/db/migrations/20260407010004_migrate-vercel-secret-syncs-to-new-destination-schema-format.ts
new file mode 100644
index 0000000000..646e7905ef
--- /dev/null
+++ b/backend/src/db/migrations/20260407010004_migrate-vercel-secret-syncs-to-new-destination-schema-format.ts
@@ -0,0 +1,35 @@
+import { Knex } from "knex";
+
+import { selectAllTableCols } from "@app/lib/knex";
+import { SecretSync } from "@app/services/secret-sync/secret-sync-enums";
+import { VercelSyncScope } from "@app/services/secret-sync/vercel";
+
+import { TableName } from "../schemas";
+
+export async function up(knex: Knex): Promise<void> {
+ const vercelSecretSyncs = await knex(TableName.SecretSync)
+ .where("destination", SecretSync.Vercel)
+ .select(selectAllTableCols(TableName.SecretSync));
+
+ if (vercelSecretSyncs?.length) {
+ await Promise.all(
+ vercelSecretSyncs.map(async (sync) => {
+ if (typeof sync.destinationConfig === "object" && sync.destinationConfig !== null) {
+ const destinationConfig = {
+ ...sync.destinationConfig,
+ scope: VercelSyncScope.Project
+ };
+
+ await knex(TableName.SecretSync).where("id", sync.id).update({
+ destinationConfig
+ });
+ }
+ })
+ );
+ }
+}
+
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
+export async function down(knex: Knex): Promise<void> {
+ // No down migration needed
+}
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index cc11399d7a..4b89a21ec9 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -2937,7 +2937,9 @@ export const SecretSyncs = {
appName: "The name of the Vercel app to sync secrets to.",
env: "The ID of the Vercel environment to sync secrets to.",
branch: "The branch to sync preview secrets to.",
- teamId: "The ID of the Vercel team to sync secrets to."
+ teamId: "The ID of the Vercel team to sync secrets to.",
+ targetEnvironments: "An optional array of Vercel environments to add shared environment variables to.",
+ targetProjects: "An optional array of Vercel projects to add shared environment variables to."
},
LARAVEL_FORGE: {
orgSlug: "The slug of the Laravel Forge org to sync secrets to.",
diff --git a/backend/src/services/app-connection/vercel/vercel-connection-fns.ts b/backend/src/services/app-connection/vercel/vercel-connection-fns.ts
index 76ad52759a..ac12f7a4d6 100644
--- a/backend/src/services/app-connection/vercel/vercel-connection-fns.ts
+++ b/backend/src/services/app-connection/vercel/vercel-connection-fns.ts
@@ -13,7 +13,9 @@ import {
TVercelConnectionConfig,
VercelApp,
VercelEnvironment,
- VercelOrgWithApps
+ VercelOrgWithApps,
+ VercelTeam,
+ VercelUserResponse
} from "./vercel-connection-types";
export const getVercelConnectionListItem = () => {
@@ -178,28 +180,11 @@ async function fetchPreviewBranches(projectId: string, apiToken: string): Promis
}
}
-type VercelTeam = {
- id: string;
- name: string;
- slug: string;
-};
-
-type VercelUserResponse = {
- user: {
- id: string;
- name: string;
- username: string;
- };
-};
-
-export const listProjects = async (
- appConnection: TVercelConnection,
- projectSearch?: string
-): Promise<VercelOrgWithApps[]> => {
+export const listTeams = async (appConnection: TVercelConnection): Promise<VercelTeam[]> => {
const { credentials } = appConnection;
const { apiToken } = credentials;
- const orgs = await fetchAllPages<VercelTeam>({
+ const teams = await fetchAllPages<VercelTeam>({
apiUrl: `${IntegrationUrls.VERCEL_API_URL}/v2/teams`,
apiToken,
initialParams: {},
@@ -215,13 +200,25 @@ export const listProjects = async (
if (personalAccountResponse?.data?.user) {
const { user } = personalAccountResponse.data;
- orgs.push({
+ teams.push({
id: user.id,
name: user.name || "Personal Account",
slug: user.username || "personal"
});
}
+ return teams;
+};
+
+export const listProjects = async (
+ appConnection: TVercelConnection,
+ projectSearch?: string
+): Promise<VercelOrgWithApps[]> => {
+ const { credentials } = appConnection;
+ const { apiToken } = credentials;
+
+ const orgs = await listTeams(appConnection);
+
const orgsWithApps: VercelOrgWithApps[] = [];
const orgPromises = orgs.map(async (org) => {
diff --git a/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts b/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts
index 26afce35e7..958a54e0ab 100644
--- a/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts
+++ b/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts
@@ -1,6 +1,6 @@
import axios from "axios";
import { OAuth2Client } from "google-auth-library";
-import { RE2 } from "re2";
+import RE2 from "re2";
import { crypto } from "@app/lib/crypto";
import { UnauthorizedError } from "@app/lib/errors";
diff --git a/backend/src/services/secret-sync/vercel/vercel-sync-enums.ts b/backend/src/services/secret-sync/vercel/vercel-sync-enums.ts
index 36c46985b3..de6f2f127d 100644
--- a/backend/src/services/secret-sync/vercel/vercel-sync-enums.ts
+++ b/backend/src/services/secret-sync/vercel/vercel-sync-enums.ts
@@ -1,6 +1,6 @@
export enum VercelSyncScope {
- Application = "application",
- Environment = "environment"
+ Project = "project",
+ Team = "team"
}
export const VercelEnvironmentType = {
diff --git a/backend/src/services/secret-sync/vercel/vercel-sync-fns.ts b/backend/src/services/secret-sync/vercel/vercel-sync-fns.ts
index b5ea982652..0442f9e50d 100644
--- a/backend/src/services/secret-sync/vercel/vercel-sync-fns.ts
+++ b/backend/src/services/secret-sync/vercel/vercel-sync-fns.ts
@@ -5,8 +5,13 @@ import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";
import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
-import { VercelEnvironmentType } from "./vercel-sync-enums";
-import { DefaultVercelEnvType, TVercelSyncWithCredentials, VercelApiSecret } from "./vercel-sync-types";
+import { VercelEnvironmentType, VercelSyncScope } from "./vercel-sync-enums";
+import {
+ DefaultVercelEnvType,
+ TVercelSyncWithCredentials,
+ VercelApiSecret,
+ VercelSharedEnvVar
+} from "./vercel-sync-types";
function isVercelDefaultEnvType(value: string): value is DefaultVercelEnvType {
return Object.values(VercelEnvironmentType).map(String).includes(value);
@@ -30,6 +35,13 @@ const getVercelSecretsWithRetries = async (
}
} = secretSync;
+ if (destinationConfig.scope !== VercelSyncScope.Project) {
+ throw new SecretSyncError({
+ message: "Invalid scope for Vercel secret sync",
+ shouldRetry: false
+ });
+ }
+
const params: { [key: string]: string } = {
decrypt: "true",
...(destinationConfig.branch ? { gitBranch: destinationConfig.branch } : {})
@@ -67,6 +79,13 @@ const getDecryptedVercelSecret = async (
}
} = secretSync;
+ if (destinationConfig.scope !== VercelSyncScope.Project) {
+ throw new SecretSyncError({
+ message: "Invalid scope for Vercel secret sync",
+ shouldRetry: false
+ });
+ }
+
const params: { [key: string]: string } = {
decrypt: "true",
...(destinationConfig.branch ? { gitBranch: destinationConfig.branch } : {})
@@ -99,6 +118,13 @@ const getVercelSecrets = async (secretSync: TVercelSyncWithCredentials): Promise
const secrets = await getVercelSecretsWithRetries(secretSync);
+ if (destinationConfig.scope !== VercelSyncScope.Project) {
+ throw new SecretSyncError({
+ message: "Invalid scope for Vercel secret sync",
+ shouldRetry: false
+ });
+ }
+
const filteredSecrets = secrets.filter((secret) => {
if (!isVercelDefaultEnvType(destinationConfig.env)) {
if (secret.customEnvironmentIds?.includes(destinationConfig.env)) {
@@ -147,6 +173,13 @@ const deleteSecret = async (
}
} = secretSync;
+ if (destinationConfig.scope !== VercelSyncScope.Project) {
+ throw new SecretSyncError({
+ message: "Invalid scope for Vercel secret sync",
+ shouldRetry: false
+ });
+ }
+
try {
await request.delete(
`${IntegrationUrls.VERCEL_API_URL}/v9/projects/${destinationConfig.app}/env/${vercelSecret.id}?teamId=${destinationConfig.teamId}`,
@@ -183,6 +216,13 @@ const createSecret = async (
}
} = secretSync;
+ if (destinationConfig.scope !== VercelSyncScope.Project) {
+ throw new SecretSyncError({
+ message: "Invalid scope for Vercel secret sync",
+ shouldRetry: false
+ });
+ }
+
await request.post(
`${IntegrationUrls.VERCEL_API_URL}/v10/projects/${destinationConfig.app}/env?teamId=${destinationConfig.teamId}`,
{
@@ -228,6 +268,13 @@ const updateSecret = async (
}
} = secretSync;
+ if (destinationConfig.scope !== VercelSyncScope.Project) {
+ throw new SecretSyncError({
+ message: "Invalid scope for Vercel secret sync",
+ shouldRetry: false
+ });
+ }
+
let target = [...vercelSecret.target];
if (isVercelDefaultEnvType(destinationConfig.env) && !vercelSecret.target.includes(destinationConfig.env)) {
target = [...target, destinationConfig.env];
@@ -271,8 +318,332 @@ const updateSecret = async (
}
};
+// ===== Team-scoped shared environment variable functions =====
+
+const listTeamSharedEnvVarsWithRetries = async (
+ secretSync: TVercelSyncWithCredentials
+): Promise<VercelSharedEnvVar[]> => {
+ const {
+ destinationConfig,
+ connection: {
+ credentials: { apiToken }
+ }
+ } = secretSync;
+
+ if (destinationConfig.scope !== VercelSyncScope.Team) {
+ throw new SecretSyncError({
+ message: "Invalid scope for team-level Vercel secret sync",
+ shouldRetry: false
+ });
+ }
+
+ const allEnvVars: VercelSharedEnvVar[] = [];
+ let hasMore = true;
+ let params: Record<string, string | number> = {};
+ let attempt = 0;
+
+ while (hasMore) {
+ try {
+ // eslint-disable-next-line no-await-in-loop
+ const { data: listResponse } = await request.get<{
+ data: VercelSharedEnvVar[];
+ pagination: { next: number | null };
+ }>(`${IntegrationUrls.VERCEL_API_URL}/v1/env?teamId=${destinationConfig.teamId}`, {
+ params,
+ headers: {
+ Authorization: `Bearer ${apiToken}`,
+ "Accept-Encoding": "application/json"
+ }
+ });
+
+ allEnvVars.push(...listResponse.data);
+ attempt = 0;
+
+ if (listResponse.pagination?.next) {
+ params = { ...params, since: listResponse.pagination.next };
+ } else {
+ hasMore = false;
+ }
+ } catch (error) {
+ if ((error as { response: { status: number } }).response.status === 429 && attempt < MAX_RETRIES) {
+ attempt += 1;
+ // eslint-disable-next-line no-await-in-loop
+ await sleep();
+ } else {
+ throw error;
+ }
+ }
+ }
+
+ return allEnvVars;
+};
+
+const getDecryptedTeamSharedEnvVar = async (
+ secretSync: TVercelSyncWithCredentials,
+ envVar: VercelSharedEnvVar,
+ attempt = 0
+): Promise<VercelSharedEnvVar> => {
+ const {
+ destinationConfig,
+ connection: {
+ credentials: { apiToken }
+ }
+ } = secretSync;
+
+ if (destinationConfig.scope !== VercelSyncScope.Team) {
+ throw new SecretSyncError({
+ message: "Invalid scope for team-level Vercel secret sync",
+ shouldRetry: false
+ });
+ }
+
+ try {
+ const { data: decryptedEnvVar } = await request.get<VercelSharedEnvVar>(
+ `${IntegrationUrls.VERCEL_API_URL}/v1/env/${envVar.id}?teamId=${destinationConfig.teamId}`,
+ {
+ headers: {
+ Authorization: `Bearer ${apiToken}`,
+ "Accept-Encoding": "application/json"
+ }
+ }
+ );
+ return decryptedEnvVar;
+ } catch (error) {
+ if ((error as { response: { status: number } }).response.status === 429 && attempt < MAX_RETRIES) {
+ await sleep();
+ return getDecryptedTeamSharedEnvVar(secretSync, envVar, attempt + 1);
+ }
+ throw error;
+ }
+};
+
+const getTeamSharedEnvVars = async (secretSync: TVercelSyncWithCredentials): Promise<VercelSharedEnvVar[]> => {
+ const envVars = await listTeamSharedEnvVarsWithRetries(secretSync);
+
+ const envVarsWithValues = await Promise.all(
+ envVars.map(async (envVar) => {
+ if (envVar.type === "encrypted") {
+ return getDecryptedTeamSharedEnvVar(secretSync, envVar);
+ }
+ return envVar;
+ })
+ );
+
+ return envVarsWithValues;
+};
+
+const createTeamSharedEnvVar = async (
+ secretSync: TVercelSyncWithCredentials,
+ key: string,
+ value: string,
+ attempt = 0
+): Promise<void> => {
+ const {
+ destinationConfig,
+ connection: {
+ credentials: { apiToken }
+ }
+ } = secretSync;
+
+ if (destinationConfig.scope !== VercelSyncScope.Team) {
+ throw new SecretSyncError({
+ message: "Invalid scope for team-level Vercel secret sync",
+ shouldRetry: false
+ });
+ }
+
+ try {
+ const { data: createResponse } = await request.post<{
+ created: VercelSharedEnvVar[];
+ failed: { error: { code: string; message: string } }[];
+ }>(
+ `${IntegrationUrls.VERCEL_API_URL}/v1/env?teamId=${destinationConfig.teamId}`,
+ {
+ evs: [{ key, value }],
+ type: "encrypted",
+ ...(destinationConfig.targetEnvironments?.length ? { target: destinationConfig.targetEnvironments } : {}),
+ ...(destinationConfig.targetProjects !== undefined ? { projectId: destinationConfig.targetProjects } : {})
+ },
+ {
+ headers: {
+ Authorization: `Bearer ${apiToken}`,
+ "Accept-Encoding": "application/json"
+ }
+ }
+ );
+
+ if (createResponse.failed?.length > 0) {
+ throw new SecretSyncError({
+ message: `Failed to create shared env var: ${createResponse.failed[0].error.message}`,
+ secretKey: key,
+ shouldRetry: false
+ });
+ }
+ } catch (error) {
+ if (error instanceof SecretSyncError) throw error;
+ if ((error as { response: { status: number } }).response.status === 429 && attempt < MAX_RETRIES) {
+ await sleep();
+ return createTeamSharedEnvVar(secretSync, key, value, attempt + 1);
+ }
+ throw new SecretSyncError({ error, secretKey: key });
+ }
+};
+
+const updateTeamSharedEnvVar = async (
+ secretSync: TVercelSyncWithCredentials,
+ envVar: VercelSharedEnvVar,
+ value: string,
+ attempt = 0
+): Promise<void> => {
+ const {
+ destinationConfig,
+ connection: {
+ credentials: { apiToken }
+ }
+ } = secretSync;
+
+ if (destinationConfig.scope !== VercelSyncScope.Team) {
+ throw new SecretSyncError({
+ message: "Invalid scope for team-level Vercel secret sync",
+ shouldRetry: false
+ });
+ }
+
+ try {
+ const { data: updateResponse } = await request.patch<{
+ updated: VercelSharedEnvVar[];
+ failed: { error: { code: string; message: string } }[];
+ }>(
+ `${IntegrationUrls.VERCEL_API_URL}/v1/env?teamId=${destinationConfig.teamId}`,
+ {
+ updates: {
+ [envVar.id]: {
+ value,
+ ...(destinationConfig.targetEnvironments?.length ? { target: destinationConfig.targetEnvironments } : {}),
+ ...(destinationConfig.targetProjects !== undefined ? { projectId: destinationConfig.targetProjects } : {})
+ }
+ }
+ },
+ {
+ headers: {
+ Authorization: `Bearer ${apiToken}`,
+ "Accept-Encoding": "application/json"
+ }
+ }
+ );
+
+ if (updateResponse.failed?.length > 0) {
+ throw new SecretSyncError({
+ message: `Failed to update shared env var: ${updateResponse.failed[0].error.message}`,
+ secretKey: envVar.key,
+ shouldRetry: false
+ });
+ }
+ } catch (error) {
+ if (error instanceof SecretSyncError) throw error;
+ if ((error as { response: { status: number } }).response.status === 429 && attempt < MAX_RETRIES) {
+ await sleep();
+ return updateTeamSharedEnvVar(secretSync, envVar, value, attempt + 1);
+ }
+ throw new SecretSyncError({ error, secretKey: envVar.key });
+ }
+};
+
+const deleteTeamSharedEnvVar = async (
+ secretSync: TVercelSyncWithCredentials,
+ envVar: VercelSharedEnvVar,
+ attempt = 0
+): Promise<void> => {
+ const {
+ destinationConfig,
+ connection: {
+ credentials: { apiToken }
+ }
+ } = secretSync;
+
+ if (destinationConfig.scope !== VercelSyncScope.Team) {
+ throw new SecretSyncError({
+ message: "Invalid scope for team-level Vercel secret sync",
+ shouldRetry: false
+ });
+ }
+
+ try {
+ const { data: deleteResponse } = await request.delete<{
+ deleted: string[];
+ failed: { error: { code: string; message: string } }[];
+ }>(`${IntegrationUrls.VERCEL_API_URL}/v1/env?teamId=${destinationConfig.teamId}`, {
+ data: { ids: [envVar.id] },
+ headers: {
+ Authorization: `Bearer ${apiToken}`,
+ "Accept-Encoding": "application/json"
+ }
+ });
+
+ if (deleteResponse.failed?.length > 0) {
+ throw new SecretSyncError({
+ message: `Failed to delete shared env var: ${deleteResponse.failed[0].error.message}`,
+ secretKey: envVar.key,
+ shouldRetry: false
+ });
+ }
+ } catch (error) {
+ if (error instanceof SecretSyncError) throw error;
+ if ((error as { response: { status: number } }).response.status === 429 && attempt < MAX_RETRIES) {
+ await sleep();
+ return deleteTeamSharedEnvVar(secretSync, envVar, attempt + 1);
+ }
+ throw new SecretSyncError({ error, secretKey: envVar.key });
+ }
+};
+
export const VercelSyncFns = {
syncSecrets: async (secretSync: TVercelSyncWithCredentials, secretMap: TSecretMap) => {
+ if (secretSync.destinationConfig.scope === VercelSyncScope.Team) {
+ const sharedEnvVars = await getTeamSharedEnvVars(secretSync);
+ const sharedEnvVarsMap = new Map(sharedEnvVars.map((s) => [s.key, s]));
+
+ const { targetEnvironments, targetProjects } = secretSync.destinationConfig;
+
+ for await (const key of Object.keys(secretMap)) {
+ const existingVar = sharedEnvVarsMap.get(key);
+
+ if (!existingVar) {
+ await createTeamSharedEnvVar(secretSync, key, secretMap[key].value);
+ } else {
+ const hasValueChanged = existingVar.value !== secretMap[key].value;
+
+ const hasTargetChanged = targetEnvironments?.length
+ ? existingVar.target.length !== targetEnvironments.length ||
+ !targetEnvironments.every((env) => existingVar.target.includes(env))
+ : false;
+
+ const hasProjectsChanged = targetProjects
+ ? (existingVar.projectId?.length ?? 0) !== targetProjects.length ||
+ !targetProjects.every((pid) => existingVar.projectId?.includes(pid))
+ : false;
+
+ if (hasValueChanged || hasTargetChanged || hasProjectsChanged) {
+ await updateTeamSharedEnvVar(secretSync, existingVar, secretMap[key].value);
+ }
+ }
+ }
+
+ if (secretSync.syncOptions.disableSecretDeletion) return;
+
+ for await (const sharedEnvVar of sharedEnvVars) {
+ if (!matchesSchema(sharedEnvVar.key, secretSync.environment?.slug || "", secretSync.syncOptions.keySchema))
+ // eslint-disable-next-line no-continue
+ continue;
+
+ if (!secretMap[sharedEnvVar.key]) {
+ await deleteTeamSharedEnvVar(secretSync, sharedEnvVar);
+ }
+ }
+
+ return;
+ }
+
const vercelSecrets = await getVercelSecrets(secretSync);
const vercelSecretsMap = new Map(vercelSecrets.map((s) => [s.key, s]));
@@ -302,11 +673,28 @@ export const VercelSyncFns = {
},
getSecrets: async (secretSync: TVercelSyncWithCredentials): Promise<TSecretMap> => {
+ if (secretSync.destinationConfig.scope === VercelSyncScope.Team) {
+ const sharedEnvVars = await getTeamSharedEnvVars(secretSync);
+ return Object.fromEntries(sharedEnvVars.map((s) => [s.key, { value: s.value ?? "" }]));
+ }
+
const vercelSecrets = await getVercelSecrets(secretSync);
return Object.fromEntries(vercelSecrets.map((s) => [s.key, { value: s.value ?? "" }]));
},
removeSecrets: async (secretSync: TVercelSyncWithCredentials, secretMap: TSecretMap) => {
+ if (secretSync.destinationConfig.scope === VercelSyncScope.Team) {
+ const sharedEnvVars = await getTeamSharedEnvVars(secretSync);
+
+ for await (const sharedEnvVar of sharedEnvVars) {
+ if (sharedEnvVar.key in secretMap) {
+ await deleteTeamSharedEnvVar(secretSync, sharedEnvVar);
+ }
+ }
+
+ return;
+ }
+
const vercelSecrets = await getVercelSecrets(secretSync);
for await (const vercelSecret of vercelSecrets) {
diff --git a/backend/src/services/secret-sync/vercel/vercel-sync-schemas.ts b/backend/src/services/secret-sync/vercel/vercel-sync-schemas.ts
index aa026bf9f5..709510e292 100644
--- a/backend/src/services/secret-sync/vercel/vercel-sync-schemas.ts
+++ b/backend/src/services/secret-sync/vercel/vercel-sync-schemas.ts
@@ -11,15 +11,27 @@ import {
import { TSyncOptionsConfig } from "@app/services/secret-sync/secret-sync-types";
import { SECRET_SYNC_NAME_MAP } from "../secret-sync-maps";
-import { VercelEnvironmentType } from "./vercel-sync-enums";
-
-const VercelSyncDestinationConfigSchema = z.object({
- app: z.string().min(1, "App ID is required").describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.app),
- appName: z.string().min(1, "App Name is required").describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.appName),
- env: z.nativeEnum(VercelEnvironmentType).or(z.string()).describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.env),
- branch: z.string().optional().describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.branch),
- teamId: z.string().describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.teamId)
-});
+import { VercelEnvironmentType, VercelSyncScope } from "./vercel-sync-enums";
+
+const VercelSyncDestinationConfigSchema = z.discriminatedUnion("scope", [
+ z.object({
+ scope: z.literal(VercelSyncScope.Project),
+ app: z.string().min(1, "App ID is required").describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.app),
+ appName: z.string().min(1, "App Name is required").describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.appName),
+ env: z.nativeEnum(VercelEnvironmentType).or(z.string()).describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.env),
+ branch: z.string().optional().describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.branch),
+ teamId: z.string().describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.teamId)
+ }),
+ z.object({
+ scope: z.literal(VercelSyncScope.Team),
+ teamId: z.string().min(1, "Team ID is required").describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.teamId),
+ targetEnvironments: z
+ .array(z.nativeEnum(VercelEnvironmentType))
+ .min(1, "At least one environment is required")
+ .describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.targetEnvironments),
+ targetProjects: z.array(z.string()).optional().describe(SecretSyncs.DESTINATION_CONFIG.VERCEL.targetProjects)
+ })
+]);
const VercelSyncOptionsConfig: TSyncOptionsConfig = { canImportSecrets: true };
diff --git a/backend/src/services/secret-sync/vercel/vercel-sync-types.ts b/backend/src/services/secret-sync/vercel/vercel-sync-types.ts
index d6d2b64330..6d29e517ec 100644
--- a/backend/src/services/secret-sync/vercel/vercel-sync-types.ts
+++ b/backend/src/services/secret-sync/vercel/vercel-sync-types.ts
@@ -38,3 +38,16 @@ export interface VercelApiSecret {
}
export type DefaultVercelEnvType = (typeof VercelEnvironmentType)[keyof typeof VercelEnvironmentType];
+
+export interface VercelSharedEnvVar {
+ id: string;
+ key: string;
+ value: string;
+ type: string;
+ target: string[];
+ projectId?: string[];
+ decrypted?: boolean;
+ comment?: string;
+ createdAt?: number;
+ updatedAt?: number;
+}
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/VercelSyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/VercelSyncFields.tsx
index 219f2f81cd..129cb1f7fd 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/VercelSyncFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/VercelSyncFields.tsx
@@ -1,6 +1,6 @@
import { useMemo, useState } from "react";
import { Controller, useFormContext, useWatch } from "react-hook-form";
-import { SingleValue } from "react-select";
+import { MultiValue, SingleValue } from "react-select";
import { faCircleInfo } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -10,9 +10,11 @@ import { CreatableSelect } from "@app/components/v2/CreatableSelect";
import { useDebounce } from "@app/hooks";
import {
TVercelConnectionApp,
+ TVercelConnectionOrganization,
useVercelConnectionListOrganizations
} from "@app/hooks/api/appConnections/vercel";
import { SecretSync } from "@app/hooks/api/secretSyncs";
+import { VercelSyncScope } from "@app/hooks/api/secretSyncs/types/vercel-sync";
import { TSecretSyncForm } from "../schemas";
@@ -20,7 +22,7 @@ const vercelEnvironments = [
{ name: "Development", slug: "development" },
{ name: "Preview", slug: "preview" },
{ name: "Production", slug: "production" }
-];
+] as const;
export const VercelSyncFields = () => {
const { control, watch, setValue } = useFormContext<
@@ -33,8 +35,9 @@ export const VercelSyncFields = () => {
const connectionId = useWatch({ name: "connection.id", control });
const currentApp = watch("destinationConfig.app");
const currentEnv = watch("destinationConfig.env");
+ const scope = watch("destinationConfig.scope");
- const { data: projects, isLoading: isProjectsLoading } = useVercelConnectionListOrganizations(
+ const { data: teams, isLoading: isTeamsLoading } = useVercelConnectionListOrganizations(
connectionId,
debouncedProjectSearch,
{
@@ -42,18 +45,18 @@ export const VercelSyncFields = () => {
}
);
- const selectedProject = projects
- ?.find((project) => project.apps.some((app) => app.id === currentApp))
+ const selectedProject = teams
+ ?.find((team) => team.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 }))
+ teams?.flatMap((team) =>
+ team.apps.map((project) => ({ ...project, teamName: team.name, teamId: team.id }))
) || [];
const environmentOptions = useMemo(() => {
return vercelEnvironments
- .map((env) => ({
+ .map((env): { key: string; type: string; name: string } => ({
key: env.slug,
type: env.slug,
name: env.name
@@ -73,7 +76,13 @@ export const VercelSyncFields = () => {
name: branch
})) || [];
+ const scopeOptions = Object.values(VercelSyncScope).map((s) => ({
+ value: s,
+ label: s.replace("-", " ").replace(/\b\w/g, (c) => c.toUpperCase())
+ }));
+
const isPreviewEnvironment = currentEnv === "preview";
+ const isTeamScope = scope === VercelSyncScope.Team;
return (
<>
@@ -83,155 +92,273 @@ export const VercelSyncFields = () => {
setValue("destinationConfig.appName", "");
setValue("destinationConfig.env", "production");
setValue("destinationConfig.branch", "");
+ setValue("destinationConfig.teamId", "");
+ setValue("destinationConfig.scope", VercelSyncScope.Project);
}}
/>
<Controller
- name="destinationConfig.app"
+ name="destinationConfig.scope"
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={
- <div className="flex flex-col gap-2">
- <span>
- Ensure the project exists and the API token scope for this connection includes
- the desired project.
- </span>
- <span>
- Use the search bar to filter projects by name. By default only 10 projects are
- shown, but you can search for more projects by name.
- </span>
- </div>
- }
- >
- <div>
- <span>Don&#39;t see the project you&#39;re looking for?</span>{" "}
- <FontAwesomeIcon icon={faCircleInfo} className="text-mineshaft-400" />
- </div>
- </Tooltip>
- }
- >
+ <FormControl isError={Boolean(error)} errorText={error?.message} label="Scope">
<FilterableSelect
- menuPlacement="top"
- noOptionsMessage={({ inputValue }) => {
- return inputValue
- ? "No projects found matching your search."
- : "No projects found.";
- }}
- isLoading={isProjectsLoading && Boolean(connectionId)}
+ isLoading={isTeamsLoading}
isDisabled={!connectionId}
- value={allApps.find((app) => app.id === value) ?? null}
+ value={scopeOptions.find((opt) => opt.value === 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 || ""
- );
+ const newScope =
+ (option as SingleValue<(typeof scopeOptions)[number]>)?.value ?? null;
+ onChange(newScope);
+
+ if (newScope === VercelSyncScope.Team) {
+ setValue("destinationConfig.teamId", "");
+ setValue("destinationConfig.targetEnvironments", []);
+ setValue("destinationConfig.targetProjects", undefined);
+ } else {
+ setValue("destinationConfig.app", "");
+ setValue("destinationConfig.appName", "");
+ setValue("destinationConfig.env", "production");
+ setValue("destinationConfig.branch", "");
+ setValue("destinationConfig.teamId", "");
+ }
}}
- onInputChange={(newValue) => setProjectSearch(newValue)}
- filterOption={null}
- options={allApps}
- placeholder="Search for a project..."
- getOptionLabel={(option) => option.name}
- getOptionValue={(option) => option.id.toString()}
- groupBy="project"
+ options={scopeOptions}
+ placeholder="Select a scope..."
+ getOptionLabel={(opt) => opt.label}
+ getOptionValue={(opt) => opt.value}
/>
</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
+ {isTeamScope && (
+ <>
+ <Controller
+ name="destinationConfig.teamId"
+ control={control}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl isError={Boolean(error)} errorText={error?.message} label="Team">
+ <FilterableSelect
+ value={teams?.find((team) => team.id === value) ?? null}
+ onChange={(option) =>
+ onChange((option as SingleValue<TVercelConnectionOrganization>)?.id ?? null)
+ }
+ options={teams}
+ placeholder="Select a team..."
+ getOptionLabel={(option) => option.name}
+ getOptionValue={(option) => option.id}
+ />
+ </FormControl>
+ )}
+ />
+
+ <Controller
+ name="destinationConfig.targetEnvironments"
+ control={control}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ isError={Boolean(error)}
+ errorText={error?.message}
+ label="Target Environments"
+ >
+ <FilterableSelect
+ isMulti
+ value={vercelEnvironments.filter((env) => (value || []).includes(env.slug))}
+ onChange={(option) =>
+ onChange(
+ (option as MultiValue<(typeof vercelEnvironments)[number]>).map((o) => o.slug)
+ )
+ }
+ options={vercelEnvironments}
+ placeholder="Select target environments..."
+ getOptionLabel={(option) => option.name}
+ getOptionValue={(option) => option.slug}
+ />
+ </FormControl>
+ )}
+ />
+
+ <Controller
+ name="destinationConfig.targetProjects"
+ control={control}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ isOptional
+ isError={Boolean(error)}
+ errorText={error?.message}
+ label="Target Projects"
+ >
+ <FilterableSelect
+ isMulti
+ value={allApps.filter((app) => (value || []).includes(app.id))}
+ onChange={(option) =>
+ onChange((option as MultiValue<(typeof allApps)[number]>).map((o) => o.id))
+ }
+ options={allApps}
+ placeholder="Select target projects..."
+ getOptionLabel={(option) => option.name}
+ getOptionValue={(option) => option.id}
+ />
+ </FormControl>
+ )}
+ />
+ </>
+ )}
+
+ {!isTeamScope && (
+ <>
+ <Controller
+ name="destinationConfig.app"
+ control={control}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ isError={Boolean(error)}
+ errorText={error?.message}
+ label="Vercel Project"
+ helperText={
+ <Tooltip
+ className="max-w-md"
+ content={
+ <div className="flex flex-col gap-2">
+ <span>
+ Ensure the project exists and the API token scope for this connection
+ includes the desired project.
+ </span>
+ <span>
+ Use the search bar to filter projects by name. By default only 10 projects
+ are shown, but you can search for more projects by name.
+ </span>
+ </div>
}
- : null
- }
- onChange={(option) => {
- const envKey = (option as any)?.key ?? null;
- onChange(envKey);
+ >
+ <div>
+ <span>Don&#39;t see the project you&#39;re looking for?</span>{" "}
+ <FontAwesomeIcon icon={faCircleInfo} className="text-mineshaft-400" />
+ </div>
+ </Tooltip>
+ }
+ >
+ <FilterableSelect
+ menuPlacement="top"
+ noOptionsMessage={({ inputValue }) => {
+ return inputValue
+ ? "No projects found matching your search."
+ : "No projects found.";
+ }}
+ isLoading={isTeamsLoading && 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 || ""
+ );
+ }}
+ onInputChange={(newValue) => setProjectSearch(newValue)}
+ filterOption={null}
+ options={allApps}
+ placeholder="Search for a project..."
+ getOptionLabel={(option) => option.name}
+ getOptionValue={(option) => option.id.toString()}
+ groupBy="project"
+ />
+ </FormControl>
+ )}
+ />
- setValue("destinationConfig.branch", "");
- }}
- options={environmentOptions}
- placeholder="Select an environment..."
- getOptionLabel={(option) => option.name || option.key || ""}
- getOptionValue={(option) => option.key || ""}
- />
- </FormControl>
- )}
- />
+ <Controller
+ name="destinationConfig.env"
+ control={control}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ isError={Boolean(error)}
+ errorText={error?.message}
+ label="Vercel Project 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);
- {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)"
- >
- <CreatableSelect
- className="w-full"
- placeholder="Select a branch..."
- isLoading={isProjectsLoading && Boolean(connectionId) && Boolean(currentApp)}
- isDisabled={!connectionId || !currentApp}
- options={previewBranchOptions}
- menuPlacement="top"
- value={previewBranchOptions.find((branch) => branch.id === value) ?? null}
- onChange={(option) => onChange((option as SingleValue<{ id: string }>)?.id || "")}
- onCreateOption={(option) => {
- onChange(option);
- if (!option || option.trim() === "") return;
- previewBranchOptions.push({ id: option, name: option });
- }}
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- getNewOptionData={(inputValue, _optionLabel) => {
- return {
- id: inputValue,
- name: `${inputValue} - press Enter`
- };
- }}
- getOptionLabel={(option) => option.name}
- getOptionValue={(option) => option?.id || ""}
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- isValidNewOption={(inputValue, _value, _options, _accessors) => {
- return (
- inputValue.trim().length > 0 &&
- previewBranchOptions.filter((branch) => branch.id === inputValue).length === 0
- );
- }}
- />
- </FormControl>
+ 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)"
+ >
+ <CreatableSelect
+ className="w-full"
+ placeholder="Select a branch..."
+ isLoading={isTeamsLoading && Boolean(connectionId) && Boolean(currentApp)}
+ isDisabled={!connectionId || !currentApp}
+ options={previewBranchOptions}
+ menuPlacement="top"
+ value={previewBranchOptions.find((branch) => branch.id === value) ?? null}
+ onChange={(option) =>
+ onChange((option as SingleValue<{ id: string }>)?.id || "")
+ }
+ onCreateOption={(option) => {
+ onChange(option);
+ if (!option || option.trim() === "") return;
+ previewBranchOptions.push({ id: option, name: option });
+ }}
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ getNewOptionData={(inputValue, _optionLabel) => {
+ return {
+ id: inputValue,
+ name: `${inputValue} - press Enter`
+ };
+ }}
+ getOptionLabel={(option) => option.name}
+ getOptionValue={(option) => option?.id || ""}
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ isValidNewOption={(inputValue, _value, _options, _accessors) => {
+ return (
+ inputValue.trim().length > 0 &&
+ previewBranchOptions.filter((branch) => branch.id === inputValue).length ===
+ 0
+ );
+ }}
+ />
+ </FormControl>
+ )}
+ />
)}
- />
+ </>
)}
</>
);
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/VercelSyncReviewFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/VercelSyncReviewFields.tsx
index 43e83cf964..fc981a9093 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/VercelSyncReviewFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/VercelSyncReviewFields.tsx
@@ -1,22 +1,67 @@
+/* eslint-disable react/jsx-no-useless-fragment */
+import { useMemo } from "react";
import { useFormContext } from "react-hook-form";
import { TSecretSyncForm } from "@app/components/secret-syncs/forms/schemas";
import { GenericFieldLabel } from "@app/components/v2";
+import { useVercelConnectionListOrganizations } from "@app/hooks/api/appConnections/vercel";
import { SecretSync } from "@app/hooks/api/secretSyncs";
-import { VercelEnvironmentType } from "@app/hooks/api/secretSyncs/types/vercel-sync";
+import {
+ VercelEnvironmentType,
+ VercelSyncScope
+} 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");
+ const scope = watch("destinationConfig.scope");
+ const teamId = watch("destinationConfig.teamId");
+ const targetEnvironments = watch("destinationConfig.targetEnvironments");
+ const targetProjects = watch("destinationConfig.targetProjects");
+ const connectionId = watch("connection.id");
+
+ const { data: teams } = useVercelConnectionListOrganizations(connectionId, undefined, {
+ enabled: scope === VercelSyncScope.Team
+ });
+
+ const selectedTeam = useMemo(() => {
+ if (scope !== VercelSyncScope.Team) return undefined;
+
+ return teams?.find((team) => team.id === teamId);
+ }, [teams, teamId]);
+
+ const selectedProjects = useMemo(() => {
+ if (scope !== VercelSyncScope.Team) return undefined;
+
+ return targetProjects?.map((projectId) =>
+ selectedTeam?.apps.find((app) => app.id === projectId)
+ );
+ }, [selectedTeam, targetProjects]);
return (
<>
- <GenericFieldLabel label="Vercel App">{appName}</GenericFieldLabel>
- <GenericFieldLabel label="Environment">{envId}</GenericFieldLabel>
- {envId === VercelEnvironmentType.Preview && branchId && (
- <GenericFieldLabel label="Preview Branch">{branchId}</GenericFieldLabel>
+ {scope === VercelSyncScope.Team ? (
+ <>
+ <GenericFieldLabel label="Scope">Team</GenericFieldLabel>
+ <GenericFieldLabel label="Vercel Team">{selectedTeam?.name}</GenericFieldLabel>
+ <GenericFieldLabel label="Target Environments">
+ {targetEnvironments?.join(", ")}
+ </GenericFieldLabel>
+ <GenericFieldLabel label="Target Projects">
+ {selectedProjects?.map((project) => project?.name).join(", ")}
+ </GenericFieldLabel>
+ </>
+ ) : (
+ <>
+ <GenericFieldLabel label="Scope">Project</GenericFieldLabel>
+ <GenericFieldLabel label="Vercel Project">{appName}</GenericFieldLabel>
+ <GenericFieldLabel label="Environment">{envId}</GenericFieldLabel>
+ {envId === VercelEnvironmentType.Preview && branchId && (
+ <GenericFieldLabel label="Preview Branch">{branchId}</GenericFieldLabel>
+ )}
+ </>
)}
</>
);
diff --git a/frontend/src/components/secret-syncs/forms/schemas/vercel-sync-destination-schema.ts b/frontend/src/components/secret-syncs/forms/schemas/vercel-sync-destination-schema.ts
index 9d3678803a..d8ea050b9d 100644
--- a/frontend/src/components/secret-syncs/forms/schemas/vercel-sync-destination-schema.ts
+++ b/frontend/src/components/secret-syncs/forms/schemas/vercel-sync-destination-schema.ts
@@ -2,17 +2,33 @@ 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";
+import {
+ VercelEnvironmentType,
+ VercelSyncScope
+} 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()
- })
+ destinationConfig: z.discriminatedUnion("scope", [
+ z.object({
+ scope: z.literal(VercelSyncScope.Project),
+ 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()
+ }),
+ z.object({
+ scope: z.literal(VercelSyncScope.Team),
+ teamId: z.string().trim().min(1, "Team required"),
+ targetEnvironments: z
+ .array(z.nativeEnum(VercelEnvironmentType), {
+ message: "At least one environment is required"
+ })
+ .min(1, "At least one environment is required"),
+ targetProjects: z.array(z.string()).optional()
+ })
+ ])
})
);
diff --git a/frontend/src/hooks/api/secretSyncs/types/vercel-sync.ts b/frontend/src/hooks/api/secretSyncs/types/vercel-sync.ts
index ffae61e233..e5b307917d 100644
--- a/frontend/src/hooks/api/secretSyncs/types/vercel-sync.ts
+++ b/frontend/src/hooks/api/secretSyncs/types/vercel-sync.ts
@@ -2,6 +2,11 @@ import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { SecretSync } from "@app/hooks/api/secretSyncs";
import { TRootSecretSync } from "@app/hooks/api/secretSyncs/types/root-sync";
+export enum VercelSyncScope {
+ Project = "project",
+ Team = "team"
+}
+
export const VercelEnvironmentType = {
Development: "development",
Preview: "preview",
@@ -12,13 +17,21 @@ export type VercelEnvironment = (typeof VercelEnvironmentType)[keyof typeof Verc
export type TVercelSync = TRootSecretSync & {
destination: SecretSync.Vercel;
- destinationConfig: {
- app: string;
- env: VercelEnvironment | string;
- branch?: string;
- appName?: string;
- teamId: string;
- };
+ destinationConfig:
+ | {
+ scope: VercelSyncScope.Project;
+ app: string;
+ env: VercelEnvironment | string;
+ branch?: string;
+ appName?: string;
+ teamId: string;
+ }
+ | {
+ scope: VercelSyncScope.Team;
+ teamId: string;
+ targetEnvironments: string[];
+ targetProjects?: string[];
+ };
connection: {
app: AppConnection.Vercel;
name: string;
diff --git a/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncDestinationSection/VercelSyncDestinationSection.tsx b/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncDestinationSection/VercelSyncDestinationSection.tsx
index bc4a8531d4..d6b9d7d3fc 100644
--- a/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncDestinationSection/VercelSyncDestinationSection.tsx
+++ b/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncDestinationSection/VercelSyncDestinationSection.tsx
@@ -1,7 +1,12 @@
-import { ReactNode } from "react";
+import { ReactNode, useMemo } from "react";
import { GenericFieldLabel } from "@app/components/secret-syncs";
-import { TVercelSync, VercelEnvironmentType } from "@app/hooks/api/secretSyncs/types/vercel-sync";
+import { useVercelConnectionListOrganizations } from "@app/hooks/api/appConnections/vercel";
+import {
+ TVercelSync,
+ VercelEnvironmentType,
+ VercelSyncScope
+} from "@app/hooks/api/secretSyncs/types/vercel-sync";
type Props = {
secretSync: TVercelSync;
@@ -10,11 +15,49 @@ type Props = {
export const VercelSyncDestinationSection = ({ secretSync }: Props) => {
const { destinationConfig } = secretSync;
+ const { data: teams } = useVercelConnectionListOrganizations(
+ secretSync.connection.id,
+ undefined,
+ {
+ enabled: secretSync.destinationConfig.scope === VercelSyncScope.Team
+ }
+ );
+
+ const selectedTeam = useMemo(() => {
+ if (secretSync.destinationConfig.scope !== VercelSyncScope.Team) return undefined;
+
+ return teams?.find((team) => team.id === secretSync.destinationConfig.teamId);
+ }, [teams, secretSync.destinationConfig.teamId]);
+
+ const selectedProjects = useMemo(() => {
+ if (secretSync.destinationConfig.scope !== VercelSyncScope.Team) return undefined;
+
+ return secretSync.destinationConfig.targetProjects?.map((projectId) =>
+ selectedTeam?.apps.find((app) => app.id === projectId)
+ );
+ }, [selectedTeam, secretSync.destinationConfig]);
+
+ if (destinationConfig.scope === VercelSyncScope.Team) {
+ return (
+ <>
+ <GenericFieldLabel label="Scope">Team</GenericFieldLabel>
+ <GenericFieldLabel label="Vercel Team">{selectedTeam?.name}</GenericFieldLabel>
+ <GenericFieldLabel label="Target Environments">
+ {destinationConfig.targetEnvironments?.join(", ")}
+ </GenericFieldLabel>
+ <GenericFieldLabel label="Target Projects">
+ {selectedProjects?.map((project) => project?.name).join(", ")}
+ </GenericFieldLabel>
+ </>
+ );
+ }
+
let Components: ReactNode;
if (destinationConfig.env === VercelEnvironmentType.Preview && destinationConfig.branch) {
Components = (
<>
- <GenericFieldLabel label="Vercel App">
+ <GenericFieldLabel label="Scope">Project</GenericFieldLabel>
+ <GenericFieldLabel label="Vercel Project">
{destinationConfig.appName || destinationConfig.app}
</GenericFieldLabel>
<GenericFieldLabel label="Environment">{destinationConfig.env}</GenericFieldLabel>
@@ -24,7 +67,8 @@ export const VercelSyncDestinationSection = ({ secretSync }: Props) => {
} else {
Components = (
<>
- <GenericFieldLabel label="Vercel App">
+ <GenericFieldLabel label="Scope">Project</GenericFieldLabel>
+ <GenericFieldLabel label="Vercel Project">
{destinationConfig.appName || destinationConfig.app}
</GenericFieldLabel>
<GenericFieldLabel label="Environment">{destinationConfig.env}</GenericFieldLabel>