Skip to content

Commit 73edd05

Browse files
committed
feat(sdk): add workspace parameter support for repository endpoints
Add workspace parameter to repository and full scan methods for multi-workspace support.
1 parent 77a3d8f commit 73edd05

File tree

5 files changed

+163
-32
lines changed

5 files changed

+163
-32
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export type {
114114
FullScanListData,
115115
FullScanListResult,
116116
FullScanResult,
117+
GetRepositoryOptions,
117118
ListFullScansOptions,
118119
ListRepositoriesOptions,
119120
OrganizationItem,

src/socket-sdk-class.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ import type {
9999
FullScanItem,
100100
FullScanListResult,
101101
FullScanResult,
102+
GetRepositoryOptions,
102103
ListFullScansOptions,
103104
ListRepositoriesOptions,
104105
OrganizationsResult,
@@ -1422,6 +1423,7 @@ export class SocketSdk {
14221423
*
14231424
* @param orgSlug - Organization identifier
14241425
* @param repoSlug - Repository slug/name to delete
1426+
* @param options - Optional parameters including workspace
14251427
* @returns Success confirmation
14261428
*
14271429
* @example
@@ -1442,14 +1444,22 @@ export class SocketSdk {
14421444
async deleteRepository(
14431445
orgSlug: string,
14441446
repoSlug: string,
1447+
options?: GetRepositoryOptions | undefined,
14451448
): Promise<DeleteResult | StrictErrorResult> {
1449+
const { workspace } = {
1450+
__proto__: null,
1451+
...options,
1452+
} as GetRepositoryOptions
1453+
const queryString = workspace
1454+
? `?${queryToSearchParams({ workspace } as QueryParams)}`
1455+
: ''
14461456
try {
14471457
const data = await this.#executeWithRetry(
14481458
async () =>
14491459
await getResponseJson(
14501460
await createDeleteRequest(
14511461
this.#baseUrl,
1452-
`orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}`,
1462+
`orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}${queryString}`,
14531463
{ ...this.#reqOptions, hooks: this.#hooks },
14541464
),
14551465
),
@@ -2262,6 +2272,7 @@ export class SocketSdk {
22622272
*
22632273
* @param orgSlug - Organization identifier
22642274
* @param repoSlug - Repository slug/name
2275+
* @param options - Optional parameters including workspace
22652276
* @returns Repository details with configuration
22662277
*
22672278
* @example
@@ -2284,17 +2295,25 @@ export class SocketSdk {
22842295
async getRepository(
22852296
orgSlug: string,
22862297
repoSlug: string,
2298+
options?: GetRepositoryOptions | undefined,
22872299
): Promise<RepositoryResult | StrictErrorResult> {
22882300
const orgSlugParam = encodeURIComponent(orgSlug)
22892301
const repoSlugParam = encodeURIComponent(repoSlug)
2302+
const { workspace } = {
2303+
__proto__: null,
2304+
...options,
2305+
} as GetRepositoryOptions
2306+
const queryString = workspace
2307+
? `?${queryToSearchParams({ workspace } as QueryParams)}`
2308+
: ''
22902309

22912310
try {
22922311
const data = await this.#executeWithRetry(
22932312
async () =>
22942313
await getResponseJson(
22952314
await createGetRequest(
22962315
this.#baseUrl,
2297-
`orgs/${orgSlugParam}/repos/${repoSlugParam}`,
2316+
`orgs/${orgSlugParam}/repos/${repoSlugParam}${queryString}`,
22982317
{ ...this.#reqOptions, hooks: this.#hooks },
22992318
),
23002319
),
@@ -3217,6 +3236,7 @@ export class SocketSdk {
32173236
* @param orgSlug - Organization identifier
32183237
* @param repoSlug - Repository slug/name
32193238
* @param params - Configuration updates (description, homepage, default_branch, etc.)
3239+
* @param options - Optional parameters including workspace
32203240
* @returns Updated repository details
32213241
*
32223242
* @example
@@ -3241,15 +3261,23 @@ export class SocketSdk {
32413261
orgSlug: string,
32423262
repoSlug: string,
32433263
params?: QueryParams | undefined,
3264+
options?: GetRepositoryOptions | undefined,
32443265
): Promise<RepositoryResult | StrictErrorResult> {
3266+
const { workspace } = {
3267+
__proto__: null,
3268+
...options,
3269+
} as GetRepositoryOptions
3270+
const queryString = workspace
3271+
? `?${queryToSearchParams({ workspace } as QueryParams)}`
3272+
: ''
32453273
try {
32463274
const data = await this.#executeWithRetry(
32473275
async () =>
32483276
await getResponseJson(
32493277
await createRequestWithJson(
32503278
'POST',
32513279
this.#baseUrl,
3252-
`orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}`,
3280+
`orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}${queryString}`,
32533281
params,
32543282
{ ...this.#reqOptions, hooks: this.#hooks },
32553283
),

src/types-strict.ts

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,36 +73,44 @@ export type FullScanResult = {
7373
* Options for listing full scans.
7474
*/
7575
export type ListFullScansOptions = {
76-
sort?: 'name' | 'created_at'
77-
direction?: 'asc' | 'desc'
78-
per_page?: number
79-
page?: number
80-
startAfterCursor?: string
81-
use_cursor?: boolean
82-
from?: string
83-
repo?: string
84-
branch?: string
85-
pull_request?: string
86-
commit_hash?: string
76+
branch?: string | undefined
77+
commit_hash?: string | undefined
78+
direction?: 'asc' | 'desc' | undefined
79+
from?: string | undefined
80+
page?: number | undefined
81+
per_page?: number | undefined
82+
pull_request?: string | undefined
83+
repo?: string | undefined
84+
sort?: 'created_at' | 'name' | undefined
85+
startAfterCursor?: string | undefined
86+
use_cursor?: boolean | undefined
87+
workspace?: string | undefined
8788
}
8889

8990
/**
9091
* Options for creating a full scan.
9192
*/
9293
export type CreateFullScanOptions = {
93-
pathsRelativeTo?: string
94+
branch?: string | undefined
95+
commit_hash?: string | undefined
96+
commit_message?: string | undefined
97+
committers?: string | undefined
98+
integration_org_slug?: string | undefined
99+
integration_type?:
100+
| 'api'
101+
| 'azure'
102+
| 'bitbucket'
103+
| 'github'
104+
| 'gitlab'
105+
| undefined
106+
make_default_branch?: boolean | undefined
107+
pathsRelativeTo?: string | undefined
108+
pull_request?: number | undefined
94109
repo: string
95-
branch?: string
96-
commit_message?: string
97-
commit_hash?: string
98-
pull_request?: number
99-
committers?: string
100-
integration_type?: 'api' | 'github' | 'gitlab' | 'bitbucket' | 'azure'
101-
integration_org_slug?: string
102-
make_default_branch?: boolean
103-
set_as_pending_head?: boolean
104-
tmp?: boolean
105-
scan_type?: string
110+
scan_type?: string | undefined
111+
set_as_pending_head?: boolean | undefined
112+
tmp?: boolean | undefined
113+
workspace?: string | undefined
106114
}
107115

108116
/**
@@ -197,16 +205,23 @@ export type RepositoriesListResult = {
197205
success: true
198206
}
199207

208+
/**
209+
* Options for getting a single repository.
210+
*/
211+
export type GetRepositoryOptions = {
212+
workspace?: string | undefined
213+
}
214+
200215
/**
201216
* Options for listing repositories.
202217
*/
203218
export type ListRepositoriesOptions = {
204-
sort?: 'name' | 'created_at'
205-
direction?: 'asc' | 'desc'
206-
per_page?: number
207-
page?: number
208-
startAfterCursor?: string
209-
use_cursor?: boolean
219+
direction?: 'asc' | 'desc' | undefined
220+
page?: number | undefined
221+
per_page?: number | undefined
222+
sort?: 'created_at' | 'name' | undefined
223+
startAfterCursor?: string | undefined
224+
use_cursor?: boolean | undefined
210225
}
211226

212227
/**

test/unit/socket-sdk-batch.test.mts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,34 @@ describe('SocketSdk - Batch Operations', () => {
486486
expect(contentType).toContain('boundary=')
487487
})
488488

489+
it('should upload files with createFullScan with workspace option', async () => {
490+
nock('https://api.socket.dev')
491+
.post('/v0/orgs/test-org/full-scans')
492+
.query({ repo: 'test-repo', workspace: 'my-workspace' })
493+
.reply(200, {
494+
id: 'org-scan-789',
495+
organization_slug: 'test-org',
496+
status: 'complete',
497+
workspace: 'my-workspace',
498+
})
499+
500+
const client = new SocketSdk('test-token', NO_RETRY_CONFIG)
501+
const res = await client.createFullScan(
502+
'test-org',
503+
[packageJsonPath, packageLockPath],
504+
{
505+
pathsRelativeTo: tempDir,
506+
repo: 'test-repo',
507+
workspace: 'my-workspace',
508+
},
509+
)
510+
511+
expect(res.success).toBe(true)
512+
if (res.success) {
513+
expect(res.data.id).toBe('org-scan-789')
514+
}
515+
})
516+
489517
it('should handle connection interruption during upload', async () => {
490518
nock('https://api.socket.dev')
491519
.post('/v0/dependencies/upload')

test/unit/socket-sdk-success-paths.test.mts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,50 @@ describe('SocketSdk - Success Path Coverage', () => {
6969

7070
expect(result.success).toBe(true)
7171
})
72+
73+
it('should successfully get a repository with workspace option', async () => {
74+
nock('https://api.socket.dev')
75+
.get('/v0/orgs/test-org/repos/test-repo')
76+
.query({ workspace: 'my-workspace' })
77+
.reply(200, { data: { name: 'test-repo', workspace: 'my-workspace' } })
78+
79+
const result = await getClient().getRepository('test-org', 'test-repo', {
80+
workspace: 'my-workspace',
81+
})
82+
83+
expect(result.success).toBe(true)
84+
})
85+
86+
it('should successfully delete a repository with workspace option', async () => {
87+
nock('https://api.socket.dev')
88+
.delete('/v0/orgs/test-org/repos/test-repo')
89+
.query({ workspace: 'my-workspace' })
90+
.reply(200, { success: true })
91+
92+
const result = await getClient().deleteRepository(
93+
'test-org',
94+
'test-repo',
95+
{ workspace: 'my-workspace' },
96+
)
97+
98+
expect(result.success).toBe(true)
99+
})
100+
101+
it('should successfully update a repository with workspace option', async () => {
102+
nock('https://api.socket.dev')
103+
.post('/v0/orgs/test-org/repos/test-repo')
104+
.query({ workspace: 'my-workspace' })
105+
.reply(200, { data: { name: 'test-repo', workspace: 'my-workspace' } })
106+
107+
const result = await getClient().updateRepository(
108+
'test-org',
109+
'test-repo',
110+
{ defaultBranch: 'develop' },
111+
{ workspace: 'my-workspace' },
112+
)
113+
114+
expect(result.success).toBe(true)
115+
})
72116
})
73117

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

166210
expect(result.success).toBe(true)
167211
})
212+
213+
it('should successfully list full scans with workspace option', async () => {
214+
nock('https://api.socket.dev')
215+
.get('/v0/orgs/test-org/full-scans')
216+
.query({ workspace: 'my-workspace' })
217+
.reply(200, {
218+
results: [{ id: 'scan-123', workspace: 'my-workspace' }],
219+
})
220+
221+
const result = await getClient().listFullScans('test-org', {
222+
workspace: 'my-workspace',
223+
})
224+
225+
expect(result.success).toBe(true)
226+
})
168227
})
169228

170229
describe('Organizations', () => {

0 commit comments

Comments
 (0)