import {z} from 'zod' export type PatchApiV1UserIdArgs = {Authorization: string, id: string, body: {name?: string | undefined, number?: string | undefined, email?: string | undefined, caller_id?: Array | undefined, agent_group?: Array | undefined, block_agent?: boolean | undefined, international_outbound?: boolean | undefined, designation?: string | undefined, login_id?: string | undefined, user_role?: string | undefined, password?: string | undefined, block_web_login?: boolean | undefined, user_for_cdr?: ({type?: string | undefined, value?: Array | undefined}) | undefined, login_based_calling?: boolean | undefined, disable_agent?: boolean | undefined}}; export type PatchApiV1UserIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiV1UserIdResponse = z.object({success: z.boolean().optional(), message: z.string().optional(), errors: z.unknown(), data: z.unknown()}); 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 }; /** * Patch a User * * PATCH /v1/user/{id} */ export const patchApiV1UserId = async (args: PatchApiV1UserIdArgs, options?: PatchApiV1UserIdOptions) => { const {baseUrl = "https://api-smartflo.tatateleservices.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/user/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiV1UserIdResponse, await res.json()) };