Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"@socketregistry/packageurl-js": "1.0.9",
"@socketsecurity/config": "3.0.1",
"@socketsecurity/registry": "1.1.17",
"@socketsecurity/sdk": "1.4.96",
"@socketsecurity/sdk": "4.0.3",
"@types/blessed": "0.1.25",
"@types/cmd-shim": "5.0.2",
"@types/js-yaml": "4.0.9",
Expand Down
14 changes: 6 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 35 additions & 27 deletions src/commands/audit-log/output-audit-log.mts
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,29 @@ export async function outputAsJson(
org: orgSlug,
page,
perPage,
logs: auditLogs.data.results.map(log => {
// Note: The subset is pretty arbitrary
const {
created_at,
event_id,
ip_address,
type,
user_agent,
user_email,
} = log
return {
event_id,
created_at,
ip_address,
type,
user_agent,
user_email,
}
}),
logs: auditLogs.data.results.map(
(
log: SocketSdkSuccessResult<'getAuditLogEvents'>['data']['results'][number],
) => {
// Note: The subset is pretty arbitrary
const {
created_at,
event_id,
ip_address,
type,
user_agent,
user_email,
} = log
return {
event_id,
created_at,
ip_address,
type,
user_agent,
user_email,
}
},
),
},
})
}
Expand Down Expand Up @@ -196,14 +200,18 @@ async function outputWithBlessed(
orgSlug: string,
) {
const filteredLogs = data.results
const formattedOutput = filteredLogs.map(logs => [
logs.event_id ?? '',
msAtHome(logs.created_at ?? ''),
logs.type ?? '',
logs.user_email ?? '',
logs.ip_address ?? '',
logs.user_agent ?? '',
])
const formattedOutput: string[][] = filteredLogs.map(
(
logs: SocketSdkSuccessResult<'getAuditLogEvents'>['data']['results'][number],
) => [
logs.event_id ?? '',
msAtHome(logs.created_at ?? ''),
logs.type ?? '',
logs.user_email ?? '',
logs.ip_address ?? '',
logs.user_agent ?? '',
],
)
const headers = [
' Event id',
' Created at',
Expand Down
5 changes: 4 additions & 1 deletion src/commands/fix/coana-fix.mts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export async function coanaFix(
const sockSdk = sockSdkCResult.data

const supportedFilesCResult = await fetchSupportedScanFileNames({
orgSlug,
spinner: silence ? undefined : spinner,
silence,
})
Expand Down Expand Up @@ -209,7 +210,9 @@ export async function coanaFix(
}
}
const uploadCResult = await handleApiCall(
sockSdk.uploadManifestFiles(orgSlug, scanFilepaths, cwd),
sockSdk.uploadManifestFiles(orgSlug, scanFilepaths, {
pathsRelativeTo: cwd,
}),
{
description: 'upload manifests',
spinner,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/login/attempt-login.mts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export async function attemptLogin(
const enterpriseOrgs = getEnterpriseOrgs(organizations)

const enforcedChoices: OrgChoices = enterpriseOrgs.map(org => ({
name: org.name ?? 'undefined',
value: org.id,
name: org['name'] ?? 'undefined',
value: org['id'],
}))

let enforcedOrgs: string[] = []
Expand Down
7 changes: 3 additions & 4 deletions src/commands/organization/fetch-organization-list.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { setupSdk } from '../../utils/sdk.mts'

import type { CResult } from '../../types.mts'
import type { SetupSdkOptions } from '../../utils/sdk.mts'
import type { SocketSdk, SocketSdkSuccessResult } from '@socketsecurity/sdk'
import type { OrganizationsResult, SocketSdk } from '@socketsecurity/sdk'

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

export type EnterpriseOrganizations = EnterpriseOrganization[]

export type Organization =
SocketSdkSuccessResult<'getOrganizations'>['data']['organizations'][string]
export type Organization = OrganizationsResult['data']['organizations'][number]

export type Organizations = Organization[]

Expand Down Expand Up @@ -51,7 +50,7 @@ export async function fetchOrganization(
sockSdk = sockSdkCResult.data
}

const orgsCResult = await handleApiCall(sockSdk.getOrganizations(), {
const orgsCResult = await handleApiCall(sockSdk.listOrganizations(), {
description,
silence,
})
Expand Down
28 changes: 16 additions & 12 deletions src/commands/package/output-purls-shallow-score.mts
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,24 @@ export function preProcess(
row.score.license = artifact.score?.license || 100
}

artifact.alerts?.forEach(({ severity, type }) => {
row.alerts.set(`${type}:${severity}`, {
type: (type as string) ?? 'unknown',
severity: (severity as string) ?? 'none',
})
})
artifact.alerts?.forEach(
({ severity, type }: NonNullable<typeof artifact.alerts>[number]) => {
row.alerts.set(`${type}:${severity}`, {
type: (type as string) ?? 'unknown',
severity: (severity as string) ?? 'none',
})
},
)
} else {
const alerts = new Map<string, { type: string; severity: string }>()
artifact.alerts?.forEach(({ severity, type }) => {
alerts.set(`${type}:${severity}`, {
type: (type as string) ?? 'unknown',
severity: (severity as string) ?? 'none',
})
})
artifact.alerts?.forEach(
({ severity, type }: NonNullable<typeof artifact.alerts>[number]) => {
alerts.set(`${type}:${severity}`, {
type: (type as string) ?? 'unknown',
severity: (severity as string) ?? 'none',
})
},
)

rows.set(purl, {
ecosystem: artifact.type,
Expand Down
9 changes: 4 additions & 5 deletions src/commands/repository/fetch-create-repo.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupSdk } from '../../utils/sdk.mts'

import type { CResult } from '../../types.mts'
import type { SetupSdkOptions } from '../../utils/sdk.mts'
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
import type { RepositoryResult } from '@socketsecurity/sdk'

export type FetchCreateRepoConfig = {
defaultBranch: string
Expand All @@ -21,7 +21,7 @@ export type FetchCreateRepoOptions = {
export async function fetchCreateRepo(
config: FetchCreateRepoConfig,
options?: FetchCreateRepoOptions | undefined,
): Promise<CResult<SocketSdkSuccessResult<'createOrgRepo'>['data']>> {
): Promise<CResult<RepositoryResult['data']>> {
const {
defaultBranch,
description,
Expand All @@ -43,12 +43,11 @@ export async function fetchCreateRepo(
const sockSdk = sockSdkCResult.data

return await handleApiCall(
sockSdk.createOrgRepo(orgSlug, {
sockSdk.createRepository(orgSlug, repoName, {
default_branch: defaultBranch,
description,
homepage,
name: repoName,
visibility,
visibility: visibility as 'private' | 'public',
}),
{ description: 'to create a repository' },
)
Expand Down
6 changes: 3 additions & 3 deletions src/commands/repository/fetch-delete-repo.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupSdk } from '../../utils/sdk.mts'

import type { CResult } from '../../types.mts'
import type { SetupSdkOptions } from '../../utils/sdk.mts'
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
import type { DeleteResult } from '@socketsecurity/sdk'

export type FetchDeleteRepoOptions = {
sdkOpts?: SetupSdkOptions | undefined
Expand All @@ -13,7 +13,7 @@ export async function fetchDeleteRepo(
orgSlug: string,
repoName: string,
options?: FetchDeleteRepoOptions | undefined,
): Promise<CResult<SocketSdkSuccessResult<'deleteOrgRepo'>['data']>> {
): Promise<CResult<DeleteResult['data']>> {
const { sdkOpts } = {
__proto__: null,
...options,
Expand All @@ -25,7 +25,7 @@ export async function fetchDeleteRepo(
}
const sockSdk = sockSdkCResult.data

return await handleApiCall(sockSdk.deleteOrgRepo(orgSlug, repoName), {
return await handleApiCall(sockSdk.deleteRepository(orgSlug, repoName), {
description: 'to delete a repository',
})
}
16 changes: 8 additions & 8 deletions src/commands/repository/fetch-list-all-repos.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupSdk } from '../../utils/sdk.mts'

import type { CResult } from '../../types.mts'
import type { SetupSdkOptions } from '../../utils/sdk.mts'
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
import type { RepositoriesListResult } from '@socketsecurity/sdk'

export type FetchListAllReposOptions = {
direction?: string | undefined
Expand All @@ -14,7 +14,7 @@ export type FetchListAllReposOptions = {
export async function fetchListAllRepos(
orgSlug: string,
options?: FetchListAllReposOptions | undefined,
): Promise<CResult<SocketSdkSuccessResult<'getOrgRepoList'>['data']>> {
): Promise<CResult<RepositoriesListResult['data']>> {
const { direction, sdkOpts, sort } = {
__proto__: null,
...options,
Expand All @@ -26,7 +26,7 @@ export async function fetchListAllRepos(
}
const sockSdk = sockSdkCResult.data

const rows: SocketSdkSuccessResult<'getOrgRepoList'>['data']['results'] = []
const rows: RepositoriesListResult['data']['results'] = []
let protection = 0
let nextPage = 0
while (nextPage >= 0) {
Expand All @@ -39,11 +39,11 @@ export async function fetchListAllRepos(
}
// eslint-disable-next-line no-await-in-loop
const orgRepoListCResult = await handleApiCall(
sockSdk.getOrgRepoList(orgSlug, {
sort,
direction,
per_page: String(100), // max
page: String(nextPage),
sockSdk.listRepositories(orgSlug, {
...(sort ? { sort: sort as 'name' | 'updated_at' | 'created_at' } : {}),
...(direction ? { direction: direction as 'asc' | 'desc' } : {}),
per_page: 100, // max
page: nextPage,
}),
{ description: 'list of repositories' },
)
Expand Down
14 changes: 7 additions & 7 deletions src/commands/repository/fetch-list-repos.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupSdk } from '../../utils/sdk.mts'

import type { CResult } from '../../types.mts'
import type { SetupSdkOptions } from '../../utils/sdk.mts'
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
import type { RepositoriesListResult } from '@socketsecurity/sdk'

export type FetchListReposConfig = {
direction: string
Expand All @@ -20,7 +20,7 @@ export type FetchListReposOptions = {
export async function fetchListRepos(
config: FetchListReposConfig,
options?: FetchListReposOptions | undefined,
): Promise<CResult<SocketSdkSuccessResult<'getOrgRepoList'>['data']>> {
): Promise<CResult<RepositoriesListResult['data']>> {
const { direction, orgSlug, page, perPage, sort } = {
__proto__: null,
...config,
Expand All @@ -38,11 +38,11 @@ export async function fetchListRepos(
const sockSdk = sockSdkCResult.data

return await handleApiCall(
sockSdk.getOrgRepoList(orgSlug, {
sort,
direction,
per_page: String(perPage),
page: String(page),
sockSdk.listRepositories(orgSlug, {
...(sort ? { sort: sort as 'name' | 'updated_at' | 'created_at' } : {}),
...(direction ? { direction: direction as 'asc' | 'desc' } : {}),
per_page: perPage,
page,
}),
{ description: 'list of repositories' },
)
Expand Down
6 changes: 3 additions & 3 deletions src/commands/repository/fetch-update-repo.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupSdk } from '../../utils/sdk.mts'

import type { CResult } from '../../types.mts'
import type { SetupSdkOptions } from '../../utils/sdk.mts'
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
import type { RepositoryResult } from '@socketsecurity/sdk'

export type FetchUpdateRepoConfig = {
defaultBranch: string
Expand All @@ -21,7 +21,7 @@ export type FetchUpdateRepoOptions = {
export async function fetchUpdateRepo(
config: FetchUpdateRepoConfig,
options?: FetchUpdateRepoOptions | undefined,
): Promise<CResult<SocketSdkSuccessResult<'updateOrgRepo'>['data']>> {
): Promise<CResult<RepositoryResult['data']>> {
const {
defaultBranch,
description,
Expand All @@ -43,7 +43,7 @@ export async function fetchUpdateRepo(
const sockSdk = sockSdkCResult.data

return await handleApiCall(
sockSdk.updateOrgRepo(orgSlug, repoName, {
sockSdk.updateRepository(orgSlug, repoName, {
default_branch: defaultBranch,
description,
homepage,
Expand Down
Loading