import {z} from 'zod' export type PageSize = number; export type PageCursor = string; export type IssueSnapshotItemOrderBy = 'createdAt' | 'lastModifiedAt' | 'detectedAt'; export type OrderDirection = 'asc' | 'desc'; export type GetApiAuditsAuditIdIssuesItemsArgs = {auditId: string, pageSize?: PageSize | undefined, pageCursor?: PageCursor | undefined, search?: string | undefined, snapshotIdMatchesAny?: Array | undefined, createdAfterDate?: string | undefined, createdBeforeDate?: string | undefined, detectedAfterDate?: string | undefined, detectedBeforeDate?: string | undefined, orderBy?: IssueSnapshotItemOrderBy | undefined, orderDirection?: OrderDirection | undefined}; export type GetApiAuditsAuditIdIssuesItemsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const issueStatusTypeForSnapshot = z.enum(["IN_PROGRESS", "NOT_STARTED", "CLOSED"]); export const issueSnapshotItem = z.object({id: z.string(), title: z.string().optional(), description: z.string().optional(), readableIssueId: z.string(), issueId: z.string(), snapshotId: z.string(), dueDate: z.string().nullable().optional(), status: issueStatusTypeForSnapshot.optional(), lastModifiedAt: z.string().optional(), createdAt: z.string().optional(), detectedAt: z.string().optional()}); export const pageInfo = z.object({endCursor: z.string().nullable(), hasNextPage: z.boolean(), hasPreviousPage: z.boolean(), startCursor: z.string().nullable()}); export const paginatedIssueSnapshotItemsResponse = z.object({results: z.object({data: z.array(issueSnapshotItem), pageInfo: pageInfo})}); 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 snapshotted issues for an audit * * GET /audits/{auditId}/issues/items */ export const getApiAuditsAuditIdIssuesItems = async (args: GetApiAuditsAuditIdIssuesItemsArgs, options?: GetApiAuditsAuditIdIssuesItemsOptions) => { const {baseUrl = "https://api.vanta.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageCursor != null) query.append("pageCursor", String(args.pageCursor)) if (args.search != null) query.append("search", String(args.search)) for (const item of args.snapshotIdMatchesAny ?? []) query.append("snapshotIdMatchesAny", String(item)) if (args.createdAfterDate != null) query.append("createdAfterDate", String(args.createdAfterDate)) if (args.createdBeforeDate != null) query.append("createdBeforeDate", String(args.createdBeforeDate)) if (args.detectedAfterDate != null) query.append("detectedAfterDate", String(args.detectedAfterDate)) if (args.detectedBeforeDate != null) query.append("detectedBeforeDate", String(args.detectedBeforeDate)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.orderDirection != null) query.append("orderDirection", String(args.orderDirection)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/audits/${encodeURIComponent(String(args.auditId))}/issues/items${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(paginatedIssueSnapshotItemsResponse, await res.json()) };