@oya-ai/cli 1.0.154 → 1.0.155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +31 -15
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1158,7 +1158,7 @@ async function migrate(root, databaseUrl) {
|
|
|
1158
1158
|
} catch (e) {
|
|
1159
1159
|
spin.fail();
|
|
1160
1160
|
throw new Error(`Migrations failed: ${e.message}
|
|
1161
|
-
${RETRY}
|
|
1161
|
+
${RETRY}`, { cause: e });
|
|
1162
1162
|
}
|
|
1163
1163
|
}
|
|
1164
1164
|
|
|
@@ -1614,11 +1614,6 @@ var Http = class {
|
|
|
1614
1614
|
this.fetchImpl = fetchImpl;
|
|
1615
1615
|
this.origin = origin3;
|
|
1616
1616
|
}
|
|
1617
|
-
baseUrl;
|
|
1618
|
-
apiKey;
|
|
1619
|
-
timeoutMs;
|
|
1620
|
-
fetchImpl;
|
|
1621
|
-
origin;
|
|
1622
1617
|
/** Sends one request and returns the parsed answer, or throws an OyaError when it failed. */
|
|
1623
1618
|
async request(method, path, body, timeoutMs = this.timeoutMs, headers = {}) {
|
|
1624
1619
|
const res = await this.send(`${this.baseUrl}${path}`, this.init(method, body, timeoutMs, headers), timeoutMs);
|
|
@@ -1812,8 +1807,6 @@ var Run = class {
|
|
|
1812
1807
|
this.done.catch(() => {
|
|
1813
1808
|
});
|
|
1814
1809
|
}
|
|
1815
|
-
http;
|
|
1816
|
-
id;
|
|
1817
1810
|
/** Settles with the result when the run succeeds, or rejects when it fails. */
|
|
1818
1811
|
done;
|
|
1819
1812
|
/** The run's current state. */
|
|
@@ -1837,8 +1830,6 @@ var Browser = class {
|
|
|
1837
1830
|
({ id: this.id, provider: this.provider, persona: this.persona, cdpUrl: this.cdpUrl } = info);
|
|
1838
1831
|
this.reused = info.reused === true;
|
|
1839
1832
|
}
|
|
1840
|
-
http;
|
|
1841
|
-
autoCaptcha;
|
|
1842
1833
|
/** The browser's id. */
|
|
1843
1834
|
id;
|
|
1844
1835
|
/** Which provider runs it. */
|
|
@@ -2501,16 +2492,21 @@ async function targetBrowser(oya, flags) {
|
|
|
2501
2492
|
}
|
|
2502
2493
|
|
|
2503
2494
|
// src/commands/login.ts
|
|
2504
|
-
|
|
2505
|
-
|
|
2495
|
+
var credentials = (token2, cookie = "") => ({
|
|
2496
|
+
...token2 ? { Authorization: `Bearer ${token2}` } : {},
|
|
2497
|
+
...cookie ? { Cookie: cookie } : {}
|
|
2498
|
+
});
|
|
2499
|
+
async function postJson(url, body, token2, cookie = "") {
|
|
2500
|
+
const headers = { ...credentials(token2, cookie), "Content-Type": "application/json" };
|
|
2506
2501
|
const signal = AbortSignal.timeout(LOGIN_TIMEOUT_MS);
|
|
2507
2502
|
const res = await fetch(url, { method: "POST", headers, body: JSON.stringify(body), signal }).catch(() => {
|
|
2508
2503
|
throw new CliError(`Could not reach ${new URL(url).origin}.`, "unreachable", {
|
|
2509
2504
|
hint: "Check the address, then run oya login again."
|
|
2510
2505
|
});
|
|
2511
2506
|
});
|
|
2512
|
-
return { ok: res.ok, body: jsonOr(await res.text(), `${res.status} from ${url}`) };
|
|
2507
|
+
return { ok: res.ok, body: jsonOr(await res.text(), `${res.status} from ${url}`), cookies: cookiesOf(res) };
|
|
2513
2508
|
}
|
|
2509
|
+
var cookiesOf = (res) => res.headers.getSetCookie().map((c) => c.split(";")[0]).join("; ");
|
|
2514
2510
|
function jsonOr(text, answer) {
|
|
2515
2511
|
try {
|
|
2516
2512
|
return JSON.parse(text);
|
|
@@ -2518,12 +2514,32 @@ function jsonOr(text, answer) {
|
|
|
2518
2514
|
return { error: `Not a JSON answer: ${answer}` };
|
|
2519
2515
|
}
|
|
2520
2516
|
}
|
|
2521
|
-
async function
|
|
2517
|
+
async function verifiedFactor(baseUrl, session2, body) {
|
|
2518
|
+
const url = `${baseUrl}/api/auth/mfa/status`;
|
|
2519
|
+
const status = await postJson(url, body, session2.body.access_token, session2.cookies);
|
|
2520
|
+
const factor = status.body.factors?.find((f) => f.status === "verified");
|
|
2521
|
+
if (!factor) throw new Error(status.body.error || "No authenticator app found for this account");
|
|
2522
|
+
return factor.id;
|
|
2523
|
+
}
|
|
2524
|
+
async function steppedUp(baseUrl, session2) {
|
|
2525
|
+
if (!session2.body.mfa_required) return session2.body.access_token;
|
|
2526
|
+
const body = { refresh_token: session2.body.refresh_token };
|
|
2527
|
+
const factorId = await verifiedFactor(baseUrl, session2, body);
|
|
2528
|
+
const asked = { ...body, factor_id: factorId, code: await ask("Code from your authenticator app:") };
|
|
2529
|
+
const verify = `${baseUrl}/api/auth/mfa/verify`;
|
|
2530
|
+
const verified = await postJson(verify, asked, session2.body.access_token, session2.cookies);
|
|
2531
|
+
if (!verified.ok || !verified.body.access_token) throw new Error(verified.body.error || "That code did not work");
|
|
2532
|
+
return verified.body.access_token;
|
|
2533
|
+
}
|
|
2534
|
+
async function signIn(baseUrl) {
|
|
2522
2535
|
const email = await ask("Email:");
|
|
2523
2536
|
const password = await askSecret("Password:");
|
|
2524
2537
|
const session2 = await postJson(`${baseUrl}/api/auth/login`, { email, password });
|
|
2525
2538
|
if (!session2.ok || !session2.body.access_token) throw new Error(session2.body.error || "Sign-in failed");
|
|
2526
|
-
|
|
2539
|
+
return steppedUp(baseUrl, session2);
|
|
2540
|
+
}
|
|
2541
|
+
async function mintKey(baseUrl) {
|
|
2542
|
+
const minted = await postJson(`${baseUrl}/api/auth/keys`, { label: "CLI" }, await signIn(baseUrl));
|
|
2527
2543
|
if (!minted.ok || !minted.body.key) throw new Error(minted.body.error || "Could not create an API key");
|
|
2528
2544
|
console.log(' Created a new API key labelled "CLI".');
|
|
2529
2545
|
return minted.body.key;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oya-ai/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.155",
|
|
4
4
|
"description": "Command line for the Oya browser control plane.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://oyabrowser.com",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@oya-ai/browser": "1.0.
|
|
53
|
+
"@oya-ai/browser": "1.0.155",
|
|
54
54
|
"@types/node": "^20.19.43",
|
|
55
|
-
"tsup": "^8.
|
|
56
|
-
"typescript": "^
|
|
55
|
+
"tsup": "^8.5.1",
|
|
56
|
+
"typescript": "^6.0.3"
|
|
57
57
|
},
|
|
58
58
|
"author": "mk@getoya.ai"
|
|
59
59
|
}
|