import {z} from 'zod' export type IUserUpdate = {first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, email?: (string | null) | undefined, is_active?: (boolean | null) | undefined, is_superuser?: (boolean | null) | undefined, birthdate?: (string | null) | undefined, is_enterprise?: (boolean | null) | undefined, role_id?: (string | null) | undefined, phone?: (string | null) | undefined, state?: (string | null) | undefined, country?: (string | null) | undefined, address?: (string | null) | undefined, active_billing_plan_id?: (string | null) | undefined, next_billing_plan_id?: (string | null) | undefined, stripe_customer_id?: (string | null) | undefined, stripe_subscription_id?: (string | null) | undefined, stripe_subscription_status?: (string | null) | undefined, stripe_has_payment_method?: (boolean | null) | undefined, stripe_card_brand?: (string | null) | undefined, stripe_card_last4?: (string | null) | undefined, is_trial?: (boolean | null) | undefined, used_trial?: (boolean | null) | undefined, is_paying?: (boolean | null) | undefined, stripe_last_payment_date?: (string | null) | undefined, billing_updated_at?: (string | null) | undefined, last_credits_refresh?: (string | null) | undefined, next_credits_refresh?: (string | null) | undefined, tutorial_completed_at?: (string | null) | undefined}; export type UpdateApiApiV1UserUserIdArgs = {user_id: string, body: IUserUpdate}; export type UpdateApiApiV1UserUserIdOptions = {baseUrl: string, YourAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const iUserRead = z.object({first_name: z.string(), last_name: z.string(), email: z.string(), is_active: z.boolean().optional(), is_superuser: z.boolean().optional(), birthdate: z.string().nullable().optional(), is_enterprise: z.boolean().nullable().optional(), role_id: z.string().nullable().optional(), phone: z.string().nullable().optional(), state: z.string().nullable().optional(), country: z.string().nullable().optional(), address: z.string().nullable().optional(), active_billing_plan_id: z.string().nullable().optional(), next_billing_plan_id: z.string().nullable().optional(), stripe_customer_id: z.string().nullable().optional(), stripe_subscription_id: z.string().nullable().optional(), stripe_subscription_status: z.string().nullable().optional(), stripe_has_payment_method: z.boolean().nullable().optional(), stripe_card_brand: z.string().nullable().optional(), stripe_card_last4: z.string().nullable().optional(), is_trial: z.boolean().nullable().optional(), used_trial: z.boolean().nullable().optional(), is_paying: z.boolean().nullable().optional(), stripe_last_payment_date: z.string().nullable().optional(), billing_updated_at: z.string().nullable().optional(), last_credits_refresh: z.string().nullable().optional(), next_credits_refresh: z.string().nullable().optional(), tutorial_completed_at: z.string().nullable().optional(), id: z.string(), follower_count: z.number().int().nullable().optional(), following_count: z.number().int().nullable().optional()}).and(z.record(z.string(), z.unknown())); export const iPutResponseBaseIUserRead = z.object({message: z.string().nullable().optional(), meta: z.union([z.record(z.string(), z.unknown()), z.unknown()]).nullable().optional(), data: iUserRead.nullable().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 }; /** * Update User Profile * * PUT /api/v1/user/{user_id} * * Also accepts auth: HTTPBearer */ export const updateApiApiV1UserUserId = async (args: UpdateApiApiV1UserUserIdArgs, options: UpdateApiApiV1UserUserIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, YourAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (YourAPIKey !== undefined) query.set("api_key", YourAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/user/${encodeURIComponent(String(args.user_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(iPutResponseBaseIUserRead, await res.json()) };