@mearl/cloud-client
Advanced tools
| export {}; |
| import { type CloudClientOptions } from './index.js'; | ||
| interface CheckClient { | ||
| invoke(action: string, data?: Record<string, any>, options?: { | ||
| timeoutSec?: number; | ||
| connector?: string; | ||
| }): Promise<any>; | ||
| disconnect(): void; | ||
| } | ||
| export interface CloudCheckOptions { | ||
| clientVersion: string; | ||
| serverUrl?: string; | ||
| serverUrlSource?: string; | ||
| timeoutSec?: number; | ||
| connector?: string; | ||
| } | ||
| export interface CloudCheckDependencies { | ||
| createClient?: (options: CloudClientOptions) => CheckClient; | ||
| probeServer?: (serverUrl: string, timeoutSec: number) => Promise<void>; | ||
| writeLine?: (line: string) => void; | ||
| } | ||
| export declare function parseCloudCheckTimeout(value: string | undefined): number | null; | ||
| export declare function probeCloudServer(serverUrl: string, timeoutSec: number): Promise<void>; | ||
| export declare function runCloudCheck(options: CloudCheckOptions, dependencies?: CloudCheckDependencies): Promise<boolean>; | ||
| export {}; |
| export interface CloudInvokeOptions { | ||
| timeoutSec?: number; | ||
| /** Target a specific browser on the connector's machine by id / name. */ | ||
| browser?: string; | ||
| /** Target a specific browser-side cloud connector by id / name. */ | ||
| connector?: string; | ||
| } |
+522
-54
@@ -42,30 +42,50 @@ #!/usr/bin/env node | ||
| getRequests(...args2) { | ||
| return this.invoke("get_requests", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "get_requests", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| getLogs(...args2) { | ||
| return this.invoke("get_logs", args2[0] ?? {}); | ||
| return this.invoke("get_logs", args2[0] ?? {}, args2[1]); | ||
| } | ||
| getEvents(...args2) { | ||
| return this.invoke("get_events", args2[0] ?? {}); | ||
| return this.invoke("get_events", args2[0] ?? {}, args2[1]); | ||
| } | ||
| setMock(...args2) { | ||
| return this.invoke("set_mock", args2[0] ?? {}); | ||
| return this.invoke("set_mock", args2[0] ?? {}, args2[1]); | ||
| } | ||
| getMocks(...args2) { | ||
| return this.invoke("get_mocks", args2[0] ?? {}); | ||
| return this.invoke("get_mocks", args2[0] ?? {}, args2[1]); | ||
| } | ||
| getApiSchema(...args2) { | ||
| return this.invoke("get_api_schema", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "get_api_schema", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| sendRequest(...args2) { | ||
| return this.invoke("send_request", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "send_request", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| sendMtopRequest(...args2) { | ||
| return this.invoke("send_mtop_request", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "send_mtop_request", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| tdbankAccount(...args2) { | ||
| return this.invoke("tdbank_account", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "tdbank_account", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| browserList(..._args) { | ||
| return this.invoke("browser_list", {}); | ||
| browserList(...args2) { | ||
| return this.invoke("browser_list", {}, args2[0]); | ||
| } | ||
@@ -75,22 +95,35 @@ selectBrowser(...args2) { | ||
| "browser_select_browser", | ||
| args2[0] ?? {} | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| browserRelease(..._args) { | ||
| return this.invoke("browser_release", {}); | ||
| browserRelease(...args2) { | ||
| return this.invoke("browser_release", {}, args2[0]); | ||
| } | ||
| browserLaunch(...args2) { | ||
| return this.invoke("browser_launch", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "browser_launch", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| browserClose(...args2) { | ||
| return this.invoke("browser_close", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "browser_close", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| setRule(...args2) { | ||
| return this.invoke("set_rule", args2[0] ?? {}); | ||
| return this.invoke("set_rule", args2[0] ?? {}, args2[1]); | ||
| } | ||
| getRules(..._args) { | ||
| return this.invoke("get_rules", {}); | ||
| getRules(...args2) { | ||
| return this.invoke("get_rules", {}, args2[0]); | ||
| } | ||
| pageScreenshot(...args2) { | ||
| return this.invoke("page_screenshot", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "page_screenshot", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
@@ -100,46 +133,67 @@ pageSelectedElement(...args2) { | ||
| "page_selected_element", | ||
| args2[0] ?? {} | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| tabOpen(...args2) { | ||
| return this.invoke("tab_open", args2[0] ?? {}); | ||
| return this.invoke("tab_open", args2[0] ?? {}, args2[1]); | ||
| } | ||
| tabClose(...args2) { | ||
| return this.invoke("tab_close", args2[0] ?? {}); | ||
| return this.invoke("tab_close", args2[0] ?? {}, args2[1]); | ||
| } | ||
| tabList(..._args) { | ||
| return this.invoke("tab_list", {}); | ||
| tabList(...args2) { | ||
| return this.invoke("tab_list", {}, args2[0]); | ||
| } | ||
| pageClick(...args2) { | ||
| return this.invoke("page_click", args2[0] ?? {}); | ||
| return this.invoke("page_click", args2[0] ?? {}, args2[1]); | ||
| } | ||
| pageType(...args2) { | ||
| return this.invoke("page_type", args2[0] ?? {}); | ||
| return this.invoke("page_type", args2[0] ?? {}, args2[1]); | ||
| } | ||
| pageScroll(...args2) { | ||
| return this.invoke("page_scroll", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "page_scroll", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| pageHover(...args2) { | ||
| return this.invoke("page_hover", args2[0] ?? {}); | ||
| return this.invoke("page_hover", args2[0] ?? {}, args2[1]); | ||
| } | ||
| pageEval(...args2) { | ||
| return this.invoke("page_eval", args2[0] ?? {}); | ||
| return this.invoke("page_eval", args2[0] ?? {}, args2[1]); | ||
| } | ||
| pageSnapshot(...args2) { | ||
| return this.invoke("page_snapshot", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "page_snapshot", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| pagePress(...args2) { | ||
| return this.invoke("page_press", args2[0] ?? {}); | ||
| return this.invoke("page_press", args2[0] ?? {}, args2[1]); | ||
| } | ||
| pageWait(...args2) { | ||
| return this.invoke("page_wait", args2[0] ?? {}); | ||
| return this.invoke("page_wait", args2[0] ?? {}, args2[1]); | ||
| } | ||
| pageNavigate(...args2) { | ||
| return this.invoke("page_navigate", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "page_navigate", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| pageUpload(...args2) { | ||
| return this.invoke("page_upload", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "page_upload", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| pageFrames(...args2) { | ||
| return this.invoke("page_frames", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "page_frames", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
@@ -149,19 +203,32 @@ setDeviceEmulation(...args2) { | ||
| "set_device_emulation", | ||
| args2[0] ?? {} | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| setTimezone(...args2) { | ||
| return this.invoke("set_timezone", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "set_timezone", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| getCookie(...args2) { | ||
| return this.invoke("get_cookie", args2[0] ?? {}); | ||
| return this.invoke("get_cookie", args2[0] ?? {}, args2[1]); | ||
| } | ||
| setCookie(...args2) { | ||
| return this.invoke("set_cookie", args2[0] ?? {}); | ||
| return this.invoke("set_cookie", args2[0] ?? {}, args2[1]); | ||
| } | ||
| getUserInfo(...args2) { | ||
| return this.invoke("get_user_info", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "get_user_info", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
| runActions(...args2) { | ||
| return this.invoke("run_actions", args2[0] ?? {}); | ||
| return this.invoke( | ||
| "run_actions", | ||
| args2[0] ?? {}, | ||
| args2[1] | ||
| ); | ||
| } | ||
@@ -182,2 +249,3 @@ }; | ||
| defaultBrowser; | ||
| defaultConnector; | ||
| ws = null; | ||
@@ -199,2 +267,3 @@ connectPromise = null; | ||
| this.defaultBrowser = options.defaultBrowser; | ||
| this.defaultConnector = options.defaultConnector; | ||
| } | ||
@@ -229,2 +298,3 @@ async ensureConnected() { | ||
| clearTimeout(connectTimer); | ||
| this.ws?.send(JSON.stringify({ type: "agent_hello" }) + "\n"); | ||
| this.startHeartbeat(); | ||
@@ -315,4 +385,8 @@ resolve2(); | ||
| invoke(action, data = {}, options = {}) { | ||
| if (action === "browser_select_browser") return this.selectDefaultBrowser(data); | ||
| const browser = action === "browser_list" ? void 0 : options.browser ?? this.defaultBrowser; | ||
| if (action === "browser_select_browser") { | ||
| return this.selectDefaultBrowser(data, options.connector); | ||
| } | ||
| const connector = action === "connector_list" ? void 0 : options.connector ?? this.defaultConnector; | ||
| const usesDefaultConnector = options.connector === void 0 || this.defaultConnector !== void 0 && options.connector.trim().toLowerCase() === this.defaultConnector.trim().toLowerCase(); | ||
| const browser = action === "browser_list" || action === "connector_list" ? void 0 : options.browser ?? (usesDefaultConnector ? this.defaultBrowser : void 0); | ||
| const timeoutSec = options.timeoutSec ?? resolveActionTimeoutSec(action, data, this.options.requestTimeoutSec); | ||
@@ -339,2 +413,3 @@ const request = (async () => { | ||
| if (browser) message.browser = browser; | ||
| if (connector) message.connector = connector; | ||
| ws.send(JSON.stringify(message) + "\n"); | ||
@@ -346,3 +421,3 @@ }); | ||
| const browsers = Array.isArray(result?.browsers) ? result.browsers : []; | ||
| if (!this.defaultBrowser) return result; | ||
| if (!this.defaultBrowser || !usesDefaultConnector) return result; | ||
| const selected = findConnectedBrowser(browsers, this.defaultBrowser); | ||
@@ -355,3 +430,6 @@ return { | ||
| } | ||
| async selectDefaultBrowser(data) { | ||
| listCloudConnectors() { | ||
| return this.invoke("connector_list", {}); | ||
| } | ||
| async selectDefaultBrowser(data, connector) { | ||
| const selector = typeof data.browser === "string" ? data.browser.trim() : ""; | ||
@@ -365,3 +443,8 @@ if (!selector) { | ||
| } | ||
| const listing = await this.invoke("browser_list", {}); | ||
| const targetConnector = connector ?? this.defaultConnector; | ||
| const listing = await this.invoke( | ||
| "browser_list", | ||
| {}, | ||
| targetConnector ? { connector: targetConnector } : {} | ||
| ); | ||
| const browsers = Array.isArray(listing?.browsers) ? listing.browsers : []; | ||
@@ -375,2 +458,3 @@ const match = findConnectedBrowser(browsers, selector); | ||
| this.defaultBrowser = match.browserId; | ||
| this.defaultConnector = targetConnector; | ||
| return { selected: { browserId: match.browserId, name: match.name } }; | ||
@@ -390,3 +474,355 @@ } | ||
| import { resolve } from "node:path"; | ||
| var CLOUD_CLIENT_VERSION = true ? "2.1.0" : "unknown"; | ||
| // src/check.ts | ||
| import WebSocket2 from "ws"; | ||
| import { | ||
| isHeartbeatMessage as isHeartbeatMessage2, | ||
| resolveCloudConnectorSelector | ||
| } from "@mearl/cloud-types"; | ||
| function formatError(error) { | ||
| return error instanceof Error ? error.message : String(error); | ||
| } | ||
| function isAgentConnectionRejection(message) { | ||
| return message.includes("Agent requests are only accepted on the local interface") || message.includes("Agent must be local"); | ||
| } | ||
| function redactServerUrl(serverUrl) { | ||
| try { | ||
| const parsed = new URL(serverUrl); | ||
| for (const key of parsed.searchParams.keys()) { | ||
| if (key.toLowerCase().includes("token")) parsed.searchParams.set(key, "redacted"); | ||
| } | ||
| return parsed.toString(); | ||
| } catch { | ||
| return serverUrl.replace(/([?&][^=&\s]*token[^=&\s]*=)[^&\s]*/gi, "$1redacted"); | ||
| } | ||
| } | ||
| function validateServerUrl(serverUrl) { | ||
| try { | ||
| const parsed = new URL(serverUrl); | ||
| if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") { | ||
| return "Server URL must use ws:// or wss://"; | ||
| } | ||
| if (!parsed.hostname) return "Server URL must include a hostname"; | ||
| return null; | ||
| } catch { | ||
| return "Server URL is invalid"; | ||
| } | ||
| } | ||
| function formatBrowser(browser, isDefault) { | ||
| const id = browser.browserId.length > 12 ? `${browser.browserId.slice(0, 8)}…` : browser.browserId; | ||
| const transport = browser.transport === "cdp" ? " [CDP]" : browser.transport === "extension" ? " [Extension]" : ""; | ||
| return ` ${isDefault ? "★" : " "} ${browser.name} [${id}]${transport}`; | ||
| } | ||
| function formatConnector(connector, isSelected) { | ||
| const id = connector.connectorId.length > 12 ? `${connector.connectorId.slice(0, 8)}…` : connector.connectorId; | ||
| const version = connector.version ? ` [v${connector.version}]` : ""; | ||
| const legacy = connector.legacy ? " [legacy]" : ""; | ||
| return ` ${isSelected ? "★" : " "} ${connector.name} [${id}]${version}${legacy}`; | ||
| } | ||
| function printSection(writeLine, title, items) { | ||
| writeLine(title); | ||
| for (const item of items) { | ||
| const marker = item.status === "ok" ? "✅" : item.status === "warning" ? "⚠️ " : "❌"; | ||
| writeLine(` ${marker} ${item.label}`); | ||
| for (const detail of item.details ?? []) writeLine(` ${detail}`); | ||
| } | ||
| writeLine(""); | ||
| } | ||
| function printCheckReport(writeLine, versions, environment) { | ||
| const versionItems = versions.map(([name, value]) => ({ | ||
| status: "ok", | ||
| label: `${name} ${value}` | ||
| })); | ||
| writeLine(""); | ||
| printSection(writeLine, "Versions", versionItems); | ||
| printSection(writeLine, "Environment", environment); | ||
| } | ||
| function printFailedCheck(writeLine, versions, environment) { | ||
| printCheckReport(writeLine, versions, environment); | ||
| writeLine("⚠️ Cloud checks failed. See above for fix instructions."); | ||
| return false; | ||
| } | ||
| function parseCloudCheckTimeout(value) { | ||
| const input = value ?? "5"; | ||
| if (!/^[1-9]\d*$/.test(input)) return null; | ||
| const timeoutSec = Number(input); | ||
| return Number.isSafeInteger(timeoutSec) ? timeoutSec : null; | ||
| } | ||
| function probeCloudServer(serverUrl, timeoutSec) { | ||
| return new Promise((resolve2, reject) => { | ||
| const ws = new WebSocket2(serverUrl); | ||
| let settled = false; | ||
| let buffer = ""; | ||
| const finish = (error) => { | ||
| if (settled) return; | ||
| settled = true; | ||
| clearTimeout(timer); | ||
| ws.close(); | ||
| if (error) reject(error); | ||
| else resolve2(); | ||
| }; | ||
| const timer = setTimeout( | ||
| () => finish(new Error(`Connection timeout after ${timeoutSec}s`)), | ||
| timeoutSec * 1e3 | ||
| ); | ||
| ws.on("open", () => { | ||
| ws.send(JSON.stringify({ type: "ping", timestamp: Date.now() }) + "\n"); | ||
| }); | ||
| ws.on("message", (data) => { | ||
| buffer += data.toString(); | ||
| let newlineIndex; | ||
| while ((newlineIndex = buffer.indexOf("\n")) !== -1) { | ||
| const line = buffer.slice(0, newlineIndex); | ||
| buffer = buffer.slice(newlineIndex + 1); | ||
| if (!line.trim()) continue; | ||
| try { | ||
| const message = JSON.parse(line); | ||
| if (isHeartbeatMessage2(message) && message.type === "pong") { | ||
| finish(); | ||
| return; | ||
| } | ||
| } catch { | ||
| } | ||
| } | ||
| }); | ||
| ws.on("close", (code, reason) => { | ||
| const suffix = reason.length > 0 ? `: ${reason.toString()}` : ""; | ||
| finish(new Error(`Connection closed (${code}${suffix})`)); | ||
| }); | ||
| ws.on("error", (error) => finish(error)); | ||
| }); | ||
| } | ||
| async function runCloudCheck(options, dependencies = {}) { | ||
| const timeoutSec = options.timeoutSec ?? 5; | ||
| const writeLine = dependencies.writeLine ?? ((line) => console.error(line)); | ||
| const probeServer = dependencies.probeServer ?? probeCloudServer; | ||
| const createClient = dependencies.createClient ?? ((clientOptions) => new CloudClient(clientOptions)); | ||
| const environment = []; | ||
| const versions = [["cloud-client", `v${options.clientVersion}`]]; | ||
| if (!options.serverUrl) { | ||
| environment.push({ | ||
| status: "error", | ||
| label: "Cloud server URL not found", | ||
| details: ["Start cloud-server, pass --server <url>, or set MEARL_SERVER_URL."] | ||
| }); | ||
| return printFailedCheck(writeLine, versions, environment); | ||
| } | ||
| const serverUrl = options.serverUrl; | ||
| const source = options.serverUrlSource ? ` (${options.serverUrlSource})` : ""; | ||
| const urlError = validateServerUrl(serverUrl); | ||
| if (urlError) { | ||
| environment.push({ | ||
| status: "error", | ||
| label: `Cloud server URL${source}`, | ||
| details: [urlError, redactServerUrl(serverUrl)] | ||
| }); | ||
| return printFailedCheck(writeLine, versions, environment); | ||
| } | ||
| environment.push({ | ||
| status: "ok", | ||
| label: `Cloud server URL${source}`, | ||
| details: [redactServerUrl(serverUrl)] | ||
| }); | ||
| try { | ||
| await probeServer(serverUrl, timeoutSec); | ||
| environment.push({ status: "ok", label: "Cloud server connection and authentication" }); | ||
| } catch (error) { | ||
| environment.push({ | ||
| status: "error", | ||
| label: "Cloud server connection or authentication failed", | ||
| details: [formatError(error), "Run mearl-cloud-server status and verify the URL and token."] | ||
| }); | ||
| return printFailedCheck(writeLine, versions, environment); | ||
| } | ||
| const client = createClient({ | ||
| serverUrl, | ||
| connectTimeoutSec: timeoutSec, | ||
| requestTimeoutSec: timeoutSec, | ||
| defaultConnector: options.connector | ||
| }); | ||
| let canQueryRuntime = false; | ||
| let runtime = null; | ||
| let browserList = null; | ||
| let connectorList = null; | ||
| let selectedConnector = null; | ||
| let shouldProbeLegacyConnector = false; | ||
| const invokeOptions = options.connector ? { timeoutSec, connector: options.connector } : { timeoutSec }; | ||
| try { | ||
| try { | ||
| const result = await client.invoke( | ||
| "connector_list", | ||
| {}, | ||
| { timeoutSec } | ||
| ); | ||
| if (!Array.isArray(result?.connectors)) { | ||
| throw new Error("Invalid connector_list response"); | ||
| } | ||
| connectorList = result; | ||
| if (result.connectors.length === 0) { | ||
| environment.push({ | ||
| status: "error", | ||
| label: "Cloud connector not connected", | ||
| details: [ | ||
| "Connect the browser machine using the command shown by mearl-cloud-server status." | ||
| ] | ||
| }); | ||
| } else if (options.connector) { | ||
| const selection = resolveCloudConnectorSelector(result.connectors, options.connector); | ||
| if (selection.status === "matched") { | ||
| selectedConnector = selection.connector; | ||
| environment.push({ | ||
| status: "ok", | ||
| label: `Cloud connectors (${result.connectors.length}); selected ${selectedConnector.name}` | ||
| }); | ||
| canQueryRuntime = true; | ||
| } else { | ||
| environment.push({ | ||
| status: "error", | ||
| label: selection.status === "ambiguous" ? `Cloud connector "${options.connector}" is ambiguous` : `Cloud connector "${options.connector}" was not found`, | ||
| details: ["Run mearl connector_list and choose an exact connector id or name."] | ||
| }); | ||
| } | ||
| } else if (result.connectors.length === 1) { | ||
| selectedConnector = result.connectors[0]; | ||
| environment.push({ status: "ok", label: "Cloud connector" }); | ||
| canQueryRuntime = true; | ||
| } else { | ||
| environment.push({ | ||
| status: "error", | ||
| label: `Multiple cloud connectors are connected (${result.connectors.length})`, | ||
| details: ["Run mearl check --connector <id|name> to inspect one connector."] | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| const message = formatError(error); | ||
| if (message.includes("Unknown action")) { | ||
| shouldProbeLegacyConnector = true; | ||
| } else if (isAgentConnectionRejection(message)) { | ||
| environment.push({ | ||
| status: "error", | ||
| label: "Cloud server rejected the agent connection", | ||
| details: [message, "Use the loopback agent URL written by the co-located cloud-server."] | ||
| }); | ||
| } else { | ||
| environment.push({ | ||
| status: "error", | ||
| label: "Cloud connector inventory request failed", | ||
| details: [message] | ||
| }); | ||
| } | ||
| } | ||
| try { | ||
| if (shouldProbeLegacyConnector || canQueryRuntime) { | ||
| runtime = await client.invoke("get_versions", {}, invokeOptions); | ||
| canQueryRuntime = true; | ||
| if (shouldProbeLegacyConnector) | ||
| environment.push({ status: "ok", label: "Cloud connector" }); | ||
| environment.push({ status: "ok", label: "Remote native-host" }); | ||
| } | ||
| } catch (error) { | ||
| const message = formatError(error); | ||
| if (message.includes("Unknown action")) { | ||
| canQueryRuntime = true; | ||
| if (!connectorList) environment.push({ status: "ok", label: "Cloud connector" }); | ||
| environment.push({ | ||
| status: "warning", | ||
| label: "Remote native-host is reachable but does not support get_versions", | ||
| details: ["Update @mearl/native-host to get complete version diagnostics."] | ||
| }); | ||
| } else if (message.includes("No local connector available")) { | ||
| environment.push({ | ||
| status: "error", | ||
| label: "Cloud connector not connected", | ||
| details: [ | ||
| "Connect the browser machine using the command shown by mearl-cloud-server status." | ||
| ] | ||
| }); | ||
| } else if (isAgentConnectionRejection(message)) { | ||
| environment.push({ | ||
| status: "error", | ||
| label: "Cloud server rejected the agent connection", | ||
| details: [message, "Use the loopback agent URL written by the co-located cloud-server."] | ||
| }); | ||
| } else { | ||
| environment.push({ | ||
| status: "error", | ||
| label: "Connector → native-host request failed", | ||
| details: [message, "Check cloud-connector and native-host on the browser machine."] | ||
| }); | ||
| } | ||
| } | ||
| if (canQueryRuntime) { | ||
| try { | ||
| browserList = await client.invoke("browser_list", {}, invokeOptions); | ||
| const connectedBrowsers2 = (browserList.browsers ?? []).filter( | ||
| (browser) => browser.status === "connected" | ||
| ); | ||
| const connectedCount = browserList.connectedCount ?? connectedBrowsers2.length; | ||
| if (connectedCount > 0) { | ||
| environment.push({ | ||
| status: "ok", | ||
| label: `Connected browsers (${connectedCount})` | ||
| }); | ||
| } else { | ||
| environment.push({ | ||
| status: "error", | ||
| label: "No connected browser", | ||
| details: [ | ||
| "Open Chrome with the Mearl extension, or enable Chrome remote debugging for CDP mode." | ||
| ] | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| environment.push({ | ||
| status: "error", | ||
| label: "Browser inventory request failed", | ||
| details: [formatError(error)] | ||
| }); | ||
| } | ||
| } | ||
| } finally { | ||
| client.disconnect(); | ||
| } | ||
| if (runtime?.nativeHost) versions.push(["native-host", `v${runtime.nativeHost}`]); | ||
| if (runtime?.extension) versions.push(["extension", `v${runtime.extension}`]); | ||
| if (runtime?.browser) versions.push(["browser", `Chrome ${runtime.browser}`]); | ||
| printCheckReport(writeLine, versions, environment); | ||
| if (connectorList && connectorList.connectors.length > 0) { | ||
| writeLine("Cloud connectors"); | ||
| for (const connector of connectorList.connectors) { | ||
| writeLine( | ||
| formatConnector(connector, connector.connectorId === selectedConnector?.connectorId) | ||
| ); | ||
| } | ||
| if (connectorList.connectors.length > 1) { | ||
| writeLine( | ||
| selectedConnector ? " ★ = selected connector. Use --connector to pick another." : " Use --connector <id|name> to select one." | ||
| ); | ||
| } | ||
| writeLine(""); | ||
| } | ||
| const connectedBrowsers = (browserList?.browsers ?? []).filter( | ||
| (browser) => browser.status === "connected" | ||
| ); | ||
| if (connectedBrowsers.length > 0) { | ||
| writeLine("Connected browsers"); | ||
| for (const browser of connectedBrowsers) { | ||
| writeLine(formatBrowser(browser, browser.browserId === browserList?.defaultBrowserId)); | ||
| } | ||
| if (browserList?.defaultBrowserId) { | ||
| writeLine(" ★ = default target. Use --browser to pick another."); | ||
| } | ||
| writeLine(""); | ||
| } | ||
| const hasError = environment.some((item) => item.status === "error"); | ||
| if (hasError) { | ||
| writeLine("⚠️ Cloud checks failed. See above for fix instructions."); | ||
| return false; | ||
| } | ||
| writeLine("🎉 All cloud checks passed!"); | ||
| return true; | ||
| } | ||
| // src/cli.ts | ||
| var CLOUD_CLIENT_VERSION = true ? "2.2.0" : "unknown"; | ||
| var args = process.argv.slice(2); | ||
@@ -397,3 +833,3 @@ if (args.includes("--version") || args.includes("-v")) { | ||
| } | ||
| function showHelp() { | ||
| function showHelp(exitCode = 1) { | ||
| console.error(`mearl-cloud v${CLOUD_CLIENT_VERSION} | ||
@@ -403,2 +839,3 @@ | ||
| mearl-cloud <action> [options] | ||
| mearl-cloud check [options] | ||
@@ -408,2 +845,6 @@ Arguments: | ||
| Commands: | ||
| check Check cloud-server, connector, native-host, and browser connectivity | ||
| connector_list List browser-side connectors registered with cloud-server | ||
| Options: | ||
@@ -415,2 +856,3 @@ --server <url> WebSocket server URL (default: MEARL_SERVER_URL env or config file) | ||
| --timeout <seconds> Request timeout in seconds (default: action-specific; normally 60) | ||
| --connector <id|name> Target a browser-side cloud connector | ||
| --browser <id|name> Target a specific browser (multi-browser; defaults to most-recently focused) | ||
@@ -437,6 +879,10 @@ --help, -h Show this help message | ||
| # List browsers, then target a connected one explicitly | ||
| mearl-cloud connector_list | ||
| mearl-cloud browser_list | ||
| mearl-cloud get_requests --browser edge --payload '{"count": 5}' | ||
| # Diagnose the complete cloud connection path | ||
| mearl-cloud check | ||
| `); | ||
| process.exit(1); | ||
| process.exit(exitCode); | ||
| } | ||
@@ -457,3 +903,3 @@ function saveOutputToFile(result, outputPath) { | ||
| if (args.length === 0 || args.includes("--help") || args.includes("-h")) { | ||
| showHelp(); | ||
| showHelp(args.length === 0 ? 1 : 0); | ||
| } | ||
@@ -475,2 +921,3 @@ const action = args[0]; | ||
| const outputPath = getArgValue("--output"); | ||
| const connector = getArgValue("--connector"); | ||
| const browser = getArgValue("--browser"); | ||
@@ -501,3 +948,3 @@ let payload = {}; | ||
| }); | ||
| return { action, client, payload, outputPath, timeoutSec, browser }; | ||
| return { action, client, payload, outputPath, timeoutSec, connector, browser }; | ||
| } | ||
@@ -512,5 +959,26 @@ function getArgValue(name) { | ||
| async function main() { | ||
| const { action, client, payload, outputPath, browser } = parseArgs(); | ||
| if (args[0] === "check") { | ||
| if (args.includes("--help") || args.includes("-h")) showHelp(0); | ||
| const explicitServerUrl = getArgValue("--server"); | ||
| const envServerUrl = process.env.MEARL_SERVER_URL; | ||
| const config = explicitServerUrl || envServerUrl ? null : loadConfigFile(); | ||
| const serverUrl = explicitServerUrl || envServerUrl || config?.server; | ||
| const serverUrlSource = explicitServerUrl ? "--server" : envServerUrl ? "MEARL_SERVER_URL" : config?.server ? getConfigPath() : void 0; | ||
| const timeoutSec = parseCloudCheckTimeout(getArgValue("--timeout")); | ||
| if (timeoutSec === null) { | ||
| console.error("Error: --timeout must be a positive integer number of seconds"); | ||
| process.exit(2); | ||
| } | ||
| const ok = await runCloudCheck({ | ||
| clientVersion: CLOUD_CLIENT_VERSION, | ||
| serverUrl, | ||
| serverUrlSource, | ||
| timeoutSec, | ||
| connector: getArgValue("--connector") | ||
| }); | ||
| process.exit(ok ? 0 : 1); | ||
| } | ||
| const { action, client, payload, outputPath, connector, browser } = parseArgs(); | ||
| try { | ||
| const result = await client.invoke(action, payload, { browser }); | ||
| const result = await client.invoke(action, payload, { connector, browser }); | ||
| if (outputPath) { | ||
@@ -517,0 +985,0 @@ saveOutputToFile(result, outputPath); |
| import type * as Client from '@mearl/client'; | ||
| export declare function getRequests(...args: Parameters<typeof Client.getRequests>): ReturnType<typeof Client.getRequests>; | ||
| export declare function getLogs(...args: Parameters<typeof Client.getLogs>): ReturnType<typeof Client.getLogs>; | ||
| export declare function getEvents(...args: Parameters<typeof Client.getEvents>): ReturnType<typeof Client.getEvents>; | ||
| export declare function setMock(...args: Parameters<typeof Client.setMock>): ReturnType<typeof Client.setMock>; | ||
| export declare function getMocks(...args: Parameters<typeof Client.getMocks>): ReturnType<typeof Client.getMocks>; | ||
| export declare function getApiSchema(...args: Parameters<typeof Client.getApiSchema>): ReturnType<typeof Client.getApiSchema>; | ||
| export declare function sendRequest(...args: Parameters<typeof Client.sendRequest>): ReturnType<typeof Client.sendRequest>; | ||
| export declare function sendMtopRequest(...args: Parameters<typeof Client.sendMtopRequest>): ReturnType<typeof Client.sendMtopRequest>; | ||
| export declare function tdbankAccount(...args: Parameters<typeof Client.tdbankAccount>): ReturnType<typeof Client.tdbankAccount>; | ||
| export declare function browserList(..._args: Parameters<typeof Client.browserList>): ReturnType<typeof Client.browserList>; | ||
| export declare function selectBrowser(...args: Parameters<typeof Client.selectBrowser>): ReturnType<typeof Client.selectBrowser>; | ||
| export declare function browserRelease(..._args: Parameters<typeof Client.browserRelease>): ReturnType<typeof Client.browserRelease>; | ||
| export declare function browserLaunch(...args: Parameters<typeof Client.browserLaunch>): ReturnType<typeof Client.browserLaunch>; | ||
| export declare function browserClose(...args: Parameters<typeof Client.browserClose>): ReturnType<typeof Client.browserClose>; | ||
| export declare function setRule(...args: Parameters<typeof Client.setRule>): ReturnType<typeof Client.setRule>; | ||
| export declare function getRules(..._args: Parameters<typeof Client.getRules>): ReturnType<typeof Client.getRules>; | ||
| export declare function pageScreenshot(...args: Parameters<typeof Client.pageScreenshot>): ReturnType<typeof Client.pageScreenshot>; | ||
| export declare function pageSelectedElement(...args: Parameters<typeof Client.pageSelectedElement>): ReturnType<typeof Client.pageSelectedElement>; | ||
| export declare function tabOpen(...args: Parameters<typeof Client.tabOpen>): ReturnType<typeof Client.tabOpen>; | ||
| export declare function tabClose(...args: Parameters<typeof Client.tabClose>): ReturnType<typeof Client.tabClose>; | ||
| export declare function tabList(..._args: Parameters<typeof Client.tabList>): ReturnType<typeof Client.tabList>; | ||
| export declare function pageClick(...args: Parameters<typeof Client.pageClick>): ReturnType<typeof Client.pageClick>; | ||
| export declare function pageType(...args: Parameters<typeof Client.pageType>): ReturnType<typeof Client.pageType>; | ||
| export declare function pageScroll(...args: Parameters<typeof Client.pageScroll>): ReturnType<typeof Client.pageScroll>; | ||
| export declare function pageHover(...args: Parameters<typeof Client.pageHover>): ReturnType<typeof Client.pageHover>; | ||
| export declare function pageEval(...args: Parameters<typeof Client.pageEval>): ReturnType<typeof Client.pageEval>; | ||
| export declare function pageSnapshot(...args: Parameters<typeof Client.pageSnapshot>): ReturnType<typeof Client.pageSnapshot>; | ||
| export declare function pagePress(...args: Parameters<typeof Client.pagePress>): ReturnType<typeof Client.pagePress>; | ||
| export declare function pageWait(...args: Parameters<typeof Client.pageWait>): ReturnType<typeof Client.pageWait>; | ||
| export declare function pageNavigate(...args: Parameters<typeof Client.pageNavigate>): ReturnType<typeof Client.pageNavigate>; | ||
| export declare function pageUpload(...args: Parameters<typeof Client.pageUpload>): ReturnType<typeof Client.pageUpload>; | ||
| export declare function pageFrames(...args: Parameters<typeof Client.pageFrames>): ReturnType<typeof Client.pageFrames>; | ||
| export declare function setDeviceEmulation(...args: Parameters<typeof Client.setDeviceEmulation>): ReturnType<typeof Client.setDeviceEmulation>; | ||
| export declare function setTimezone(...args: Parameters<typeof Client.setTimezone>): ReturnType<typeof Client.setTimezone>; | ||
| export declare function getCookie(...args: Parameters<typeof Client.getCookie>): ReturnType<typeof Client.getCookie>; | ||
| export declare function setCookie(...args: Parameters<typeof Client.setCookie>): ReturnType<typeof Client.setCookie>; | ||
| export declare function getUserInfo(...args: Parameters<typeof Client.getUserInfo>): ReturnType<typeof Client.getUserInfo>; | ||
| export declare function runActions(...args: Parameters<typeof Client.runActions>): ReturnType<typeof Client.runActions>; | ||
| import type { CloudInvokeOptions } from './invoke-options.js'; | ||
| export declare function getRequests(...args: [...Parameters<typeof Client.getRequests>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getRequests>; | ||
| export declare function getLogs(...args: [...Parameters<typeof Client.getLogs>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getLogs>; | ||
| export declare function getEvents(...args: [...Parameters<typeof Client.getEvents>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getEvents>; | ||
| export declare function setMock(...args: [...Parameters<typeof Client.setMock>, options?: CloudInvokeOptions]): ReturnType<typeof Client.setMock>; | ||
| export declare function getMocks(...args: [...Parameters<typeof Client.getMocks>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getMocks>; | ||
| export declare function getApiSchema(...args: [...Parameters<typeof Client.getApiSchema>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getApiSchema>; | ||
| export declare function sendRequest(...args: [...Parameters<typeof Client.sendRequest>, options?: CloudInvokeOptions]): ReturnType<typeof Client.sendRequest>; | ||
| export declare function sendMtopRequest(...args: [...Parameters<typeof Client.sendMtopRequest>, options?: CloudInvokeOptions]): ReturnType<typeof Client.sendMtopRequest>; | ||
| export declare function tdbankAccount(...args: [...Parameters<typeof Client.tdbankAccount>, options?: CloudInvokeOptions]): ReturnType<typeof Client.tdbankAccount>; | ||
| export declare function browserList(...args: [...Parameters<typeof Client.browserList>, options?: CloudInvokeOptions]): ReturnType<typeof Client.browserList>; | ||
| export declare function selectBrowser(...args: [...Parameters<typeof Client.selectBrowser>, options?: CloudInvokeOptions]): ReturnType<typeof Client.selectBrowser>; | ||
| export declare function browserRelease(...args: [...Parameters<typeof Client.browserRelease>, options?: CloudInvokeOptions]): ReturnType<typeof Client.browserRelease>; | ||
| export declare function browserLaunch(...args: [...Parameters<typeof Client.browserLaunch>, options?: CloudInvokeOptions]): ReturnType<typeof Client.browserLaunch>; | ||
| export declare function browserClose(...args: [...Parameters<typeof Client.browserClose>, options?: CloudInvokeOptions]): ReturnType<typeof Client.browserClose>; | ||
| export declare function setRule(...args: [...Parameters<typeof Client.setRule>, options?: CloudInvokeOptions]): ReturnType<typeof Client.setRule>; | ||
| export declare function getRules(...args: [...Parameters<typeof Client.getRules>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getRules>; | ||
| export declare function pageScreenshot(...args: [...Parameters<typeof Client.pageScreenshot>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageScreenshot>; | ||
| export declare function pageSelectedElement(...args: [...Parameters<typeof Client.pageSelectedElement>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageSelectedElement>; | ||
| export declare function tabOpen(...args: [...Parameters<typeof Client.tabOpen>, options?: CloudInvokeOptions]): ReturnType<typeof Client.tabOpen>; | ||
| export declare function tabClose(...args: [...Parameters<typeof Client.tabClose>, options?: CloudInvokeOptions]): ReturnType<typeof Client.tabClose>; | ||
| export declare function tabList(...args: [...Parameters<typeof Client.tabList>, options?: CloudInvokeOptions]): ReturnType<typeof Client.tabList>; | ||
| export declare function pageClick(...args: [...Parameters<typeof Client.pageClick>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageClick>; | ||
| export declare function pageType(...args: [...Parameters<typeof Client.pageType>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageType>; | ||
| export declare function pageScroll(...args: [...Parameters<typeof Client.pageScroll>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageScroll>; | ||
| export declare function pageHover(...args: [...Parameters<typeof Client.pageHover>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageHover>; | ||
| export declare function pageEval(...args: [...Parameters<typeof Client.pageEval>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageEval>; | ||
| export declare function pageSnapshot(...args: [...Parameters<typeof Client.pageSnapshot>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageSnapshot>; | ||
| export declare function pagePress(...args: [...Parameters<typeof Client.pagePress>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pagePress>; | ||
| export declare function pageWait(...args: [...Parameters<typeof Client.pageWait>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageWait>; | ||
| export declare function pageNavigate(...args: [...Parameters<typeof Client.pageNavigate>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageNavigate>; | ||
| export declare function pageUpload(...args: [...Parameters<typeof Client.pageUpload>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageUpload>; | ||
| export declare function pageFrames(...args: [...Parameters<typeof Client.pageFrames>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageFrames>; | ||
| export declare function setDeviceEmulation(...args: [...Parameters<typeof Client.setDeviceEmulation>, options?: CloudInvokeOptions]): ReturnType<typeof Client.setDeviceEmulation>; | ||
| export declare function setTimezone(...args: [...Parameters<typeof Client.setTimezone>, options?: CloudInvokeOptions]): ReturnType<typeof Client.setTimezone>; | ||
| export declare function getCookie(...args: [...Parameters<typeof Client.getCookie>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getCookie>; | ||
| export declare function setCookie(...args: [...Parameters<typeof Client.setCookie>, options?: CloudInvokeOptions]): ReturnType<typeof Client.setCookie>; | ||
| export declare function getUserInfo(...args: [...Parameters<typeof Client.getUserInfo>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getUserInfo>; | ||
| export declare function runActions(...args: [...Parameters<typeof Client.runActions>, options?: CloudInvokeOptions]): ReturnType<typeof Client.runActions>; |
| import type * as Client from '@mearl/client'; | ||
| import type { CloudInvokeOptions } from './invoke-options.js'; | ||
| export declare abstract class CloudClientApiBase { | ||
| abstract invoke(action: string, data?: Record<string, any>): Promise<any>; | ||
| getRequests(...args: Parameters<typeof Client.getRequests>): ReturnType<typeof Client.getRequests>; | ||
| getLogs(...args: Parameters<typeof Client.getLogs>): ReturnType<typeof Client.getLogs>; | ||
| getEvents(...args: Parameters<typeof Client.getEvents>): ReturnType<typeof Client.getEvents>; | ||
| setMock(...args: Parameters<typeof Client.setMock>): ReturnType<typeof Client.setMock>; | ||
| getMocks(...args: Parameters<typeof Client.getMocks>): ReturnType<typeof Client.getMocks>; | ||
| getApiSchema(...args: Parameters<typeof Client.getApiSchema>): ReturnType<typeof Client.getApiSchema>; | ||
| sendRequest(...args: Parameters<typeof Client.sendRequest>): ReturnType<typeof Client.sendRequest>; | ||
| sendMtopRequest(...args: Parameters<typeof Client.sendMtopRequest>): ReturnType<typeof Client.sendMtopRequest>; | ||
| tdbankAccount(...args: Parameters<typeof Client.tdbankAccount>): ReturnType<typeof Client.tdbankAccount>; | ||
| browserList(..._args: Parameters<typeof Client.browserList>): ReturnType<typeof Client.browserList>; | ||
| selectBrowser(...args: Parameters<typeof Client.selectBrowser>): ReturnType<typeof Client.selectBrowser>; | ||
| browserRelease(..._args: Parameters<typeof Client.browserRelease>): ReturnType<typeof Client.browserRelease>; | ||
| browserLaunch(...args: Parameters<typeof Client.browserLaunch>): ReturnType<typeof Client.browserLaunch>; | ||
| browserClose(...args: Parameters<typeof Client.browserClose>): ReturnType<typeof Client.browserClose>; | ||
| setRule(...args: Parameters<typeof Client.setRule>): ReturnType<typeof Client.setRule>; | ||
| getRules(..._args: Parameters<typeof Client.getRules>): ReturnType<typeof Client.getRules>; | ||
| pageScreenshot(...args: Parameters<typeof Client.pageScreenshot>): ReturnType<typeof Client.pageScreenshot>; | ||
| pageSelectedElement(...args: Parameters<typeof Client.pageSelectedElement>): ReturnType<typeof Client.pageSelectedElement>; | ||
| tabOpen(...args: Parameters<typeof Client.tabOpen>): ReturnType<typeof Client.tabOpen>; | ||
| tabClose(...args: Parameters<typeof Client.tabClose>): ReturnType<typeof Client.tabClose>; | ||
| tabList(..._args: Parameters<typeof Client.tabList>): ReturnType<typeof Client.tabList>; | ||
| pageClick(...args: Parameters<typeof Client.pageClick>): ReturnType<typeof Client.pageClick>; | ||
| pageType(...args: Parameters<typeof Client.pageType>): ReturnType<typeof Client.pageType>; | ||
| pageScroll(...args: Parameters<typeof Client.pageScroll>): ReturnType<typeof Client.pageScroll>; | ||
| pageHover(...args: Parameters<typeof Client.pageHover>): ReturnType<typeof Client.pageHover>; | ||
| pageEval(...args: Parameters<typeof Client.pageEval>): ReturnType<typeof Client.pageEval>; | ||
| pageSnapshot(...args: Parameters<typeof Client.pageSnapshot>): ReturnType<typeof Client.pageSnapshot>; | ||
| pagePress(...args: Parameters<typeof Client.pagePress>): ReturnType<typeof Client.pagePress>; | ||
| pageWait(...args: Parameters<typeof Client.pageWait>): ReturnType<typeof Client.pageWait>; | ||
| pageNavigate(...args: Parameters<typeof Client.pageNavigate>): ReturnType<typeof Client.pageNavigate>; | ||
| pageUpload(...args: Parameters<typeof Client.pageUpload>): ReturnType<typeof Client.pageUpload>; | ||
| pageFrames(...args: Parameters<typeof Client.pageFrames>): ReturnType<typeof Client.pageFrames>; | ||
| setDeviceEmulation(...args: Parameters<typeof Client.setDeviceEmulation>): ReturnType<typeof Client.setDeviceEmulation>; | ||
| setTimezone(...args: Parameters<typeof Client.setTimezone>): ReturnType<typeof Client.setTimezone>; | ||
| getCookie(...args: Parameters<typeof Client.getCookie>): ReturnType<typeof Client.getCookie>; | ||
| setCookie(...args: Parameters<typeof Client.setCookie>): ReturnType<typeof Client.setCookie>; | ||
| getUserInfo(...args: Parameters<typeof Client.getUserInfo>): ReturnType<typeof Client.getUserInfo>; | ||
| runActions(...args: Parameters<typeof Client.runActions>): ReturnType<typeof Client.runActions>; | ||
| abstract invoke(action: string, data?: Record<string, any>, options?: CloudInvokeOptions): Promise<any>; | ||
| getRequests(...args: [...Parameters<typeof Client.getRequests>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getRequests>; | ||
| getLogs(...args: [...Parameters<typeof Client.getLogs>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getLogs>; | ||
| getEvents(...args: [...Parameters<typeof Client.getEvents>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getEvents>; | ||
| setMock(...args: [...Parameters<typeof Client.setMock>, options?: CloudInvokeOptions]): ReturnType<typeof Client.setMock>; | ||
| getMocks(...args: [...Parameters<typeof Client.getMocks>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getMocks>; | ||
| getApiSchema(...args: [...Parameters<typeof Client.getApiSchema>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getApiSchema>; | ||
| sendRequest(...args: [...Parameters<typeof Client.sendRequest>, options?: CloudInvokeOptions]): ReturnType<typeof Client.sendRequest>; | ||
| sendMtopRequest(...args: [...Parameters<typeof Client.sendMtopRequest>, options?: CloudInvokeOptions]): ReturnType<typeof Client.sendMtopRequest>; | ||
| tdbankAccount(...args: [...Parameters<typeof Client.tdbankAccount>, options?: CloudInvokeOptions]): ReturnType<typeof Client.tdbankAccount>; | ||
| browserList(...args: [...Parameters<typeof Client.browserList>, options?: CloudInvokeOptions]): ReturnType<typeof Client.browserList>; | ||
| selectBrowser(...args: [...Parameters<typeof Client.selectBrowser>, options?: CloudInvokeOptions]): ReturnType<typeof Client.selectBrowser>; | ||
| browserRelease(...args: [...Parameters<typeof Client.browserRelease>, options?: CloudInvokeOptions]): ReturnType<typeof Client.browserRelease>; | ||
| browserLaunch(...args: [...Parameters<typeof Client.browserLaunch>, options?: CloudInvokeOptions]): ReturnType<typeof Client.browserLaunch>; | ||
| browserClose(...args: [...Parameters<typeof Client.browserClose>, options?: CloudInvokeOptions]): ReturnType<typeof Client.browserClose>; | ||
| setRule(...args: [...Parameters<typeof Client.setRule>, options?: CloudInvokeOptions]): ReturnType<typeof Client.setRule>; | ||
| getRules(...args: [...Parameters<typeof Client.getRules>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getRules>; | ||
| pageScreenshot(...args: [...Parameters<typeof Client.pageScreenshot>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageScreenshot>; | ||
| pageSelectedElement(...args: [...Parameters<typeof Client.pageSelectedElement>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageSelectedElement>; | ||
| tabOpen(...args: [...Parameters<typeof Client.tabOpen>, options?: CloudInvokeOptions]): ReturnType<typeof Client.tabOpen>; | ||
| tabClose(...args: [...Parameters<typeof Client.tabClose>, options?: CloudInvokeOptions]): ReturnType<typeof Client.tabClose>; | ||
| tabList(...args: [...Parameters<typeof Client.tabList>, options?: CloudInvokeOptions]): ReturnType<typeof Client.tabList>; | ||
| pageClick(...args: [...Parameters<typeof Client.pageClick>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageClick>; | ||
| pageType(...args: [...Parameters<typeof Client.pageType>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageType>; | ||
| pageScroll(...args: [...Parameters<typeof Client.pageScroll>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageScroll>; | ||
| pageHover(...args: [...Parameters<typeof Client.pageHover>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageHover>; | ||
| pageEval(...args: [...Parameters<typeof Client.pageEval>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageEval>; | ||
| pageSnapshot(...args: [...Parameters<typeof Client.pageSnapshot>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageSnapshot>; | ||
| pagePress(...args: [...Parameters<typeof Client.pagePress>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pagePress>; | ||
| pageWait(...args: [...Parameters<typeof Client.pageWait>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageWait>; | ||
| pageNavigate(...args: [...Parameters<typeof Client.pageNavigate>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageNavigate>; | ||
| pageUpload(...args: [...Parameters<typeof Client.pageUpload>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageUpload>; | ||
| pageFrames(...args: [...Parameters<typeof Client.pageFrames>, options?: CloudInvokeOptions]): ReturnType<typeof Client.pageFrames>; | ||
| setDeviceEmulation(...args: [...Parameters<typeof Client.setDeviceEmulation>, options?: CloudInvokeOptions]): ReturnType<typeof Client.setDeviceEmulation>; | ||
| setTimezone(...args: [...Parameters<typeof Client.setTimezone>, options?: CloudInvokeOptions]): ReturnType<typeof Client.setTimezone>; | ||
| getCookie(...args: [...Parameters<typeof Client.getCookie>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getCookie>; | ||
| setCookie(...args: [...Parameters<typeof Client.setCookie>, options?: CloudInvokeOptions]): ReturnType<typeof Client.setCookie>; | ||
| getUserInfo(...args: [...Parameters<typeof Client.getUserInfo>, options?: CloudInvokeOptions]): ReturnType<typeof Client.getUserInfo>; | ||
| runActions(...args: [...Parameters<typeof Client.runActions>, options?: CloudInvokeOptions]): ReturnType<typeof Client.runActions>; | ||
| } |
@@ -1,1 +0,1 @@ | ||
| export type { ActionStep, BrowserCloseParams, BrowserInfo, BrowserInfoBase, BrowserLaunchParams, BrowserListResult, BrowserReleaseFailure, BrowserReleaseResult, BrowserStatus, DevicePresetName, EmulationOptions, GetApiSchemaParams, GetCookieParams, GetCookieResult, GetEventsParams, GetLogsParams, GetMocksParams, GetRequestsParams, GetUserInfoParams, InvokeOptions, ManagedBrowserAccount, ManagedBrowserInfo, PageClickParams, PageEvalParams, PageFramesParams, PageHoverParams, PageNavigateParams, PageObserveOptions, PagePressParams, PageScreenshotParams, PageScrollParams, PageSelectedElementParams, PageSnapshotParams, PageSnapshotQuery, PageTypeParams, PageUploadParams, PageWaitParams, RegularBrowserInfo, RunActionsParams, SelectBrowserParams, SelectBrowserResult, SendMtopRequestParams, SendRequestParams, SetCookieParams, SetCookieResult, SetDeviceEmulationParams, SetMockParams, SetRuleParams, SetTimezoneParams, SetTimezoneResult, TabCloseParams, TabOpenParams, TdbankAccountParams, } from '@mearl/client'; | ||
| export type { ActionStep, BrowserAction, BrowserActionMap, BrowserActionRequest, BrowserActionResponse, BrowserCloseParams, BrowserCommandAction, BrowserDevicePresetName, BrowserEmulationOptions, BrowserInfo, BrowserInfoBase, BrowserLaunchParams, BrowserListResult, BrowserReleaseFailure, BrowserReleaseResult, BrowserStatus, ExtensionBrowserAction, GetApiSchemaParams, GetCookieParams, GetCookieResult, GetEventsParams, GetLogsParams, GetMocksParams, GetRequestsParams, GetUserInfoParams, InvokeOptions, ManagedBrowserAccount, ManagedBrowserInfo, PageActAction, PageClickParams, PageEvalParams, PageFramesParams, PageHoverParams, PageNavigateParams, PageObservationWaitOptions, PagePressParams, PageScreenshotParams, PageScrollParams, PageSelectedElementParams, PageSnapshotParams, PageSnapshotQuery, PageTypeParams, PageUploadParams, PageWaitParams, RecordParams, RegularBrowserInfo, RequestDomainPermissionParams, RulesResult, RunActionName, RunActionsParams, SelectBrowserParams, SelectBrowserResult, SendMtopRequestParams, SendRequestParams, SetCookieParams, SetCookieResult, SetDeviceEmulationParams, SetMockParams, SetRuleParams, SetTimezoneParams, SetTimezoneResult, TabCloseParams, TabOpenParams, TdbankAccountParams, } from '@mearl/client'; |
+8
-5
@@ -0,4 +1,8 @@ | ||
| import { CloudConnectorListResult } from '@mearl/cloud-types'; | ||
| import { CloudClientApiBase } from './generated-client-methods.js'; | ||
| import type { CloudInvokeOptions } from './invoke-options.js'; | ||
| export type * from './generated-client-types.js'; | ||
| export * from './generated-client-exports.js'; | ||
| export type { CloudConnectorInfo, CloudConnectorListResult } from '@mearl/cloud-types'; | ||
| export type { CloudInvokeOptions } from './invoke-options.js'; | ||
| export interface CloudClientOptions { | ||
@@ -10,11 +14,8 @@ serverUrl: string; | ||
| defaultBrowser?: string; | ||
| defaultConnector?: string; | ||
| } | ||
| export interface CloudInvokeOptions { | ||
| timeoutSec?: number; | ||
| /** Target a specific browser on the connector's machine by id / name. */ | ||
| browser?: string; | ||
| } | ||
| export declare class CloudClient extends CloudClientApiBase { | ||
| private options; | ||
| private defaultBrowser; | ||
| private defaultConnector; | ||
| private ws; | ||
@@ -36,2 +37,3 @@ private connectPromise; | ||
| invoke(action: string, data?: Record<string, any>, options?: CloudInvokeOptions): Promise<any>; | ||
| listCloudConnectors(): Promise<CloudConnectorListResult>; | ||
| private selectDefaultBrowser; | ||
@@ -41,1 +43,2 @@ private rejectAllPending; | ||
| export declare function invoke(action: string, data?: Record<string, any>, options?: CloudInvokeOptions): Promise<any>; | ||
| export declare function listCloudConnectors(): Promise<CloudConnectorListResult>; |
+192
-90
@@ -40,30 +40,50 @@ // src/index.ts | ||
| getRequests(...args) { | ||
| return this.invoke("get_requests", args[0] ?? {}); | ||
| return this.invoke( | ||
| "get_requests", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| getLogs(...args) { | ||
| return this.invoke("get_logs", args[0] ?? {}); | ||
| return this.invoke("get_logs", args[0] ?? {}, args[1]); | ||
| } | ||
| getEvents(...args) { | ||
| return this.invoke("get_events", args[0] ?? {}); | ||
| return this.invoke("get_events", args[0] ?? {}, args[1]); | ||
| } | ||
| setMock(...args) { | ||
| return this.invoke("set_mock", args[0] ?? {}); | ||
| return this.invoke("set_mock", args[0] ?? {}, args[1]); | ||
| } | ||
| getMocks(...args) { | ||
| return this.invoke("get_mocks", args[0] ?? {}); | ||
| return this.invoke("get_mocks", args[0] ?? {}, args[1]); | ||
| } | ||
| getApiSchema(...args) { | ||
| return this.invoke("get_api_schema", args[0] ?? {}); | ||
| return this.invoke( | ||
| "get_api_schema", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| sendRequest(...args) { | ||
| return this.invoke("send_request", args[0] ?? {}); | ||
| return this.invoke( | ||
| "send_request", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| sendMtopRequest(...args) { | ||
| return this.invoke("send_mtop_request", args[0] ?? {}); | ||
| return this.invoke( | ||
| "send_mtop_request", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| tdbankAccount(...args) { | ||
| return this.invoke("tdbank_account", args[0] ?? {}); | ||
| return this.invoke( | ||
| "tdbank_account", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| browserList(..._args) { | ||
| return this.invoke("browser_list", {}); | ||
| browserList(...args) { | ||
| return this.invoke("browser_list", {}, args[0]); | ||
| } | ||
@@ -73,22 +93,35 @@ selectBrowser(...args) { | ||
| "browser_select_browser", | ||
| args[0] ?? {} | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| browserRelease(..._args) { | ||
| return this.invoke("browser_release", {}); | ||
| browserRelease(...args) { | ||
| return this.invoke("browser_release", {}, args[0]); | ||
| } | ||
| browserLaunch(...args) { | ||
| return this.invoke("browser_launch", args[0] ?? {}); | ||
| return this.invoke( | ||
| "browser_launch", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| browserClose(...args) { | ||
| return this.invoke("browser_close", args[0] ?? {}); | ||
| return this.invoke( | ||
| "browser_close", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| setRule(...args) { | ||
| return this.invoke("set_rule", args[0] ?? {}); | ||
| return this.invoke("set_rule", args[0] ?? {}, args[1]); | ||
| } | ||
| getRules(..._args) { | ||
| return this.invoke("get_rules", {}); | ||
| getRules(...args) { | ||
| return this.invoke("get_rules", {}, args[0]); | ||
| } | ||
| pageScreenshot(...args) { | ||
| return this.invoke("page_screenshot", args[0] ?? {}); | ||
| return this.invoke( | ||
| "page_screenshot", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
@@ -98,46 +131,67 @@ pageSelectedElement(...args) { | ||
| "page_selected_element", | ||
| args[0] ?? {} | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| tabOpen(...args) { | ||
| return this.invoke("tab_open", args[0] ?? {}); | ||
| return this.invoke("tab_open", args[0] ?? {}, args[1]); | ||
| } | ||
| tabClose(...args) { | ||
| return this.invoke("tab_close", args[0] ?? {}); | ||
| return this.invoke("tab_close", args[0] ?? {}, args[1]); | ||
| } | ||
| tabList(..._args) { | ||
| return this.invoke("tab_list", {}); | ||
| tabList(...args) { | ||
| return this.invoke("tab_list", {}, args[0]); | ||
| } | ||
| pageClick(...args) { | ||
| return this.invoke("page_click", args[0] ?? {}); | ||
| return this.invoke("page_click", args[0] ?? {}, args[1]); | ||
| } | ||
| pageType(...args) { | ||
| return this.invoke("page_type", args[0] ?? {}); | ||
| return this.invoke("page_type", args[0] ?? {}, args[1]); | ||
| } | ||
| pageScroll(...args) { | ||
| return this.invoke("page_scroll", args[0] ?? {}); | ||
| return this.invoke( | ||
| "page_scroll", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| pageHover(...args) { | ||
| return this.invoke("page_hover", args[0] ?? {}); | ||
| return this.invoke("page_hover", args[0] ?? {}, args[1]); | ||
| } | ||
| pageEval(...args) { | ||
| return this.invoke("page_eval", args[0] ?? {}); | ||
| return this.invoke("page_eval", args[0] ?? {}, args[1]); | ||
| } | ||
| pageSnapshot(...args) { | ||
| return this.invoke("page_snapshot", args[0] ?? {}); | ||
| return this.invoke( | ||
| "page_snapshot", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| pagePress(...args) { | ||
| return this.invoke("page_press", args[0] ?? {}); | ||
| return this.invoke("page_press", args[0] ?? {}, args[1]); | ||
| } | ||
| pageWait(...args) { | ||
| return this.invoke("page_wait", args[0] ?? {}); | ||
| return this.invoke("page_wait", args[0] ?? {}, args[1]); | ||
| } | ||
| pageNavigate(...args) { | ||
| return this.invoke("page_navigate", args[0] ?? {}); | ||
| return this.invoke( | ||
| "page_navigate", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| pageUpload(...args) { | ||
| return this.invoke("page_upload", args[0] ?? {}); | ||
| return this.invoke( | ||
| "page_upload", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| pageFrames(...args) { | ||
| return this.invoke("page_frames", args[0] ?? {}); | ||
| return this.invoke( | ||
| "page_frames", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
@@ -147,19 +201,32 @@ setDeviceEmulation(...args) { | ||
| "set_device_emulation", | ||
| args[0] ?? {} | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| setTimezone(...args) { | ||
| return this.invoke("set_timezone", args[0] ?? {}); | ||
| return this.invoke( | ||
| "set_timezone", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| getCookie(...args) { | ||
| return this.invoke("get_cookie", args[0] ?? {}); | ||
| return this.invoke("get_cookie", args[0] ?? {}, args[1]); | ||
| } | ||
| setCookie(...args) { | ||
| return this.invoke("set_cookie", args[0] ?? {}); | ||
| return this.invoke("set_cookie", args[0] ?? {}, args[1]); | ||
| } | ||
| getUserInfo(...args) { | ||
| return this.invoke("get_user_info", args[0] ?? {}); | ||
| return this.invoke( | ||
| "get_user_info", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| runActions(...args) { | ||
| return this.invoke("run_actions", args[0] ?? {}); | ||
| return this.invoke( | ||
| "run_actions", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
@@ -170,114 +237,126 @@ }; | ||
| function getRequests(...args) { | ||
| return invoke("get_requests", args[0] ?? {}); | ||
| return invoke("get_requests", args[0] ?? {}, args[1]); | ||
| } | ||
| function getLogs(...args) { | ||
| return invoke("get_logs", args[0] ?? {}); | ||
| return invoke("get_logs", args[0] ?? {}, args[1]); | ||
| } | ||
| function getEvents(...args) { | ||
| return invoke("get_events", args[0] ?? {}); | ||
| return invoke("get_events", args[0] ?? {}, args[1]); | ||
| } | ||
| function setMock(...args) { | ||
| return invoke("set_mock", args[0] ?? {}); | ||
| return invoke("set_mock", args[0] ?? {}, args[1]); | ||
| } | ||
| function getMocks(...args) { | ||
| return invoke("get_mocks", args[0] ?? {}); | ||
| return invoke("get_mocks", args[0] ?? {}, args[1]); | ||
| } | ||
| function getApiSchema(...args) { | ||
| return invoke("get_api_schema", args[0] ?? {}); | ||
| return invoke("get_api_schema", args[0] ?? {}, args[1]); | ||
| } | ||
| function sendRequest(...args) { | ||
| return invoke("send_request", args[0] ?? {}); | ||
| return invoke("send_request", args[0] ?? {}, args[1]); | ||
| } | ||
| function sendMtopRequest(...args) { | ||
| return invoke("send_mtop_request", args[0] ?? {}); | ||
| return invoke("send_mtop_request", args[0] ?? {}, args[1]); | ||
| } | ||
| function tdbankAccount(...args) { | ||
| return invoke("tdbank_account", args[0] ?? {}); | ||
| return invoke("tdbank_account", args[0] ?? {}, args[1]); | ||
| } | ||
| function browserList(..._args) { | ||
| return invoke("browser_list", {}); | ||
| function browserList(...args) { | ||
| return invoke("browser_list", {}, args[0]); | ||
| } | ||
| function selectBrowser(...args) { | ||
| return invoke("browser_select_browser", args[0] ?? {}); | ||
| return invoke( | ||
| "browser_select_browser", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| function browserRelease(..._args) { | ||
| return invoke("browser_release", {}); | ||
| function browserRelease(...args) { | ||
| return invoke("browser_release", {}, args[0]); | ||
| } | ||
| function browserLaunch(...args) { | ||
| return invoke("browser_launch", args[0] ?? {}); | ||
| return invoke("browser_launch", args[0] ?? {}, args[1]); | ||
| } | ||
| function browserClose(...args) { | ||
| return invoke("browser_close", args[0] ?? {}); | ||
| return invoke("browser_close", args[0] ?? {}, args[1]); | ||
| } | ||
| function setRule(...args) { | ||
| return invoke("set_rule", args[0] ?? {}); | ||
| return invoke("set_rule", args[0] ?? {}, args[1]); | ||
| } | ||
| function getRules(..._args) { | ||
| return invoke("get_rules", {}); | ||
| function getRules(...args) { | ||
| return invoke("get_rules", {}, args[0]); | ||
| } | ||
| function pageScreenshot(...args) { | ||
| return invoke("page_screenshot", args[0] ?? {}); | ||
| return invoke("page_screenshot", args[0] ?? {}, args[1]); | ||
| } | ||
| function pageSelectedElement(...args) { | ||
| return invoke("page_selected_element", args[0] ?? {}); | ||
| return invoke( | ||
| "page_selected_element", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| function tabOpen(...args) { | ||
| return invoke("tab_open", args[0] ?? {}); | ||
| return invoke("tab_open", args[0] ?? {}, args[1]); | ||
| } | ||
| function tabClose(...args) { | ||
| return invoke("tab_close", args[0] ?? {}); | ||
| return invoke("tab_close", args[0] ?? {}, args[1]); | ||
| } | ||
| function tabList(..._args) { | ||
| return invoke("tab_list", {}); | ||
| function tabList(...args) { | ||
| return invoke("tab_list", {}, args[0]); | ||
| } | ||
| function pageClick(...args) { | ||
| return invoke("page_click", args[0] ?? {}); | ||
| return invoke("page_click", args[0] ?? {}, args[1]); | ||
| } | ||
| function pageType(...args) { | ||
| return invoke("page_type", args[0] ?? {}); | ||
| return invoke("page_type", args[0] ?? {}, args[1]); | ||
| } | ||
| function pageScroll(...args) { | ||
| return invoke("page_scroll", args[0] ?? {}); | ||
| return invoke("page_scroll", args[0] ?? {}, args[1]); | ||
| } | ||
| function pageHover(...args) { | ||
| return invoke("page_hover", args[0] ?? {}); | ||
| return invoke("page_hover", args[0] ?? {}, args[1]); | ||
| } | ||
| function pageEval(...args) { | ||
| return invoke("page_eval", args[0] ?? {}); | ||
| return invoke("page_eval", args[0] ?? {}, args[1]); | ||
| } | ||
| function pageSnapshot(...args) { | ||
| return invoke("page_snapshot", args[0] ?? {}); | ||
| return invoke("page_snapshot", args[0] ?? {}, args[1]); | ||
| } | ||
| function pagePress(...args) { | ||
| return invoke("page_press", args[0] ?? {}); | ||
| return invoke("page_press", args[0] ?? {}, args[1]); | ||
| } | ||
| function pageWait(...args) { | ||
| return invoke("page_wait", args[0] ?? {}); | ||
| return invoke("page_wait", args[0] ?? {}, args[1]); | ||
| } | ||
| function pageNavigate(...args) { | ||
| return invoke("page_navigate", args[0] ?? {}); | ||
| return invoke("page_navigate", args[0] ?? {}, args[1]); | ||
| } | ||
| function pageUpload(...args) { | ||
| return invoke("page_upload", args[0] ?? {}); | ||
| return invoke("page_upload", args[0] ?? {}, args[1]); | ||
| } | ||
| function pageFrames(...args) { | ||
| return invoke("page_frames", args[0] ?? {}); | ||
| return invoke("page_frames", args[0] ?? {}, args[1]); | ||
| } | ||
| function setDeviceEmulation(...args) { | ||
| return invoke("set_device_emulation", args[0] ?? {}); | ||
| return invoke( | ||
| "set_device_emulation", | ||
| args[0] ?? {}, | ||
| args[1] | ||
| ); | ||
| } | ||
| function setTimezone(...args) { | ||
| return invoke("set_timezone", args[0] ?? {}); | ||
| return invoke("set_timezone", args[0] ?? {}, args[1]); | ||
| } | ||
| function getCookie(...args) { | ||
| return invoke("get_cookie", args[0] ?? {}); | ||
| return invoke("get_cookie", args[0] ?? {}, args[1]); | ||
| } | ||
| function setCookie(...args) { | ||
| return invoke("set_cookie", args[0] ?? {}); | ||
| return invoke("set_cookie", args[0] ?? {}, args[1]); | ||
| } | ||
| function getUserInfo(...args) { | ||
| return invoke("get_user_info", args[0] ?? {}); | ||
| return invoke("get_user_info", args[0] ?? {}, args[1]); | ||
| } | ||
| function runActions(...args) { | ||
| return invoke("run_actions", args[0] ?? {}); | ||
| return invoke("run_actions", args[0] ?? {}, args[1]); | ||
| } | ||
@@ -297,2 +376,3 @@ | ||
| defaultBrowser; | ||
| defaultConnector; | ||
| ws = null; | ||
@@ -314,2 +394,3 @@ connectPromise = null; | ||
| this.defaultBrowser = options.defaultBrowser; | ||
| this.defaultConnector = options.defaultConnector; | ||
| } | ||
@@ -344,2 +425,3 @@ async ensureConnected() { | ||
| clearTimeout(connectTimer); | ||
| this.ws?.send(JSON.stringify({ type: "agent_hello" }) + "\n"); | ||
| this.startHeartbeat(); | ||
@@ -430,4 +512,8 @@ resolve(); | ||
| invoke(action, data = {}, options = {}) { | ||
| if (action === "browser_select_browser") return this.selectDefaultBrowser(data); | ||
| const browser = action === "browser_list" ? void 0 : options.browser ?? this.defaultBrowser; | ||
| if (action === "browser_select_browser") { | ||
| return this.selectDefaultBrowser(data, options.connector); | ||
| } | ||
| const connector = action === "connector_list" ? void 0 : options.connector ?? this.defaultConnector; | ||
| const usesDefaultConnector = options.connector === void 0 || this.defaultConnector !== void 0 && options.connector.trim().toLowerCase() === this.defaultConnector.trim().toLowerCase(); | ||
| const browser = action === "browser_list" || action === "connector_list" ? void 0 : options.browser ?? (usesDefaultConnector ? this.defaultBrowser : void 0); | ||
| const timeoutSec = options.timeoutSec ?? resolveActionTimeoutSec(action, data, this.options.requestTimeoutSec); | ||
@@ -454,2 +540,3 @@ const request = (async () => { | ||
| if (browser) message.browser = browser; | ||
| if (connector) message.connector = connector; | ||
| ws.send(JSON.stringify(message) + "\n"); | ||
@@ -461,3 +548,3 @@ }); | ||
| const browsers = Array.isArray(result?.browsers) ? result.browsers : []; | ||
| if (!this.defaultBrowser) return result; | ||
| if (!this.defaultBrowser || !usesDefaultConnector) return result; | ||
| const selected = findConnectedBrowser(browsers, this.defaultBrowser); | ||
@@ -470,3 +557,6 @@ return { | ||
| } | ||
| async selectDefaultBrowser(data) { | ||
| listCloudConnectors() { | ||
| return this.invoke("connector_list", {}); | ||
| } | ||
| async selectDefaultBrowser(data, connector) { | ||
| const selector = typeof data.browser === "string" ? data.browser.trim() : ""; | ||
@@ -480,3 +570,8 @@ if (!selector) { | ||
| } | ||
| const listing = await this.invoke("browser_list", {}); | ||
| const targetConnector = connector ?? this.defaultConnector; | ||
| const listing = await this.invoke( | ||
| "browser_list", | ||
| {}, | ||
| targetConnector ? { connector: targetConnector } : {} | ||
| ); | ||
| const browsers = Array.isArray(listing?.browsers) ? listing.browsers : []; | ||
@@ -490,2 +585,3 @@ const match = findConnectedBrowser(browsers, selector); | ||
| this.defaultBrowser = match.browserId; | ||
| this.defaultConnector = targetConnector; | ||
| return { selected: { browserId: match.browserId, name: match.name } }; | ||
@@ -502,2 +598,3 @@ } | ||
| var defaultBrowser; | ||
| var defaultConnector; | ||
| async function invoke(action, data = {}, options = {}) { | ||
@@ -516,3 +613,3 @@ let serverUrl = process.env.MEARL_SERVER_URL; | ||
| } | ||
| const client = new CloudClient({ serverUrl, defaultBrowser }); | ||
| const client = new CloudClient({ serverUrl, defaultBrowser, defaultConnector }); | ||
| try { | ||
@@ -522,2 +619,3 @@ const result = await client.invoke(action, data, options); | ||
| defaultBrowser = result?.selected?.browserId; | ||
| defaultConnector = options.connector ?? defaultConnector; | ||
| } | ||
@@ -529,2 +627,5 @@ return result; | ||
| } | ||
| function listCloudConnectors() { | ||
| return invoke("connector_list", {}); | ||
| } | ||
| export { | ||
@@ -545,2 +646,3 @@ CloudClient, | ||
| invoke, | ||
| listCloudConnectors, | ||
| pageClick, | ||
@@ -547,0 +649,0 @@ pageEval, |
+3
-3
| { | ||
| "name": "@mearl/cloud-client", | ||
| "version": "2.1.0", | ||
| "version": "2.2.0", | ||
| "description": "Cloud client SDK for Mearl — communicate with local browser via cloud server", | ||
@@ -32,4 +32,4 @@ "type": "module", | ||
| "ws": "^8.18.0", | ||
| "@mearl/cloud-types": "2.1.0", | ||
| "@mearl/client": "2.1.0" | ||
| "@mearl/client": "2.2.0", | ||
| "@mearl/cloud-types": "2.2.0" | ||
| }, | ||
@@ -36,0 +36,0 @@ "devDependencies": { |
+35
-7
@@ -21,3 +21,9 @@ # @mearl/cloud-client | ||
| ```typescript | ||
| import { browserLaunch, browserList, invoke, selectBrowser } from '@mearl/cloud-client'; | ||
| import { | ||
| browserLaunch, | ||
| browserList, | ||
| invoke, | ||
| listCloudConnectors, | ||
| selectBrowser, | ||
| } from '@mearl/cloud-client'; | ||
@@ -34,9 +40,13 @@ // 设置环境变量 | ||
| // 托管浏览器也提供具名方法 | ||
| const managed = await browserLaunch({ name: 'account-a', accountId: 12345 }); | ||
| // 多台浏览器机器接入时,先列出并选择 connector | ||
| const connectors = await listCloudConnectors(); | ||
| const connector = connectors.connectors[0]?.connectorId; | ||
| // 浏览器列表和默认目标选择也是异步 API | ||
| const browsers = await browserList(); | ||
| // 具名方法的最后一个参数接受 cloud 调用选项 | ||
| const managed = await browserLaunch({ name: 'account-a', accountId: 12345 }, { connector }); | ||
| // browser_list 只返回目标 connector 下的浏览器 | ||
| const browsers = await browserList({ connector }); | ||
| const connected = browsers.browsers.find(browser => browser.status === 'connected'); | ||
| if (connected) await selectBrowser({ browser: connected.browserId }); | ||
| if (connected) await selectBrowser({ browser: connected.browserId }, { connector }); | ||
| ``` | ||
@@ -53,2 +63,3 @@ | ||
| requestTimeoutSec: 60, | ||
| defaultConnector: 'work-mac', | ||
| }); | ||
@@ -83,4 +94,13 @@ | ||
| ```bash | ||
| # 检查 cloud-server 到浏览器的完整连接链路 | ||
| mearl check | ||
| # 列出接入当前 cloud-server 的浏览器侧 connector | ||
| mearl connector_list | ||
| # 多个 connector 同时在线时,先选机器,再列该机器的浏览器 | ||
| mearl browser_list --connector work-mac | ||
| # 获取请求 | ||
| mearl get_requests --payload '{"count": 5}' | ||
| mearl get_requests --connector work-mac --browser edge --payload '{"count": 5}' | ||
@@ -94,2 +114,8 @@ # 获取截图并保存 | ||
| `mearl check` 会依次检查 server URL、cloud-server 连接及鉴权、cloud-connector、 | ||
| 远端 native-host 和浏览器清单,并输出各端版本与浏览器传输方式。只有一个 | ||
| connector 时会自动选择;多个 connector 同时在线时,使用 `--connector <id|name>` | ||
| 选择目标。可通过 `--server <url>` 指定地址,通过 `--timeout <seconds>` 调整每项 | ||
| 检查的超时时间。输出 server URL 时会隐藏 token。 | ||
| **环境变量:** | ||
@@ -171,3 +197,5 @@ | ||
| - 确保本地已运行 `@mearl/cloud-connector` | ||
| - 多个 connector 同时在线时,每次 CLI 调用都传 `--connector <id|name>`;`--browser` | ||
| 只在该 connector 的浏览器列表中解析 | ||
| - 建议使用长连接复用 `CloudClient` 实例,避免频繁连接 | ||
| - 使用完毕后调用 `disconnect()` 释放资源 |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
72834
50.33%14
27.27%1779
51.4%196
16.67%8
14.29%+ Added
+ Added
- Removed
- Removed
Updated
Updated