import { ProjectJsonFile } from './project-json-file'; import { CliTerseError } from '@alwaysai/alwayscli'; import { CliAuthenticationClient, CliRpcClient, getBaseURL } from '../../infrastructure'; export async function requireUserIsCollaboratorOnProject(projectUuid: string) { const { username } = await CliAuthenticationClient().getInfo(); const collabProjects = await CliRpcClient().listProjectsUserIsCollaborator({ user_name: username }); let isCollab = false; for (const p of collabProjects) { if (p.uuid) { if (projectUuid === p.uuid.toString()) { isCollab = true; } } } if (!isCollab) { throw new CliTerseError( `Project "${projectUuid}" does not match any projects for which you are a member. Please either contact the project owner to add you, or check that the project exists on your dashboard. \nIf the project no longer exists on your dashboard, delete the alwaysai.project.json file and re-run "aai app configure", and choose to create a new project.` ); } } export async function getProjectByUUID(uuid: string) { await requireUserIsCollaboratorOnProject(uuid); const project = await CliRpcClient().getProjectByUUID({ uuid }); return project; } export async function getCurrentProjectId() { const projectJsonFile = ProjectJsonFile(); const project = projectJsonFile.read().project; if (!project) { throw new CliTerseError('No project configured for this app!'); } const uuidProject = await getProjectByUUID(project.id); return uuidProject.id; } export async function getUpgradeUrl() { return `${getBaseURL()}/dashboard/team/upgrade`; }