Skip to content

Commit f49df6e

Browse files
authored
Upgrade Socket SDK to v4 and sync Claude Code version (#1183)
* chore(deps): bump @socketsecurity/sdk to 4.0.0 and @anthropic-ai/claude-code to 2.1.98 SDK v4 adds checkMalware() for integrated malware detection. Claude Code bumped to match installed version. * fix: migrate getSupportedScanFiles to getSupportedFiles (SDK v4) SDK v4 removed deprecated getSupportedScanFiles(). The replacement getSupportedFiles(orgSlug) requires an org parameter. Updated all type references from getReportSupportedFiles to getSupportedFiles. * fix(tests): update supported files tests for SDK v4 getSupportedFiles(orgSlug) * fix(tests): correct mock path for fetch-default-org-slug (.mjs not .mts) * fix: pass orgSlug to fetchSupportedScanFileNames instead of discovering internally
1 parent 038a113 commit f49df6e

File tree

8 files changed

+67
-130
lines changed

8 files changed

+67
-130
lines changed

packages/cli/src/commands/scan/create-scan-from-github.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ async function testAndDownloadManifestFile({
350350
orgGithub: string
351351
repoSlug: string
352352
supportedFiles:
353-
| SocketSdkSuccessResult<'getReportSupportedFiles'>['data']
353+
| SocketSdkSuccessResult<'getSupportedFiles'>['data']
354354
| undefined
355355
tmpDir: string
356356
}): Promise<CResult<{ isManifest: boolean }>> {

packages/cli/src/commands/scan/fetch-supported-scan-file-names.mts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getDefaultOrgSlug } from '../ci/fetch-default-org-slug.mjs'
12
import { handleApiCall } from '../../utils/socket/api.mjs'
23
import { setupSdk } from '../../utils/socket/sdk.mjs'
34

@@ -7,14 +8,15 @@ import type { Spinner } from '@socketsecurity/lib/spinner'
78
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
89

910
export type FetchSupportedScanFileNamesOptions = {
11+
orgSlug?: string | undefined
1012
sdkOpts?: SetupSdkOptions | undefined
1113
spinner?: Spinner | undefined
1214
}
1315

1416
export async function fetchSupportedScanFileNames(
1517
options?: FetchSupportedScanFileNamesOptions | undefined,
16-
): Promise<CResult<SocketSdkSuccessResult<'getReportSupportedFiles'>['data']>> {
17-
const { sdkOpts, spinner } = {
18+
): Promise<CResult<SocketSdkSuccessResult<'getSupportedFiles'>['data']>> {
19+
const { orgSlug, sdkOpts, spinner } = {
1820
__proto__: null,
1921
...options,
2022
} as FetchSupportedScanFileNamesOptions
@@ -25,8 +27,18 @@ export async function fetchSupportedScanFileNames(
2527
}
2628
const sockSdk = sockSdkCResult.data
2729

28-
return await handleApiCall<'getReportSupportedFiles'>(
29-
sockSdk.getSupportedScanFiles(),
30+
// Use provided orgSlug or discover it.
31+
let resolvedOrgSlug = orgSlug
32+
if (!resolvedOrgSlug) {
33+
const orgSlugCResult = await getDefaultOrgSlug()
34+
if (!orgSlugCResult.ok) {
35+
return orgSlugCResult
36+
}
37+
resolvedOrgSlug = orgSlugCResult.data
38+
}
39+
40+
return await handleApiCall<'getSupportedFiles'>(
41+
sockSdk.getSupportedFiles(resolvedOrgSlug),
3042
{
3143
description: 'supported scan file types',
3244
spinner,

packages/cli/src/commands/scan/handle-create-new-scan.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export async function handleCreateNewScan({
131131

132132
const spinner = getDefaultSpinner()
133133

134-
const supportedFilesCResult = await fetchSupportedScanFileNames({ spinner })
134+
const supportedFilesCResult = await fetchSupportedScanFileNames({ orgSlug, spinner })
135135
if (!supportedFilesCResult.ok) {
136136
debug('warn', 'Failed to fetch supported scan file names')
137137
debugDir('inspect', { supportedFilesCResult })

packages/cli/src/utils/fs/glob.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,22 @@ function workspacePatternToGlobPattern(workspace: string): string {
159159

160160
export function filterBySupportedScanFiles(
161161
filepaths: string[] | readonly string[],
162-
supportedFiles: SocketSdkSuccessResult<'getReportSupportedFiles'>['data'],
162+
supportedFiles: SocketSdkSuccessResult<'getSupportedFiles'>['data'],
163163
): string[] {
164164
const patterns = getSupportedFilePatterns(supportedFiles)
165165
return filepaths.filter(p => micromatch.some(p, patterns, { dot: true }))
166166
}
167167

168168
export function createSupportedFilesFilter(
169-
supportedFiles: SocketSdkSuccessResult<'getReportSupportedFiles'>['data'],
169+
supportedFiles: SocketSdkSuccessResult<'getSupportedFiles'>['data'],
170170
): (filepath: string) => boolean {
171171
const patterns = getSupportedFilePatterns(supportedFiles)
172172
return (filepath: string) =>
173173
micromatch.some(filepath, patterns, { dot: true })
174174
}
175175

176176
export function getSupportedFilePatterns(
177-
supportedFiles: SocketSdkSuccessResult<'getReportSupportedFiles'>['data'],
177+
supportedFiles: SocketSdkSuccessResult<'getSupportedFiles'>['data'],
178178
): string[] {
179179
const patterns: string[] = []
180180
for (const key of Object.keys(supportedFiles)) {
@@ -309,7 +309,7 @@ export async function globWorkspace(
309309

310310
export function isReportSupportedFile(
311311
filepath: string,
312-
supportedFiles: SocketSdkSuccessResult<'getReportSupportedFiles'>['data'],
312+
supportedFiles: SocketSdkSuccessResult<'getSupportedFiles'>['data'],
313313
) {
314314
const patterns = getSupportedFilePatterns(supportedFiles)
315315
return micromatch.some(filepath, patterns, { dot: true })

packages/cli/src/utils/fs/path-resolve.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export type PackageFilesForScanOptions = {
111111

112112
export async function getPackageFilesForScan(
113113
inputPaths: string[],
114-
supportedFiles: SocketSdkSuccessResult<'getReportSupportedFiles'>['data'],
114+
supportedFiles: SocketSdkSuccessResult<'getSupportedFiles'>['data'],
115115
options?: PackageFilesForScanOptions | undefined,
116116
): Promise<string[]> {
117117
const { config: socketConfig, cwd = process.cwd() } = {
Lines changed: 27 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
/**
22
* Unit tests for fetchSupportedScanFileNames.
33
*
4-
* Purpose:
5-
* Tests fetching supported manifest file names for scanning. Validates which files Socket can analyze.
6-
*
7-
* Test Coverage:
8-
* - Successful API operation
9-
* - SDK setup failure handling
10-
* - API call error scenarios
11-
* - Custom SDK options (API tokens, base URLs)
12-
* - Supported file types
13-
* - Ecosystem detection
14-
* - Null prototype usage for security
15-
*
16-
* Testing Approach:
17-
* Uses SDK test helpers to mock Socket API interactions. Validates comprehensive
18-
* error handling and API integration.
19-
*
20-
* Related Files:
21-
* - src/commands/SupportedScanFileNames.mts (implementation)
4+
* Tests fetching supported manifest file names for scanning.
5+
* Validates which files Socket can analyze via the SDK v4 getSupportedFiles API.
226
*/
237

248
import { describe, expect, it, vi } from 'vitest'
@@ -51,13 +35,13 @@ describe('fetchSupportedScanFileNames', () => {
5135
}
5236

5337
const { mockHandleApi, mockSdk } = await setupSdkMockSuccess(
54-
'getSupportedScanFiles',
38+
'getSupportedFiles',
5539
mockData,
5640
)
5741

58-
const result = await fetchSupportedScanFileNames()
42+
const result = await fetchSupportedScanFileNames({ orgSlug: 'test-org' })
5943

60-
expect(mockSdk.getSupportedScanFiles).toHaveBeenCalledWith()
44+
expect(mockSdk.getSupportedFiles).toHaveBeenCalledWith('test-org')
6145
expect(mockHandleApi).toHaveBeenCalledWith(expect.any(Promise), {
6246
description: 'supported scan file types',
6347
})
@@ -74,7 +58,7 @@ describe('fetchSupportedScanFileNames', () => {
7458
cause: 'Invalid configuration',
7559
})
7660

77-
const result = await fetchSupportedScanFileNames()
61+
const result = await fetchSupportedScanFileNames({ orgSlug: 'test-org' })
7862

7963
expect(result.ok).toBe(false)
8064
expect(result.message).toBe('Failed to setup SDK')
@@ -85,9 +69,9 @@ describe('fetchSupportedScanFileNames', () => {
8569
const { fetchSupportedScanFileNames } =
8670
await import('../../../../../src/commands/scan/fetch-supported-scan-file-names.mts')
8771

88-
await setupSdkMockError('getSupportedScanFiles', 'API error', 500)
72+
await setupSdkMockError('getSupportedFiles', 'API error', 500)
8973

90-
const result = await fetchSupportedScanFileNames()
74+
const result = await fetchSupportedScanFileNames({ orgSlug: 'test-org' })
9175

9276
expect(result.ok).toBe(false)
9377
expect(result.code).toBe(500)
@@ -98,29 +82,31 @@ describe('fetchSupportedScanFileNames', () => {
9882
await import('../../../../../src/commands/scan/fetch-supported-scan-file-names.mts')
9983

10084
const { mockSdk, mockSetupSdk } = await setupSdkMockSuccess(
101-
'getSupportedScanFiles',
85+
'getSupportedFiles',
10286
{},
10387
)
10488

105-
const options = {
89+
await fetchSupportedScanFileNames({
90+
orgSlug: 'my-org',
10691
sdkOpts: {
10792
apiToken: 'custom-token',
10893
baseUrl: 'https://api.example.com',
10994
},
110-
}
111-
112-
await fetchSupportedScanFileNames(options)
95+
})
11396

114-
expect(mockSetupSdk).toHaveBeenCalledWith(options.sdkOpts)
115-
expect(mockSdk.getSupportedScanFiles).toHaveBeenCalledWith()
97+
expect(mockSetupSdk).toHaveBeenCalledWith({
98+
apiToken: 'custom-token',
99+
baseUrl: 'https://api.example.com',
100+
})
101+
expect(mockSdk.getSupportedFiles).toHaveBeenCalledWith('my-org')
116102
})
117103

118104
it('passes custom spinner', async () => {
119105
const { fetchSupportedScanFileNames } =
120106
await import('../../../../../src/commands/scan/fetch-supported-scan-file-names.mts')
121107

122108
const { mockHandleApi } = await setupSdkMockSuccess(
123-
'getSupportedScanFiles',
109+
'getSupportedFiles',
124110
{},
125111
)
126112

@@ -131,11 +117,7 @@ describe('fetchSupportedScanFileNames', () => {
131117
fail: vi.fn(),
132118
}
133119

134-
const options = {
135-
spinner: mockSpinner,
136-
}
137-
138-
await fetchSupportedScanFileNames(options)
120+
await fetchSupportedScanFileNames({ orgSlug: 'test-org', spinner: mockSpinner })
139121

140122
expect(mockHandleApi).toHaveBeenCalledWith(expect.any(Promise), {
141123
description: 'supported scan file types',
@@ -147,76 +129,28 @@ describe('fetchSupportedScanFileNames', () => {
147129
const { fetchSupportedScanFileNames } =
148130
await import('../../../../../src/commands/scan/fetch-supported-scan-file-names.mts')
149131

150-
await setupSdkMockSuccess('getSupportedScanFiles', {
132+
await setupSdkMockSuccess('getSupportedFiles', {
151133
supportedFiles: [],
152134
ecosystems: [],
153135
})
154136

155-
const result = await fetchSupportedScanFileNames()
137+
const result = await fetchSupportedScanFileNames({ orgSlug: 'test-org' })
156138

157139
expect(result.ok).toBe(true)
158140
expect(result.data?.supportedFiles).toEqual([])
159141
expect(result.data?.ecosystems).toEqual([])
160142
})
161143

162-
it('handles comprehensive file types', async () => {
163-
const { fetchSupportedScanFileNames } =
164-
await import('../../../../../src/commands/scan/fetch-supported-scan-file-names.mts')
165-
166-
const comprehensiveFiles = [
167-
// JavaScript/Node.js
168-
'package.json',
169-
'package-lock.json',
170-
'yarn.lock',
171-
'pnpm-lock.yaml',
172-
// PHP
173-
'composer.json',
174-
'composer.lock',
175-
// Ruby
176-
'Gemfile',
177-
'Gemfile.lock',
178-
// Python
179-
'requirements.txt',
180-
'Pipfile',
181-
'Pipfile.lock',
182-
'poetry.lock',
183-
'pyproject.toml',
184-
// Go
185-
'go.mod',
186-
'go.sum',
187-
// Java
188-
'pom.xml',
189-
'build.gradle',
190-
// .NET
191-
'packages.config',
192-
'*.csproj',
193-
// Rust
194-
'Cargo.toml',
195-
'Cargo.lock',
196-
]
197-
198-
await setupSdkMockSuccess('getSupportedScanFiles', {
199-
supportedFiles: comprehensiveFiles,
200-
})
201-
202-
const result = await fetchSupportedScanFileNames()
203-
204-
expect(result.ok).toBe(true)
205-
expect(result.data?.supportedFiles).toContain('package.json')
206-
expect(result.data?.supportedFiles).toContain('Cargo.toml')
207-
expect(result.data?.supportedFiles).toContain('pom.xml')
208-
})
209-
210-
it('works without options parameter', async () => {
144+
it('works with orgSlug provided', async () => {
211145
const { fetchSupportedScanFileNames } =
212146
await import('../../../../../src/commands/scan/fetch-supported-scan-file-names.mts')
213147

214148
const { mockHandleApi, mockSetupSdk } = await setupSdkMockSuccess(
215-
'getSupportedScanFiles',
149+
'getSupportedFiles',
216150
{ supportedFiles: ['package.json'] },
217151
)
218152

219-
const result = await fetchSupportedScanFileNames()
153+
const result = await fetchSupportedScanFileNames({ orgSlug: 'test-org' })
220154

221155
expect(mockSetupSdk).toHaveBeenCalledWith(undefined)
222156
expect(mockHandleApi).toHaveBeenCalledWith(expect.any(Promise), {
@@ -230,12 +164,10 @@ describe('fetchSupportedScanFileNames', () => {
230164
const { fetchSupportedScanFileNames } =
231165
await import('../../../../../src/commands/scan/fetch-supported-scan-file-names.mts')
232166

233-
const { mockSdk } = await setupSdkMockSuccess('getSupportedScanFiles', {})
167+
const { mockSdk } = await setupSdkMockSuccess('getSupportedFiles', {})
234168

235-
// This tests that the function properly uses __proto__: null.
236-
await fetchSupportedScanFileNames()
169+
await fetchSupportedScanFileNames({ orgSlug: 'test-org' })
237170

238-
// The function should work without prototype pollution issues.
239-
expect(mockSdk.getSupportedScanFiles).toHaveBeenCalled()
171+
expect(mockSdk.getSupportedFiles).toHaveBeenCalled()
240172
})
241173
})

0 commit comments

Comments
 (0)