import {z} from 'zod' export type UpdateApiV1IvrIdArgs = {'IVR ID': string, Authorization: string, body: {name: string, description: string, recording: string, timeout: number, 'transfer code': number, option: Array, destination: Array, 'incorrect count': number, 'invalid recording': string, 'invalid destination': string, 'timeout retry recording': string, 'timeout recording': string, 'timeout destination': string, 'timeout tries': number, 'recording invalid': string}}; export type UpdateApiV1IvrIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV1IvrIdResponse = z.object({}); 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 IVR * * PUT /v1/ivr/id */ export const updateApiV1IvrId = async (args: UpdateApiV1IvrIdArgs, options?: UpdateApiV1IvrIdOptions) => { 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['IVR ID'] != null) query.append("IVR ID", String(args['IVR ID'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ivr/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(updateApiV1IvrIdResponse, await res.json()) };