Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix TypeScript errors in login and logout files #6880

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion src/commands/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
6 changes: 3 additions & 3 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,17 @@ 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,
cachedConfig,
packagePath,
deployId,
siteId,
token,
token: blobsToken,
})

if (!success) {
Expand Down Expand Up @@ -566,7 +567,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,
Expand Down
6 changes: 2 additions & 4 deletions src/commands/integration/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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,
Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions src/commands/login/login.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { OptionValues } from 'commander'

import { chalk, exit, getToken, log } from '../../utils/command-helpers.js'
import { Location } 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: Location) {
switch (location) {
case 'env':
return 'via process.env.NETLIFY_AUTH_TOKEN set in your terminal session'
Expand All @@ -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 })
Expand Down
1 change: 0 additions & 1 deletion src/commands/logout/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/commands/status/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 14 additions & 5 deletions src/utils/command-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ 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'

import getGlobalConfig from './get-global-config.js'
import getPackageJson from './get-package-json.js'
import { reportError } from './telemetry/report-error.js'
import { Location } from './types.js'

/** The parsed process argv without the binary only arguments and flags */
const argv = process.argv.slice(2)
Expand Down Expand Up @@ -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 })
Expand All @@ -119,14 +127,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, Location]

export const getToken = async (tokenFromOptions?: string): Promise<tokenTuple> => {
// 1. First honor command flag --auth
if (tokenFromOptions) {
return [tokenFromOptions, 'flag']
Expand Down
2 changes: 2 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ export interface Request extends IncomingMessage {
}

export type Rewriter = (req: Request) => Match | null

export type Location = 'env' | 'flag' | 'config' | 'not found'