import {z} from 'zod' export type CreateApiApiTransfersTransferIdRejectArgs = {transfer_id: string}; export type CreateApiApiTransfersTransferIdRejectOptions = {baseUrl: string, HTTPBearerJWT?: string | undefined, fetch?: typeof fetch | undefined}; export const transferResponse = z.object({id: z.string(), resource_type: z.string(), resource_id: z.string(), source_organization_id: z.string(), target_organization_id: z.string(), initiated_by_user_id: z.string(), status: z.string(), source_approved_by_user_id: z.string().nullable(), target_approved_by_user_id: z.string().nullable(), completed_at: z.string().nullable(), reason: z.string().nullable(), created_at: z.string()}); 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 }; /** * Reject transfer request * * POST /api/transfers/{transfer_id}/reject */ export const createApiApiTransfersTransferIdReject = async (args: CreateApiApiTransfersTransferIdRejectArgs, options: CreateApiApiTransfersTransferIdRejectOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearerJWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearerJWT !== undefined) headers.set('authorization', `Bearer ${HTTPBearerJWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/transfers/${encodeURIComponent(String(args.transfer_id))}/reject${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(transferResponse, await res.json()) };