import {z} from 'zod' export type DataSecurityIssueUpdateSchema = {status?: ('Open' | 'Resolved' | 'Accepted' | 'Not an issue') | undefined, acceptedReason?: string | undefined, acceptedUntil?: Record | undefined, assignedToUserId?: string | undefined, assignedToTeamId?: string | undefined}; export type UpdateApiDataSecurityIssueIdArgs = {id: string, body: {data: DataSecurityIssueUpdateSchema}}; export type UpdateApiDataSecurityIssueIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const dataSecurityIssueReadSchema = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), projectId: z.string().optional(), dataStoreId: z.string(), issueKey: z.string(), checkId: z.string(), checkGroup: z.string().optional(), title: z.string(), evidence: z.string().optional(), severity: z.enum(["Critical", "High", "Medium", "Low"]), riskScore: z.number().optional(), riskFactors: z.object({}).optional(), status: z.enum(["Open", "Resolved", "Accepted", "Not an issue"]).optional(), dataTypeIds: z.object({}).optional(), frameworks: z.object({}).optional(), acceptedReason: z.string().optional(), acceptedUntil: z.object({}).optional(), acceptedByUserId: z.string().optional(), assignedToUserId: z.string().optional(), assignedToTeamId: z.string().optional(), securityCaseId: z.string().optional(), alertId: z.string().optional(), incidentId: z.string().optional(), firstDetectedAt: z.object({}).optional(), lastDetectedAt: z.object({}).optional(), resolvedAt: z.object({}).optional(), reopenCount: z.number().optional(), recheckRequestedAt: z.object({}).optional(), isOwnerNotified: z.boolean().optional()}); export const updateApiDataSecurityIssueIdResponse = z.object({data: dataSecurityIssueReadSchema.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 }; /** * Update Data Security Issue * * PUT /data-security-issue/{id} */ export const updateApiDataSecurityIssueId = async (args: UpdateApiDataSecurityIssueIdArgs, options?: UpdateApiDataSecurityIssueIdOptions) => { const {baseUrl = "https://oneuptime.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/data-security-issue/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiDataSecurityIssueIdResponse, await res.json()) };