import {z} from 'zod' export type ImportPhoneNumberRequestByo = {friendlyName?: string | undefined, phoneNumber?: string | undefined, inboundAgentId?: string | undefined, outboundAgentId?: string | undefined, trunkUsername?: string | undefined, trunkPassword?: string | undefined, terminationSipURI?: string | undefined, outboundPhoneNumber?: string | undefined}; export type CreateApiV1PhoneNumbersImportArgs = {body: ImportPhoneNumberRequestByo}; export type CreateApiV1PhoneNumbersImportOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const phoneNumberResponseByo = z.object({sipPhoneNumber: z.string().optional(), inboundAgentId: z.string().optional(), outboundAgentId: z.string().optional(), outboundPhoneNumber: z.string().optional(), active: z.boolean().optional(), terminationSipURI: z.string().optional(), friendlyName: z.string().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 }; /** * Import Phone Number * * POST /v1/phone-numbers/import */ export const createApiV1PhoneNumbersImport = async (args: CreateApiV1PhoneNumbersImportArgs, options?: CreateApiV1PhoneNumbersImportOptions) => { const {baseUrl = "https://api.sigmamind.ai", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("X-API-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/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(phoneNumberResponseByo, await res.json()) };