import {z} from 'zod' export type ChangePasswordUser = {password?: string | undefined, new_password?: string | undefined}; export type UpdateApiUsersUserIdChangePasswordArgs = {userId: number, body: ChangePasswordUser}; export type UpdateApiUsersUserIdChangePasswordOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const user = z.object({user_type_id: z.number().int().optional(), id: z.number().int().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), role_id: z.number().int().optional(), username: z.string().optional(), email: z.string().optional(), password: z.string().optional(), provider_id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional(), gender_id: z.number().int().optional(), dob: z.string().optional(), about_me: z.string().optional(), address: z.string().optional(), address1: z.string().optional(), city_id: z.number().int().optional(), state_id: z.number().int().optional(), country_id: z.number().int().optional(), zip_code: z.string().optional(), latitude: z.number().optional(), longitude: z.number().optional(), phone: z.string().optional(), mobile: z.string().optional(), available_wallet_amount: z.number().optional(), last_login_ip_id: z.string().optional(), last_logged_in_time: z.string().optional(), is_active: z.number().int().optional(), is_email_confirmed: z.number().int().optional(), is_agree_terms_conditions: z.number().int().optional(), is_subscribed: z.number().int().optional()}); 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 }; /** * Change password * * PUT /users/{userId}/change_password */ export const updateApiUsersUserIdChangePassword = async (args: UpdateApiUsersUserIdChangePasswordArgs, options: UpdateApiUsersUserIdChangePasswordOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/users/${encodeURIComponent(String(args.userId))}/change_password${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()) };