Skip to content

Commit 106abaa

Browse files
committed
update command to typescript
1 parent ff1c575 commit 106abaa

File tree

1 file changed

+20
-49
lines changed

1 file changed

+20
-49
lines changed

src/commands/analytics.ts

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/* eslint-disable no-console */
2-
31
import chalk from 'chalk'
42
import meow from 'meow'
53
import ora from 'ora'
64

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"
1213

13-
/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */
14-
export const analytics = {
14+
export const analytics: CliSubcommand = {
1515
description: 'Look up analytics data',
1616
async run (argv, importMeta, { parentName }) {
1717
const name = parentName + ' analytics'
@@ -32,22 +32,14 @@ export const analytics = {
3232

3333
// Internal functions
3434

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 } = {
5143
...outputFlags,
5244
...validationFlags,
5345
}
@@ -100,17 +92,7 @@ function setupCommand (name, description, argv, importMeta) {
10092
}
10193
}
10294

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> {
11496
const socketSdk = await setupSdk(getDefaultKey())
11597
const result = await handleApiCall(socketSdk.getOrgAnalytics(time), 'fetching analytics data')
11698

@@ -120,7 +102,7 @@ async function fetchOrgAnalyticsData (time, spinner) {
120102

121103
spinner.stop()
122104

123-
const data = result.data.reduce((/** @type {{ [key: string]: any }} */ acc, current) => {
105+
const data = result.data.reduce((acc: { [key: string]: any }, current) => {
124106
const formattedDate = new Date(current.created_at).toLocaleDateString()
125107

126108
if (acc[formattedDate]) {
@@ -147,18 +129,7 @@ async function fetchOrgAnalyticsData (time, spinner) {
147129
console.table(data, ['repository_name', 'total_critical_prevented', 'total_high_prevented', 'total_medium_prevented', 'total_low_prevented'])
148130
}
149131

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> {
162133
const socketSdk = await setupSdk(getDefaultKey())
163134
const result = await handleApiCall(socketSdk.getRepoAnalytics(repo, time), 'fetching analytics data')
164135

0 commit comments

Comments
 (0)