@@ -4,10 +4,10 @@ import meow from 'meow'
4
4
import ora from 'ora'
5
5
6
6
import { outputFlags , validationFlags } from '../../flags/index.js'
7
- // import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
7
+ import { handleApiCall , handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
8
8
import { InputError } from '../../utils/errors.js'
9
9
import { printFlagList } from '../../utils/formatting.js'
10
- // import { FREE_API_KEY, getDefaultKey, setupSdk } from '../../utils/sdk.js'
10
+ import { getDefaultKey , setupSdk } from '../../utils/sdk.js'
11
11
12
12
/** @type {import('../../utils/meow-with-subcommands').CliSubcommand } */
13
13
export const analytics = {
@@ -18,7 +18,6 @@ export const analytics = {
18
18
const input = setupCommand ( name , analytics . description , argv , importMeta )
19
19
if ( input ) {
20
20
const spinner = ora ( 'Fetching analytics data' ) . start ( )
21
- console . log ( input )
22
21
if ( input . scope === 'org' ) {
23
22
await fetchOrgAnalyticsData ( input . time , spinner )
24
23
} else {
@@ -94,29 +93,32 @@ function setupCommand (name, description, argv, importMeta) {
94
93
}
95
94
}
96
95
97
- // / **
98
- // * @typedef AnalyticsData
99
- // * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgAnalytics'>["data"] } data
100
- // */
96
+ /**
97
+ * @typedef AnalyticsData
98
+ * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgAnalytics'>["data"] } data
99
+ */
101
100
102
101
/**
103
102
* @param {string } time
104
103
* @param {import('ora').Ora } spinner
105
104
* @returns {Promise<void> }
106
105
*/
107
- // * @returns {Promise<void|AnalyticsData> }
108
106
async function fetchOrgAnalyticsData ( time , spinner ) {
109
- // const socketSdk = await setupSdk(getDefaultKey() || FREE_API_KEY)
110
- console . table ( time )
111
- console . log ( spinner )
107
+ const socketSdk = await setupSdk ( getDefaultKey ( ) )
108
+ const result = await handleApiCall ( socketSdk . getOrgAnalytics ( time ) , 'fetching analytics data' )
112
109
113
- // const result = await handleApiCall(socketSdk.getOrgAnalytics(time), 'fetching analytics data')
114
-
115
- // if (result.success === false) {
116
- // return handleUnsuccessfulApiResponse('getOrgAnalytics', result, spinner)
117
- // }
110
+ if ( result . success === false ) {
111
+ return handleUnsuccessfulApiResponse ( 'getOrgAnalytics' , result , spinner )
112
+ }
118
113
119
- // return {
114
+ const formattedData = result . data . map ( d => {
115
+ const formattedDate = new Date ( d . created_at ) . toLocaleDateString ( )
116
+ return {
117
+ ...d ,
118
+ created_at : formattedDate ,
119
+ }
120
+ } )
121
+ const data = { ...formattedData . flat ( 1 ) }
120
122
121
- // }
123
+ console . table ( data , [ 'created_at' , 'repository_name' , 'total_critical_alerts' , 'total_high_alerts' , 'total_critical_added' , 'total_high_added' , 'total_critical_prevented' , 'total_high_prevented' , 'total_medium_prevented' , 'total_low_prevented' , 'top_five_alert_types' ] )
122
124
}
0 commit comments