Skip to content

Commit 4b34e98

Browse files
committed
wip
1 parent b4f250e commit 4b34e98

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

index.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict'
22

3+
const fs = require('node:fs')
34
const path = require('node:path')
5+
const { pipeline } = require('stream/promises')
46

57
const { 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))

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@socketsecurity/sdk",
3-
"version": "0.9.0",
3+
"version": "0.9.1",
44
"license": "MIT",
55
"description": "SDK for the Socket API client",
66
"author": {
@@ -35,7 +35,7 @@
3535
"@types/chai": "^4.3.4",
3636
"@types/chai-as-promised": "^7.1.5",
3737
"@types/mocha": "^10.0.1",
38-
"@types/node": "^14.18.36",
38+
"@types/node": "^18.0.0",
3939
"@types/tap": "^15.0.7",
4040
"@typescript-eslint/eslint-plugin": "^6.7.3",
4141
"@typescript-eslint/parser": "^6.7.3",

0 commit comments

Comments
 (0)