import {z} from 'zod' export type GetApiV1CommunicationPhoneNumbersPhoneNumberIdChannelsArgs = {phone_number_id: string, channel_type?: (string | null) | undefined}; export type GetApiV1CommunicationPhoneNumbersPhoneNumberIdChannelsOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const channelType = z.enum(["sms", "inbound_call", "outbound_call"]); export const channelResponse = z.object({id: z.string(), phone_number_id: z.string(), channel_type: channelType, agent_id: z.string().nullable().optional(), agent_revision_id: z.string().nullable().optional(), team_id: z.string().nullable().optional(), team_revision_id: z.string().nullable().optional(), created_at: z.string(), revision_state: z.enum(["pinned_current", "pinned_stale", "legacy_unpinned"]).nullable().optional(), pinned_revision_name: z.string().nullable().optional(), active_revision_id: z.string().nullable().optional()}); export const getApiV1CommunicationPhoneNumbersPhoneNumberIdChannelsResponse = z.array(channelResponse); 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 }; /** * List channel bindings for a phone number * * GET /v1/communication/phone-numbers/{phone_number_id}/channels */ export const getApiV1CommunicationPhoneNumbersPhoneNumberIdChannels = async (args: GetApiV1CommunicationPhoneNumbersPhoneNumberIdChannelsArgs, options: GetApiV1CommunicationPhoneNumbersPhoneNumberIdChannelsOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.channel_type != null) query.append("channel_type", String(args.channel_type)) if (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/communication/phone-numbers/${encodeURIComponent(String(args.phone_number_id))}/channels${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1CommunicationPhoneNumbersPhoneNumberIdChannelsResponse, await res.json()) };