From 5391bcd3b2e2e78a48a1f23ad8c0afe10ff43569 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Wed, 5 Mar 2025 01:33:58 +0400 Subject: [PATCH] fix: vercel integration custom envs --- .../integration-auth/integration-app-list.ts | 73 ++++++++++++++----- .../integration-auth-service.ts | 1 + 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/backend/src/services/integration-auth/integration-app-list.ts b/backend/src/services/integration-auth/integration-app-list.ts index 126037895..df61411dd 100644 --- a/backend/src/services/integration-auth/integration-app-list.ts +++ b/backend/src/services/integration-auth/integration-app-list.ts @@ -134,7 +134,15 @@ const getAppsHeroku = async ({ accessToken }: { accessToken: string }) => { * Return list of names of apps for Vercel integration * This is re-used for getting custom environments for Vercel */ -export const getAppsVercel = async ({ accessToken, teamId }: { teamId?: string | null; accessToken: string }) => { +export const getAppsVercel = async ({ + accessToken, + teamId, + includeCustomEnvironments = false +}: { + teamId?: string | null; + accessToken: string; + includeCustomEnvironments?: boolean; +}) => { const apps: Array<{ name: string; appId: string; customEnvironments: Array<{ slug: string; id: string }> }> = []; const limit = "20"; @@ -145,12 +153,6 @@ export const getAppsVercel = async ({ accessToken, teamId }: { teamId?: string | projects: { name: string; id: string; - customEnvironments?: { - id: string; - type: string; - description: string; - slug: string; - }[]; }[]; pagination: { count: number; @@ -159,6 +161,20 @@ export const getAppsVercel = async ({ accessToken, teamId }: { teamId?: string | }; } + const getProjectCustomEnvironments = async (projectId: string) => { + const { data } = await request.get<{ environments: { id: string; slug: string }[] }>( + `${IntegrationUrls.VERCEL_API_URL}/v9/projects/${projectId}/custom-environments`, + { + headers: { + Authorization: `Bearer ${accessToken}`, + "Accept-Encoding": "application/json" + } + } + ); + + return data.environments; + }; + while (hasMorePages) { const params: { [key: string]: string } = { limit @@ -180,17 +196,40 @@ export const getAppsVercel = async ({ accessToken, teamId }: { teamId?: string | } }); - data.projects.forEach((a) => { - apps.push({ - name: a.name, - appId: a.id, - customEnvironments: - a.customEnvironments?.map((env) => ({ - slug: env.slug, - id: env.id - })) ?? [] + if (includeCustomEnvironments) { + const projectsWithCustomEnvironments = await Promise.all( + data.projects.map(async (a) => { + const customEnvironments = await getProjectCustomEnvironments(a.id); + + return { + ...a, + customEnvironments + }; + }) + ); + + console.log(projectsWithCustomEnvironments); + + projectsWithCustomEnvironments.forEach((a) => { + apps.push({ + name: a.name, + appId: a.id, + customEnvironments: + a.customEnvironments?.map((env) => ({ + slug: env.slug, + id: env.id + })) ?? [] + }); }); - }); + } else { + data.projects.forEach((a) => { + apps.push({ + name: a.name, + appId: a.id, + customEnvironments: [] + }); + }); + } next = data.pagination.next; diff --git a/backend/src/services/integration-auth/integration-auth-service.ts b/backend/src/services/integration-auth/integration-auth-service.ts index 61f753348..1d9fedde7 100644 --- a/backend/src/services/integration-auth/integration-auth-service.ts +++ b/backend/src/services/integration-auth/integration-auth-service.ts @@ -1851,6 +1851,7 @@ export const integrationAuthServiceFactory = ({ const { accessToken } = await getIntegrationAccessToken(integrationAuth, shouldUseSecretV2Bridge, botKey); const vercelApps = await getAppsVercel({ + includeCustomEnvironments: true, accessToken, teamId });