import {z} from 'zod' export type GetApiApiScaDeploymentsDeploymentIdDependenciesArgs = {deploymentId: unknown, 'dependencyFilter.name'?: string | undefined, 'dependencyFilter.version'?: string | undefined, 'dependencyFilter.repositoryId'?: Array | undefined, 'dependencyFilter.transitivity'?: (Array<'UNKNOWN_TRANSITIVITY' | 'TRANSITIVE' | 'DIRECT'>) | undefined, 'dependencyFilter.ecosystem'?: (Array<'no_package_manager' | 'npm' | 'pypi' | 'gomod' | 'cargo' | 'maven' | 'gem' | 'composer' | 'nuget' | 'pub' | 'swiftpm' | 'hex' | 'cocoapods' | 'mix' | 'opam'>) | undefined, 'dependencyFilter.lockfilePath'?: string | undefined, 'dependencyFilter.licensePolicySettings'?: (Array<'LICENSE_POLICY_SETTING_UNSPECIFIED' | 'LICENSE_POLICY_SETTING_ALLOW' | 'LICENSE_POLICY_SETTING_COMMENT' | 'LICENSE_POLICY_SETTING_BLOCK'>) | undefined, 'dependencyFilter.license'?: Array | undefined, cursor?: unknown | undefined, pageSize?: number | undefined}; export type GetApiApiScaDeploymentsDeploymentIdDependenciesOptions = {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 * * GET /api/sca/deployments/{deploymentId}/dependencies * * Also accepts auth: SemgrepJWT */ export const getApiApiScaDeploymentsDeploymentIdDependencies = async (args: GetApiApiScaDeploymentsDeploymentIdDependenciesArgs, options: GetApiApiScaDeploymentsDeploymentIdDependenciesOptions) => { const {baseUrl, fetch: fetchFn = fetch, SemgrepWebToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['dependencyFilter.name'] != null) query.append("dependencyFilter.name", String(args['dependencyFilter.name'])) if (args['dependencyFilter.version'] != null) query.append("dependencyFilter.version", String(args['dependencyFilter.version'])) for (const item of args['dependencyFilter.repositoryId'] ?? []) query.append("dependencyFilter.repositoryId", String(item)) for (const item of args['dependencyFilter.transitivity'] ?? []) query.append("dependencyFilter.transitivity", String(item)) for (const item of args['dependencyFilter.ecosystem'] ?? []) query.append("dependencyFilter.ecosystem", String(item)) if (args['dependencyFilter.lockfilePath'] != null) query.append("dependencyFilter.lockfilePath", String(args['dependencyFilter.lockfilePath'])) for (const item of args['dependencyFilter.licensePolicySettings'] ?? []) query.append("dependencyFilter.licensePolicySettings", String(item)) for (const item of args['dependencyFilter.license'] ?? []) query.append("dependencyFilter.license", String(item)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) 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: "GET", headers}) 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()) };