import {z} from 'zod' export type CreateApiApiV1AccountAuthIdTrunksArgs = {auth_id: string, body: {name: string, trunk_direction?: ('inbound' | 'outbound') | undefined, trunk_status?: ('enabled' | 'disabled') | undefined, secure?: boolean | undefined, trunk_domain?: string | undefined, transport?: ('udp' | 'tcp' | 'tls') | undefined, inbound_destination?: string | undefined, description?: string | undefined, concurrent_calls_limit?: number | undefined, cps_limit?: number | undefined, credential_uuid?: string | undefined, ipacl_uuid?: string | undefined, primary_uri_uuid?: string | undefined, fallback_uri_uuid?: string | undefined, recording?: boolean | undefined, enable_transcription?: boolean | undefined, pii_redaction?: boolean | undefined, pii_entity_types?: string | undefined, webhook_url?: string | undefined, webhook_method?: ('POST' | 'GET') | undefined, recording_webhook_enabled?: boolean | undefined, username?: string | undefined, password?: string | undefined, ip_whitelist?: Array | undefined}}; export type CreateApiApiV1AccountAuthIdTrunksOptions = {baseUrl?: string | undefined, AuthID?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1AccountAuthIdTrunksResponse = z.object({trunk_id: z.string(), account_id: z.string(), name: z.string(), trunk_domain: z.string(), trunk_status: z.string(), secure: z.boolean(), trunk_direction: z.string(), concurrent_calls_limit: z.number().int(), cps_limit: z.number().int(), description: z.string(), transport: z.string(), recording: z.boolean(), enable_transcription: z.boolean(), pii_redaction: z.boolean(), webhook_method: z.string(), recording_webhook_enabled: z.boolean(), created_at: z.string(), updated_at: z.string()}); 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 }; /** * Create a trunk * * POST /api/v1/Account/{auth_id}/trunks */ export const createApiApiV1AccountAuthIdTrunks = async (args: CreateApiApiV1AccountAuthIdTrunksArgs, options?: CreateApiApiV1AccountAuthIdTrunksOptions) => { const {baseUrl = "https://api.vobiz.ai", fetch: fetchFn = fetch, AuthID, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AuthID !== undefined) headers.set("X-Auth-ID", AuthID) if (AuthToken !== undefined) headers.set("X-Auth-Token", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/Account/${encodeURIComponent(String(args.auth_id))}/trunks${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiApiV1AccountAuthIdTrunksResponse, await res.json()) };