import {z} from 'zod' export type GetApiV1PublicIncidentsSecretsIncidentIdOccurrencesArgs = {incident_id: number, cursor?: string | undefined, per_page?: number | undefined, date_before?: unknown | undefined, date_after?: unknown | undefined, source_id?: number | undefined, presence?: ('present' | 'removed' | 'unknown') | undefined, sha?: string | undefined, filepath?: string | undefined, attachment_reason?: ('by_dev_from_perimeter' | 'on_github_org_in_perimeter' | 'from_secret_grasper') | undefined, severity?: ('critical' | 'high' | 'medium' | 'low' | 'info' | 'unknown') | undefined, status?: ('IGNORED' | 'TRIGGERED' | 'ASSIGNED' | 'RESOLVED') | undefined, validity?: ('valid' | 'invalid' | 'failed_to_check' | 'no_checker' | 'unknown') | undefined, tags?: ('SENSITIVE_FILE' | 'TEST_FILE' | 'MINIFIED_FILE' | 'PROD' | 'WHITELISTED' | 'DECODED_BASE64' | 'DECRYPTED' | 'JWT_PROPERTIES' | 'COMPANY_DOMAIN_IN_CONTENT' | 'COMPANY_NAME_IN_CONTENT' | 'FROM_HISTORICAL_SCAN' | 'FROM_SECRET_GRASPER' | 'FROM_EXPLORE' | 'FALSE_POSITIVE' | 'IS_COMPANY_CONTEXT' | 'INTERNALLY_LEAKED' | 'HONEYTOKEN' | 'REVOCABLE_BY_GG') | undefined, ordering?: ('id' | '-id' | 'date' | '-date') | undefined}; export type GetApiV1PublicIncidentsSecretsIncidentIdOccurrencesOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1PublicIncidentsSecretsIncidentIdOccurrencesResponse = z.array(z.object({id: z.number().int().optional(), incident_id: z.number().int().optional(), date: z.string().optional(), filepath: z.string().nullable().optional(), kind: z.enum(["realtime", "historical", "explore"]).optional(), presence: z.enum(["present", "removed", "unknown"]).optional(), matches: z.array(z.object({name: z.string(), indice_start: z.number().int(), indice_end: z.number().int(), pre_line_start: z.number().int().nullable(), pre_line_end: z.number().int().nullable(), post_line_start: z.number().int().nullable(), post_line_end: z.number().int().nullable()})).optional(), tags: z.array(z.string()).optional(), sha: z.string().nullable().optional(), url: z.string().optional(), source: z.object({id: z.number().int().optional(), url: z.string().optional(), type: z.string().optional(), full_name: z.string().optional(), full_path: z.string().nullable().optional(), health: z.enum(["safe", "unknown", "at_risk"]).optional(), default_branch: z.string().nullable().optional(), default_branch_head: z.string().nullable().optional(), open_incidents_count: z.number().int().optional(), closed_incidents_count: z.number().int().optional(), secret_incidents_breakdown: z.object({open_secret_incidents: z.object({total: z.number().int().optional(), severity_breakdown: z.object({critical: z.number().int().optional(), high: z.number().int().optional(), medium: z.number().int().optional(), low: z.number().int().optional(), info: z.number().int().optional(), unknown: z.number().int().optional()}).optional()}).optional(), closed_secret_incidents: z.object({total: z.number().int().optional(), severity_breakdown: z.object({critical: z.number().int().optional(), high: z.number().int().optional(), medium: z.number().int().optional(), low: z.number().int().optional(), info: z.number().int().optional(), unknown: z.number().int().optional()}).optional()}).optional()}).optional(), visibility: z.string().optional(), external_id: z.string().optional(), source_criticality: z.string().optional(), last_scan: z.object({date: z.string().optional(), status: z.enum(["launched", "pending", "running", "finished", "failed", "canceled", "too_large", "timeout", "skipped", "pending_timeout", "running_failed", "running_cancelled"]).optional(), failing_reason: z.string().optional(), commits_scanned: z.number().int().optional(), branches_scanned: z.number().int().optional(), duration: z.string().optional()}).nullable().optional(), monitored: z.boolean().optional(), monitoring_status: z.enum(["active", "disabled", "unreachable", "archived", "deleted_on_remote"]).optional(), provider_metadata: z.object({archived: z.boolean()}).optional(), deleted: z.boolean().optional()}).optional(), actor: z.object({id: z.number().int(), type: z.enum(["github_user", "git_user", "container_image_user"]), name: z.string(), email: z.string(), url: z.string()}).optional(), attachment_reasons: z.array(z.enum(["by_dev_from_perimeter", "on_github_org_in_perimeter", "from_secret_grasper"])).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 public secret occurrences * * GET /v1/public-incidents/secrets/{incident_id}/occurrences */ export const getApiV1PublicIncidentsSecretsIncidentIdOccurrences = async (args: GetApiV1PublicIncidentsSecretsIncidentIdOccurrencesArgs, options?: GetApiV1PublicIncidentsSecretsIncidentIdOccurrencesOptions) => { const {baseUrl = "https://api.gitguardian.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.date_before != null) query.append("date_before", String(args.date_before)) if (args.date_after != null) query.append("date_after", String(args.date_after)) if (args.source_id != null) query.append("source_id", String(args.source_id)) if (args.presence != null) query.append("presence", String(args.presence)) if (args.sha != null) query.append("sha", String(args.sha)) if (args.filepath != null) query.append("filepath", String(args.filepath)) if (args.attachment_reason != null) query.append("attachment_reason", String(args.attachment_reason)) if (args.severity != null) query.append("severity", String(args.severity)) if (args.status != null) query.append("status", String(args.status)) if (args.validity != null) query.append("validity", String(args.validity)) if (args.tags != null) query.append("tags", String(args.tags)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/public-incidents/secrets/${encodeURIComponent(String(args.incident_id))}/occurrences${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(getApiV1PublicIncidentsSecretsIncidentIdOccurrencesResponse, await res.json()) };