import {z} from 'zod' export type GetApiApiV1AccountAuthIdNumbersArgs = {auth_id: string, limit?: number | undefined, offset?: number | undefined}; export type GetApiApiV1AccountAuthIdNumbersOptions = {baseUrl?: string | undefined, AuthID?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1AccountAuthIdNumbersResponse = z.object({items: z.array(z.object({id: z.string(), account_id: z.string(), e164: z.string(), country: z.string(), region: z.string(), capabilities: z.object({voice: z.boolean(), sms: z.boolean(), mms: z.boolean(), fax: z.boolean()}), status: z.string(), provider: z.string(), setup_fee: z.number().int(), monthly_fee: z.number().int(), currency: z.string(), application_id: z.string().optional(), voice_enabled: z.boolean(), tags: z.array(z.string()), purchased_at: z.string(), is_blocked: z.boolean(), created_at: z.string(), updated_at: z.string(), is_trial_number: z.boolean(), last_billing_date: z.string().optional(), next_billing_date: z.string().optional(), minimum_commitment_months: z.number().int(), aadhaar_verification_required: z.boolean(), aadhaar_verified: z.boolean(), source: z.string(), released_at: z.string().optional(), trunk_group_id: z.string().optional()})), page: z.number().int(), per_page: z.number().int(), total: z.number().int()}); 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 phone numbers * * GET /api/v1/Account/{auth_id}/numbers */ export const getApiApiV1AccountAuthIdNumbers = async (args: GetApiApiV1AccountAuthIdNumbersArgs, options?: GetApiApiV1AccountAuthIdNumbersOptions) => { const {baseUrl = "https://api.vobiz.ai", fetch: fetchFn = fetch, AuthID, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) 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))}/numbers${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(getApiApiV1AccountAuthIdNumbersResponse, await res.json()) };