Skip to content

Commit 39d4f2c

Browse files
committed
feat(sdk): bump socket-cli v1.x to @socketsecurity/sdk 4.x (SURF-1446, SURF-742)
Bumps @socketsecurity/sdk 1.4.96 -> 4.0.3 and migrates every call site to the 4.x API. SDK v4 renamed most org-scoped methods (getOrgFullScan* -> getFullScan/streamFullScan/listFullScans, *OrgRepo -> *Repository, getOrganizations -> listOrganizations, getSupportedScanFiles -> getSupportedFiles) and reshaped several option/result types. - Repository, scan, org and audit-log fetchers updated to the renamed methods and new option shapes; result annotations retargeted to the new operation-name keys so they stay type-safe. - getSupportedFiles is org-scoped now: fetchSupportedScanFileNames takes an orgSlug (threaded from callers, getDefaultOrgSlug fallback). - createFullScan drops the positional cwd for options.pathsRelativeTo and a numeric pull_request; uploadManifestFiles takes { pathsRelativeTo }. - setupSdk clamps SOCKET_CLI_API_TIMEOUT into [5000, 300000] before forwarding (v4 throws a TypeError outside that range; the CLI default of 0/unset is invalid). - ALL_ECOSYSTEMS gains clawhub + socket for the PURL_Type exhaustiveness check against 4.x. - handleApiCall / handleApiCallNoSpinner infer the whole result union and derive success data via a distributive conditional so the SDK 4.x strict result types (OrganizationsResult, RepositoryResult, DeleteResult, ...) stay assignable under exactOptionalPropertyTypes; callers drop explicit operation type args. SURF-742: socket scan view (default and --json non-stream) reads cached immutable results via ?cached=true with 202->200 backoff polling; --stream stays on the streaming method. Adds fetch-scan.test.mts.
1 parent ee09686 commit 39d4f2c

45 files changed

Lines changed: 563 additions & 249 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"@socketregistry/packageurl-js": "1.0.9",
126126
"@socketsecurity/config": "3.0.1",
127127
"@socketsecurity/registry": "1.1.17",
128-
"@socketsecurity/sdk": "1.4.96",
128+
"@socketsecurity/sdk": "4.0.3",
129129
"@types/blessed": "0.1.25",
130130
"@types/cmd-shim": "5.0.2",
131131
"@types/js-yaml": "4.0.9",

