import {z} from 'zod' export type DeleteApiV1CallcenterCalllogsIdArgs = {id: number}; export type DeleteApiV1CallcenterCalllogsIdOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const callSourceType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]); export const callDestinationType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]); export const callStatus = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const callDirectionType = z.union([z.literal(0), z.literal(1)]); export const callLog = z.object({id: z.number().int().optional(), departmentId: z.number().int().optional(), userRatingId: z.number().int().nullable().optional(), userRatingScore: z.number().nullable().optional(), visitorFeedbackId: z.number().int().nullable().optional(), visitorFeedbackRate: z.number().nullable().optional(), createdDate: z.string().optional(), callDuration: z.number().int().optional(), ringDuration: z.number().int().optional(), sourceType: callSourceType.optional(), sourceId: z.number().int().optional(), destinationType: callDestinationType.optional(), destinationId: z.number().int().optional(), eventType: callStatus.optional(), callDirection: callDirectionType.optional(), recordStatus: z.number().int().optional(), callerName: z.string().nullable().optional(), callerNumber: z.string().nullable().optional(), calledName: z.string().nullable().optional(), calledNumber: z.string().nullable().optional(), dialedNumber: z.string().nullable().optional(), dtmf: z.string().nullable().optional(), sipServerId: z.number().int().optional(), notes: z.string().nullable().optional(), directory: z.string().nullable().optional(), sourceIpAddress: z.string().nullable().optional(), destinationIpAddress: z.string().nullable().optional(), s3BucketName: z.string().nullable().optional(), s3Key: z.string().nullable().optional(), contactId: z.number().int().optional(), companyId: z.number().int().optional(), view: z.number().int().optional(), listen: z.number().int().optional(), deleted: z.number().int().optional(), saveas: z.number().int().optional(), tagIds: z.string().nullable().optional(), linkedTicketIds: z.string().nullable().optional(), linkedDealIds: z.string().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 }; /** * Deletes the call recording of the call * * DELETE /v1/callcenter/calllogs/{id} * * Also accepts auth: API Key */ export const deleteApiV1CallcenterCalllogsId = async (args: DeleteApiV1CallcenterCalllogsIdArgs, options: DeleteApiV1CallcenterCalllogsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/callcenter/calllogs/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(callLog, await res.json()) };