@@ -15,24 +15,20 @@ import type { components } from '@socketsecurity/sdk/types/api'
1515/**
1616 * This fetches all the relevant pieces of data to generate a report, given a
1717 * full scan ID.
18- * It can optionally only fetch the security or license side of things.
1918 */
2019export async function fetchReportData (
2120 orgSlug : string ,
2221 scanId : string ,
23- // includeLicensePolicy: boolean,
24- includeSecurityPolicy : boolean
22+ includeLicensePolicy : boolean
2523) : Promise <
2624 | {
2725 ok : true
2826 scan : Array < components [ 'schemas' ] [ 'SocketArtifact' ] >
29- // licensePolicy: undefined | SocketSdkReturnType<'getOrgSecurityPolicy'>
3027 securityPolicy : undefined | SocketSdkReturnType < 'getOrgSecurityPolicy' >
3128 }
3229 | {
3330 ok : false
3431 scan : undefined
35- // licensePolicy: undefined
3632 securityPolicy : undefined
3733 }
3834> {
@@ -46,7 +42,6 @@ export async function fetchReportData(
4642 const sockSdk = await setupSdk ( apiToken )
4743
4844 let haveScan = false
49- // let haveLicensePolicy = false
5045 let haveSecurityPolicy = false
5146
5247 // Lazily access constants.spinner.
@@ -55,54 +50,32 @@ export async function fetchReportData(
5550 function updateProgress ( ) {
5651 const needs = [
5752 ! haveScan ? 'scan' : undefined ,
58- // includeLicensePolicy && !haveLicensePolicy ? 'license policy' : undefined,
59- includeSecurityPolicy && ! haveSecurityPolicy
60- ? 'security policy'
61- : undefined
53+ ! haveSecurityPolicy ? 'security policy' : undefined
6254 ] . filter ( Boolean )
63- if ( needs . length > 2 ) {
64- // .toOxford()
65- needs [ needs . length - 1 ] = `and ${ needs [ needs . length - 1 ] } `
66- }
6755 const haves = [
6856 haveScan ? 'scan' : undefined ,
69- // includeLicensePolicy && haveLicensePolicy ? 'license policy' : undefined,
70- includeSecurityPolicy && haveSecurityPolicy
71- ? 'security policy'
72- : undefined
57+ haveSecurityPolicy ? 'security policy' : undefined
7358 ] . filter ( Boolean )
74- if ( haves . length > 2 ) {
75- // .toOxford()
76- haves [ haves . length - 1 ] = `and ${ haves [ haves . length - 1 ] } `
77- }
7859
7960 if ( needs . length ) {
8061 spinner . start (
81- `Fetching ${ needs . join ( needs . length > 2 ? ', ' : ' and ') } ...${ haves . length ? ` Completed fetching ${ haves . join ( haves . length > 2 ? ', ' : ' and ' ) } .` : '' } `
62+ `Fetching ${ needs . join ( ' and ') } ...${ haves . length ? ` Completed fetching ${ haves . join ( ' and ' ) } .` : '' } `
8263 )
8364 } else {
84- spinner . successAndStop (
85- `Completed fetching ${ haves . join ( haves . length > 2 ? ', ' : ' and ' ) } .`
86- )
65+ spinner . successAndStop ( `Completed fetching ${ haves . join ( ' and ' ) } .` )
8766 }
8867 }
8968
9069 updateProgress ( )
9170
92- // @ts -ignore
93- const [
94- scan ,
95- // licensePolicyMaybe,
96- securityPolicyMaybe
97- ] : [
71+ const [ scan , securityPolicyMaybe ] : [
9872 undefined | Array < components [ 'schemas' ] [ 'SocketArtifact' ] > ,
99- // undefined | SocketSdkResultType<'getOrgSecurityPolicy'>,
100- undefined | SocketSdkResultType < 'getOrgSecurityPolicy' >
73+ SocketSdkResultType < 'getOrgSecurityPolicy' >
10174 ] = await Promise . all ( [
10275 ( async ( ) => {
10376 try {
10477 const response = await queryApi (
105- `orgs/${ orgSlug } /full-scans/${ encodeURIComponent ( scanId ) } ` ,
78+ `orgs/${ orgSlug } /full-scans/${ encodeURIComponent ( scanId ) } ${ includeLicensePolicy ? '?include_license_details=true' : '' } ` ,
10679 apiToken
10780 )
10881
@@ -138,26 +111,12 @@ export async function fetchReportData(
138111 throw e
139112 }
140113 } ) ( ) ,
141- // includeLicensePolicy &&
142- // (async () => {
143- // const r = await sockSdk.getOrgSecurityPolicy(orgSlug)
144- // haveLicensePolicy = true
145- // updateProgress()
146- // return await handleApiCall(
147- // r,
148- // "looking up organization's license policy"
149- // )
150- // })(),
151- includeSecurityPolicy &&
152- ( async ( ) => {
153- const r = await sockSdk . getOrgSecurityPolicy ( orgSlug )
154- haveSecurityPolicy = true
155- updateProgress ( )
156- return await handleApiCall (
157- r ,
158- "looking up organization's security policy"
159- )
160- } ) ( )
114+ ( async ( ) => {
115+ const r = await sockSdk . getOrgSecurityPolicy ( orgSlug )
116+ haveSecurityPolicy = true
117+ updateProgress ( )
118+ return await handleApiCall ( r , "looking up organization's security policy" )
119+ } ) ( )
161120 ] ) . finally ( ( ) => spinner . stop ( ) )
162121
163122 if ( ! Array . isArray ( scan ) ) {
@@ -166,50 +125,27 @@ export async function fetchReportData(
166125 return {
167126 ok : false ,
168127 scan : undefined ,
169- // licensePolicy: undefined,
170128 securityPolicy : undefined
171129 }
172130 }
173131
174- // // Note: security->license once the api ships in the sdk
175- // let licensePolicy: undefined | SocketSdkReturnType<'getOrgSecurityPolicy'> =
176- // undefined
177- // if (includeLicensePolicy) {
178- // if (licensePolicyMaybe && licensePolicyMaybe.success) {
179- // licensePolicy = licensePolicyMaybe
180- // } else {
181- // logger.error('Was unable to fetch license policy, bailing')
182- // process.exitCode = 1
183- // return {
184- // ok: false,
185- // scan: undefined,
186- // licensePolicy: undefined,
187- // securityPolicy: undefined
188- // }
189- // }
190- // }
191-
192132 let securityPolicy : undefined | SocketSdkReturnType < 'getOrgSecurityPolicy' > =
193133 undefined
194- if ( includeSecurityPolicy ) {
195- if ( securityPolicyMaybe && securityPolicyMaybe . success ) {
196- securityPolicy = securityPolicyMaybe
197- } else {
198- logger . error ( 'Was unable to fetch security policy, bailing' )
199- process . exitCode = 1
200- return {
201- ok : false ,
202- scan : undefined ,
203- // licensePolicy: undefined,
204- securityPolicy : undefined
205- }
134+ if ( securityPolicyMaybe && securityPolicyMaybe . success ) {
135+ securityPolicy = securityPolicyMaybe
136+ } else {
137+ logger . error ( 'Was unable to fetch security policy, bailing' )
138+ process . exitCode = 1
139+ return {
140+ ok : false ,
141+ scan : undefined ,
142+ securityPolicy : undefined
206143 }
207144 }
208145
209146 return {
210147 ok : true ,
211148 scan,
212- // licensePolicy,
213149 securityPolicy
214150 }
215151}
0 commit comments