From aa0cfb365764580ea2317072abdd36749b47d100 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 15:20:08 +0000 Subject: [PATCH] Changes Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com> --- supabase/functions/_shared/railway.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/supabase/functions/_shared/railway.ts b/supabase/functions/_shared/railway.ts index b3a52eb..f9b6184 100644 --- a/supabase/functions/_shared/railway.ts +++ b/supabase/functions/_shared/railway.ts @@ -229,6 +229,31 @@ export async function setHermesSuspended(opts: { }); } +/** Busca o ID de um serviço pelo nome dentro de um projeto. Retorna null se não existir. */ +export async function findRailwayServiceByName(opts: { + token: string; + projectId: string; + name: string; +}): Promise { + const query = ` + query Project($id: String!) { + project(id: $id) { + services { edges { node { id name } } } + } + } + `; + const res = await railwayQuery<{ + project: { services: { edges: { node: { id: string; name: string } }[] } }; + }>(query, { id: opts.projectId }, opts.token); + if (res.errors?.length) { + console.error("findRailwayServiceByName errors:", JSON.stringify(res.errors)); + return null; + } + const edges = res.data?.project?.services?.edges ?? []; + const match = edges.find((e) => e.node.name === opts.name); + return match?.node.id ?? null; +} + /** Busca env+project IDs do primeiro deployment de um serviço. Útil quando vps_pool_id está null. */ export async function getServiceContext(opts: { token: string;