Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export type {
FullScanListData,
FullScanListResult,
FullScanResult,
GetRepositoryOptions,
ListFullScansOptions,
ListRepositoriesOptions,
OrganizationItem,
Expand Down
34 changes: 31 additions & 3 deletions src/socket-sdk-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import type {
FullScanItem,
FullScanListResult,
FullScanResult,
GetRepositoryOptions,
ListFullScansOptions,
ListRepositoriesOptions,
OrganizationsResult,
Expand Down Expand Up @@ -1422,6 +1423,7 @@ export class SocketSdk {
*
* @param orgSlug - Organization identifier
* @param repoSlug - Repository slug/name to delete
* @param options - Optional parameters including workspace
* @returns Success confirmation
*
* @example
Expand All @@ -1442,14 +1444,22 @@ export class SocketSdk {
async deleteRepository(
orgSlug: string,
repoSlug: string,
options?: GetRepositoryOptions | undefined,
): Promise<DeleteResult | StrictErrorResult> {
const { workspace } = {
__proto__: null,
...options,
} as GetRepositoryOptions
const queryString = workspace
? `?${queryToSearchParams({ workspace } as QueryParams)}`
: ''
try {
const data = await this.#executeWithRetry(
async () =>
await getResponseJson(
await createDeleteRequest(
this.#baseUrl,
`orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}`,
`orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}${queryString}`,
{ ...this.#reqOptions, hooks: this.#hooks },
),
),
Expand Down Expand Up @@ -2264,6 +2274,7 @@ export class SocketSdk {
*
* @param orgSlug - Organization identifier
* @param repoSlug - Repository slug/name
* @param options - Optional parameters including workspace
* @returns Repository details with configuration
*
* @example
Expand All @@ -2286,17 +2297,25 @@ export class SocketSdk {
async getRepository(
orgSlug: string,
repoSlug: string,
options?: GetRepositoryOptions | undefined,
): Promise<RepositoryResult | StrictErrorResult> {
const orgSlugParam = encodeURIComponent(orgSlug)
const repoSlugParam = encodeURIComponent(repoSlug)
const { workspace } = {
__proto__: null,
...options,
} as GetRepositoryOptions
const queryString = workspace
? `?${queryToSearchParams({ workspace } as QueryParams)}`
: ''

try {
const data = await this.#executeWithRetry(
async () =>
await getResponseJson(
await createGetRequest(
this.#baseUrl,
`orgs/${orgSlugParam}/repos/${repoSlugParam}`,
`orgs/${orgSlugParam}/repos/${repoSlugParam}${queryString}`,
{ ...this.#reqOptions, hooks: this.#hooks },
),
),
Expand Down Expand Up @@ -3219,6 +3238,7 @@ export class SocketSdk {
* @param orgSlug - Organization identifier
* @param repoSlug - Repository slug/name
* @param params - Configuration updates (description, homepage, default_branch, etc.)
* @param options - Optional parameters including workspace
* @returns Updated repository details
*
* @example
Expand All @@ -3243,15 +3263,23 @@ export class SocketSdk {
orgSlug: string,
repoSlug: string,
params?: QueryParams | undefined,
options?: GetRepositoryOptions | undefined,
): Promise<RepositoryResult | StrictErrorResult> {
const { workspace } = {
__proto__: null,
...options,
} as GetRepositoryOptions
const queryString = workspace
? `?${queryToSearchParams({ workspace } as QueryParams)}`
: ''
try {
const data = await this.#executeWithRetry(
async () =>
await getResponseJson(
await createRequestWithJson(
'POST',
this.#baseUrl,
`orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}`,
`orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}${queryString}`,
params,
{ ...this.#reqOptions, hooks: this.#hooks },
),
Expand Down
43 changes: 26 additions & 17 deletions src/types-strict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,42 +73,44 @@ export type FullScanResult = {
* Options for listing full scans.
*/
export type ListFullScansOptions = {
sort?: 'name' | 'created_at' | undefined
branch?: string | undefined
commit_hash?: string | undefined
direction?: 'asc' | 'desc' | undefined
per_page?: number | undefined
from?: string | undefined
page?: number | undefined
per_page?: number | undefined
pull_request?: string | undefined
repo?: string | undefined
sort?: 'created_at' | 'name' | undefined
startAfterCursor?: string | undefined
use_cursor?: boolean | undefined
from?: string | undefined
repo?: string | undefined
branch?: string | undefined
pull_request?: string | undefined
commit_hash?: string | undefined
workspace?: string | undefined
}

/**
* Options for creating a full scan.
*/
export type CreateFullScanOptions = {
pathsRelativeTo?: string | undefined
repo: string
branch?: string | undefined
commit_message?: string | undefined
commit_hash?: string | undefined
pull_request?: number | undefined
commit_message?: string | undefined
committers?: string | undefined
integration_org_slug?: string | undefined
integration_type?:
| 'api'
| 'azure'
| 'bitbucket'
| 'github'
| 'gitlab'
| 'bitbucket'
| 'azure'
| undefined
integration_org_slug?: string | undefined
make_default_branch?: boolean | undefined
pathsRelativeTo?: string | undefined
pull_request?: number | undefined
repo: string
scan_type?: string | undefined
set_as_pending_head?: boolean | undefined
tmp?: boolean | undefined
scan_type?: string | undefined
workspace?: string | undefined
}

/**
Expand Down Expand Up @@ -203,14 +205,21 @@ export type RepositoriesListResult = {
success: true
}

/**
* Options for getting a single repository.
*/
export type GetRepositoryOptions = {
workspace?: string | undefined
}

/**
* Options for listing repositories.
*/
export type ListRepositoriesOptions = {
sort?: 'name' | 'created_at' | undefined
direction?: 'asc' | 'desc' | undefined
per_page?: number | undefined
page?: number | undefined
per_page?: number | undefined
sort?: 'created_at' | 'name' | undefined
startAfterCursor?: string | undefined
use_cursor?: boolean | undefined
}
Expand Down
28 changes: 28 additions & 0 deletions test/unit/socket-sdk-batch.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,34 @@ describe('SocketSdk - Batch Operations', () => {
expect(contentType).toContain('boundary=')
})

it('should upload files with createFullScan with workspace option', async () => {
nock('https://api.socket.dev')
.post('/v0/orgs/test-org/full-scans')
.query({ repo: 'test-repo', workspace: 'my-workspace' })
.reply(200, {
id: 'org-scan-789',
organization_slug: 'test-org',
status: 'complete',
workspace: 'my-workspace',
})

const client = new SocketSdk('test-token', NO_RETRY_CONFIG)
const res = await client.createFullScan(
'test-org',
[packageJsonPath, packageLockPath],
{
pathsRelativeTo: tempDir,
repo: 'test-repo',
workspace: 'my-workspace',
},
)

expect(res.success).toBe(true)
if (res.success) {
expect(res.data.id).toBe('org-scan-789')
}
})

it('should handle connection interruption during upload', async () => {
nock('https://api.socket.dev')
.post('/v0/dependencies/upload')
Expand Down
59 changes: 59 additions & 0 deletions test/unit/socket-sdk-success-paths.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,50 @@ describe('SocketSdk - Success Path Coverage', () => {

expect(result.success).toBe(true)
})

it('should successfully get a repository with workspace option', async () => {
nock('https://api.socket.dev')
.get('/v0/orgs/test-org/repos/test-repo')
.query({ workspace: 'my-workspace' })
.reply(200, { data: { name: 'test-repo', workspace: 'my-workspace' } })

const result = await getClient().getRepository('test-org', 'test-repo', {
workspace: 'my-workspace',
})

expect(result.success).toBe(true)
})

it('should successfully delete a repository with workspace option', async () => {
nock('https://api.socket.dev')
.delete('/v0/orgs/test-org/repos/test-repo')
.query({ workspace: 'my-workspace' })
.reply(200, { success: true })

const result = await getClient().deleteRepository(
'test-org',
'test-repo',
{ workspace: 'my-workspace' },
)

expect(result.success).toBe(true)
})

it('should successfully update a repository with workspace option', async () => {
nock('https://api.socket.dev')
.post('/v0/orgs/test-org/repos/test-repo')
.query({ workspace: 'my-workspace' })
.reply(200, { data: { name: 'test-repo', workspace: 'my-workspace' } })

const result = await getClient().updateRepository(
'test-org',
'test-repo',
{ defaultBranch: 'develop' },
{ workspace: 'my-workspace' },
)

expect(result.success).toBe(true)
})
})

describe('Repository Labels', () => {
Expand Down Expand Up @@ -165,6 +209,21 @@ describe('SocketSdk - Success Path Coverage', () => {

expect(result.success).toBe(true)
})

it('should successfully list full scans with workspace option', async () => {
nock('https://api.socket.dev')
.get('/v0/orgs/test-org/full-scans')
.query({ workspace: 'my-workspace' })
.reply(200, {
results: [{ id: 'scan-123', workspace: 'my-workspace' }],
})

const result = await getClient().listFullScans('test-org', {
workspace: 'my-workspace',
})

expect(result.success).toBe(true)
})
})

describe('Organizations', () => {
Expand Down