@@ -259,6 +259,121 @@ class SocketSdk {
259
259
}
260
260
}
261
261
262
+ /**
263
+ * @param {string } orgSlug
264
+ * @returns {Promise<SocketSdkResultType<'getOrgFullScanList'>> }
265
+ */
266
+ async getOrgFullScanList ( orgSlug ) {
267
+ const orgSlugParam = encodeURIComponent ( orgSlug )
268
+
269
+ try {
270
+ const client = await this . #getClient( )
271
+ const data = await client . get ( `orgs/${ orgSlugParam } /full-scans` ) . json ( )
272
+ return { success : true , status : 200 , data }
273
+ } catch ( err ) {
274
+ return /** @type {SocketSdkErrorType<'getOrgFullScanList'> } */ ( this . #handleApiError( err ) )
275
+ }
276
+ }
277
+
278
+ /**
279
+ * @param {string } orgSlug
280
+ * @param {string } fullScanId
281
+ * @returns {Promise<SocketSdkResultType<'getOrgFullScan'>> }
282
+ */
283
+ async getOrgFullScan ( orgSlug , fullScanId ) {
284
+ const orgSlugParam = encodeURIComponent ( orgSlug )
285
+ const fullScanIdParam = encodeURIComponent ( fullScanId )
286
+
287
+ try {
288
+ const client = await this . #getClient( )
289
+ const readStream = await client . stream ( `orgs/${ orgSlugParam } /full-scans/${ fullScanIdParam } ` ) . pipe ( process . stdout )
290
+
291
+ return { success : true , status : 200 , data : readStream }
292
+ } catch ( err ) {
293
+ return /** @type {SocketSdkErrorType<'getOrgFullScan'> } */ ( this . #handleApiError( err ) )
294
+ }
295
+ }
296
+
297
+ /**
298
+ * @param {string } orgSlug
299
+ * @param {string } fullScanId
300
+ * @returns {Promise<SocketSdkResultType<'getOrgFullScanMetadata'>> }
301
+ */
302
+ async getOrgFullScanMetadata ( orgSlug , fullScanId ) {
303
+ const orgSlugParam = encodeURIComponent ( orgSlug )
304
+ const fullScanIdParam = encodeURIComponent ( fullScanId )
305
+
306
+ try {
307
+ const client = await this . #getClient( )
308
+ const data = await client . get ( `orgs/${ orgSlugParam } /full-scans/${ fullScanIdParam } /metadata` ) . json ( )
309
+ return { success : true , status : 200 , data }
310
+ } catch ( err ) {
311
+ return /** @type {SocketSdkErrorType<'getOrgFullScanMetadata'> } */ ( this . #handleApiError( err ) )
312
+ }
313
+ }
314
+
315
+ /**
316
+ * @param {string } orgSlug
317
+ * @param {string } fullScanId
318
+ * @returns {Promise<SocketSdkResultType<'deleteOrgFullScan'>> }
319
+ */
320
+ async deleteOrgFullScan ( orgSlug , fullScanId ) {
321
+ const orgSlugParam = encodeURIComponent ( orgSlug )
322
+ const fullScanIdParam = encodeURIComponent ( fullScanId )
323
+
324
+ try {
325
+ const client = await this . #getClient( )
326
+ const data = await client . delete ( `orgs/${ orgSlugParam } /full-scans/${ fullScanIdParam } ` ) . json ( )
327
+ return { success : true , status : 200 , data }
328
+ } catch ( err ) {
329
+ return /** @type {SocketSdkErrorType<'deleteOrgFullScan'> } */ ( this . #handleApiError( err ) )
330
+ }
331
+ }
332
+
333
+ /**
334
+ * @param {string } orgSlug
335
+ * @param {{[key: string]: any } } queryParams
336
+ * @param {string[] } filePaths
337
+ * @param {string } pathsRelativeTo
338
+ * @returns {Promise<SocketSdkResultType<'CreateOrgFullScan'>> }
339
+ */
340
+ async createOrgFullScan ( orgSlug , queryParams , filePaths , pathsRelativeTo = '.' ) {
341
+ const basePath = path . resolve ( process . cwd ( ) , pathsRelativeTo )
342
+ const absoluteFilePaths = filePaths . map ( filePath => path . resolve ( basePath , filePath ) )
343
+ const orgSlugParam = encodeURIComponent ( orgSlug )
344
+ const formattedQueryParams = new URLSearchParams ( queryParams )
345
+
346
+ const [
347
+ { FormData } ,
348
+ { fileFromPath } ,
349
+ client
350
+ ] = await Promise . all ( [
351
+ import ( 'formdata-node' ) ,
352
+ import ( 'formdata-node/file-from-path' ) ,
353
+ this . #getClient( ) ,
354
+ ] )
355
+
356
+ const body = new FormData ( )
357
+
358
+ const files = await Promise . all ( absoluteFilePaths . map ( absoluteFilePath => fileFromPath ( absoluteFilePath ) ) )
359
+
360
+ for ( let i = 0 , length = files . length ; i < length ; i ++ ) {
361
+ const absoluteFilePath = absoluteFilePaths [ i ]
362
+ if ( absoluteFilePath ) {
363
+ const relativeFilePath = path . relative ( basePath , absoluteFilePath )
364
+ body . set ( relativeFilePath , files [ i ] )
365
+ }
366
+ }
367
+
368
+ try {
369
+ const data = await client . post ( `orgs/${ orgSlugParam } /full-scans?${ formattedQueryParams } ` , { body } ) . json ( )
370
+
371
+ return { success : true , status : 200 , data }
372
+ } catch ( err ) {
373
+ return /** @type {SocketSdkErrorType<'CreateOrgFullScan'> } */ ( this . #handleApiError( err ) )
374
+ }
375
+ }
376
+
262
377
/**
263
378
* @param {Array<{ organization?: string }> } selectors
264
379
* @returns {Promise<SocketSdkResultType<'postSettings'>> }
0 commit comments