1
- /* eslint-disable no-console */
2
-
3
1
import chalk from 'chalk'
4
2
import meow from 'meow'
5
3
import ora from 'ora'
6
4
7
- import { outputFlags , validationFlags } from '../../flags/index.js'
8
- import { handleApiCall , handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
9
- import { InputError } from '../../utils/errors.js'
10
- import { printFlagList } from '../../utils/formatting.js'
11
- import { getDefaultKey , setupSdk } from '../../utils/sdk.js'
5
+ import { outputFlags , validationFlags } from '../flags'
6
+ import { handleApiCall , handleUnsuccessfulApiResponse } from '../utils/api-helpers'
7
+ import { InputError } from '../utils/errors'
8
+ import { printFlagList } from '../utils/formatting'
9
+ import { getDefaultKey , setupSdk } from '../utils/sdk'
10
+
11
+ import type { CliSubcommand } from '../utils/meow-with-subcommands'
12
+ import type { Ora } from "ora"
12
13
13
- /** @type {import('../../utils/meow-with-subcommands').CliSubcommand } */
14
- export const analytics = {
14
+ export const analytics : CliSubcommand = {
15
15
description : 'Look up analytics data' ,
16
16
async run ( argv , importMeta , { parentName } ) {
17
17
const name = parentName + ' analytics'
@@ -32,22 +32,14 @@ export const analytics = {
32
32
33
33
// Internal functions
34
34
35
- /**
36
- * @typedef CommandContext
37
- * @property {string } scope
38
- * @property {string } time
39
- * @property {string|undefined } repo
40
- */
41
-
42
- /**
43
- * @param {string } name
44
- * @param {string } description
45
- * @param {readonly string[] } argv
46
- * @param {ImportMeta } importMeta
47
- * @returns {void|CommandContext }
48
- */
49
- function setupCommand ( name , description , argv , importMeta ) {
50
- const flags = {
35
+ type CommandContext = {
36
+ scope : string
37
+ time : string
38
+ repo : string | undefined
39
+ }
40
+
41
+ function setupCommand ( name : string , description : string , argv : readonly string [ ] , importMeta : ImportMeta ) : void | CommandContext {
42
+ const flags : { [ key : string ] : any } = {
51
43
...outputFlags ,
52
44
...validationFlags ,
53
45
}
@@ -100,17 +92,7 @@ function setupCommand (name, description, argv, importMeta) {
100
92
}
101
93
}
102
94
103
- /**
104
- * @typedef OrgAnalyticsData
105
- * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgAnalytics'>["data"] } data
106
- */
107
-
108
- /**
109
- * @param {string } time
110
- * @param {import('ora').Ora } spinner
111
- * @returns {Promise<void> }
112
- */
113
- async function fetchOrgAnalyticsData ( time , spinner ) {
95
+ async function fetchOrgAnalyticsData ( time : string , spinner : Ora ) : Promise < void > {
114
96
const socketSdk = await setupSdk ( getDefaultKey ( ) )
115
97
const result = await handleApiCall ( socketSdk . getOrgAnalytics ( time ) , 'fetching analytics data' )
116
98
@@ -120,7 +102,7 @@ async function fetchOrgAnalyticsData (time, spinner) {
120
102
121
103
spinner . stop ( )
122
104
123
- const data = result . data . reduce ( ( /** @type { { [key: string]: any }} */ acc , current ) => {
105
+ const data = result . data . reduce ( ( acc : { [ key : string ] : any } , current ) => {
124
106
const formattedDate = new Date ( current . created_at ) . toLocaleDateString ( )
125
107
126
108
if ( acc [ formattedDate ] ) {
@@ -147,18 +129,7 @@ async function fetchOrgAnalyticsData (time, spinner) {
147
129
console . table ( data , [ 'repository_name' , 'total_critical_prevented' , 'total_high_prevented' , 'total_medium_prevented' , 'total_low_prevented' ] )
148
130
}
149
131
150
- /**
151
- * @typedef RepoAnalyticsData
152
- * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getRepoAnalytics'>["data"] } data
153
- */
154
-
155
- /**
156
- * @param {string } repo
157
- * @param {string } time
158
- * @param {import('ora').Ora } spinner
159
- * @returns {Promise<void> }
160
- */
161
- async function fetchRepoAnalyticsData ( repo , time , spinner ) {
132
+ async function fetchRepoAnalyticsData ( repo : string , time : string , spinner : Ora ) : Promise < void > {
162
133
const socketSdk = await setupSdk ( getDefaultKey ( ) )
163
134
const result = await handleApiCall ( socketSdk . getRepoAnalytics ( repo , time ) , 'fetching analytics data' )
164
135
0 commit comments