import {z} from 'zod' export type OJKBreachNotification = {id?: string | undefined, incident_timestamp: string, discovery_time: string, notification_deadline?: string | undefined, data_subjects_affected: number, data_types_involved: Array, description: string, remediation_steps: Array, notified_authority?: string | undefined, status?: ('draft' | 'submitted' | 'acknowledged' | 'overdue' | 'failed') | undefined, submitted_at?: string | undefined, acknowledged_at?: string | undefined, created_at?: string | undefined}; export type CreateApiApiV1OjkBreachNotifyArgs = {'X-Tenant-ID'?: string | undefined, 'X-Org-ID'?: string | undefined, body: OJKBreachNotification}; export type CreateApiApiV1OjkBreachNotifyOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const oJKBreachNotification = z.object({id: z.string().optional(), incident_timestamp: z.string(), discovery_time: z.string(), notification_deadline: z.string().optional(), data_subjects_affected: z.number().int().gte(1), data_types_involved: z.array(z.string()), description: z.string(), remediation_steps: z.array(z.string()), notified_authority: z.string().optional(), status: z.enum(["draft", "submitted", "acknowledged", "overdue", "failed"]).optional(), submitted_at: z.string().optional(), acknowledged_at: z.string().optional(), created_at: z.string().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 }; /** * Submit a UU PDP breach notification * * POST /api/v1/ojk/breach/notify */ export const createApiApiV1OjkBreachNotify = async (args: CreateApiApiV1OjkBreachNotifyArgs, options?: CreateApiApiV1OjkBreachNotifyOptions) => { const {baseUrl = "https://orchestrator.getaxonflow.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Tenant-ID'] != null) headers.set("X-Tenant-ID", String(args['X-Tenant-ID'])) if (args['X-Org-ID'] != null) headers.set("X-Org-ID", String(args['X-Org-ID'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/ojk/breach/notify${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(oJKBreachNotification, await res.json()) };