1import { CommandError } from '../utils/errors';
2import { fetchAsync } from './rest/client';
3import { ensureLoggedInAsync } from './user/actions';
4
5export async function getProjectDevelopmentCertificateAsync(
6  easProjectId: string,
7  csrPEM: string
8): Promise<string> {
9  await ensureLoggedInAsync();
10  const response = await fetchAsync(
11    `projects/${encodeURIComponent(easProjectId)}/development-certificates`,
12    {
13      method: 'POST',
14      body: JSON.stringify({
15        csrPEM,
16      }),
17    }
18  );
19  if (!response.ok) {
20    throw new CommandError('API', `Unexpected error from Expo servers: ${response.statusText}.`);
21  }
22  const buffer = await response.buffer();
23  return buffer.toString('utf8');
24}
25