import {z} from 'zod' export type UserProfileUpdateRequest = {name: string, avatar?: string | undefined, email: unknown, phone?: string | undefined, work_phone?: string | undefined, email_status?: string | undefined, email_status_updated?: boolean | undefined, manual_email_status?: string | undefined, manual_email_status_updated_at?: string | undefined, linkedin?: string | undefined, facebook?: string | undefined, twitter?: string | undefined, instagram?: string | undefined, id: number}; export type UpdateApiApiUserIdProfileArgs = {id: number, body: UserProfileUpdateRequest}; export type UpdateApiApiUserIdProfileOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const role = z.object({id: z.number().int().optional(), name: z.string().optional(), display_name: z.string().optional(), description: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const organization = z.object({id: z.number().int().optional(), name: z.string().optional(), logo: z.string().optional(), mfa_enabled: z.number().int().optional(), intercom_company_id: z.string().optional(), intercom_company_company_id: z.string().optional(), contract_status_id: z.number().int().optional(), contract_payment_type_id: z.number().int().optional(), contract_monthly_spend: z.number().int().optional(), contract_file_url: z.string().optional(), contract_onboarding_date: z.string().optional(), contract_start_date: z.string().optional(), contract_end_date: z.string().optional(), contract_auto_renew: z.number().int().optional(), product_id: z.number().int().optional(), sales_user_id: z.number().int().optional(), salesforce_id: z.string().optional(), account_manager_id: z.number().int().optional(), default_user_subscription_plan_id: z.string().optional(), default_user_subscription_product_name: z.string().optional(), default_user_subscription_cancel_date: z.string().optional(), user_email_domain: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), deleted_at: z.string().optional()}); export const personProfile = z.object({id: z.number().int().optional(), user_id: z.number().int().optional(), avatar_id: z.number().int().nullable().optional(), person_profile_job_role_id: z.number().int().nullable().optional(), market_id: z.number().int().nullable().optional(), name: z.string().optional(), job_title: z.string().nullable().optional(), location: z.string().nullable().optional(), school: z.string().nullable().optional(), info: z.string().nullable().optional(), suggested: z.number().int().nullable().optional(), previous_suggested: z.number().int().nullable().optional(), approved: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), deleted_at: z.string().optional()}); export const userProfileResource = z.object({id: z.number().int().optional(), email: z.string().optional(), currency: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), deleted_at: z.string().optional(), last_active_at: z.string().optional(), is_external: z.boolean().optional(), verified: z.number().int().optional(), genuine: z.number().int().optional(), hubspot_id: z.number().int().optional(), hubspot_synced_on: z.string().optional(), force_new_password: z.number().int().optional(), credentials_sent_at: z.string().optional(), roles: z.array(role).optional(), organizations: z.array(organization).optional(), person_profile: personProfile.optional(), user_permissions: z.array(z.unknown()).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/user/{id}/profile */ export const updateApiApiUserIdProfile = async (args: UpdateApiApiUserIdProfileArgs, options: UpdateApiApiUserIdProfileOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/user/${encodeURIComponent(String(args.id))}/profile${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(userProfileResource, await res.json()) };