From 0b092ec2a4c84300d1732ad8458cc42666d0cf52 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Tue, 4 Mar 2025 15:16:00 +0100 Subject: [PATCH 1/2] Move getOrgFullScan to streamOrgFullScan and getOrgFullScanBuffered --- src/index.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7981a590..ea222e7c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -209,10 +209,10 @@ class SocketSdk { } } - async getOrgFullScan ( + async streamOrgFullScan ( orgSlug: string, fullScanId: string, - file?: string + file?: string | false // When `false`, just .get rather than .stream ): Promise> { const orgSlugParam = encodeURIComponent(orgSlug) const fullScanIdParam = encodeURIComponent(fullScanId) @@ -223,7 +223,7 @@ class SocketSdk { this.#getClient().stream(`orgs/${orgSlugParam}/full-scans/${fullScanIdParam}`), createWriteStream(file) ) - } else { + } else if (file !== false) { readStream = this.#getClient().stream(`orgs/${orgSlugParam}/full-scans/${fullScanIdParam}`).pipe(process.stdout) } return this.#handleApiSuccess<'getOrgFullScan'>(readStream) @@ -232,6 +232,31 @@ class SocketSdk { } } + /** @deprecated in favor of streamOrgFullScan */ + async getOrgFullScan ( + orgSlug: string, + fullScanId: string, + file?: string | false // When `false`, just .get rather than .stream + ) { return this.streamOrgFullScan(orgSlug, fullScanId, file) } + + /** + * Name is "buffered" because getOrgFullScan was a previous api that streamed + * the contents and I don't want to risk version collisions. + */ + async getOrgFullScanBuffered ( + orgSlug: string, + fullScanId: string + ): Promise> { + const orgSlugParam = encodeURIComponent(orgSlug) + const fullScanIdParam = encodeURIComponent(fullScanId) + try { + const data = this.#getClient().get(`orgs/${orgSlugParam}/full-scans/${fullScanIdParam}`).json() + return this.#handleApiSuccess<'getOrgFullScan'>(data) + } catch (err) { + return this.#handleApiError<'getOrgFullScan'>(err) + } + } + async getOrgFullScanMetadata ( orgSlug: string, fullScanId: string From 6cea62e4ae5dd1ea755de151ea474700a7b4c68f Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Tue, 4 Mar 2025 15:19:02 +0100 Subject: [PATCH 2/2] comment --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index ea222e7c..5cedbc48 100644 --- a/src/index.ts +++ b/src/index.ts @@ -236,7 +236,7 @@ class SocketSdk { async getOrgFullScan ( orgSlug: string, fullScanId: string, - file?: string | false // When `false`, just .get rather than .stream + file?: string ) { return this.streamOrgFullScan(orgSlug, fullScanId, file) } /**