import {z} from 'zod' export type PatchApiV1HouseholdsHouseholdIdNotesIdArgs = {id: string, 'Idempotency-Key'?: string | undefined, body: {note: {content?: string | undefined, pinned?: boolean | undefined, tag_ids?: Array | undefined, references?: (Array<{id: string, type: 'Business' | 'Client' | 'Contact' | 'Household' | 'Person' | 'Prospect' | 'Trust' | 'User'}>) | undefined}}}; export type PatchApiV1HouseholdsHouseholdIdNotesIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiV1HouseholdsHouseholdIdNotesIdResponse = z.object({id: z.string(), content: z.string(), pinned: z.boolean(), hidden: z.boolean().optional(), tag_ids: z.array(z.string()), references: z.array(z.object({id: z.string(), type: z.enum(["Business", "Client", "Contact", "Household", "Person", "Prospect", "Trust", "User"]), label: z.string()})), book_id: z.string(), household_id: z.string().nullable().optional(), notable_type: z.string(), notable_id: z.string(), created_by_id: z.string().nullable().optional(), created_at: z.string(), updated_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 }; /** * Update a note * * PATCH /v1/households/{household_id}/notes/{id} */ export const patchApiV1HouseholdsHouseholdIdNotesId = async (args: PatchApiV1HouseholdsHouseholdIdNotesIdArgs, options?: PatchApiV1HouseholdsHouseholdIdNotesIdOptions) => { const {baseUrl = "https://api.slant.app", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/households/${encodeURIComponent(String(args.household_id))}/notes/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiV1HouseholdsHouseholdIdNotesIdResponse, await res.json()) };