import {z} from 'zod' export type GetApiServiceProvidersServiceProviderSidVoipCarriersOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const voipCarrier = z.object({service_provider_sid: z.string(), name: z.string(), description: z.string().optional(), account_sid: z.string().optional(), application_sid: z.string().optional(), e164_leading_plus: z.boolean().optional(), requires_register: z.boolean().optional(), register_username: z.string().optional(), register_sip_realm: z.string().optional(), register_password: z.string().optional(), tech_prefix: z.string().optional(), diversion: z.string().optional(), is_active: z.boolean().optional(), smpp_system_id: z.string().optional(), smpp_password: z.string().optional(), smpp_inbound_system_id: z.string().optional(), smpp_inbound_password: z.string().optional(), smpp_enquire_link_interval: z.number().int().optional(), trunk_type: z.enum(["static_ip", "auth", "reg"]).optional(), inbound_auth_username: z.string().max(64).optional(), inbound_auth_password: z.string().max(64).optional()}); export const getApiServiceProvidersServiceProviderSidVoipCarriersResponse = z.array(voipCarrier); 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 }; /** * get all carriers availlble to the account * * GET /ServiceProviders/{ServiceProviderSid}/VoipCarriers */ export const getApiServiceProvidersServiceProviderSidVoipCarriers = async (options?: GetApiServiceProvidersServiceProviderSidVoipCarriersOptions) => { const {baseUrl = "https://api.jambonz.cloud/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/ServiceProviders/${encodeURIComponent(String(args.ServiceProviderSid))}/VoipCarriers${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(getApiServiceProvidersServiceProviderSidVoipCarriersResponse, await res.json()) };