Skip to content

Commit 5f48265

Browse files
Merge pull request #185 from SocketDev/cg/updateFullScansEndpoints
Updates to the full scans endpoints
2 parents 3307aaf + dd3acb9 commit 5f48265

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
uses: SocketDev/workflows/.github/workflows/reusable-base.yml@master
2929
with:
3030
npm-test-script: 'ci-test'
31-
node-versions: '14,16,18,19'
31+
node-versions: '16,18,19'

index.js

+17-6
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('node: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-lock.json

+18-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
},
3232
"devDependencies": {
3333
"@socketsecurity/eslint-config": "^4.0.1",
34-
"@tsconfig/node14": "^14.1.2",
34+
"@tsconfig/node16": "^16.1.3",
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": "^16.0.0",
3939
"@types/tap": "^15.0.7",
4040
"@typescript-eslint/eslint-plugin": "^6.7.3",
4141
"@typescript-eslint/parser": "^6.7.3",

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "@tsconfig/node14/tsconfig.json",
2+
"extends": "@tsconfig/node16/tsconfig.json",
33
"files": [
44
"index.js"
55
],

0 commit comments

Comments
 (0)