From bcc99b0cb5acc06dabddbc62dadabf8d1d753398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Mon, 8 Jan 2024 06:59:29 +0100 Subject: [PATCH] ref: Use separate endpoint for retrieving single Vercel project (#19836) ref: Use separate endpoint for retrieving single vercel project --- .../VercelIntegration/VercelSection.tsx | 8 ++- .../to-be-cleaned/Integration/Vercel.utils.ts | 68 ++++++++----------- apps/studio/pages/vercel/integrate.tsx | 6 +- 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/apps/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsx b/apps/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsx index 3f28da24576..30cc6f8cebc 100644 --- a/apps/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsx +++ b/apps/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsx @@ -120,9 +120,11 @@ You can change the scope of the access for Supabase by configuring : '' const integrationUrl = - process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging' - ? 'https://vercel.com/integrations/supabase-v2-staging' - : 'https://vercel.com/integrations/supabase' + process.env.NEXT_PUBLIC_ENVIRONMENT === 'prod' + ? 'https://vercel.com/integrations/supabase' + : process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging' + ? `https://vercel.com/integrations/supabase-v2-staging` + : 'https://vercel.com/integrations/supabase-v2-local' let connections = (isProjectScoped diff --git a/apps/studio/components/to-be-cleaned/Integration/Vercel.utils.ts b/apps/studio/components/to-be-cleaned/Integration/Vercel.utils.ts index ba2af99b6d5..b9ae4c8c945 100644 --- a/apps/studio/components/to-be-cleaned/Integration/Vercel.utils.ts +++ b/apps/studio/components/to-be-cleaned/Integration/Vercel.utils.ts @@ -1,61 +1,51 @@ import { post, get } from 'lib/common/fetch' import { INTEGRATION_ENVS_ALIAS } from 'lib/vercelConfigs' -import { Dictionary } from 'types' import { API_URL } from 'lib/constants' -export async function fetchVercelProjects({ - vercelTeamId, +async function doFetchVercelProjects({ vercelToken, + vercelTeamId, + id, }: { - vercelTeamId?: string vercelToken: string -}): Promise<{ data?: Dictionary[]; error?: string }> { + vercelTeamId?: string + id?: string +}) { let url = `${API_URL}/vercel/projects` + if (id) { + url += `/${id}` + } if (vercelTeamId && vercelTeamId != 'null') { const query = new URLSearchParams({ teamId: vercelTeamId }).toString() url = `${url}?${query}` } - const response = await get(url, { - headers: { vercel_authorization: `Bearer ${vercelToken}` }, - }) - if (response.error != null) { - return { error: `Retrieve vercel projects failed. ${response.error?.message}` } - } - return { data: response } -} - -/** - * /v6/projects/:id returns project alias with domain info. - * We need this to setup Supabase Auth site url on project creation. - * - * Do not update to /v8/projects/:id as it doesn't return alias info - */ -export async function fetchVercelProject({ - id, - vercelTeamId, - vercelToken, -}: { - id: string - vercelTeamId?: string - vercelToken: string -}): Promise<{ data?: Dictionary; error?: string }> { - let url = `${API_URL}/vercel/projects` - if (vercelTeamId && vercelTeamId != 'null') { - const query = new URLSearchParams({ id, teamId: vercelTeamId }).toString() - url = `${url}?${query}` - } else { - const query = new URLSearchParams({ id }).toString() - url = `${url}?${query}` - } const data = await get(url, { headers: { vercel_authorization: `Bearer ${vercelToken}` }, }) if (data.error != null) { - return { error: `Retrieve vercel project failed. ${data.error.message}` } + return { error: `Retrieve vercel project${id ? '' : 's'} failed. ${data.error.message}` } } return { data } } +export async function fetchVercelProjects(params: { vercelToken: string; vercelTeamId?: string }) { + return (await doFetchVercelProjects(params)) as { + data?: Record[] + error?: string + } +} + +export async function fetchVercelProject(params: { + id: string + vercelToken: string + vercelTeamId?: string +}) { + return (await doFetchVercelProjects(params)) as { + data?: Record + error?: string + } +} + export async function fetchVercelProjectEnvs({ id, vercelTeamId, @@ -64,7 +54,7 @@ export async function fetchVercelProjectEnvs({ id: string vercelTeamId?: string vercelToken: string -}): Promise<{ data?: Dictionary[]; error?: string }> { +}): Promise<{ data?: Record[]; error?: string }> { let url = `${API_URL}/vercel/projects/envs` if (vercelTeamId && vercelTeamId != 'null') { const query = new URLSearchParams({ projectId: id, teamId: vercelTeamId }).toString() diff --git a/apps/studio/pages/vercel/integrate.tsx b/apps/studio/pages/vercel/integrate.tsx index 70d927ee5ce..38b349d0a5a 100644 --- a/apps/studio/pages/vercel/integrate.tsx +++ b/apps/studio/pages/vercel/integrate.tsx @@ -154,16 +154,16 @@ class VercelIntegrationStore implements IVercelIntegrationStore { } } async getVercelProjects() { - const { data, error }: any = await fetchVercelProjects({ + const { data, error } = await fetchVercelProjects({ vercelTeamId: this.teamId, vercelToken: this.token, }) if (error) { toast.error(error) - } else { + } else if (data) { this.vercelProjects = data // if currentProjectId available. Auto select it - if (data && this.currentProjectId) { + if (this.currentProjectId) { // @ts-ignore const found = data.find((x: { id: string }) => (x.id = this.currentProjectId)) if (found) this.selectedVercelProjectId = found.id