import {z} from 'zod' export type CreateApiApiPublicV1InboundIntegrationIdCallRoutingMediaPurposeArgs = {id: string, purpose: string, body: BodyInit}; export type CreateApiApiPublicV1InboundIntegrationIdCallRoutingMediaPurposeOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const allQuietApiCallRoutingModelsInboundNumberAudioFile = z.object({objectKey: z.string().nullable().optional(), fileName: z.string().nullable().optional(), contentType: z.string().nullable().optional(), fileSizeBytes: z.number().int().nullable().optional(), durationSeconds: z.number().int().nullable().optional(), uploadedAt: z.string().nullable().optional(), uploadedByUserId: 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 }; /** * Upload call routing media for an inbound integration * * POST /api/public/v1/inbound-integration/{id}/call-routing-media/{purpose} */ export const createApiApiPublicV1InboundIntegrationIdCallRoutingMediaPurpose = async (args: CreateApiApiPublicV1InboundIntegrationIdCallRoutingMediaPurposeArgs, options: CreateApiApiPublicV1InboundIntegrationIdCallRoutingMediaPurposeOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("Authorization", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v1/inbound-integration/${encodeURIComponent(String(args.id))}/call-routing-media/${encodeURIComponent(String(args.purpose))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(allQuietApiCallRoutingModelsInboundNumberAudioFile, await res.json()) };