@oya-ai/cli 1.0.202 → 1.0.203
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 +51 -9
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1517,11 +1517,23 @@ function first(flag, env2, saved, names) {
|
|
|
1517
1517
|
}
|
|
1518
1518
|
function origin({ apiKey, baseUrl } = {}) {
|
|
1519
1519
|
const saved = load();
|
|
1520
|
-
const key = first(apiKey, process.env.OYA_API_KEY, saved.apiKey, KEY_SOURCES);
|
|
1521
1520
|
const url = first(baseUrl, process.env.OYA_BASE_URL, saved.baseUrl, URL_SOURCES);
|
|
1522
1521
|
const address = (url?.value ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
1522
|
+
const key = first(apiKey, process.env.OYA_API_KEY, savedKeyFor(saved, address), KEY_SOURCES);
|
|
1523
1523
|
const found = { apiKey: key?.value ?? "", apiKeyFrom: key?.from ?? "none", baseUrl: address };
|
|
1524
|
-
return { ...found, baseUrlFrom: url?.from ?? "default", savedKey: !!saved.apiKey };
|
|
1524
|
+
return { ...found, baseUrlFrom: url?.from ?? "default", savedKey: !!saved.apiKey, savedUrl: saved.baseUrl };
|
|
1525
|
+
}
|
|
1526
|
+
function savedKeyFor(saved, address) {
|
|
1527
|
+
if (!saved.baseUrl || deploymentOf(saved.baseUrl) === deploymentOf(address)) return saved.apiKey;
|
|
1528
|
+
return void 0;
|
|
1529
|
+
}
|
|
1530
|
+
function deploymentOf(url) {
|
|
1531
|
+
try {
|
|
1532
|
+
const { origin: site, pathname } = new URL(String(url).trim());
|
|
1533
|
+
return `${site}${pathname.replace(/\/+$/, "")}`;
|
|
1534
|
+
} catch {
|
|
1535
|
+
return String(url).trim().replace(/\/+$/, "");
|
|
1536
|
+
}
|
|
1525
1537
|
}
|
|
1526
1538
|
var KEY_SOURCES = ["--key", "OYA_API_KEY", "saved"];
|
|
1527
1539
|
var URL_SOURCES = ["--url", "OYA_BASE_URL", "saved"];
|
|
@@ -1631,6 +1643,11 @@ var Http = class {
|
|
|
1631
1643
|
this.fetchImpl = fetchImpl;
|
|
1632
1644
|
this.origin = origin3;
|
|
1633
1645
|
}
|
|
1646
|
+
baseUrl;
|
|
1647
|
+
apiKey;
|
|
1648
|
+
timeoutMs;
|
|
1649
|
+
fetchImpl;
|
|
1650
|
+
origin;
|
|
1634
1651
|
/** Sends one request and returns the parsed answer, or throws an OyaError when it failed. */
|
|
1635
1652
|
async request(method, path, body, timeoutMs = this.timeoutMs, headers = {}) {
|
|
1636
1653
|
const res = await this.send(`${this.baseUrl}${path}`, this.init(method, body, timeoutMs, headers), timeoutMs);
|
|
@@ -1705,15 +1722,32 @@ function addressOf(options, saved) {
|
|
|
1705
1722
|
const found = firstOf(options.baseUrl, "OYA_BASE_URL", saved, "baseUrl");
|
|
1706
1723
|
return found.value ? found : { value: DEFAULT_BASE_URL2, from: "default" };
|
|
1707
1724
|
}
|
|
1708
|
-
function keyOf(options, saved) {
|
|
1709
|
-
const found = firstOf(options.apiKey, "OYA_API_KEY", saved, "apiKey");
|
|
1710
|
-
if (!found.value) throw new Error(
|
|
1725
|
+
function keyOf(options, saved, address) {
|
|
1726
|
+
const found = firstOf(options.apiKey, "OYA_API_KEY", savedKeyFor2(saved, address), "apiKey");
|
|
1727
|
+
if (!found.value) throw new Error(noKey(saved, address));
|
|
1711
1728
|
return { ...found, value: headerSafe(found.value, "apiKey", "Copy the key again.") };
|
|
1712
1729
|
}
|
|
1730
|
+
function savedKeyFor2(saved, address) {
|
|
1731
|
+
if (!saved.baseUrl || deploymentOf2(saved.baseUrl) === deploymentOf2(address)) return saved.apiKey;
|
|
1732
|
+
return void 0;
|
|
1733
|
+
}
|
|
1734
|
+
function deploymentOf2(url) {
|
|
1735
|
+
try {
|
|
1736
|
+
const { origin: origin3, pathname } = new URL(String(url).trim());
|
|
1737
|
+
return `${origin3}${pathname.replace(/\/+$/, "")}`;
|
|
1738
|
+
} catch {
|
|
1739
|
+
return String(url).trim().replace(/\/+$/, "");
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
function noKey(saved, address) {
|
|
1743
|
+
if (!saved.apiKey) return "No API key. Pass { apiKey }, set OYA_API_KEY, or run `npx @oya-ai/cli login`.";
|
|
1744
|
+
const why = `the key saved in ~/.oya/config.json is for ${saved.baseUrl} and is only sent there`;
|
|
1745
|
+
return `No API key for ${address}: ${why}. Pass { apiKey }, set OYA_API_KEY, or run \`npx @oya-ai/cli login --url ${address}\`.`;
|
|
1746
|
+
}
|
|
1713
1747
|
function createHttp(options) {
|
|
1714
1748
|
const saved = savedConfig();
|
|
1715
|
-
const key = keyOf(options, saved.apiKey);
|
|
1716
1749
|
const address = addressOf(options, saved.baseUrl);
|
|
1750
|
+
const key = keyOf(options, saved, webAddress(address));
|
|
1717
1751
|
const fetchImpl = options.fetch || globalThis.fetch;
|
|
1718
1752
|
if (!fetchImpl) throw new Error("No fetch available, pass { fetch } or use Node 18+.");
|
|
1719
1753
|
const origin3 = { apiKeyFrom: key.from, baseUrlFrom: address.from, savedKey: !!saved.apiKey };
|
|
@@ -1824,6 +1858,8 @@ var Run = class {
|
|
|
1824
1858
|
this.done.catch(() => {
|
|
1825
1859
|
});
|
|
1826
1860
|
}
|
|
1861
|
+
http;
|
|
1862
|
+
id;
|
|
1827
1863
|
/** Settles with the result when the run succeeds, or rejects when it fails. */
|
|
1828
1864
|
done;
|
|
1829
1865
|
/** The run's current state. */
|
|
@@ -1847,6 +1883,8 @@ var Browser = class {
|
|
|
1847
1883
|
({ id: this.id, provider: this.provider, persona: this.persona, cdpUrl: this.cdpUrl } = info);
|
|
1848
1884
|
this.reused = info.reused === true;
|
|
1849
1885
|
}
|
|
1886
|
+
http;
|
|
1887
|
+
autoCaptcha;
|
|
1850
1888
|
/** The browser's id. */
|
|
1851
1889
|
id;
|
|
1852
1890
|
/** Which provider runs it. */
|
|
@@ -2501,11 +2539,15 @@ var Oya = class {
|
|
|
2501
2539
|
// src/context.ts
|
|
2502
2540
|
var origin2 = (flags) => origin({ apiKey: flagStr(flags, "key"), baseUrl: flagStr(flags, "url") });
|
|
2503
2541
|
function client(flags) {
|
|
2504
|
-
const { apiKey, baseUrl } = origin2(flags);
|
|
2505
|
-
if (!apiKey)
|
|
2506
|
-
throw new CliError("No API key.", "no_api_key", { hint: "Run oya login, or pass --key, or set OYA_API_KEY." });
|
|
2542
|
+
const { apiKey, baseUrl, savedKey, savedUrl } = origin2(flags);
|
|
2543
|
+
if (!apiKey) throw new CliError("No API key.", "no_api_key", { hint: noKeyHint(baseUrl, savedKey, savedUrl) });
|
|
2507
2544
|
return new Oya({ apiKey, baseUrl });
|
|
2508
2545
|
}
|
|
2546
|
+
function noKeyHint(baseUrl, savedKey, savedUrl) {
|
|
2547
|
+
if (!savedKey) return "Run oya login, or pass --key, or set OYA_API_KEY.";
|
|
2548
|
+
const why = `The key oya login saved is for ${savedUrl ?? "another control plane"} and is only sent there.`;
|
|
2549
|
+
return `${why} Pass --key or set OYA_API_KEY for ${baseUrl}, or run oya login --url ${baseUrl} to replace the saved key.`;
|
|
2550
|
+
}
|
|
2509
2551
|
var printJson = (value) => console.log(JSON.stringify(value, null, JSON_INDENT2));
|
|
2510
2552
|
var out = (flags, value, human) => {
|
|
2511
2553
|
if (flags.json) printJson(value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oya-ai/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.203",
|
|
4
4
|
"description": "Command line for the Oya browser control plane.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://oyabrowser.com",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@oya-ai/browser": "1.0.
|
|
53
|
+
"@oya-ai/browser": "1.0.203",
|
|
54
54
|
"@types/node": "^20.19.43",
|
|
55
|
-
"tsup": "^
|
|
55
|
+
"tsup": "^9.0.0",
|
|
56
56
|
"typescript": "^6.0.3"
|
|
57
57
|
},
|
|
58
58
|
"author": "mk@getoya.ai"
|