diff --git a/bin/run.js b/bin/run.js index 2e34d199ca8..8ef0578026f 100755 --- a/bin/run.js +++ b/bin/run.js @@ -3,10 +3,10 @@ import { argv } from 'process' import updateNotifier from 'update-notifier' -import { runProgram } from '../dist/utils/run-program.js' +import { createMainCommand } from '../dist/commands/main.js' import { error } from '../dist/utils/command-helpers.js' import getPackageJson from '../dist/utils/get-package-json.js' -import { createMainCommand } from '../dist/commands/main.js' +import { runProgram } from '../dist/utils/run-program.js' // 12 hours const UPDATE_CHECK_INTERVAL = 432e5 diff --git a/src/commands/base-command.ts b/src/commands/base-command.ts index 129197271fe..d0910f14c55 100644 --- a/src/commands/base-command.ts +++ b/src/commands/base-command.ts @@ -596,7 +596,7 @@ export default class BaseCommand extends Command { token, ...apiUrlOpts, }) - const { buildDir, config, configPath, repositoryRoot, siteInfo } = cachedConfig + const { accounts, buildDir, config, configPath, repositoryRoot, siteInfo } = cachedConfig let { env } = cachedConfig if (flags.offlineEnv) { env = {} @@ -642,6 +642,7 @@ export default class BaseCommand extends Command { const configFilePath = configPath || join(this.workingDir, 'netlify.toml') actionCommand.netlify = { + accounts, // api methods api, apiOpts, diff --git a/src/commands/sites/sites-create-template.ts b/src/commands/sites/sites-create-template.ts index dadc1dea2e3..1b232912aa3 100644 --- a/src/commands/sites/sites-create-template.ts +++ b/src/commands/sites/sites-create-template.ts @@ -1,10 +1,11 @@ +import path from 'node:path' +import { fileURLToPath } from 'node:url' + import { OptionValues } from 'commander' import inquirer from 'inquirer' import pick from 'lodash/pick.js' import { render } from 'prettyjson' import { v4 as uuid } from 'uuid' -import path from 'node:path' -import { fileURLToPath } from 'node:url' import { chalk, @@ -30,7 +31,7 @@ import BaseCommand from '../base-command.js' import { getSiteNameInput } from './sites-create.js' export const sitesCreateTemplate = async (repository: string, options: OptionValues, command: BaseCommand) => { - const { api } = command.netlify + const { accounts, api } = command.netlify await command.authenticate() const { globalConfig } = command.netlify @@ -52,7 +53,6 @@ export const sitesCreateTemplate = async (repository: string, options: OptionVal error(`${getTerminalLink(chalk.bold(templateName), githubLink)} is not a valid GitHub template`) return } - const accounts = await api.listAccountsForUser() let { accountSlug } = options diff --git a/src/commands/sites/sites-create.ts b/src/commands/sites/sites-create.ts index 2f97b2e8334..98cc594124f 100644 --- a/src/commands/sites/sites-create.ts +++ b/src/commands/sites/sites-create.ts @@ -29,12 +29,10 @@ export const getSiteNameInput = async (name: string | undefined): Promise<{ name } export const sitesCreate = async (options: OptionValues, command: BaseCommand) => { - const { api } = command.netlify + const { accounts, api } = command.netlify await command.authenticate() - const accounts: Account[] = await api.listAccountsForUser() - let { accountSlug }: { accountSlug?: string } = options if (!accountSlug) { const { accountSlug: accountSlugInput }: { accountSlug: string } = await inquirer.prompt< diff --git a/src/commands/status/status.ts b/src/commands/status/status.ts index 1912c6be418..09c5a4f1816 100644 --- a/src/commands/status/status.ts +++ b/src/commands/status/status.ts @@ -6,7 +6,7 @@ import { chalk, error, exit, getToken, log, logJson, warn, APIError } from '../. import BaseCommand from '../base-command.js' export const status = async (options: OptionValues, command: BaseCommand) => { - const { api, globalConfig, site, siteInfo } = command.netlify + const { accounts, api, globalConfig, site, siteInfo } = command.netlify const current = globalConfig.get('userId') const [accessToken] = await getToken() @@ -23,12 +23,10 @@ export const status = async (options: OptionValues, command: BaseCommand) => { Current Netlify User │ ──────────────────────┘`) - let accounts let user try { - // eslint-disable-next-line @typescript-eslint/no-extra-semi - ;[accounts, user] = await Promise.all([api.listAccountsForUser(), api.getCurrentUser()]) + user = await api.getCurrentUser() } catch (error_) { if ((error_ as APIError).status === 401) { error('Your session has expired. Please try to re-authenticate by running `netlify logout` and `netlify login`.') @@ -45,7 +43,6 @@ export const status = async (options: OptionValues, command: BaseCommand) => { } const teamsData = {} - // @ts-expect-error TS(7006) FIXME: Parameter 'team' implicitly has an 'any' type. accounts.forEach((team) => { // @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message teamsData[team.name] = team.roles_allowed.join(' ') diff --git a/src/commands/types.d.ts b/src/commands/types.d.ts index bfeb5c28cfe..06f8a4789e5 100644 --- a/src/commands/types.d.ts +++ b/src/commands/types.d.ts @@ -4,6 +4,7 @@ import type { NetlifyAPI } from 'netlify' import type { FrameworksAPIPaths } from "../utils/frameworks-api.ts"; import StateConfig from '../utils/state-config.js' +import { Account } from "../utils/types.ts"; // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -57,6 +58,7 @@ export type EnvironmentVariables = Record Promise<$TSFixMe>> apiOpts: $TSFixMe diff --git a/src/utils/types.ts b/src/utils/types.ts index f424abcce82..faef693e903 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -168,16 +168,7 @@ export interface Account { name: string slug: string type: string - capabilities: { - sites: { - included: number - used: number - } - collaborators: { - included: number - used: number - } - } + capabilities: Record billing_name: string billing_email: string billing_details: string