import {z} from 'zod' export type GetApiV1ProxyPackagesPackageIdConnectionStringArgs = {package_id: string, protocol?: ('https' | 'http' | 'socks5' | null) | undefined, count?: number | undefined, network?: ('residential' | 'mobile' | 'any' | null) | undefined, country?: (string | null) | undefined, region?: (string | null) | undefined, city?: (string | null) | undefined, isp?: (string | null) | undefined, asn?: (string | null) | undefined, zip?: (string | null) | undefined, prefer?: ('lookalike' | null) | undefined, 'rotate-time'?: (number | null) | undefined, 'rotate-requests'?: (number | null) | undefined, 'on-error'?: ('replace' | 'fail' | 'retry' | null) | undefined, retries?: (number | null) | undefined, session?: (string | null) | undefined, bind?: ('node' | null) | undefined}; export type GetApiV1ProxyPackagesPackageIdConnectionStringOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const proxyConnectionStringResponse = z.object({uri: z.string(), username: z.string(), password: z.string().nullable().optional(), host: z.string(), port: z.number().int()}); export const getApiV1ProxyPackagesPackageIdConnectionStringResponse = z.array(proxyConnectionStringResponse); 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 proxy connection strings * * GET /v1/proxy/packages/{package_id}/connection-string */ export const getApiV1ProxyPackagesPackageIdConnectionString = async (args: GetApiV1ProxyPackagesPackageIdConnectionStringArgs, options?: GetApiV1ProxyPackagesPackageIdConnectionStringOptions) => { const {baseUrl = "https://api.platform.soax.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.protocol != null) query.append("protocol", String(args.protocol)) if (args.count != null) query.append("count", String(args.count)) if (args.network != null) query.append("network", String(args.network)) if (args.country != null) query.append("country", String(args.country)) if (args.region != null) query.append("region", String(args.region)) if (args.city != null) query.append("city", String(args.city)) if (args.isp != null) query.append("isp", String(args.isp)) if (args.asn != null) query.append("asn", String(args.asn)) if (args.zip != null) query.append("zip", String(args.zip)) if (args.prefer != null) query.append("prefer", String(args.prefer)) if (args['rotate-time'] != null) query.append("rotate-time", String(args['rotate-time'])) if (args['rotate-requests'] != null) query.append("rotate-requests", String(args['rotate-requests'])) if (args['on-error'] != null) query.append("on-error", String(args['on-error'])) if (args.retries != null) query.append("retries", String(args.retries)) if (args.session != null) query.append("session", String(args.session)) if (args.bind != null) query.append("bind", String(args.bind)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/proxy/packages/${encodeURIComponent(String(args.package_id))}/connection-string${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(getApiV1ProxyPackagesPackageIdConnectionStringResponse, await res.json()) };