import {z} from 'zod' export type UpdateUser = {job_title?: string | undefined, mobile_number?: string | undefined, mobile_prefix?: string | undefined, email?: string | undefined, enable_mobile_credential?: boolean | undefined, enable_web_credential?: boolean | undefined, custom_reference_id?: string | undefined, reports_to?: string | undefined, skip_credential_notification?: boolean | undefined}; export type UpdateApiBusinessV2EmployeesUserIdArgs = {userId: string, 'X-Soldo-Fingerprint': string, 'X-Soldo-Fingerprint-Signature': string, body: UpdateUser}; export type UpdateApiBusinessV2EmployeesUserIdOptions = {baseUrl?: string | undefined, standardAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const userStatus = z.enum(["ACTIVE", "INACTIVE", "BLOCKED", "SUSPENDED", "PENDING", "ARCHIVED"]); export const addressCategory = z.enum(["USER", "COMPANY"]); export const address = z.object({id: z.string().optional(), recipient: z.string().optional(), name: z.string().optional(), line1: z.string().optional(), line2: z.string().optional(), country: z.string().optional(), county: z.string().optional(), city: z.string().optional(), post_code: z.string().optional(), delivery_phone_number: z.string().optional(), default_shipping: z.boolean().optional(), type: z.string().optional(), category: addressCategory.optional(), user_id: z.string().optional(), creation_time: z.string().optional(), last_update: z.string().optional()}); export const userRole = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), scope: z.string().optional()}); export const workStatus = z.enum(["AVAILABLE", "OUT_OF_OFFICE"]); export const user = z.object({id: z.string().optional(), name: z.string().optional(), surname: z.string().optional(), middlename: z.string().optional(), dob: z.string().optional(), job_title: z.string().optional(), department: z.string().optional(), email: z.string().optional(), mobile: z.string().optional(), mobile_prefix: z.string().optional(), custom_reference_id: z.string().optional(), status: userStatus.optional(), visible: z.boolean().optional(), mobile_access: z.boolean().optional(), web_access: z.boolean().optional(), groups: z.array(z.string()).optional(), shipping_address: address.optional(), reports_to: z.string().optional(), roles: z.array(userRole).optional(), contact_id: z.string().optional(), creation_time: z.string().optional(), last_update: z.string().optional(), work_status: workStatus.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 * * PUT /business/v2/employees/{userId} */ export const updateApiBusinessV2EmployeesUserId = async (args: UpdateApiBusinessV2EmployeesUserIdArgs, options?: UpdateApiBusinessV2EmployeesUserIdOptions) => { const {baseUrl = "https://api.soldo.com", fetch: fetchFn = fetch, standardAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Soldo-Fingerprint'] != null) headers.set("X-Soldo-Fingerprint", String(args['X-Soldo-Fingerprint'])) if (args['X-Soldo-Fingerprint-Signature'] != null) headers.set("X-Soldo-Fingerprint-Signature", String(args['X-Soldo-Fingerprint-Signature'])) if (standardAuth !== undefined) headers.set('authorization', `Bearer ${standardAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/business/v2/employees/${encodeURIComponent(String(args.userId))}${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()) };