1
1
'use strict'
2
2
3
+ const fs = require ( 'node:fs' )
3
4
const path = require ( 'node:path' )
5
+ const { pipeline } = require ( 'node:stream/promises' )
4
6
5
7
const { ErrorWithCause } = require ( 'pony-cause' )
6
8
@@ -261,14 +263,16 @@ class SocketSdk {
261
263
262
264
/**
263
265
* @param {string } orgSlug
266
+ * @param {{[key: string]: any } } queryParams
264
267
* @returns {Promise<SocketSdkResultType<'getOrgFullScanList'>> }
265
268
*/
266
- async getOrgFullScanList ( orgSlug ) {
269
+ async getOrgFullScanList ( orgSlug , queryParams ) {
267
270
const orgSlugParam = encodeURIComponent ( orgSlug )
271
+ const formattedQueryParams = new URLSearchParams ( queryParams )
268
272
269
273
try {
270
274
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 ( )
272
276
return { success : true , status : 200 , data }
273
277
} catch ( err ) {
274
278
return /** @type {SocketSdkErrorType<'getOrgFullScanList'> } */ ( this . #handleApiError( err ) )
@@ -278,16 +282,23 @@ class SocketSdk {
278
282
/**
279
283
* @param {string } orgSlug
280
284
* @param {string } fullScanId
285
+ * @param {string } file
281
286
* @returns {Promise<SocketSdkResultType<'getOrgFullScan'>> }
282
287
*/
283
- async getOrgFullScan ( orgSlug , fullScanId ) {
288
+ async getOrgFullScan ( orgSlug , fullScanId , file ) {
284
289
const orgSlugParam = encodeURIComponent ( orgSlug )
285
290
const fullScanIdParam = encodeURIComponent ( fullScanId )
286
-
287
291
try {
288
292
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
+ }
291
302
return { success : true , status : 200 , data : readStream }
292
303
} catch ( err ) {
293
304
return /** @type {SocketSdkErrorType<'getOrgFullScan'> } */ ( this . #handleApiError( err ) )
0 commit comments