diff --git a/src/commands/build/build.ts b/src/commands/build/build.ts index 7151a67e226..0f2a30fbff1 100644 --- a/src/commands/build/build.ts +++ b/src/commands/build/build.ts @@ -27,7 +27,6 @@ export const build = async (options: OptionValues, command: BaseCommand) => { const { cachedConfig, siteInfo } = command.netlify command.setAnalyticsPayload({ dry: options.dry }) // Retrieve Netlify Build options - // @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 0. const [token] = await getToken() const settings = await detectFrameworkSettings(command, 'build') diff --git a/src/commands/deploy/deploy.ts b/src/commands/deploy/deploy.ts index 098d6c1e14e..a2ad454b014 100644 --- a/src/commands/deploy/deploy.ts +++ b/src/commands/deploy/deploy.ts @@ -371,8 +371,9 @@ const uploadDeployBlobs = async ({ phase: 'start', }) - const [token] = await getToken(false) + const [token] = await getToken() + const blobsToken = token || undefined const { success } = await runCoreSteps(['blobs_upload'], { ...options, quiet: silent, @@ -380,7 +381,7 @@ const uploadDeployBlobs = async ({ packagePath, deployId, siteId, - token, + token: blobsToken, }) if (!success) { @@ -565,7 +566,6 @@ const handleBuild = async ({ cachedConfig, currentDir, defaultConfig, deployHand if (!options.build) { return {} } - // @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 0. const [token] = await getToken() const resolvedOptions = await getBuildOptions({ cachedConfig, diff --git a/src/commands/integration/deploy.ts b/src/commands/integration/deploy.ts index df2f74ce22d..9a86d6ec23f 100644 --- a/src/commands/integration/deploy.ts +++ b/src/commands/integration/deploy.ts @@ -394,7 +394,6 @@ export const getConfiguration = (workingDir) => { export const deploy = async (options: OptionValues, command: BaseCommand) => { const { api, cachedConfig, site, siteInfo } = command.netlify const { id: siteId } = site - // @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 0. const [token] = await getToken() const workingDir = resolve(command.workingDir) const buildOptions = await getBuildOptions({ @@ -412,6 +411,7 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => { const { description, integrationLevel, name, scopes, slug } = await getConfiguration(command.workingDir) const localIntegrationConfig = { name, description, scopes, slug, integrationLevel } + const headers = token ? { 'netlify-token': token } : undefined // @ts-expect-error TS(2345) FIXME: Argument of type '{ api: any; site: any; siteInfo:... Remove this comment to see the full error message const { accountId } = await getSiteInformation({ api, @@ -422,9 +422,7 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => { const { body: registeredIntegration, statusCode } = await fetch( `${getIntegrationAPIUrl()}/${accountId}/integrations?site_id=${siteId}`, { - headers: { - 'netlify-token': token, - }, + headers, }, ).then(async (res) => { const body = await res.json() diff --git a/src/commands/login/login.ts b/src/commands/login/login.ts index 4917460434e..c4ca33f562b 100644 --- a/src/commands/login/login.ts +++ b/src/commands/login/login.ts @@ -1,10 +1,10 @@ import { OptionValues } from 'commander' import { chalk, exit, getToken, log } from '../../utils/command-helpers.js' +import { TokenLocation } from '../../utils/types.js' import BaseCommand from '../base-command.js' -// @ts-expect-error TS(7006) FIXME: Parameter 'location' implicitly has an 'any' type. -const msg = function (location) { +const msg = function (location: TokenLocation) { switch (location) { case 'env': return 'via process.env.NETLIFY_AUTH_TOKEN set in your terminal session' @@ -18,7 +18,6 @@ const msg = function (location) { } export const login = async (options: OptionValues, command: BaseCommand) => { - // @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 0. const [accessToken, location] = await getToken() command.setAnalyticsPayload({ new: options.new }) diff --git a/src/commands/logout/logout.ts b/src/commands/logout/logout.ts index f6abe875b6d..03881179654 100644 --- a/src/commands/logout/logout.ts +++ b/src/commands/logout/logout.ts @@ -5,7 +5,6 @@ import { track } from '../../utils/telemetry/index.js' import BaseCommand from '../base-command.js' export const logout = async (options: OptionValues, command: BaseCommand) => { - // @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 0. const [accessToken, location] = await getToken() if (!accessToken) { diff --git a/src/commands/status/status.ts b/src/commands/status/status.ts index 1a14e3592bb..1912c6be418 100644 --- a/src/commands/status/status.ts +++ b/src/commands/status/status.ts @@ -8,7 +8,6 @@ import BaseCommand from '../base-command.js' export const status = async (options: OptionValues, command: BaseCommand) => { const { api, globalConfig, site, siteInfo } = command.netlify const current = globalConfig.get('userId') - // @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 0. const [accessToken] = await getToken() if (!accessToken) { diff --git a/src/utils/command-helpers.ts b/src/utils/command-helpers.ts index 1ea8c39a2cf..ec033cf6703 100644 --- a/src/utils/command-helpers.ts +++ b/src/utils/command-helpers.ts @@ -8,6 +8,7 @@ import chokidar from 'chokidar' import decache from 'decache' import WSL from 'is-wsl' import debounce from 'lodash/debounce.js' +import { NetlifyAPI } from 'netlify' import terminalLink from 'terminal-link' import { clearSpinner, startSpinner } from '../lib/spinner.js' @@ -15,6 +16,7 @@ import { clearSpinner, startSpinner } from '../lib/spinner.js' import getGlobalConfig from './get-global-config.js' import getPackageJson from './get-package-json.js' import { reportError } from './telemetry/report-error.js' +import { TokenLocation } from './types.js' /** The parsed process argv without the binary only arguments and flags */ const argv = process.argv.slice(2) @@ -92,8 +94,14 @@ const TOKEN_TIMEOUT = 3e5 * @param {object} config.ticket * @returns */ -// @ts-expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message -export const pollForToken = async ({ api, ticket }) => { + +export const pollForToken = async ({ + api, + ticket, +}: { + api: NetlifyAPI + ticket: { id: string; client_id: string; authorized: boolean; created_at: string } +}) => { const spinner = startSpinner({ text: 'Waiting for authorization...' }) try { const accessToken = await api.getAccessToken(ticket, { timeout: TOKEN_TIMEOUT }) @@ -118,14 +126,15 @@ export const pollForToken = async ({ api, ticket }) => { clearSpinner({ spinner }) } } - /** * Get a netlify token * @param {string} [tokenFromOptions] optional token from the provided --auth options * @returns {Promise<[null|string, 'flag' | 'env' |'config' |'not found']>} */ -// @ts-expect-error TS(7006) FIXME: Parameter 'tokenFromOptions' implicitly has an 'an... Remove this comment to see the full error message -export const getToken = async (tokenFromOptions) => { + +export type tokenTuple = [string | null, TokenLocation] + +export const getToken = async (tokenFromOptions?: string): Promise => { // 1. First honor command flag --auth if (tokenFromOptions) { return [tokenFromOptions, 'flag'] diff --git a/src/utils/types.ts b/src/utils/types.ts index 95f1b5266ba..38ab8682b2b 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -62,3 +62,5 @@ export interface Request extends IncomingMessage { } export type Rewriter = (req: Request) => Match | null + +export type TokenLocation = 'env' | 'flag' | 'config' | 'not found'