import {z} from 'zod' export type UsersUpdate = {user?: ({data_transfer_consent?: (boolean | null) | undefined, description?: (string | null) | undefined, faved_project_ids?: Array | undefined, email?: string | undefined, icon?: (Record | null) | undefined, locale?: (string | null) | undefined, login?: string | undefined, make_observation_licenses_same?: boolean | undefined, make_photo_licenses_same?: boolean | undefined, make_sound_licenses_same?: boolean | undefined, name?: (string | null) | undefined, pi_consent?: (boolean | null) | undefined, place_id?: (number | null) | undefined, preferred_observation_fields_by?: string | undefined, preferred_observation_license?: (string | null) | undefined, preferred_photo_license?: (string | null) | undefined, preferred_project_addition_by?: string | undefined, preferred_sound_license?: (string | null) | undefined, prefers_automatic_taxonomic_changes?: boolean | undefined, prefers_comment_email_notification?: boolean | undefined, prefers_common_names?: boolean | undefined, prefers_community_taxa?: boolean | undefined, prefers_identification_email_notification?: boolean | undefined, prefers_infraspecies_identification_notifications?: boolean | undefined, prefers_mention_email_notification?: boolean | undefined, prefers_message_email_notification?: boolean | undefined, prefers_monthly_supporter_badge?: boolean | undefined, prefers_no_email?: boolean | undefined, prefers_no_tracking?: boolean | undefined, prefers_non_disagreeing_identification_notifications?: boolean | undefined, prefers_project_added_your_observation_email_notification?: boolean | undefined, prefers_project_curator_change_email_notification?: boolean | undefined, prefers_project_journal_post_email_notification?: boolean | undefined, prefers_receive_mentions?: boolean | undefined, prefers_redundant_identification_notifications?: boolean | undefined, prefers_scientific_name_first?: boolean | undefined, prefers_taxon_change_email_notification?: boolean | undefined, prefers_taxon_or_place_observation_email_notification?: boolean | undefined, prefers_user_observation_email_notification?: boolean | undefined, search_place_id?: (number | null) | undefined, site_id?: (number | null) | undefined, time_zone?: (string | null) | undefined, password?: string | undefined, password_confirmation?: string | undefined}) | undefined, icon_delete?: boolean | undefined}; export type UpdateApiUsersIdArgs = {id: string, body: UsersUpdate}; export type UpdateApiUsersIdOptions = {baseUrl?: string | undefined, userJwtRequired?: string | undefined, fetch?: typeof fetch | undefined}; export const site = z.object({id: z.number().int(), icon_url: z.string().optional(), locale: z.string().nullable().optional(), name: z.string().optional(), place_id: z.number().int().nullable().optional(), site_name_short: z.string().nullable().optional(), url: z.string().optional()}).nullable(); export const user = z.object({id: z.number().int(), uuid: z.string().optional(), created_at: z.string().optional(), description: z.string().nullable().optional(), faved_project_ids: z.array(z.number()).optional(), icon: z.string().nullable().optional(), icon_url: z.string().nullable().optional(), identifications_count: z.number().int().optional(), journal_posts_count: z.number().int().optional(), annotated_observations_count: z.number().int().optional(), last_active: z.string().optional(), login: z.string().optional(), monthly_supporter: z.boolean().nullable().optional(), name: z.string().nullable().optional(), observations_count: z.number().int().optional(), orcid: z.string().nullable().optional(), preferences: z.object({prefers_community_taxa: z.boolean().optional(), prefers_observation_fields_by: z.enum(["anyone", "curators", "observer"]).optional(), prefers_project_addition_by: z.enum(["any", "joined", "none"]).optional()}).optional(), roles: z.array(z.string()).optional(), site: site.optional(), site_id: z.number().int().nullable().optional(), spam: z.boolean().optional(), species_count: z.number().int().optional(), suspended: z.boolean().optional(), updated_at: z.string().optional()}).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 }; /** * Update users. * * PUT /users/{id} */ export const updateApiUsersId = async (args: UpdateApiUsersIdArgs, options?: UpdateApiUsersIdOptions) => { const {baseUrl = "https://api.inaturalist.org/v2", fetch: fetchFn = fetch, userJwtRequired} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (userJwtRequired !== undefined) headers.set("Authorization", userJwtRequired) const url = `${baseUrl.replace(/\/+$/, '')}/users/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(user, await res.json()) };