import {z} from 'zod' export type ProtosScaV1PackageFilter = {name?: string | undefined, versionLowerBound?: string | undefined, versionUpperBound?: string | undefined, exactVersion?: string | undefined, exactNameMatch?: boolean | undefined}; export type ProtosScaV1DependencyFilter = {name?: string | undefined, version?: string | undefined, repositoryId?: Array | undefined, transitivity?: (Array<'UNKNOWN_TRANSITIVITY' | 'TRANSITIVE' | 'DIRECT'>) | undefined, ecosystem?: (Array<'no_package_manager' | 'npm' | 'pypi' | 'gomod' | 'cargo' | 'maven' | 'gem' | 'composer' | 'nuget' | 'pub' | 'swiftpm' | 'hex' | 'cocoapods' | 'mix' | 'opam'>) | undefined, lockfilePath?: string | undefined, licensePolicySettings?: (Array<'LICENSE_POLICY_SETTING_UNSPECIFIED' | 'LICENSE_POLICY_SETTING_ALLOW' | 'LICENSE_POLICY_SETTING_COMMENT' | 'LICENSE_POLICY_SETTING_BLOCK'>) | undefined, license?: Array | undefined, packageFilters?: Array | undefined}; export type ProtosOpenapiV1ListRepositoriesForDependenciesRequest = {cursor?: number | undefined, dependencyFilter?: ProtosScaV1DependencyFilter | undefined, deploymentId?: unknown | undefined, pageSize?: number | undefined}; export type CreateApiApiV1DeploymentsDeploymentIdDependenciesRepositoriesArgs = {deploymentId: unknown, body: ProtosOpenapiV1ListRepositoriesForDependenciesRequest}; export type CreateApiApiV1DeploymentsDeploymentIdDependenciesRepositoriesOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosScaV1RepositoryDependencySummary = z.object({id: z.number().int().optional(), name: z.string().optional(), numDependencies: z.number().int().optional(), hasDependencyPathScan: z.boolean().optional()}); export const protosOpenapiV1ListRepositoriesForDependenciesResponse = z.object({cursor: z.number().optional(), hasMore: z.boolean().optional(), repositorySummaries: z.array(protosScaV1RepositoryDependencySummary).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List repositories with dependencies * * POST /api/v1/deployments/{deploymentId}/dependencies/repositories */ export const createApiApiV1DeploymentsDeploymentIdDependenciesRepositories = async (args: CreateApiApiV1DeploymentsDeploymentIdDependenciesRepositoriesArgs, options: CreateApiApiV1DeploymentsDeploymentIdDependenciesRepositoriesOptions) => { const {baseUrl, fetch: fetchFn = fetch, SemgrepWebToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (SemgrepWebToken !== undefined) headers.set('authorization', `Bearer ${SemgrepWebToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/deployments/${encodeURIComponent(String(args.deploymentId))}/dependencies/repositories${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(protosOpenapiV1ListRepositoriesForDependenciesResponse, await res.json()) };