import {z} from 'zod' export type GetApiApiPersonsPersonIdMessagesReceivedArgs = {availableToDestination?: boolean | undefined, messageType?: ('ASSOCIATION_REQUEST' | 'CREDENTIAL' | 'INVITATION' | 'NOTICE' | 'PERSON_NOTIFICATION') | undefined, newestFirst?: boolean | undefined, page?: number | undefined, personId: string, size?: number | undefined}; export type GetApiApiPersonsPersonIdMessagesReceivedOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const pageMessageMessageDestView = z.object({}); 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 }; /** * List the current messages for this person * * GET /api/persons/{personId}/messages/received */ export const getApiApiPersonsPersonIdMessagesReceived = async (args: GetApiApiPersonsPersonIdMessagesReceivedArgs, options: GetApiApiPersonsPersonIdMessagesReceivedOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.availableToDestination != null) query.append("availableToDestination", String(args.availableToDestination)) if (args.messageType != null) query.append("messageType", String(args.messageType)) if (args.newestFirst != null) query.append("newestFirst", String(args.newestFirst)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) const url = `${baseUrl.replace(/\/+$/, '')}/api/persons/${encodeURIComponent(String(args.personId))}/messages/received${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(pageMessageMessageDestView, await res.json()) };