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 ProtosScaV1ListDependenciesRequest = {deploymentId?: unknown | undefined, dependencyFilter?: ProtosScaV1DependencyFilter | undefined, cursor?: unknown | undefined, pageSize?: number | undefined}; export type CreateApiApiScaDeploymentsDeploymentIdDependenciesArgs = {deploymentId: unknown, body: ProtosScaV1ListDependenciesRequest}; export type CreateApiApiScaDeploymentsDeploymentIdDependenciesOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosScaV1CodeLocation = z.object({path: z.string().optional(), startLine: z.string().optional(), startCol: z.string().optional(), endLine: z.string().optional(), endCol: z.string().optional(), url: z.string().optional(), committedAt: z.string().optional()}); export const protosScaV1Dependency = z.object({name: z.string().optional(), versionSpecifier: z.string().optional()}); export const protosScaV1FoundDependency = z.object({repositoryId: z.string().optional(), definedAt: protosScaV1CodeLocation.optional(), transitivity: z.enum(["UNKNOWN_TRANSITIVITY", "TRANSITIVE", "DIRECT"]).optional(), package: protosScaV1Dependency.optional(), ecosystem: z.enum(["no_package_manager", "npm", "pypi", "gomod", "cargo", "maven", "gem", "composer", "nuget", "pub", "swiftpm", "hex", "cocoapods", "mix", "opam"]).optional(), licenses: z.array(z.string()).optional(), manifestDefinition: protosScaV1CodeLocation.optional(), resolvedUrl: z.string().optional()}); export const protosScaV1ListDependenciesResponse = z.object({dependencies: z.array(protosScaV1FoundDependency), hasMore: z.boolean().optional(), cursor: z.string().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 dependencies * * POST /api/sca/deployments/{deploymentId}/dependencies * * Also accepts auth: SemgrepJWT */ export const createApiApiScaDeploymentsDeploymentIdDependencies = async (args: CreateApiApiScaDeploymentsDeploymentIdDependenciesArgs, options: CreateApiApiScaDeploymentsDeploymentIdDependenciesOptions) => { 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/sca/deployments/${encodeURIComponent(String(args.deploymentId))}/dependencies${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(protosScaV1ListDependenciesResponse, await res.json()) };