1
- // @ts -nocheck
2
1
/* eslint-disable no-console */
3
-
4
2
import chalk from 'chalk'
5
- //@ts -ignore
6
- import chalkTable from 'chalk-table '
3
+ // @ts -ignore
4
+ import Table from 'cli-table3 '
7
5
import meow from 'meow'
8
6
import ora from 'ora'
9
7
@@ -56,6 +54,9 @@ const auditLogFlags = prepareFlags({
56
54
* @property {boolean } outputJson
57
55
* @property {boolean } outputMarkdown
58
56
* @property {string } orgSlug
57
+ * @property {string } type
58
+ * @property {number } page
59
+ * @property {number } perPage
59
60
*/
60
61
61
62
/**
@@ -89,11 +90,15 @@ function setupCommand (name, description, argv, importMeta) {
89
90
90
91
const {
91
92
json : outputJson ,
92
- markdown : outputMarkdown
93
+ markdown : outputMarkdown ,
94
+ type,
95
+ page,
96
+ perPage
97
+
93
98
} = cli . flags
94
99
95
- if ( cli . input . length > 1 ) {
96
- throw new InputError ( 'Only one package lookup supported at once ' )
100
+ if ( cli . input . length < 1 ) {
101
+ throw new InputError ( 'Please provide an organization slug ' )
97
102
}
98
103
99
104
const [ orgSlug = '' ] = cli . input
@@ -106,7 +111,10 @@ function setupCommand (name, description, argv, importMeta) {
106
111
return {
107
112
outputJson,
108
113
outputMarkdown,
109
- orgSlug
114
+ orgSlug,
115
+ type,
116
+ page,
117
+ perPage
110
118
}
111
119
}
112
120
@@ -123,40 +131,39 @@ function setupCommand (name, description, argv, importMeta) {
123
131
*/
124
132
async function fetchOrgAuditLog ( orgSlug , input , spinner ) {
125
133
const socketSdk = await setupSdk ( getDefaultKey ( ) || FREE_API_KEY )
134
+ console . log ( input )
135
+ // @ts -ignore
126
136
const result = await handleApiCall ( socketSdk . getAuditLogEvents ( orgSlug , input ) , 'looking up package' )
127
137
128
138
if ( ! result . success ) {
139
+ // @ts -ignore
129
140
return handleUnsuccessfulApiResponse ( 'getAuditLogEvents' , result , spinner )
130
141
}
131
142
spinner . stop ( )
132
143
133
144
console . log ( `\n Audit log for: ${ orgSlug } \n` )
134
145
135
- const options = {
136
- columns : [
137
- { field : 'event_id' , name : chalk . magenta ( 'Event id' ) } ,
138
- { field : 'country_code' , name : chalk . magenta ( 'Country code' ) } ,
139
- { field : 'created_at' , name : chalk . magenta ( 'Created at' ) } ,
140
- { field : 'ip_address' , name : chalk . magenta ( 'IP address' ) } ,
141
- { field : 'payload' , name : chalk . magenta ( 'Payload' ) } ,
142
- { field : 'type' , name : chalk . magenta ( 'Type' ) } ,
143
- { field : 'user_agent' , name : chalk . magenta ( 'User agent' ) } ,
144
- { field : 'user_id' , name : chalk . magenta ( 'User Id' ) } ,
145
- { field : 'user_email' , name : chalk . magenta ( 'User email' ) }
146
- ]
147
- }
146
+ const table = new Table ( {
147
+ chars : { 'top' : '═' , 'top-mid' : '╤' , 'top-left' : '╔' , 'top-right' : '╗' , 'bottom' : '═' , 'bottom-mid' : '╧' , 'bottom-left' : '╚' , 'bottom-right' : '╝' , 'left' : '║' , 'left-mid' : '╟' , 'mid' : '─' , 'mid-mid' : '┼' , 'right' : '║' , 'right-mid' : '╢' , 'middle' : '│' } ,
148
+ colWidths : [ 11 , 20 ] ,
149
+ style : { head : [ ] , border : [ ] } ,
150
+ wordWrap : true
151
+ } )
148
152
149
- const formattedResults = result . data . results . map ( ( /** @type {{ event_id: any; country_code: any; created_at: string | number | Date; } } */ d ) => {
150
- return {
151
- ...d ,
152
- event_id : d . event_id ,
153
- country_code : chalk . underline ( `${ d . country_code } ` ) ,
154
- created_at : d . created_at ? new Date ( d . created_at ) . toLocaleDateString ( 'en-us' , { year : 'numeric' , month : 'short' , day : 'numeric' } ) : '' ,
155
- }
153
+ table . push ( [ chalk . magenta ( 'Date' ) , chalk . magenta ( 'User' ) , chalk . magenta ( 'Type' ) , chalk . magenta ( 'IP address' ) , chalk . magenta ( 'User agent' ) ] )
154
+
155
+ result . data . results . map ( ( /** @type {{ created_at: string | number | Date; user_email: any; type: any; ip_address: any; user_agent: string; } } */ d ) => {
156
+ const data = [
157
+ d . created_at ? new Date ( d . created_at ) . toLocaleDateString ( 'en-us' , { year : 'numeric' , month : 'numeric' , day : 'numeric' } ) : '' ,
158
+ d . user_email ,
159
+ d . type ,
160
+ d . ip_address ,
161
+ d . user_agent . split ( ';' ) . join ( '\n' )
162
+ ]
163
+ return table . push ( data )
156
164
} )
157
165
158
- const table = chalkTable ( options , formattedResults )
159
- console . log ( table , '\n' )
166
+ console . log ( table . toString ( ) )
160
167
161
168
return {
162
169
data : result . data
0 commit comments