-
Notifications
You must be signed in to change notification settings - Fork 352
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
Changes from 4 commits
e102e4a
07ce94a
d2046ff
ee7f031
f41cc50
8f6f0c3
35ccfb8
bd92af0
378756a
f480ba1
de8ea1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,7 @@ import { OptionValues } from 'commander' | |
import { chalk, exit, getToken, log } from '../../utils/command-helpers.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: 'env' | 'flag' | 'config' | 'not found') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can extract this type and move it into the types file as it's used later as well |
||
switch (location) { | ||
case 'env': | ||
return 'via process.env.NETLIFY_AUTH_TOKEN set in your terminal session' | ||
|
@@ -18,7 +17,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 }) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
|
@@ -92,8 +93,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 }) | ||
|
@@ -119,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 | undefined, 'flag' | 'env' | 'config' | 'not found'] | ||
|
||
export const getToken = async (tokenFromOptions?: string): Promise<tokenTuple> => { | ||
// 1. First honor command flag --auth | ||
if (tokenFromOptions) { | ||
return [tokenFromOptions, 'flag'] | ||
|
@@ -143,7 +151,7 @@ export const getToken = async (tokenFromOptions) => { | |
if (tokenFromConfig) { | ||
return [tokenFromConfig, 'config'] | ||
} | ||
return [null, 'not found'] | ||
return [undefined, 'not found'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did this change as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was originally intended to satisfy the type requirements of a pair of functions that use |
||
} | ||
|
||
// 'api' command uses JSON output by default | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did this need to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prior to our changes,
getToken
returned anany
type. In reality, this value would be astring
orundefined
. Thefetch
request below it (see screenshot) relies ontoken
being astring
type. BecausegetToken
can returnundefined
, and we don't want to passundefined
to thefetch
request, we reassigned it to an empty string.It does seem that our change may have unintended consequences as a result of changing
token
fromundefined
to an empty string in cases where there is no token. We are pushing a change that goes about fixing this in a way that does not involve reassigningtoken
.