11'use strict'
22
3+ const fs = require ( 'node:fs' )
34const path = require ( 'node:path' )
5+ const { pipeline } = require ( 'node:stream/promises' )
46
57const { ErrorWithCause } = require ( 'pony-cause' )
68
@@ -261,14 +263,16 @@ class SocketSdk {
261263
262264 /**
263265 * @param {string } orgSlug
266+ * @param {{[key: string]: any } } queryParams
264267 * @returns {Promise<SocketSdkResultType<'getOrgFullScanList'>> }
265268 */
266- async getOrgFullScanList ( orgSlug ) {
269+ async getOrgFullScanList ( orgSlug , queryParams ) {
267270 const orgSlugParam = encodeURIComponent ( orgSlug )
271+ const formattedQueryParams = new URLSearchParams ( queryParams )
268272
269273 try {
270274 const client = await this . #getClient( )
271- const data = await client . get ( `orgs/${ orgSlugParam } /full-scans` ) . json ( )
275+ const data = await client . get ( `orgs/${ orgSlugParam } /full-scans? ${ formattedQueryParams } ` ) . json ( )
272276 return { success : true , status : 200 , data }
273277 } catch ( err ) {
274278 return /** @type {SocketSdkErrorType<'getOrgFullScanList'> } */ ( this . #handleApiError( err ) )
@@ -278,16 +282,23 @@ class SocketSdk {
278282 /**
279283 * @param {string } orgSlug
280284 * @param {string } fullScanId
285+ * @param {string } file
281286 * @returns {Promise<SocketSdkResultType<'getOrgFullScan'>> }
282287 */
283- async getOrgFullScan ( orgSlug , fullScanId ) {
288+ async getOrgFullScan ( orgSlug , fullScanId , file ) {
284289 const orgSlugParam = encodeURIComponent ( orgSlug )
285290 const fullScanIdParam = encodeURIComponent ( fullScanId )
286-
287291 try {
288292 const client = await this . #getClient( )
289- const readStream = await client . stream ( `orgs/${ orgSlugParam } /full-scans/${ fullScanIdParam } ` ) . pipe ( process . stdout )
290-
293+ let readStream
294+ if ( file ) {
295+ readStream = await pipeline (
296+ client . stream ( `orgs/${ orgSlugParam } /full-scans/${ fullScanIdParam } ` ) ,
297+ fs . createWriteStream ( file )
298+ )
299+ } else {
300+ readStream = await client . stream ( `orgs/${ orgSlugParam } /full-scans/${ fullScanIdParam } ` ) . pipe ( process . stdout )
301+ }
291302 return { success : true , status : 200 , data : readStream }
292303 } catch ( err ) {
293304 return /** @type {SocketSdkErrorType<'getOrgFullScan'> } */ ( this . #handleApiError( err ) )
0 commit comments