import {z} from 'zod' export type GetApiV2PropertyClaimsPropertyClaimIdNotesArgs = {'X-Encircle-Attribution'?: string | undefined, 'X-Encircle-Request'?: string | undefined, order?: ('newest' | 'oldest') | undefined, limit?: number | undefined, after?: unknown | undefined}; export type GetApiV2PropertyClaimsPropertyClaimIdNotesOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const actorResponse = z.object({actor_type: z.literal("User"), actor_identifier: z.string()}); export const noteResponse = z.object({id: z.number().int(), client_created: z.string().nullable(), server_created: z.string(), creator: actorResponse, title: z.string().nullable(), text: z.string().nullable()}); export const getApiV2PropertyClaimsPropertyClaimIdNotesResponse = z.object({list: z.array(noteResponse), cursor: z.object({order: z.string(), limit: z.number().int(), after: z.string().nullable()})}); 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 }; /** * Find notes * * GET /v2/property_claims/{property_claim_id}/notes */ export const getApiV2PropertyClaimsPropertyClaimIdNotes = async (args: GetApiV2PropertyClaimsPropertyClaimIdNotesArgs, options: GetApiV2PropertyClaimsPropertyClaimIdNotesOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Encircle-Attribution'] != null) headers.set("X-Encircle-Attribution", String(args['X-Encircle-Attribution'])) if (args['X-Encircle-Request'] != null) headers.set("X-Encircle-Request", String(args['X-Encircle-Request'])) if (args.order != null) query.append("order", String(args.order)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.after != null) query.append("after", String(args.after)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/property_claims/${encodeURIComponent(String(args.property_claim_id))}/notes${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(getApiV2PropertyClaimsPropertyClaimIdNotesResponse, await res.json()) };