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 ProtosScaV1ListLockfilesForDependenciesRequest = {deploymentId?: unknown | undefined, repositoryId?: unknown | undefined, dependencyFilter?: ProtosScaV1DependencyFilter | undefined, cursor?: string | undefined, pageSize?: number | undefined}; export type CreateApiApiScaDeploymentsDeploymentIdRepositoryIdLockfilesArgs = {deploymentId: unknown, repositoryId: unknown, body: ProtosScaV1ListLockfilesForDependenciesRequest}; export type CreateApiApiScaDeploymentsDeploymentIdRepositoryIdLockfilesOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosScaV1LockfileDependencySummary = z.object({lockfilePath: z.string().optional(), numDependencies: z.number().int().optional()}); export const protosScaV1ListLockfilesForDependenciesResponse = z.object({lockfileSummaries: z.array(protosScaV1LockfileDependencySummary).optional(), 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 lockfiles with dependencies in a given repository * * POST /api/sca/deployments/{deploymentId}/{repositoryId}/lockfiles * * Also accepts auth: SemgrepJWT */ export const createApiApiScaDeploymentsDeploymentIdRepositoryIdLockfiles = async (args: CreateApiApiScaDeploymentsDeploymentIdRepositoryIdLockfilesArgs, options: CreateApiApiScaDeploymentsDeploymentIdRepositoryIdLockfilesOptions) => { 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))}/${encodeURIComponent(String(args.repositoryId))}/lockfiles${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(protosScaV1ListLockfilesForDependenciesResponse, await res.json()) };