import {z} from 'zod' export type GetApiPublicUserMobileAvailabilityCountArgs = {country_id?: string | undefined, subdivision_id?: string | undefined, city_name?: string | undefined, asn_id?: number | undefined, zip_code_alias?: string | undefined}; export type GetApiPublicUserMobileAvailabilityCountOptions = {baseUrl?: string | undefined, APIPrivateKey?: string | undefined, APIPublicKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPublicUserMobileAvailabilityCountResponse = z.object({data: z.object({total_mobile_availability_node_count: z.number().int().optional()}).optional(), message: 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 }; /** * Get Mobile Availability Count * * GET /public/user/mobile_availability/count */ export const getApiPublicUserMobileAvailabilityCount = async (args: GetApiPublicUserMobileAvailabilityCountArgs, options?: GetApiPublicUserMobileAvailabilityCountOptions) => { const {baseUrl = "https://api.byteful.com/1.0", fetch: fetchFn = fetch, APIPrivateKey, APIPublicKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.country_id != null) query.append("country_id", String(args.country_id)) if (args.subdivision_id != null) query.append("subdivision_id", String(args.subdivision_id)) if (args.city_name != null) query.append("city_name", String(args.city_name)) if (args.asn_id != null) query.append("asn_id", String(args.asn_id)) if (args.zip_code_alias != null) query.append("zip_code_alias", String(args.zip_code_alias)) if (APIPrivateKey !== undefined) headers.set("X-API-Private-Key", APIPrivateKey) if (APIPublicKey !== undefined) headers.set("X-API-Public-Key", APIPublicKey) const url = `${baseUrl.replace(/\/+$/, '')}/public/user/mobile_availability/count${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(getApiPublicUserMobileAvailabilityCountResponse, await res.json()) };