(args: string[], template: string)
| 252 | }); |
| 253 | } |
| 254 | |
| 255 | function vercelAccessError(error: unknown): Error { |
| 256 | const details = error instanceof Error ? error.message.trim() : ''; |
| 257 | return new Error( |
| 258 | [ |
| 259 | 'Could not verify Vercel access for the kilocode team.', |
| 260 | 'Install workspace tools with `pnpm install --frozen-lockfile` in the checkout.', |
| 261 | `Run \`${VERCEL_COMMAND} login\` with an account that has access to the kilocode team.`, |
| 262 | `Verify access with \`${VERCEL_COMMAND} whoami --scope kilocode --format=json\`.`, |
| 263 | details ? `Vercel reported:\n${details}` : undefined, |
| 264 | ] |
| 265 | .filter(Boolean) |
| 266 | .join('\n') |
| 267 | ); |
| 268 | } |
| 269 | |
| 270 | function onePasswordAccessError(error: unknown): Error { |
| 271 | const details = error instanceof Error ? error.message.trim() : ''; |
| 272 | return new Error( |
| 273 | [ |
| 274 | `Could not verify 1Password access to the ${VAULT} vault.`, |
| 275 | ...onePasswordInstallInstructions(), |
| 276 | `Verify access with \`op account list --format=json\`, then \`op vault get "${VAULT}" --account ${ONE_PASSWORD_ACCOUNT_URL} --format=json\`.`, |
| 277 | 'If verification says the vault is missing or forbidden, ask for access to that vault.', |
| 278 | details ? `1Password reported:\n${details}` : undefined, |
| 279 | ] |
| 280 | .filter(Boolean) |
| 281 | .join('\n') |
| 282 | ); |
| 283 | } |
| 284 | |
| 285 | export type VercelContexts = { |
| 286 | contexts: VercelContext[]; |
| 287 | missingProjects: Project[]; |
| 288 | }; |
| 289 | |
| 290 | class VercelApiError extends Error { |
| 291 | constructor( |
| 292 | operation: string, |
| 293 | readonly code: string | undefined, |
| 294 | message: string | undefined |
| 295 | ) { |
| 296 | super(`${operation} failed: ${code ?? 'unknown_error'}${message ? ` (${message})` : ''}.`); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | function apiArgs(context: VercelContext, endpoint: string): string[] { |
| 301 | const separator = endpoint.includes('?') ? '&' : '?'; |
| 302 | return ['api', `${endpoint}${separator}teamId=${context.orgId}`, '--raw']; |
| 303 | } |
| 304 | |
| 305 | // `vercel api` can also exit 0 with a JSON error body, so check both. |
| 306 | function apiResponse(output: string, operation: string): JsonRecord { |
| 307 | const response = parseJson(output, operation); |
| 308 | if (isRecord(response.error)) { |
| 309 | throw new VercelApiError( |
| 310 | operation, |
| 311 | stringValue(response.error, 'code'), |
no test coverage detected