From e22d317e512c1d69f3c4b1060dbef1ab2a37debb Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Tue, 3 Dec 2024 00:54:42 -0500 Subject: [PATCH 1/9] fix: remove second call to accounts to make status a little faster --- bin/run.js | 4 ++-- src/commands/base-command.ts | 3 ++- src/commands/status/min | 0 src/commands/status/nomin | 0 src/commands/status/status.ts | 5 ++--- src/commands/types.d.ts | 1 + 6 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 src/commands/status/min create mode 100644 src/commands/status/nomin 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/status/min b/src/commands/status/min new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/commands/status/nomin b/src/commands/status/nomin new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/commands/status/status.ts b/src/commands/status/status.ts index 1912c6be418..2450ff023e6 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,11 @@ 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 Promise.all([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`.') diff --git a/src/commands/types.d.ts b/src/commands/types.d.ts index bfeb5c28cfe..cfe4698bd43 100644 --- a/src/commands/types.d.ts +++ b/src/commands/types.d.ts @@ -57,6 +57,7 @@ export type EnvironmentVariables = Record Promise<$TSFixMe>> apiOpts: $TSFixMe From 25184df0ac971f7191f12704d107ac900d1807ad Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Tue, 3 Dec 2024 10:26:27 -0500 Subject: [PATCH 2/9] chore: remove temp files --- src/commands/status/min | 0 src/commands/status/nomin | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/commands/status/min delete mode 100644 src/commands/status/nomin diff --git a/src/commands/status/min b/src/commands/status/min deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/commands/status/nomin b/src/commands/status/nomin deleted file mode 100644 index e69de29bb2d..00000000000 From 636b61fc48edd582e5dd18275a4ad91d67983a81 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 6 Dec 2024 19:38:03 -0500 Subject: [PATCH 3/9] fix: don't await all promises when there's just one --- src/commands/status/status.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commands/status/status.ts b/src/commands/status/status.ts index 2450ff023e6..7aa47fe66a8 100644 --- a/src/commands/status/status.ts +++ b/src/commands/status/status.ts @@ -26,8 +26,7 @@ export const status = async (options: OptionValues, command: BaseCommand) => { let user try { - // eslint-disable-next-line @typescript-eslint/no-extra-semi - ;[user] = await Promise.all([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`.') From 99f6383ef32ad6bc320f791c1fbbb97f1b964c8f Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 6 Dec 2024 19:52:27 -0500 Subject: [PATCH 4/9] chore: add types for accounts --- src/commands/types.d.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/commands/types.d.ts b/src/commands/types.d.ts index cfe4698bd43..11115c5ef9d 100644 --- a/src/commands/types.d.ts +++ b/src/commands/types.d.ts @@ -57,7 +57,7 @@ export type EnvironmentVariables = Record Promise<$TSFixMe>> apiOpts: $TSFixMe @@ -82,3 +82,22 @@ export interface AddressInUseError extends Error { address: string port: number } + +export interface Account { + id: string; + name: string; + slug: string; + type: string; + capabilities: Record; + billing_name: string; + billing_email: string; + billing_details: string; + billing_period: string; + payment_method_id: string; + type_name: string; + type_id: string; + owner_ids: string[]; + roles_allowed: string[]; + created_at: string; + updated_at: string; +} From 55759777ae850356aa38f6367225b184a795b790 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 6 Dec 2024 19:56:52 -0500 Subject: [PATCH 5/9] fix: remove unused ts ignore --- src/commands/status/status.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commands/status/status.ts b/src/commands/status/status.ts index 7aa47fe66a8..09c5a4f1816 100644 --- a/src/commands/status/status.ts +++ b/src/commands/status/status.ts @@ -43,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(' ') From 79b7f408576f7df7a001883687747d986c73b51f Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 6 Dec 2024 20:00:27 -0500 Subject: [PATCH 6/9] fix: use types we already have --- src/commands/types.d.ts | 20 +------------------- src/utils/types.ts | 11 +---------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/commands/types.d.ts b/src/commands/types.d.ts index 11115c5ef9d..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 @@ -82,22 +83,3 @@ export interface AddressInUseError extends Error { address: string port: number } - -export interface Account { - id: string; - name: string; - slug: string; - type: string; - capabilities: Record; - billing_name: string; - billing_email: string; - billing_details: string; - billing_period: string; - payment_method_id: string; - type_name: string; - type_id: string; - owner_ids: string[]; - roles_allowed: string[]; - created_at: string; - updated_at: string; -} diff --git a/src/utils/types.ts b/src/utils/types.ts index f424abcce82..98b7042a14b 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 From d69913d8de6f437b38e729ee1148f04c0e3c989b Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 6 Dec 2024 20:02:18 -0500 Subject: [PATCH 7/9] chore: prettier --- src/utils/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/types.ts b/src/utils/types.ts index 98b7042a14b..faef693e903 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -168,7 +168,7 @@ export interface Account { name: string slug: string type: string - capabilities: Record + capabilities: Record billing_name: string billing_email: string billing_details: string From 24c0a91af5448f28159530238362decaa8a9251e Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Tue, 17 Dec 2024 19:33:44 -0500 Subject: [PATCH 8/9] fix: remove accounts api extra call from sites:create --- src/commands/sites/sites-create.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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< From 7e446541868b9bd3e7af876da4f378d4f0b8db69 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Tue, 17 Dec 2024 19:34:09 -0500 Subject: [PATCH 9/9] fix: remove extra call to accounts endpoint from sites:create-template --- src/commands/sites/sites-create-template.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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