-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathfetch-diff-scan.ts
More file actions
47 lines (37 loc) · 1.24 KB
/
fetch-diff-scan.ts
File metadata and controls
47 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { logger } from '@socketsecurity/registry/lib/logger'
import constants from '../../constants'
import { handleApiCall, handleApiError, queryApi } from '../../utils/api'
import { failMsgWithBadge } from '../../utils/fail-msg-with-badge'
import { getDefaultToken } from '../../utils/sdk'
import type { SocketSdkReturnType } from '@socketsecurity/sdk'
export async function fetchDiffScan({
after,
before,
orgSlug
}: {
after: string
before: string
orgSlug: string
}): Promise<SocketSdkReturnType<'GetOrgDiffScan'>['data'] | undefined> {
const apiToken = getDefaultToken()
// Lazily access constants.spinner.
const { spinner } = constants
spinner.start('Fetching diff-scan...')
const response = await queryApi(
`orgs/${orgSlug}/full-scans/diff?before=${encodeURIComponent(before)}&after=${encodeURIComponent(after)}`,
apiToken || ''
)
spinner.successAndStop('Received diff-scan response')
if (!response.ok) {
const err = await handleApiError(response.status)
logger.fail(failMsgWithBadge(response.statusText, err))
return
}
const result = await handleApiCall(
(await response.json()) as Promise<
SocketSdkReturnType<'GetOrgDiffScan'>['data']
>,
'Deserializing json'
)
return result
}