import {z} from 'zod' export type GetApiApiV1AccountAuthIdInventoryNumbersArgs = {auth_id: string, country?: string | undefined, search?: string | undefined, page?: number | undefined, per_page?: number | undefined}; export type GetApiApiV1AccountAuthIdInventoryNumbersOptions = {baseUrl?: string | undefined, AuthID?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1AccountAuthIdInventoryNumbersResponse = z.object({items: z.array(z.object({id: z.string(), account_id: z.string(), e164: z.string(), country: 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(), voice_enabled: z.boolean(), tags: z.unknown(), is_blocked: z.boolean(), created_at: z.string(), updated_at: z.string(), is_trial_number: z.boolean(), minimum_commitment_months: z.number().int(), aadhaar_verification_required: z.boolean(), aadhaar_verified: z.boolean(), region: 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 Inventory Numbers * * GET /api/v1/Account/{auth_id}/inventory/numbers */ export const getApiApiV1AccountAuthIdInventoryNumbers = async (args: GetApiApiV1AccountAuthIdInventoryNumbersArgs, options?: GetApiApiV1AccountAuthIdInventoryNumbersOptions) => { 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.country != null) query.append("country", String(args.country)) if (args.search != null) query.append("search", String(args.search)) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) 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))}/inventory/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(getApiApiV1AccountAuthIdInventoryNumbersResponse, await res.json()) };