import {z} from 'zod' export type ProtosReportingV1TimePeriod = {since?: string | undefined, until?: string | undefined}; export type ProtosReportingV1ReportFilters = {timePeriod?: ProtosReportingV1TimePeriod | undefined, timeBucketSize?: ('TIME_BUCKET_SIZE_DAY' | 'TIME_BUCKET_SIZE_WEEK' | 'TIME_BUCKET_SIZE_MONTH') | undefined, findingTypes?: (Array<'FINDING_TYPE_UNSPECIFIED' | 'FINDING_TYPE_CODE' | 'FINDING_TYPE_SCA' | 'FINDING_TYPE_SECRETS'>) | undefined, findingSeverities?: (Array<'FINDING_SEVERITY_UNSPECIFIED' | 'FINDING_SEVERITY_LOW' | 'FINDING_SEVERITY_MEDIUM' | 'FINDING_SEVERITY_HIGH' | 'FINDING_SEVERITY_CRITICAL'>) | undefined, projects?: Array | undefined, tags?: Array | undefined, confidence?: (Array<'FINDING_CONFIDENCE_UNSPECIFIED' | 'FINDING_CONFIDENCE_LOW' | 'FINDING_CONFIDENCE_MEDIUM' | 'FINDING_CONFIDENCE_HIGH'>) | undefined, reachability?: (Array<'FINDING_REACHABILITY_UNSPECIFIED' | 'FINDING_REACHABILITY_REACHABLE' | 'FINDING_REACHABILITY_ALWAYS_REACHABLE' | 'FINDING_REACHABILITY_CONDITIONALLY_REACHABLE' | 'FINDING_REACHABILITY_NO_REACHABILITY_ANALYSIS' | 'FINDING_REACHABILITY_UNREACHABLE'>) | undefined, validity?: (Array<'FINDING_VALIDITY_UNSPECIFIED' | 'FINDING_VALIDITY_VALID' | 'FINDING_VALIDITY_INVALID' | 'FINDING_VALIDITY_ERROR' | 'FINDING_VALIDITY_NO_VALIDATOR'>) | undefined, teams?: Array | undefined, ruleIds?: Array | undefined, aiVerdicts?: (Array<'VERDICT_UNSPECIFIED' | 'VERDICT_TRUE_POSITIVE' | 'VERDICT_FALSE_POSITIVE' | 'VERDICT_NO_VERDICT'>) | undefined, deploymentStatuses?: (Array<'DEPLOYMENT_STATUS_UNSPECIFIED' | 'DEPLOYMENT_STATUS_UNKNOWN' | 'DEPLOYMENT_STATUS_DEPLOYED' | 'DEPLOYMENT_STATUS_NOT_DEPLOYED'>) | undefined, publicExposures?: (Array<'PUBLIC_EXPOSURE_UNSPECIFIED' | 'PUBLIC_EXPOSURE_UNKNOWN' | 'PUBLIC_EXPOSURE_PUBLIC' | 'PUBLIC_EXPOSURE_NOT_PUBLIC'>) | undefined, findingCategories?: Array | undefined, projectIds?: Array | undefined}; export type ProtosReportingV1GetReportRequest = {filters?: ProtosReportingV1ReportFilters | undefined}; export type CreateApiApiReportingDeploymentIdReportsGuardrailsAdoptionArgs = {deploymentId: unknown, body: ProtosReportingV1GetReportRequest}; export type CreateApiApiReportingDeploymentIdReportsGuardrailsAdoptionOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosReportingV1TimePeriod = z.object({since: z.string().optional(), until: z.string().optional()}); export const protosReportingV1GetGuardrailsAdoptionReportResponseBucket = z.object({timePeriod: protosReportingV1TimePeriod.optional(), shownToDeveloperCount: z.number().int().optional(), totalCount: z.number().int().optional()}); export const protosReportingV1GetGuardrailsAdoptionReportResponse = z.object({buckets: z.array(protosReportingV1GetGuardrailsAdoptionReportResponseBucket).optional(), totalShownToDeveloper: z.number().int().optional(), totalOpened: z.number().int().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 }; /** * Get Guardrails Adoption Report * * POST /api/reporting/{deploymentId}/reports/guardrails-adoption * * Also accepts auth: SemgrepJWT */ export const createApiApiReportingDeploymentIdReportsGuardrailsAdoption = async (args: CreateApiApiReportingDeploymentIdReportsGuardrailsAdoptionArgs, options: CreateApiApiReportingDeploymentIdReportsGuardrailsAdoptionOptions) => { 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/reporting/${encodeURIComponent(String(args.deploymentId))}/reports/guardrails-adoption${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(protosReportingV1GetGuardrailsAdoptionReportResponse, await res.json()) };