import {z} from 'zod' export type DeleteApiNotificationsAllArgs = {async?: boolean | undefined, request_id?: number | undefined}; export type DeleteApiNotificationsAllOptions = {baseUrl?: string | undefined, NexlaSessionToken?: string | undefined, fetch?: typeof fetch | undefined}; export const asyncOrNull = z.object({request_id: z.number().int().optional(), status: z.enum(["pending", "running", "completed", "failed", "cancelled"]).optional(), request_started_at: z.string().optional(), progress: z.number().int().optional(), result: z.record(z.string(), z.unknown()).optional(), request_stopped_at: z.string().optional(), request_completed_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 }; /** * Delete All Notifications * * DELETE /notifications/all */ export const deleteApiNotificationsAll = async (args: DeleteApiNotificationsAllArgs, options?: DeleteApiNotificationsAllOptions) => { const {baseUrl = "https://dataops.nexla.io/nexla-api", fetch: fetchFn = fetch, NexlaSessionToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.async != null) query.append("async", String(args.async)) if (args.request_id != null) query.append("request_id", String(args.request_id)) if (NexlaSessionToken !== undefined) headers.set('authorization', `Bearer ${NexlaSessionToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/notifications/all${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(asyncOrNull, await res.json()) };