diff --git a/src/index.ts b/src/index.ts index 71ce6da4..9bf09a02 100644 --- a/src/index.ts +++ b/src/index.ts @@ -114,6 +114,7 @@ export type { FullScanListData, FullScanListResult, FullScanResult, + GetRepositoryOptions, ListFullScansOptions, ListRepositoriesOptions, OrganizationItem, diff --git a/src/socket-sdk-class.ts b/src/socket-sdk-class.ts index 94ea1a43..5d2f2a37 100644 --- a/src/socket-sdk-class.ts +++ b/src/socket-sdk-class.ts @@ -99,6 +99,7 @@ import type { FullScanItem, FullScanListResult, FullScanResult, + GetRepositoryOptions, ListFullScansOptions, ListRepositoriesOptions, OrganizationsResult, @@ -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 @@ -1442,14 +1444,22 @@ export class SocketSdk { async deleteRepository( orgSlug: string, repoSlug: string, + options?: GetRepositoryOptions | undefined, ): Promise { + 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 }, ), ), @@ -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 @@ -2286,9 +2297,17 @@ export class SocketSdk { async getRepository( orgSlug: string, repoSlug: string, + options?: GetRepositoryOptions | undefined, ): Promise { 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( @@ -2296,7 +2315,7 @@ export class SocketSdk { await getResponseJson( await createGetRequest( this.#baseUrl, - `orgs/${orgSlugParam}/repos/${repoSlugParam}`, + `orgs/${orgSlugParam}/repos/${repoSlugParam}${queryString}`, { ...this.#reqOptions, hooks: this.#hooks }, ), ), @@ -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 @@ -3243,7 +3263,15 @@ export class SocketSdk { orgSlug: string, repoSlug: string, params?: QueryParams | undefined, + options?: GetRepositoryOptions | undefined, ): Promise { + const { workspace } = { + __proto__: null, + ...options, + } as GetRepositoryOptions + const queryString = workspace + ? `?${queryToSearchParams({ workspace } as QueryParams)}` + : '' try { const data = await this.#executeWithRetry( async () => @@ -3251,7 +3279,7 @@ export class SocketSdk { await createRequestWithJson( 'POST', this.#baseUrl, - `orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}`, + `orgs/${encodeURIComponent(orgSlug)}/repos/${encodeURIComponent(repoSlug)}${queryString}`, params, { ...this.#reqOptions, hooks: this.#hooks }, ), diff --git a/src/types-strict.ts b/src/types-strict.ts index a1b491b6..94bab1e1 100644 --- a/src/types-strict.ts +++ b/src/types-strict.ts @@ -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 } /** @@ -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 } diff --git a/test/unit/socket-sdk-batch.test.mts b/test/unit/socket-sdk-batch.test.mts index 9b5e6b23..48e7251a 100644 --- a/test/unit/socket-sdk-batch.test.mts +++ b/test/unit/socket-sdk-batch.test.mts @@ -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') diff --git a/test/unit/socket-sdk-success-paths.test.mts b/test/unit/socket-sdk-success-paths.test.mts index f6517151..d044a7ce 100644 --- a/test/unit/socket-sdk-success-paths.test.mts +++ b/test/unit/socket-sdk-success-paths.test.mts @@ -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', () => { @@ -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', () => {