import {z} from 'zod' export type GetApiApiV30OrgsOrgUuidProjectsProjectUuidApprovalRequestsArgs = {projectUuid: string}; export type GetApiApiV30OrgsOrgUuidProjectsProjectUuidApprovalRequestsOptions = {baseUrl?: string | undefined, bearerKey?: string | undefined, fetch?: typeof fetch | undefined}; export const projectApprovalRequestDTOV3 = z.object({uuid: z.string().optional(), name: z.string().optional(), projectUuid: z.string().optional(), projectName: z.string().optional(), applicationUuid: z.string().optional(), applicationName: z.string().optional(), engine: z.enum(["UNIFIED", "SCA", "SAST", "IAC", "IMG", "AI", "DAST"]), findingUuid: z.string().optional(), findingCWE: z.string().optional(), findingOrigin: z.string().optional(), findingSeverity: z.enum(["LOW", "MEDIUM", "HIGH", "CRITICAL", "LOW", "MEDIUM", "HIGH", "CRITICAL"]).optional(), findingDetectionDate: z.string().optional(), branchType: z.enum(["BASE", "FEATURE", "BASE", "FEATURE"]), scanUuid: z.string().optional(), externalUser: z.string().optional(), repoIssueId: z.string().optional(), reason: z.string().optional(), state: z.enum(["PENDING", "APPROVED", "REJECTED", "REQUESTED_INFO", "PENDING", "APPROVED", "REJECTED"]), responseDate: z.string().optional(), createdAt: z.string().optional(), createdBy: z.string().optional(), updatedBy: z.string().optional()}); export const dWRResponsePageableV3CollectionProjectApprovalRequestDTOV3 = z.object({additionalData: z.object({}).optional(), supportToken: z.string().optional(), response: z.array(projectApprovalRequestDTOV3).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 project suppression requests * * GET /api/v3.0/orgs/{orgUuid}/projects/{projectUuid}/approvalRequests */ export const getApiApiV30OrgsOrgUuidProjectsProjectUuidApprovalRequests = async (args: GetApiApiV30OrgsOrgUuidProjectsProjectUuidApprovalRequestsArgs, options?: GetApiApiV30OrgsOrgUuidProjectsProjectUuidApprovalRequestsOptions) => { const {baseUrl = "https://baseUrl", fetch: fetchFn = fetch, bearerKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerKey !== undefined) headers.set('authorization', `Bearer ${bearerKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3.0/orgs/${encodeURIComponent(String(args.orgUuid))}/projects/${encodeURIComponent(String(args.projectUuid))}/approvalRequests${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(dWRResponsePageableV3CollectionProjectApprovalRequestDTOV3, await res.json()) };