import {z} from 'zod' export type GetApiV4AccountSubAccountIdDatacenterSharedProxyListArgs = {subAccountId: string, type?: ('getproxies' | 'displayproxies') | undefined, 'country[]'?: Array | undefined, protocol: 'http' | 'socks', format?: ('json' | 'data' | 'credentials') | undefined, proxy_format?: ('ipport' | 'protocolipport') | undefined, credential_format?: (1 | 2 | 3) | undefined, status?: ('online' | 'offline') | undefined, start?: number | undefined, limit?: number | undefined, length?: number | undefined, draw?: number | undefined}; export type GetApiV4AccountSubAccountIdDatacenterSharedProxyListOptions = {baseUrl?: string | undefined, apiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV4AccountSubAccountIdDatacenterSharedProxyListResponse = z.union([z.object({data: z.array(z.array(z.string())), recordsTotal: z.number().int(), recordsFiltered: z.number().int(), draw: z.number().int()}), z.object({countries: z.record(z.string(), z.number().int()), recordsTotal: 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 }; /** * Get datacenter proxy list * * GET /v4/account/{subAccountId}/datacenter_shared/proxy-list */ export const getApiV4AccountSubAccountIdDatacenterSharedProxyList = async (args: GetApiV4AccountSubAccountIdDatacenterSharedProxyListArgs, options?: GetApiV4AccountSubAccountIdDatacenterSharedProxyListOptions) => { const {baseUrl = "https://api.proxyscrape.com", fetch: fetchFn = fetch, apiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) for (const item of args['country[]'] ?? []) query.append("country[]", String(item)) if (args.protocol != null) query.append("protocol", String(args.protocol)) if (args.format != null) query.append("format", String(args.format)) if (args.proxy_format != null) query.append("proxy_format", String(args.proxy_format)) if (args.credential_format != null) query.append("credential_format", String(args.credential_format)) if (args.status != null) query.append("status", String(args.status)) if (args.start != null) query.append("start", String(args.start)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.length != null) query.append("length", String(args.length)) if (args.draw != null) query.append("draw", String(args.draw)) if (apiToken !== undefined) headers.set("api-token", apiToken) const url = `${baseUrl.replace(/\/+$/, '')}/v4/account/${encodeURIComponent(String(args.subAccountId))}/datacenter_shared/proxy-list${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(getApiV4AccountSubAccountIdDatacenterSharedProxyListResponse, await res.json()) };