pnpm-lock.yaml

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/audit-log/output-audit-log.mts

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,29 @@ export async function outputAsJson(
120120
org: orgSlug,
121121
page,
122122
perPage,
123-
logs: auditLogs.data.results.map(log => {
124-
// Note: The subset is pretty arbitrary
125-
const {
126-
created_at,
127-
event_id,
128-
ip_address,
129-
type,
130-
user_agent,
131-
user_email,
132-
} = log
133-
return {
134-
event_id,
135-
created_at,
136-
ip_address,
137-
type,
138-
user_agent,
139-
user_email,
140-
}
141-
}),
123+
logs: auditLogs.data.results.map(
124+
(
125+
log: SocketSdkSuccessResult<'getAuditLogEvents'>['data']['results'][number],
126+
) => {
127+
// Note: The subset is pretty arbitrary
128+
const {
129+
created_at,
130+
event_id,
131+
ip_address,
132+
type,
133+
user_agent,
134+
user_email,
135+
} = log
136+
return {
137+
event_id,
138+
created_at,
139+
ip_address,
140+
type,
141+
user_agent,
142+
user_email,
143+
}
144+
},
145+
),
142146
},
143147
})
144148
}
@@ -196,14 +200,18 @@ async function outputWithBlessed(
196200
orgSlug: string,
197201
) {
198202
const filteredLogs = data.results
199-
const formattedOutput = filteredLogs.map(logs => [
200-
logs.event_id ?? '',
201-
msAtHome(logs.created_at ?? ''),
202-
logs.type ?? '',
203-
logs.user_email ?? '',
204-
logs.ip_address ?? '',
205-
logs.user_agent ?? '',
206-
])
203+
const formattedOutput: string[][] = filteredLogs.map(
204+
(
205+
logs: SocketSdkSuccessResult<'getAuditLogEvents'>['data']['results'][number],
206+
) => [
207+
logs.event_id ?? '',
208+
msAtHome(logs.created_at ?? ''),
209+
logs.type ?? '',
210+
logs.user_email ?? '',
211+
logs.ip_address ?? '',
212+
logs.user_agent ?? '',
213+
],
214+
)
207215
const headers = [
208216
' Event id',
209217
' Created at',

src/commands/fix/coana-fix.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export async function coanaFix(
158158
const sockSdk = sockSdkCResult.data
159159

160160
const supportedFilesCResult = await fetchSupportedScanFileNames({
161+
orgSlug,
161162
spinner: silence ? undefined : spinner,
162163
silence,
163164
})
@@ -209,7 +210,9 @@ export async function coanaFix(
209210
}
210211
}
211212
const uploadCResult = await handleApiCall(
212-
sockSdk.uploadManifestFiles(orgSlug, scanFilepaths, cwd),
213+
sockSdk.uploadManifestFiles(orgSlug, scanFilepaths, {
214+
pathsRelativeTo: cwd,
215+
}),
213216
{
214217
description: 'upload manifests',
215218
spinner,

src/commands/login/attempt-login.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export async function attemptLogin(
7171
const enterpriseOrgs = getEnterpriseOrgs(organizations)
7272

7373
const enforcedChoices: OrgChoices = enterpriseOrgs.map(org => ({
74-
name: org.name ?? 'undefined',
75-
value: org.id,
74+
name: org['name'] ?? 'undefined',
75+
value: org['id'],
7676
}))
7777

7878
let enforcedOrgs: string[] = []

src/commands/organization/fetch-organization-list.mts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { setupSdk } from '../../utils/sdk.mts'
55

66
import type { CResult } from '../../types.mts'
77
import type { SetupSdkOptions } from '../../utils/sdk.mts'
8-
import type { SocketSdk, SocketSdkSuccessResult } from '@socketsecurity/sdk'
8+
import type { OrganizationsResult, SocketSdk } from '@socketsecurity/sdk'
99

1010
export type FetchOrganizationOptions = {
1111
description?: string | undefined
@@ -20,8 +20,7 @@ export type EnterpriseOrganization = Omit<Organization, 'plan'> & {
2020

2121
export type EnterpriseOrganizations = EnterpriseOrganization[]
2222

23-
export type Organization =
24-
SocketSdkSuccessResult<'getOrganizations'>['data']['organizations'][string]
23+
export type Organization = OrganizationsResult['data']['organizations'][number]
2524

2625
export type Organizations = Organization[]
2726

@@ -51,7 +50,7 @@ export async function fetchOrganization(
5150
sockSdk = sockSdkCResult.data
5251
}
5352

54-
const orgsCResult = await handleApiCall(sockSdk.getOrganizations(), {
53+
const orgsCResult = await handleApiCall(sockSdk.listOrganizations(), {
5554
description,
5655
silence,
5756
})

src/commands/package/output-purls-shallow-score.mts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,20 +241,24 @@ export function preProcess(
241241
row.score.license = artifact.score?.license || 100
242242
}
243243

244-
artifact.alerts?.forEach(({ severity, type }) => {
245-
row.alerts.set(`${type}:${severity}`, {
246-
type: (type as string) ?? 'unknown',
247-
severity: (severity as string) ?? 'none',
248-
})
249-
})
244+
artifact.alerts?.forEach(
245+
({ severity, type }: NonNullable<typeof artifact.alerts>[number]) => {
246+
row.alerts.set(`${type}:${severity}`, {
247+
type: (type as string) ?? 'unknown',
248+
severity: (severity as string) ?? 'none',
249+
})
250+
},
251+
)
250252
} else {
251253
const alerts = new Map<string, { type: string; severity: string }>()
252-
artifact.alerts?.forEach(({ severity, type }) => {
253-
alerts.set(`${type}:${severity}`, {
254-
type: (type as string) ?? 'unknown',
255-
severity: (severity as string) ?? 'none',
256-
})
257-
})
254+
artifact.alerts?.forEach(
255+
({ severity, type }: NonNullable<typeof artifact.alerts>[number]) => {
256+
alerts.set(`${type}:${severity}`, {
257+
type: (type as string) ?? 'unknown',
258+
severity: (severity as string) ?? 'none',
259+
})
260+
},
261+
)
258262

259263
rows.set(purl, {
260264
ecosystem: artifact.type,

src/commands/repository/fetch-create-repo.mts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { setupSdk } from '../../utils/sdk.mts'
33

44
import type { CResult } from '../../types.mts'
55
import type { SetupSdkOptions } from '../../utils/sdk.mts'
6-
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
6+
import type { RepositoryResult } from '@socketsecurity/sdk'
77

88
export type FetchCreateRepoConfig = {
99
defaultBranch: string
@@ -21,7 +21,7 @@ export type FetchCreateRepoOptions = {
2121
export async function fetchCreateRepo(
2222
config: FetchCreateRepoConfig,
2323
options?: FetchCreateRepoOptions | undefined,
24-
): Promise<CResult<SocketSdkSuccessResult<'createOrgRepo'>['data']>> {
24+
): Promise<CResult<RepositoryResult['data']>> {
2525
const {
2626
defaultBranch,
2727
description,
@@ -43,12 +43,11 @@ export async function fetchCreateRepo(
4343
const sockSdk = sockSdkCResult.data
4444

4545
return await handleApiCall(
46-
sockSdk.createOrgRepo(orgSlug, {
46+
sockSdk.createRepository(orgSlug, repoName, {
4747
default_branch: defaultBranch,
4848
description,
4949
homepage,
50-
name: repoName,
51-
visibility,
50+
visibility: visibility as 'private' | 'public',
5251
}),
5352
{ description: 'to create a repository' },
5453
)

src/commands/repository/fetch-delete-repo.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { setupSdk } from '../../utils/sdk.mts'
33

44
import type { CResult } from '../../types.mts'
55
import type { SetupSdkOptions } from '../../utils/sdk.mts'
6-
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
6+
import type { DeleteResult } from '@socketsecurity/sdk'
77

88
export type FetchDeleteRepoOptions = {
99
sdkOpts?: SetupSdkOptions | undefined
@@ -13,7 +13,7 @@ export async function fetchDeleteRepo(
1313
orgSlug: string,
1414
repoName: string,
1515
options?: FetchDeleteRepoOptions | undefined,
16-
): Promise<CResult<SocketSdkSuccessResult<'deleteOrgRepo'>['data']>> {
16+
): Promise<CResult<DeleteResult['data']>> {
1717
const { sdkOpts } = {
1818
__proto__: null,
1919
...options,
@@ -25,7 +25,7 @@ export async function fetchDeleteRepo(
2525
}
2626
const sockSdk = sockSdkCResult.data
2727

28-
return await handleApiCall(sockSdk.deleteOrgRepo(orgSlug, repoName), {
28+
return await handleApiCall(sockSdk.deleteRepository(orgSlug, repoName), {
2929
description: 'to delete a repository',
3030
})
3131
}

src/commands/repository/fetch-list-all-repos.mts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { setupSdk } from '../../utils/sdk.mts'
33

44
import type { CResult } from '../../types.mts'
55
import type { SetupSdkOptions } from '../../utils/sdk.mts'
6-
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
6+
import type { RepositoriesListResult } from '@socketsecurity/sdk'
77

88
export type FetchListAllReposOptions = {
99
direction?: string | undefined
@@ -14,7 +14,7 @@ export type FetchListAllReposOptions = {
1414
export async function fetchListAllRepos(
1515
orgSlug: string,
1616
options?: FetchListAllReposOptions | undefined,
17-
): Promise<CResult<SocketSdkSuccessResult<'getOrgRepoList'>['data']>> {
17+
): Promise<CResult<RepositoriesListResult['data']>> {
1818
const { direction, sdkOpts, sort } = {
1919
__proto__: null,
2020
...options,
@@ -26,7 +26,7 @@ export async function fetchListAllRepos(
2626
}
2727
const sockSdk = sockSdkCResult.data
2828

29-
const rows: SocketSdkSuccessResult<'getOrgRepoList'>['data']['results'] = []
29+
const rows: RepositoriesListResult['data']['results'] = []
3030
let protection = 0
3131
let nextPage = 0
3232
while (nextPage >= 0) {
@@ -39,11 +39,11 @@ export async function fetchListAllRepos(
3939
}
4040
// eslint-disable-next-line no-await-in-loop
4141
const orgRepoListCResult = await handleApiCall(
42-
sockSdk.getOrgRepoList(orgSlug, {
43-
sort,
44-
direction,
45-
per_page: String(100), // max
46-
page: String(nextPage),
42+
sockSdk.listRepositories(orgSlug, {
43+
...(sort ? { sort: sort as 'name' | 'updated_at' | 'created_at' } : {}),
44+
...(direction ? { direction: direction as 'asc' | 'desc' } : {}),
45+
per_page: 100, // max
46+
page: nextPage,
4747
}),
4848
{ description: 'list of repositories' },
4949
)

0 commit comments

Comments
 (0)