Skip to content

Commit f0297e9

Browse files
Merge pull request #199 from SocketDev/cg/parsendjson
[fix] Parse ndjson response in purl batch endpoint
2 parents 51f3ddd + 231acb5 commit f0297e9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,14 @@ class SocketSdk {
502502

503503
try {
504504
const client = await this.#getClient()
505-
const data = await client.post(`purl?${formattedQueryParam}`, { json: components }).json()
506-
return { success: true, status: 200, data }
505+
const data = await client.post(`purl?${formattedQueryParam}`, { json: components })
506+
507+
// Parse the ndjson response
508+
const /** @type {{[key: string]: any}[]} */ resp_json = []
509+
const ndjson = data.body.split('\n')
510+
ndjson.map(o => o && resp_json.push(JSON.parse(o)))
511+
512+
return { success: true, status: 200, data: resp_json }
507513
} catch (err) {
508514
return /** @type {SocketSdkErrorType<'batchPackageFetch'>} */ (this.#handleApiError(err))
509515
}

0 commit comments

Comments
 (0)