import {z} from 'zod' export type UpdateSessionProfileParams = {persistChanges?: boolean | undefined, persistNetworkCache?: boolean | undefined}; export type UpdateSessionProfileRequest = {type: 'profile', params: UpdateSessionProfileParams}; export type ProxyCountry = 'AD' | 'AE' | 'AF' | 'AL' | 'AM' | 'AO' | 'AR' | 'AT' | 'AU' | 'AW' | 'AZ' | 'BA' | 'BD' | 'BE' | 'BG' | 'BH' | 'BJ' | 'BO' | 'BR' | 'BS' | 'BT' | 'BY' | 'BZ' | 'CA' | 'CF' | 'CH' | 'CI' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'EC' | 'EE' | 'EG' | 'ES' | 'ET' | 'EU' | 'FI' | 'FJ' | 'FR' | 'GB' | 'GE' | 'GH' | 'GM' | 'GR' | 'HK' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IN' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JM' | 'JO' | 'JP' | 'KE' | 'KH' | 'KR' | 'KW' | 'KZ' | 'LB' | 'LI' | 'LR' | 'LT' | 'LU' | 'LV' | 'MA' | 'MC' | 'MD' | 'ME' | 'MG' | 'MK' | 'ML' | 'MM' | 'MN' | 'MR' | 'MT' | 'MU' | 'MV' | 'MX' | 'MY' | 'MZ' | 'NG' | 'NL' | 'NO' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PH' | 'PK' | 'PL' | 'PR' | 'PT' | 'PY' | 'QA' | 'RANDOM_COUNTRY' | 'RO' | 'RS' | 'RU' | 'SA' | 'SC' | 'SD' | 'SE' | 'SG' | 'SI' | 'SK' | 'SN' | 'SS' | 'TD' | 'TG' | 'TH' | 'TM' | 'TN' | 'TR' | 'TT' | 'TW' | 'UA' | 'UG' | 'US' | 'UY' | 'UZ' | 'VE' | 'VG' | 'VN' | 'YE' | 'ZA' | 'ZM' | 'ZW' | 'ad' | 'ae' | 'af' | 'al' | 'am' | 'ao' | 'ar' | 'at' | 'au' | 'aw' | 'az' | 'ba' | 'bd' | 'be' | 'bg' | 'bh' | 'bj' | 'bo' | 'br' | 'bs' | 'bt' | 'by' | 'bz' | 'ca' | 'cf' | 'ch' | 'ci' | 'cl' | 'cm' | 'cn' | 'co' | 'cr' | 'cu' | 'cy' | 'cz' | 'de' | 'dj' | 'dk' | 'dm' | 'ec' | 'ee' | 'eg' | 'es' | 'et' | 'eu' | 'fi' | 'fj' | 'fr' | 'gb' | 'ge' | 'gh' | 'gm' | 'gr' | 'hk' | 'hn' | 'hr' | 'ht' | 'hu' | 'id' | 'ie' | 'il' | 'in' | 'iq' | 'ir' | 'is' | 'it' | 'jm' | 'jo' | 'jp' | 'ke' | 'kh' | 'kr' | 'kw' | 'kz' | 'lb' | 'li' | 'lr' | 'lt' | 'lu' | 'lv' | 'ma' | 'mc' | 'md' | 'me' | 'mg' | 'mk' | 'ml' | 'mm' | 'mn' | 'mr' | 'mt' | 'mu' | 'mv' | 'mx' | 'my' | 'mz' | 'ng' | 'nl' | 'no' | 'nz' | 'om' | 'pa' | 'pe' | 'ph' | 'pk' | 'pl' | 'pr' | 'pt' | 'py' | 'qa' | 'ro' | 'rs' | 'ru' | 'sa' | 'sc' | 'sd' | 'se' | 'sg' | 'si' | 'sk' | 'sn' | 'ss' | 'td' | 'tg' | 'th' | 'tm' | 'tn' | 'tr' | 'tt' | 'tw' | 'ua' | 'ug' | 'us' | 'uy' | 'uz' | 've' | 'vg' | 'vn' | 'ye' | 'za' | 'zm' | 'zw'; export type ProxyState = 'AL' | 'AK' | 'AZ' | 'AR' | 'CA' | 'CO' | 'CT' | 'DE' | 'FL' | 'GA' | 'HI' | 'ID' | 'IL' | 'IN' | 'IA' | 'KS' | 'KY' | 'LA' | 'ME' | 'MD' | 'MA' | 'MI' | 'MN' | 'MS' | 'MO' | 'MT' | 'NE' | 'NV' | 'NH' | 'NJ' | 'NM' | 'NY' | 'NC' | 'ND' | 'OH' | 'OK' | 'OR' | 'PA' | 'RI' | 'SC' | 'SD' | 'TN' | 'TX' | 'UT' | 'VT' | 'VA' | 'WA' | 'WV' | 'WI' | 'WY' | 'al' | 'ak' | 'az' | 'ar' | 'ca' | 'co' | 'ct' | 'de' | 'fl' | 'ga' | 'hi' | 'id' | 'il' | 'in' | 'ia' | 'ks' | 'ky' | 'la' | 'me' | 'md' | 'ma' | 'mi' | 'mn' | 'ms' | 'mo' | 'mt' | 'ne' | 'nv' | 'nh' | 'nj' | 'nm' | 'ny' | 'nc' | 'nd' | 'oh' | 'ok' | 'or' | 'pa' | 'ri' | 'sc' | 'sd' | 'tn' | 'tx' | 'ut' | 'vt' | 'va' | 'wa' | 'wv' | 'wi' | 'wy' | null; export type UpdateSessionProxyLocationParams = {country?: ProxyCountry | undefined, state?: ProxyState | undefined, city?: string | undefined}; export type UpdateSessionProxyParams = {enabled: boolean, staticIpId?: string | undefined, location?: UpdateSessionProxyLocationParams | undefined}; export type UpdateSessionProxyRequest = {type: 'proxy', params: UpdateSessionProxyParams}; export type UpdateSessionScreenParams = {width: number, height: number}; export type UpdateSessionScreenRequest = {type: 'screen', params: UpdateSessionScreenParams}; export type UpdateSessionSolveCaptchasParams = {enabled: boolean, solverType?: 'visual' | undefined}; export type UpdateSessionSolveCaptchasRequest = {type: 'solveCaptchas', params: UpdateSessionSolveCaptchasParams}; export type UpdateSessionRequest = UpdateSessionProfileRequest | UpdateSessionProxyRequest | UpdateSessionScreenRequest | UpdateSessionSolveCaptchasRequest; export type UpdateApiApiSessionIdUpdateArgs = {id: string, body: UpdateSessionRequest}; export type UpdateApiApiSessionIdUpdateOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateSessionResponse = z.object({success: z.boolean(), solveCaptchas: z.boolean().optional(), sessionId: z.string().optional(), telemetryReady: z.boolean().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 }; /** * Update a running session * * PUT /api/session/{id}/update */ export const updateApiApiSessionIdUpdate = async (args: UpdateApiApiSessionIdUpdateArgs, options?: UpdateApiApiSessionIdUpdateOptions) => { const {baseUrl = "https://api.hyperbrowser.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/session/${encodeURIComponent(String(args.id))}/update${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(updateSessionResponse, await res.json()) };