| 351 | vercel(undefined, ['whoami', '--format=json'], undefined, { includeFailureOutput: true }), |
| 352 | 'Vercel login' |
| 353 | ); |
| 354 | } catch (error) { |
| 355 | if (error instanceof MissingCommandError) throw error; |
| 356 | throw vercelAccessError(error); |
| 357 | } |
| 358 | const team = isRecord(whoami.team) ? whoami.team : undefined; |
| 359 | const orgId = team ? stringValue(team, 'id') : undefined; |
| 360 | if (!orgId || stringValue(team ?? {}, 'slug') !== 'kilocode') { |
| 361 | throw vercelAccessError( |
| 362 | new Error('The authenticated Vercel account is not scoped to the kilocode team.') |
| 363 | ); |
| 364 | } |
| 365 | |
| 366 | const contexts: VercelContext[] = []; |
| 367 | const missingProjects: Project[] = []; |
| 368 | for (const project of PROJECTS) { |
| 369 | const context = { project, orgId, cwd: tempDirectory }; |
| 370 | if (projectExists(context)) contexts.push(context); |
| 371 | else missingProjects.push(project); |
| 372 | } |
| 373 | return { contexts, missingProjects }; |
| 374 | } |
| 375 | |
| 376 | export type EnvRecord = { |
| 377 | id: string; |
| 378 | key: string; |
| 379 | type: string; |
| 380 | target: string[]; |
| 381 | customEnvironmentIds: string[]; |
| 382 | gitBranch?: string; |
| 383 | configurationId?: string; |
| 384 | value?: string; |
| 385 | }; |
| 386 | |
| 387 | // Vercel returns `target` as either one string or an array of strings. |
| 388 | function stringArray(value: unknown): string[] { |
| 389 | if (typeof value === 'string') return [value]; |
| 390 | return Array.isArray(value) |
| 391 | ? value.filter((item): item is string => typeof item === 'string') |
| 392 | : []; |
| 393 | } |
| 394 | |
| 395 | export function listEnvRecords(context: VercelContext): EnvRecord[] { |
| 396 | const operation = `List ${context.project} environment variables`; |
| 397 | const response = vercelApi( |
| 398 | context, |
| 399 | `/v10/projects/${encodeURIComponent(context.project)}/env`, |
| 400 | operation |
| 401 | ); |
| 402 | if (isRecord(response.pagination) && response.pagination.next != null) { |
| 403 | throw new Error(`${operation} returned more than one page.`); |
| 404 | } |
| 405 | const hidden = response.hiddenProductionEnvCount; |
| 406 | if (typeof hidden === 'number' && hidden > 0) { |
| 407 | throw new Error( |
| 408 | `${operation}: ${hidden} production variables are hidden from your Vercel account. Ask for access to them first.` |
| 409 | ); |
| 410 | } |