import {z} from 'zod' export type ImportPhoneNumber = {workspaceId: string, number: string, countryDial?: string | undefined, telephonyId?: string | undefined, engineId?: string | undefined, type?: ('inbound_outbound' | 'outbound_only') | undefined, status?: ('pending' | 'active' | 'payment_failed' | 'activation_failed') | undefined, price?: number | undefined}; export type CreateApiInternalTelephonyPhoneNumbersImportArgs = {body: ImportPhoneNumber}; export type CreateApiInternalTelephonyPhoneNumbersImportOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const phoneNumber = z.object({id: z.string(), workspaceId: z.string(), number: z.string(), countryDial: z.string().nullable(), status: z.enum(["pending", "active", "payment_failed", "activation_failed"]), type: z.enum(["inbound_outbound", "outbound_only"]), engineId: z.string().nullable(), telephonyId: z.string().nullable(), price: z.number().nullable(), purchasedAt: z.string().nullable(), renewalAt: z.string().nullable(), dialsToday: z.number(), dialsTotal: z.number(), available: z.boolean(), deletedAt: z.string().nullable(), createdAt: z.string(), updatedAt: 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 }; /** * Import a phone number * * POST /internal/telephony/phone-numbers/import */ export const createApiInternalTelephonyPhoneNumbersImport = async (args: CreateApiInternalTelephonyPhoneNumbersImportArgs, options?: CreateApiInternalTelephonyPhoneNumbersImportOptions) => { const {baseUrl = "https://api.nedzo.ai/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/internal/telephony/phone-numbers/import${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(phoneNumber, await res.json()) };