-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathfetch-supported-scan-file-names.mts
More file actions
47 lines (41 loc) · 1.44 KB
/
fetch-supported-scan-file-names.mts
File metadata and controls
47 lines (41 loc) · 1.44 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 { getDefaultOrgSlug } from '../ci/fetch-default-org-slug.mjs'
import { handleApiCall } from '../../utils/socket/api.mjs'
import { setupSdk } from '../../utils/socket/sdk.mjs'
import type { CResult } from '../../types.mts'
import type { SetupSdkOptions } from '../../utils/socket/sdk.mjs'
import type { Spinner } from '@socketsecurity/lib/spinner'
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
export type FetchSupportedScanFileNamesOptions = {
orgSlug?: string | undefined
sdkOpts?: SetupSdkOptions | undefined
spinner?: Spinner | undefined
}
export async function fetchSupportedScanFileNames(
options?: FetchSupportedScanFileNamesOptions | undefined,
): Promise<CResult<SocketSdkSuccessResult<'getSupportedFiles'>['data']>> {
const { orgSlug, sdkOpts, spinner } = {
__proto__: null,
...options,
} as FetchSupportedScanFileNamesOptions
const sockSdkCResult = await setupSdk(sdkOpts)
if (!sockSdkCResult.ok) {
return sockSdkCResult
}
const sockSdk = sockSdkCResult.data
// Use provided orgSlug or discover it.
let resolvedOrgSlug = orgSlug
if (!resolvedOrgSlug) {
const orgSlugCResult = await getDefaultOrgSlug()
if (!orgSlugCResult.ok) {
return orgSlugCResult
}
resolvedOrgSlug = orgSlugCResult.data
}
return await handleApiCall<'getSupportedFiles'>(
sockSdk.getSupportedFiles(resolvedOrgSlug),
{
description: 'supported scan file types',
spinner,
},
)
}