import {z} from 'zod' export type GetApiPublicUserProxyUserSearchArgs = {proxy_user_id?: string | undefined, proxy_user_password?: string | undefined, proxy_user_ip_address_authentication_limit?: number | undefined, proxy_user_is_deleted?: boolean | undefined, proxy_user_access_type?: string | undefined, proxy_user_is_strict_security?: boolean | undefined, proxy_user_is_default?: boolean | undefined, proxy_user_creation_datetime?: string | undefined, proxy_user_last_update_datetime?: string | undefined, per_page?: number | undefined, page?: number | undefined, sort_by?: string | undefined}; export type GetApiPublicUserProxyUserSearchOptions = {baseUrl?: string | undefined, APIPrivateKey?: string | undefined, APIPublicKey?: string | undefined, fetch?: typeof fetch | undefined}; export const proxyUserSuccessfulSearchResponse = z.object({data: z.array(z.object({customer_id: z.number().int().optional(), ip_address_authentications: z.array(z.string()).optional(), mobile_bytes_left: z.number().int().optional(), proxy_user_access_type: z.enum(["all", "service_restricted", "proxy_restricted"]).optional(), proxy_user_creation_datetime: z.string().optional(), proxy_user_enforce_https: z.boolean().optional(), proxy_user_id: z.string().optional(), proxy_user_ip_address_authentication_limit: z.number().int().optional(), proxy_user_is_default: z.boolean().optional(), proxy_user_is_deleted: z.boolean().optional(), proxy_user_is_strict_security: z.boolean().optional(), proxy_user_last_update_datetime: z.string().optional(), proxy_user_metadata: z.object({}).optional(), proxy_user_mobile_bytes_limit: z.number().int().optional(), proxy_user_mobile_bytes_used: z.number().int().optional(), proxy_user_password: z.string().optional(), proxy_user_residential_bytes_limit: z.number().int().optional(), proxy_user_residential_bytes_used: z.number().int().optional(), residential_bytes_left: z.number().int().optional(), restricted_proxy_ids: z.array(z.string()).optional(), restricted_service_ids: z.array(z.string()).optional()})).optional(), item_count: z.number().int().optional(), message: z.string().optional(), page: z.number().int().optional(), per_page: z.number().int().optional(), total_count: z.number().int().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 }; /** * Search Proxy Users * * GET /public/user/proxy_user/search */ export const getApiPublicUserProxyUserSearch = async (args: GetApiPublicUserProxyUserSearchArgs, options?: GetApiPublicUserProxyUserSearchOptions) => { 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.proxy_user_id != null) query.append("proxy_user_id", String(args.proxy_user_id)) if (args.proxy_user_password != null) query.append("proxy_user_password", String(args.proxy_user_password)) if (args.proxy_user_ip_address_authentication_limit != null) query.append("proxy_user_ip_address_authentication_limit", String(args.proxy_user_ip_address_authentication_limit)) if (args.proxy_user_is_deleted != null) query.append("proxy_user_is_deleted", String(args.proxy_user_is_deleted)) if (args.proxy_user_access_type != null) query.append("proxy_user_access_type", String(args.proxy_user_access_type)) if (args.proxy_user_is_strict_security != null) query.append("proxy_user_is_strict_security", String(args.proxy_user_is_strict_security)) if (args.proxy_user_is_default != null) query.append("proxy_user_is_default", String(args.proxy_user_is_default)) if (args.proxy_user_creation_datetime != null) query.append("proxy_user_creation_datetime", String(args.proxy_user_creation_datetime)) if (args.proxy_user_last_update_datetime != null) query.append("proxy_user_last_update_datetime", String(args.proxy_user_last_update_datetime)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.page != null) query.append("page", String(args.page)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) 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/proxy_user/search${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(proxyUserSuccessfulSearchResponse, await res.json()) };