Skip to content

Commit ff95255

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 ee03e90 commit ff95255

File tree

5 files changed

+145
-20
lines changed

5 files changed

+145
-20
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
),
@@ -2264,6 +2274,7 @@ export class SocketSdk {
22642274
*
22652275
* @param orgSlug - Organization identifier
22662276
* @param repoSlug - Repository slug/name
2277+
* @param options - Optional parameters including workspace
22672278
* @returns Repository details with configuration
22682279
*
22692280
* @example
@@ -2286,17 +2297,25 @@ export class SocketSdk {
22862297
async getRepository(
22872298
orgSlug: string,
22882299
repoSlug: string,
2300+
options?: GetRepositoryOptions | undefined,
22892301
): Promise<RepositoryResult | StrictErrorResult> {
22902302
const orgSlugParam = encodeURIComponent(orgSlug)
22912303
const repoSlugParam = encodeURIComponent(repoSlug)
2304+
const { workspace } = {
2305+
__proto__: null,
2306+
...options,
2307+
} as GetRepositoryOptions
2308+
const queryString = workspace
2309+
? `?${queryToSearchParams({ workspace } as QueryParams)}`
2310+
: ''
22922311

22932312
try {
22942313
const data = await this.#executeWithRetry(
22952314
async () =>
22962315
await getResponseJson(
22972316
await createGetRequest(
22982317
this.#baseUrl,
2299-
`orgs/${orgSlugParam}/repos/${repoSlugParam}`,
2318+
`orgs/${orgSlugParam}/repos/${repoSlugParam}${queryString}`,
23002319
{ ...this.#reqOptions, hooks: this.#hooks },
23012320
),
23022321
),
@@ -3219,6 +3238,7 @@ export class SocketSdk {
32193238
* @param orgSlug - Organization identifier
32203239
* @param repoSlug - Repository slug/name
32213240
* @param params - Configuration updates (description, homepage, default_branch, etc.)
3241+
* @param options - Optional parameters including workspace
32223242
* @returns Updated repository details
32233243
*
32243244
* @example
@@ -3243,15 +3263,23 @@ export class SocketSdk {
32433263
orgSlug: string,
32443264
repoSlug: string,
32453265
params?: QueryParams | undefined,
3266+
options?: GetRepositoryOptions | undefined,
32463267
): Promise<RepositoryResult | StrictErrorResult> {
3268+
const { workspace } = {
3269+
__proto__: null,
3270+
...options,
3271+
} as GetRepositoryOptions
3272+
const queryString = workspace
3273+
? `?${queryToSearchParams({ workspace } as QueryParams)}`
3274+
: ''
32473275
try {
32483276
const data = await this.#executeWithRetry(
32493277
async () =>
32503278
await getResponseJson(
32513279
await createRequestWithJson(
32523280
'POST',
32533281
this.#baseUrl,
3254-
`orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}`,
3282+
`orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}${queryString}`,
32553283
params,
32563284
{ ...this.#reqOptions, hooks: this.#hooks },
32573285
),

src/types-strict.ts

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

8990
/**
9091
* Options for creating a full scan.
9192
*/
9293
export type CreateFullScanOptions = {
93-
pathsRelativeTo?: string | undefined
94-
repo: string
9594
branch?: string | undefined
96-
commit_message?: string | undefined
9795
commit_hash?: string | undefined
98-
pull_request?: number | undefined
96+
commit_message?: string | undefined
9997
committers?: string | undefined
98+
integration_org_slug?: string | undefined
10099
integration_type?:
101100
| 'api'
101+
| 'azure'
102+
| 'bitbucket'
102103
| 'github'
103104
| 'gitlab'
104-
| 'bitbucket'
105-
| 'azure'
106105
| undefined
107-
integration_org_slug?: string | undefined
108106
make_default_branch?: boolean | undefined
107+
pathsRelativeTo?: string | undefined
108+
pull_request?: number | undefined
109+
repo: string
110+
scan_type?: string | undefined
109111
set_as_pending_head?: boolean | undefined
110112
tmp?: boolean | undefined
111-
scan_type?: string | undefined
113+
workspace?: string | undefined
112114
}
113115

114116
/**
@@ -203,14 +205,21 @@ export type RepositoriesListResult = {
203205
success: true
204206
}
205207

208+
/**
209+
* Options for getting a single repository.
210+
*/
211+
export type GetRepositoryOptions = {
212+
workspace?: string | undefined
213+
}
214+
206215
/**
207216
* Options for listing repositories.
208217
*/
209218
export type ListRepositoriesOptions = {
210-
sort?: 'name' | 'created_at' | undefined
211219
direction?: 'asc' | 'desc' | undefined
212-
per_page?: number | undefined
213220
page?: number | undefined
221+
per_page?: number | undefined
222+
sort?: 'created_at' | 'name' | undefined
214223
startAfterCursor?: string | undefined
215224
use_cursor?: boolean | undefined
216225
}

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)