@@ -10,7 +10,7 @@ import { CLI_LOG_LEVEL_CHOICES_STRING, LOG_LEVELS_LIST } from './log-levels.js'
1010import { getName } from './build.js'
1111
1212export const logsEdgeFunction = async ( options : OptionValues , command : BaseCommand ) => {
13- let deployId : string | undefined = options . deployId
13+ let deployId = options . deployId as string | undefined
1414 await command . authenticate ( )
1515
1616 const client = command . netlify . api
@@ -22,23 +22,24 @@ export const logsEdgeFunction = async (options: OptionValues, command: BaseComma
2222 return
2323 }
2424
25- if ( options . level && ! options . level . every ( ( level : string ) => LOG_LEVELS_LIST . includes ( level ) ) ) {
26- log ( `Invalid log level. Choices are:${ CLI_LOG_LEVEL_CHOICES_STRING } ` )
25+ const levels = options . level as string [ ] | undefined
26+ if ( levels && ! levels . every ( ( level ) => LOG_LEVELS_LIST . includes ( level ) ) ) {
27+ log ( `Invalid log level. Choices are:${ CLI_LOG_LEVEL_CHOICES_STRING . toString ( ) } ` )
2728 }
2829
29- const levelsToPrint = options . level || LOG_LEVELS_LIST
30+ const levelsToPrint : string [ ] = levels || LOG_LEVELS_LIST
3031
3132 if ( options . from ) {
32- const fromMs = parseDateToMs ( options . from )
33- const toMs = options . to ? parseDateToMs ( options . to ) : Date . now ( )
33+ const fromMs = parseDateToMs ( options . from as string )
34+ const toMs = options . to ? parseDateToMs ( options . to as string ) : Date . now ( )
3435
3536 const url = `https://analytics.services.netlify.com/v2/sites/${ siteId } /edge_function_logs?from=${ fromMs . toString ( ) } &to=${ toMs . toString ( ) } `
3637 const data = await fetchHistoricalLogs ( { url, accessToken : client . accessToken ?? '' } )
3738 printHistoricalLogs ( data , levelsToPrint )
3839 return
3940 }
4041
41- const userId = command . netlify . globalConfig . get ( 'userId' )
42+ const userId = command . netlify . globalConfig . get ( 'userId' ) as string
4243
4344 if ( ! deployId ) {
4445 const deploys = await client . listSiteDeploys ( { siteId } )
@@ -51,15 +52,15 @@ export const logsEdgeFunction = async (options: OptionValues, command: BaseComma
5152 if ( deploys . length === 1 ) {
5253 deployId = deploys [ 0 ] . id
5354 } else {
54- const { result } = await inquirer . prompt ( {
55+ const { result } = ( await inquirer . prompt ( {
5556 name : 'result' ,
5657 type : 'list' ,
5758 message : `Select a deploy\n\n${ chalk . yellow ( '*' ) } indicates a deploy created by you` ,
58- choices : deploys . map ( ( deploy : any ) => ( {
59+ choices : deploys . map ( ( deploy ) => ( {
5960 name : getName ( { deploy, userId } ) ,
6061 value : deploy . id ,
6162 } ) ) ,
62- } )
63+ } ) ) as { result : string }
6364
6465 deployId = result
6566 }
@@ -79,7 +80,7 @@ export const logsEdgeFunction = async (options: OptionValues, command: BaseComma
7980 } )
8081
8182 ws . on ( 'message' , ( data : string ) => {
82- const logData = JSON . parse ( data )
83+ const logData = JSON . parse ( data ) as { level : string ; message : string ; timestamp ?: string }
8384 if ( ! levelsToPrint . includes ( logData . level . toLowerCase ( ) ) ) {
8485 return
8586 }
@@ -90,7 +91,7 @@ export const logsEdgeFunction = async (options: OptionValues, command: BaseComma
9091 log ( 'Connection closed' )
9192 } )
9293
93- ws . on ( 'error' , ( err : any ) => {
94+ ws . on ( 'error' , ( err : Error ) => {
9495 log ( 'Connection error' )
9596 log ( err )
9697 } )
0 commit comments