@orth/cli 0.3.1 → 0.5.0
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/CHANGELOG.md +58 -0
- package/README.md +113 -109
- package/dist/analytics.d.ts +36 -8
- package/dist/analytics.js +247 -47
- package/dist/api.d.ts +34 -2
- package/dist/api.js +68 -13
- package/dist/command-actions.d.ts +10 -0
- package/dist/command-actions.js +42 -0
- package/dist/commands/account.d.ts +9 -1
- package/dist/commands/account.js +26 -10
- package/dist/commands/api.d.ts +3 -0
- package/dist/commands/api.js +114 -117
- package/dist/commands/auth.d.ts +3 -1
- package/dist/commands/auth.js +53 -9
- package/dist/commands/onboard/flow.d.ts +22 -0
- package/dist/commands/onboard/flow.js +155 -0
- package/dist/commands/onboard/guide.d.ts +8 -0
- package/dist/commands/onboard/guide.js +73 -0
- package/dist/commands/onboard/listing.d.ts +18 -0
- package/dist/commands/onboard/listing.js +166 -0
- package/dist/commands/onboard/progress.d.ts +44 -0
- package/dist/commands/onboard/progress.js +108 -0
- package/dist/commands/onboard/register.d.ts +2 -0
- package/dist/commands/onboard/register.js +261 -0
- package/dist/commands/onboard/requests.d.ts +24 -0
- package/dist/commands/onboard/requests.js +96 -0
- package/dist/commands/onboard/review.d.ts +31 -0
- package/dist/commands/onboard/review.js +228 -0
- package/dist/commands/onboard/setup.d.ts +68 -0
- package/dist/commands/onboard/setup.js +215 -0
- package/dist/commands/onboard/shared.d.ts +41 -0
- package/dist/commands/onboard/shared.js +97 -0
- package/dist/commands/onboard/tools.d.ts +19 -0
- package/dist/commands/onboard/tools.js +104 -0
- package/dist/commands/org.d.ts +21 -0
- package/dist/commands/org.js +126 -0
- package/dist/commands/payouts.d.ts +44 -0
- package/dist/commands/payouts.js +125 -0
- package/dist/commands/run.d.ts +2 -1
- package/dist/commands/run.js +23 -29
- package/dist/commands/search.d.ts +8 -1
- package/dist/commands/search.js +28 -4
- package/dist/commands/skills/browse.d.ts +15 -0
- package/dist/commands/skills/browse.js +194 -0
- package/dist/commands/skills/create.d.ts +5 -0
- package/dist/commands/skills/create.js +62 -0
- package/dist/commands/skills/init.d.ts +4 -0
- package/dist/commands/skills/init.js +123 -0
- package/dist/commands/skills/install.d.ts +6 -0
- package/dist/commands/skills/install.js +191 -0
- package/dist/commands/skills/local-files.d.ts +15 -0
- package/dist/commands/skills/local-files.js +110 -0
- package/dist/commands/skills/register.d.ts +2 -0
- package/dist/commands/skills/register.js +130 -0
- package/dist/commands/skills/shared.d.ts +43 -0
- package/dist/commands/skills/shared.js +69 -0
- package/dist/commands/skills/upload.d.ts +9 -0
- package/dist/commands/skills/upload.js +223 -0
- package/dist/commands/skills/verification.d.ts +5 -0
- package/dist/commands/skills/verification.js +74 -0
- package/dist/commands/telemetry.d.ts +3 -0
- package/dist/commands/telemetry.js +38 -0
- package/dist/config.d.ts +55 -1
- package/dist/config.js +102 -3
- package/dist/http.d.ts +15 -0
- package/dist/http.js +41 -0
- package/dist/index.js +133 -162
- package/dist/last-search.d.ts +19 -0
- package/dist/last-search.js +60 -0
- package/dist/organizations.d.ts +14 -0
- package/dist/organizations.js +77 -0
- package/dist/urls.d.ts +3 -0
- package/dist/urls.js +34 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +112 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +21 -0
- package/dist/x402.d.ts +7 -0
- package/dist/x402.js +27 -0
- package/package.json +23 -22
- package/dist/commands/skills.d.ts +0 -66
- package/dist/commands/skills.js +0 -821
package/dist/commands/api.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
/** The word the website shows after a rate whose tier warns. */
|
|
2
|
+
export declare const TIER_WARNING: Record<string, string>;
|
|
1
3
|
interface ApiOptions {
|
|
2
4
|
x402?: boolean;
|
|
3
5
|
x402Full?: boolean;
|
|
6
|
+
json?: boolean;
|
|
4
7
|
}
|
|
5
8
|
export declare function apiCommand(slug?: string, path?: string, options?: ApiOptions): Promise<void>;
|
|
6
9
|
export {};
|
package/dist/commands/api.js
CHANGED
|
@@ -3,76 +3,97 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TIER_WARNING = void 0;
|
|
6
7
|
exports.apiCommand = apiCommand;
|
|
7
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
9
|
const ora_1 = __importDefault(require("ora"));
|
|
9
10
|
const api_js_1 = require("../api.js");
|
|
10
11
|
const utils_js_1 = require("../utils.js");
|
|
12
|
+
const http_js_1 = require("../http.js");
|
|
13
|
+
const urls_js_1 = require("../urls.js");
|
|
14
|
+
const x402_js_1 = require("../x402.js");
|
|
15
|
+
/** The word the website shows after a rate whose tier warns. */
|
|
16
|
+
exports.TIER_WARNING = {
|
|
17
|
+
degraded: "degraded",
|
|
18
|
+
fallback_only: "unreliable",
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* "99.6% success · 735 ms median · 30 days (API-wide)", the line `api show`
|
|
22
|
+
* prints for an endpoint's quality, the website's words; null below 100
|
|
23
|
+
* calls. The rate rounds down, as the website shows it.
|
|
24
|
+
*/
|
|
25
|
+
function qualityLine(quality) {
|
|
26
|
+
if (quality.successRate30d == null)
|
|
27
|
+
return null;
|
|
28
|
+
const percent = Math.floor(quality.successRate30d * 1000 + 1e-9) / 10;
|
|
29
|
+
const warning = exports.TIER_WARNING[quality.tier];
|
|
30
|
+
const parts = [`${percent}% success${warning ? ` ${warning}` : ""}`];
|
|
31
|
+
if (quality.medianMs != null) {
|
|
32
|
+
parts.push(`${quality.medianMs.toLocaleString("en-US")} ms median`);
|
|
33
|
+
}
|
|
34
|
+
parts.push("30 days");
|
|
35
|
+
return parts.join(" · ") + (quality.scope === "api" ? " (API-wide)" : "");
|
|
36
|
+
}
|
|
11
37
|
async function apiCommand(slug, path, options) {
|
|
12
38
|
const spinner = (0, ora_1.default)("Loading...").start();
|
|
13
39
|
try {
|
|
14
40
|
if (!slug) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const apis = (data.apis || []).sort((a, b) => a.slug.localeCompare(b.slug));
|
|
21
|
-
for (const api of apis) {
|
|
22
|
-
console.log(chalk_1.default.cyan.bold(api.slug.padEnd(20)) +
|
|
23
|
-
chalk_1.default.white(api.name || "") +
|
|
24
|
-
chalk_1.default.gray(` (${api.endpoints?.length || 0} endpoints)`));
|
|
25
|
-
}
|
|
26
|
-
console.log(chalk_1.default.gray("\nRun 'orth api show <slug>' to see endpoints for an API"));
|
|
41
|
+
const data = await (0, api_js_1.listApis)(500);
|
|
42
|
+
spinner.stop();
|
|
43
|
+
if (options?.json) {
|
|
44
|
+
console.log(JSON.stringify(data, null, 2));
|
|
45
|
+
return;
|
|
27
46
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
(
|
|
33
|
-
(
|
|
34
|
-
(0, api_js_1.search)("email", 50),
|
|
35
|
-
]);
|
|
36
|
-
spinner.stop();
|
|
37
|
-
const allResults = searches.flatMap(s => s.results || []);
|
|
38
|
-
console.log(chalk_1.default.bold("\nAvailable APIs:\n"));
|
|
39
|
-
const seen = new Set();
|
|
40
|
-
for (const api of allResults) {
|
|
41
|
-
if (!api.slug || seen.has(api.slug))
|
|
42
|
-
continue;
|
|
43
|
-
seen.add(api.slug);
|
|
44
|
-
console.log(chalk_1.default.cyan.bold(api.slug.padEnd(20)) +
|
|
45
|
-
chalk_1.default.white(api.name || "") +
|
|
46
|
-
chalk_1.default.gray(` (${api.endpoints?.length || 0} endpoints)`));
|
|
47
|
-
}
|
|
48
|
-
console.log(chalk_1.default.gray("\nRun 'orth api show <slug>' to see endpoints for an API"));
|
|
47
|
+
console.log(chalk_1.default.bold("\nAvailable APIs:\n"));
|
|
48
|
+
const apis = (data.apis || []).sort((a, b) => a.slug.localeCompare(b.slug));
|
|
49
|
+
for (const api of apis) {
|
|
50
|
+
console.log(chalk_1.default.cyan.bold(api.slug.padEnd(20)) +
|
|
51
|
+
chalk_1.default.white(api.name || "") +
|
|
52
|
+
chalk_1.default.gray(` (${api.endpoints?.length || 0} endpoints)`));
|
|
49
53
|
}
|
|
54
|
+
console.log(chalk_1.default.gray(`\nRun '${(0, utils_js_1.cliName)()} api show <slug>' to see endpoints for an API`));
|
|
50
55
|
return;
|
|
51
56
|
}
|
|
52
57
|
if (path) {
|
|
53
58
|
// Show endpoint details
|
|
54
59
|
const data = await (0, api_js_1.getDetails)(slug, path);
|
|
55
60
|
spinner.stop();
|
|
61
|
+
if (options?.json && !options.x402 && !options.x402Full) {
|
|
62
|
+
console.log(JSON.stringify(data, null, 2));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
56
65
|
console.log(chalk_1.default.bold(`\n${chalk_1.default.cyan(slug)}${chalk_1.default.white(path)}\n`));
|
|
57
66
|
// Get description from endpoint or action object if available
|
|
58
67
|
const desc = data.description || data.endpoint?.description || data.action?.description;
|
|
59
68
|
console.log(chalk_1.default.gray(desc || "No description"));
|
|
60
69
|
// Show price
|
|
61
70
|
const endpointPrice = data.price ?? data.endpoint?.price;
|
|
62
|
-
const isDynamic = data.hasDynamicPricing || !!data.pricing_formula;
|
|
71
|
+
const isDynamic = data.hasDynamicPricing || data.endpoint?.hasDynamicPricing || !!data.pricing_formula;
|
|
63
72
|
if (isDynamic) {
|
|
73
|
+
const maxPrice = data.endpoint?.maxPrice;
|
|
74
|
+
// The catalog's own words: the price, its kind and how it is worked out.
|
|
75
|
+
const [headline, ...rules] = (data.endpoint?.pricingNote ?? "").split("\n");
|
|
64
76
|
console.log(chalk_1.default.bold("Price: ") +
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
(headline
|
|
78
|
+
? chalk_1.default.yellow(headline)
|
|
79
|
+
: chalk_1.default.yellow("dynamic") +
|
|
80
|
+
(maxPrice ? chalk_1.default.yellow(`, up to $${maxPrice}`) : "")) +
|
|
81
|
+
chalk_1.default.gray(" (use --dry-run to see a request's price)"));
|
|
82
|
+
for (const rule of rules)
|
|
83
|
+
console.log(chalk_1.default.gray(rule));
|
|
67
84
|
}
|
|
68
85
|
else if (endpointPrice !== undefined && endpointPrice !== null) {
|
|
69
86
|
const isFree = endpointPrice === 0 || endpointPrice === "free" || endpointPrice === "0";
|
|
70
87
|
const priceDisplay = typeof endpointPrice === 'string'
|
|
71
88
|
? endpointPrice
|
|
72
|
-
: `$${parseFloat(Number(endpointPrice).toFixed(
|
|
89
|
+
: `$${parseFloat(Number(endpointPrice).toFixed(6))}`;
|
|
73
90
|
console.log(chalk_1.default.bold("Price: ") +
|
|
74
91
|
(isFree ? chalk_1.default.green("free") : chalk_1.default.yellow(priceDisplay)));
|
|
75
92
|
}
|
|
93
|
+
const quality = data.endpoint?.quality && qualityLine(data.endpoint.quality);
|
|
94
|
+
if (quality) {
|
|
95
|
+
console.log(chalk_1.default.bold("Quality: ") + chalk_1.default.gray(quality));
|
|
96
|
+
}
|
|
76
97
|
// Get params from nested endpoint or action object if needed
|
|
77
98
|
const actionParams = data.action?.parameters ?? [];
|
|
78
99
|
const queryParams = data.parameters?.query || data.endpoint?.queryParams || [];
|
|
@@ -102,18 +123,19 @@ async function apiCommand(slug, path, options) {
|
|
|
102
123
|
for (const param of bodyParams.slice(0, 3)) {
|
|
103
124
|
exampleBody[param.name] = param.type === 'object' ? '{}' : `<${param.name}>`;
|
|
104
125
|
}
|
|
105
|
-
console.log(chalk_1.default.white(`
|
|
126
|
+
console.log(chalk_1.default.white(` ${(0, utils_js_1.cliName)()} run ${slug} ${path} --body '${JSON.stringify(exampleBody)}'`));
|
|
106
127
|
}
|
|
107
128
|
else if (queryParams.length > 0) {
|
|
108
129
|
const exampleQuery = queryParams.slice(0, 2).map((p) => `-q ${p.name}=<value>`).join(' ');
|
|
109
|
-
console.log(chalk_1.default.white(`
|
|
130
|
+
console.log(chalk_1.default.white(` ${(0, utils_js_1.cliName)()} run ${slug} ${path} ${exampleQuery}`));
|
|
110
131
|
}
|
|
111
132
|
else {
|
|
112
|
-
console.log(chalk_1.default.white(`
|
|
133
|
+
console.log(chalk_1.default.white(` ${(0, utils_js_1.cliName)()} run ${slug} ${path}`));
|
|
113
134
|
}
|
|
114
135
|
// x402 direct payment info
|
|
115
136
|
if (options?.x402 || options?.x402Full) {
|
|
116
|
-
|
|
137
|
+
// Prefer the server's payment URL; otherwise use this deployment's native route.
|
|
138
|
+
const x402Url = data.usage?.x402 ?? new URL(`/pay/${slug}${path}`, (0, urls_js_1.apiBaseUrl)()).href;
|
|
117
139
|
// Determine HTTP method: POST if body params, GET otherwise
|
|
118
140
|
const method = bodyParams.length > 0 ? 'POST' : 'GET';
|
|
119
141
|
if (options?.x402 && !options?.x402Full) {
|
|
@@ -123,97 +145,72 @@ async function apiCommand(slug, path, options) {
|
|
|
123
145
|
else {
|
|
124
146
|
// Full output - actually call the endpoint and get the 402 response
|
|
125
147
|
try {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
148
|
+
const response = await (0, http_js_1.orthFetch)(x402Url, method === 'POST'
|
|
149
|
+
? { method, headers: { 'Content-Type': 'application/json' }, body: '{}' }
|
|
150
|
+
: { method });
|
|
151
|
+
const text = await response.text();
|
|
152
|
+
let responseData;
|
|
153
|
+
try {
|
|
154
|
+
responseData = JSON.parse(text);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
responseData = undefined;
|
|
158
|
+
}
|
|
159
|
+
const refused = (0, http_js_1.vercelProtectionMessage)(x402Url, response, responseData);
|
|
160
|
+
if (refused || responseData === undefined) {
|
|
161
|
+
throw new Error(refused ?? `the answer (status ${response.status}) is not JSON`);
|
|
130
162
|
}
|
|
131
|
-
const response = await fetch(x402Url, fetchOptions);
|
|
132
|
-
const responseData = await response.json();
|
|
133
163
|
console.log(chalk_1.default.bold.magenta("\n── x402 Payment Details ──\n"));
|
|
134
164
|
console.log(chalk_1.default.cyan(`URL: ${x402Url}`));
|
|
135
165
|
console.log(chalk_1.default.yellow(`Method: ${method}`));
|
|
136
166
|
console.log(chalk_1.default.gray(`Status: ${response.status}\n`));
|
|
137
|
-
|
|
167
|
+
const challenge = (0, x402_js_1.decodePaymentRequired)(response.headers.get("payment-required"));
|
|
168
|
+
console.log(JSON.stringify(challenge ?? responseData, null, 2));
|
|
138
169
|
}
|
|
139
170
|
catch (err) {
|
|
140
|
-
console.log(chalk_1.default.red(`\nFailed to fetch x402 details: ${err}`));
|
|
171
|
+
console.log(chalk_1.default.red(`\nFailed to fetch x402 details: ${err instanceof Error ? err.message : err}`));
|
|
141
172
|
}
|
|
142
173
|
}
|
|
143
174
|
}
|
|
144
175
|
return;
|
|
145
176
|
}
|
|
146
|
-
// Show API endpoints
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
for (const endpoint of apiData.endpoints) {
|
|
153
|
-
const method = chalk_1.default.yellow(endpoint.method.padEnd(6));
|
|
154
|
-
const ep = endpoint.price;
|
|
155
|
-
const epIsDynamic = endpoint.hasDynamicPricing || !!endpoint.pricing_formula;
|
|
156
|
-
const price = epIsDynamic
|
|
157
|
-
? chalk_1.default.dim("dynamic")
|
|
158
|
-
: (() => {
|
|
159
|
-
const isFreePrice = ep === 0 || ep == null || ep === "free" || ep === "0";
|
|
160
|
-
return isFreePrice
|
|
161
|
-
? chalk_1.default.green("free")
|
|
162
|
-
: typeof ep === 'string'
|
|
163
|
-
? chalk_1.default.dim(ep)
|
|
164
|
-
: chalk_1.default.dim(`$${parseFloat(Number(ep).toFixed(4))}`);
|
|
165
|
-
})();
|
|
166
|
-
// Group members commonly collide on the same upstream path (e.g.
|
|
167
|
-
// AbstractAPI's many products all expose "/v1") — when the endpoint's
|
|
168
|
-
// own callable slug differs from the card's flat slug, show it so the
|
|
169
|
-
// right identifier is obvious before calling `orth run`.
|
|
170
|
-
const memberTag = endpoint.apiSlug && endpoint.apiSlug !== api.slug
|
|
171
|
-
? chalk_1.default.dim(` [${(0, utils_js_1.sanitizeForTerminal)(endpoint.apiSlug)}]`)
|
|
172
|
-
: "";
|
|
173
|
-
console.log(`${method} ${chalk_1.default.white(endpoint.path)} ${price}${memberTag}`);
|
|
174
|
-
if (endpoint.description) {
|
|
175
|
-
console.log(chalk_1.default.gray(` ${endpoint.description.slice(0, 80)}${endpoint.description.length > 80 ? "..." : ""}`));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
console.log(chalk_1.default.gray("\nRun 'orth api show " + slug + " <path>' for endpoint details"));
|
|
179
|
-
console.log(chalk_1.default.gray("Run 'orth run " + slug + " <path>' to call an endpoint"));
|
|
177
|
+
// Show the API's endpoints
|
|
178
|
+
const apiData = await (0, api_js_1.getApiBySlug)(slug);
|
|
179
|
+
spinner.stop();
|
|
180
|
+
if (options?.json) {
|
|
181
|
+
console.log(JSON.stringify(apiData, null, 2));
|
|
182
|
+
return;
|
|
180
183
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
? chalk_1.default.dim(` [${(0, utils_js_1.sanitizeForTerminal)(endpoint.apiSlug)}]`)
|
|
208
|
-
: "";
|
|
209
|
-
console.log(`${method} ${chalk_1.default.white(endpoint.path)} ${price}${memberTag}`);
|
|
210
|
-
if (endpoint.description) {
|
|
211
|
-
console.log(chalk_1.default.gray(` ${endpoint.description.slice(0, 80)}${endpoint.description.length > 80 ? "..." : ""}`));
|
|
212
|
-
}
|
|
184
|
+
const api = apiData.api;
|
|
185
|
+
console.log(chalk_1.default.bold(`\n${chalk_1.default.cyan(api.name)} (${api.slug})\n`));
|
|
186
|
+
for (const endpoint of apiData.endpoints) {
|
|
187
|
+
const method = chalk_1.default.yellow(endpoint.method.padEnd(6));
|
|
188
|
+
const ep = endpoint.price;
|
|
189
|
+
const epIsDynamic = endpoint.hasDynamicPricing || !!endpoint.pricing_formula;
|
|
190
|
+
const isFreePrice = ep === 0 || ep == null || ep === "free" || ep === "0";
|
|
191
|
+
const price = endpoint.priceText
|
|
192
|
+
? endpoint.priceText === "Free"
|
|
193
|
+
? chalk_1.default.green("Free")
|
|
194
|
+
: chalk_1.default.dim(endpoint.priceText)
|
|
195
|
+
: epIsDynamic
|
|
196
|
+
? chalk_1.default.dim("price varies by request")
|
|
197
|
+
: isFreePrice
|
|
198
|
+
? chalk_1.default.green("Free")
|
|
199
|
+
: chalk_1.default.dim(typeof ep === "string" ? ep : `$${parseFloat(Number(ep).toFixed(6))}`);
|
|
200
|
+
// Group members commonly collide on the same upstream path (e.g.
|
|
201
|
+
// AbstractAPI's many products all expose "/v1"): when the endpoint's
|
|
202
|
+
// own callable slug differs from the card's flat slug, show it so the
|
|
203
|
+
// right identifier is obvious before calling `orth run`.
|
|
204
|
+
const memberTag = endpoint.apiSlug && endpoint.apiSlug !== api.slug
|
|
205
|
+
? chalk_1.default.dim(` [${(0, utils_js_1.sanitizeForTerminal)(endpoint.apiSlug)}]`)
|
|
206
|
+
: "";
|
|
207
|
+
console.log(`${method} ${chalk_1.default.white(endpoint.path)} ${price}${memberTag}`);
|
|
208
|
+
if (endpoint.description) {
|
|
209
|
+
console.log(chalk_1.default.gray(` ${endpoint.description.slice(0, 80)}${endpoint.description.length > 80 ? "..." : ""}`));
|
|
213
210
|
}
|
|
214
|
-
console.log(chalk_1.default.gray("\nRun 'orth api show " + slug + " <path>' for endpoint details"));
|
|
215
|
-
console.log(chalk_1.default.gray("Run 'orth run " + slug + " <path>' to call an endpoint"));
|
|
216
211
|
}
|
|
212
|
+
console.log(chalk_1.default.gray(`\nRun '${(0, utils_js_1.cliName)()} api show ${slug} <path>' for endpoint details`));
|
|
213
|
+
console.log(chalk_1.default.gray(`Run '${(0, utils_js_1.cliName)()} run ${slug} <path>' to call an endpoint`));
|
|
217
214
|
}
|
|
218
215
|
catch (error) {
|
|
219
216
|
spinner.stop();
|
package/dist/commands/auth.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export declare function loginCommand(options: {
|
|
|
2
2
|
key?: string;
|
|
3
3
|
}): Promise<void>;
|
|
4
4
|
export declare function logoutCommand(): Promise<void>;
|
|
5
|
-
export declare function whoamiCommand(
|
|
5
|
+
export declare function whoamiCommand(options?: {
|
|
6
|
+
json?: boolean;
|
|
7
|
+
}): Promise<void>;
|
package/dist/commands/auth.js
CHANGED
|
@@ -11,7 +11,9 @@ const crypto_1 = __importDefault(require("crypto"));
|
|
|
11
11
|
const http_1 = __importDefault(require("http"));
|
|
12
12
|
const config_js_1 = require("../config.js");
|
|
13
13
|
const api_js_1 = require("../api.js");
|
|
14
|
-
const
|
|
14
|
+
const analytics_js_1 = require("../analytics.js");
|
|
15
|
+
const urls_js_1 = require("../urls.js");
|
|
16
|
+
const utils_js_1 = require("../utils.js");
|
|
15
17
|
function escapeHtml(str) {
|
|
16
18
|
return str
|
|
17
19
|
.replace(/&/g, "&")
|
|
@@ -82,8 +84,15 @@ async function browserLogin() {
|
|
|
82
84
|
reject(new Error("Invalid key format"));
|
|
83
85
|
return;
|
|
84
86
|
}
|
|
85
|
-
|
|
87
|
+
// The team chosen on the approval page; none is the personal team.
|
|
88
|
+
const teamId = url.searchParams.get("team");
|
|
89
|
+
const team = teamId
|
|
90
|
+
? { id: teamId, name: url.searchParams.get("team_name") || teamId }
|
|
91
|
+
: undefined;
|
|
92
|
+
(0, config_js_1.setApiKey)(key, team);
|
|
93
|
+
(0, analytics_js_1.queueEvent)("login.succeeded", { method: "browser" });
|
|
86
94
|
console.log(chalk_1.default.green("\n✓ Logged in successfully!"));
|
|
95
|
+
console.log(chalk_1.default.gray(` Team: ${(0, utils_js_1.sanitizeForTerminal)(team?.name ?? "Personal team")}`));
|
|
87
96
|
console.log(chalk_1.default.gray(` Key: ${key.slice(0, 15)}...${key.slice(-4)}`));
|
|
88
97
|
server.close();
|
|
89
98
|
resolve();
|
|
@@ -120,7 +129,7 @@ async function browserLogin() {
|
|
|
120
129
|
}
|
|
121
130
|
const port = address.port;
|
|
122
131
|
const callbackUrl = `http://127.0.0.1:${port}/callback`;
|
|
123
|
-
const authUrl = `${
|
|
132
|
+
const authUrl = `${(0, urls_js_1.webBaseUrl)()}/cli-auth?callback=${encodeURIComponent(callbackUrl)}&state=${state}`;
|
|
124
133
|
console.log(chalk_1.default.gray("Opening browser to authenticate..."));
|
|
125
134
|
console.log(chalk_1.default.gray(`If it doesn't open, visit: ${authUrl}\n`));
|
|
126
135
|
openBrowser(authUrl);
|
|
@@ -138,7 +147,15 @@ async function browserLogin() {
|
|
|
138
147
|
});
|
|
139
148
|
}
|
|
140
149
|
async function loginCommand(options) {
|
|
141
|
-
|
|
150
|
+
(0, analytics_js_1.sendLoginStarted)();
|
|
151
|
+
// ORTHOGONAL_API_KEY wins over any stored login (getApiKey), so a login
|
|
152
|
+
// here would change nothing: say so instead of storing that key.
|
|
153
|
+
if (!options.key && process.env.ORTHOGONAL_API_KEY) {
|
|
154
|
+
console.error(chalk_1.default.yellow("ORTHOGONAL_API_KEY is set in this shell, and it overrides any login: every command sends that key."));
|
|
155
|
+
console.error(chalk_1.default.yellow(`To sign in, run \`unset ORTHOGONAL_API_KEY\` first, then: ${(0, utils_js_1.cliName)()} login`));
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
const key = options.key;
|
|
142
159
|
if (key) {
|
|
143
160
|
// Direct key login (existing flow)
|
|
144
161
|
if (!key.startsWith("orth_")) {
|
|
@@ -146,6 +163,7 @@ async function loginCommand(options) {
|
|
|
146
163
|
process.exit(1);
|
|
147
164
|
}
|
|
148
165
|
(0, config_js_1.setApiKey)(key);
|
|
166
|
+
(0, analytics_js_1.queueEvent)("login.succeeded", { method: "key" });
|
|
149
167
|
console.log(chalk_1.default.green("✓ Logged in successfully!"));
|
|
150
168
|
console.log(chalk_1.default.gray(` Key: ${key.slice(0, 15)}...${key.slice(-4)}`));
|
|
151
169
|
return;
|
|
@@ -160,13 +178,37 @@ async function loginCommand(options) {
|
|
|
160
178
|
}
|
|
161
179
|
async function logoutCommand() {
|
|
162
180
|
(0, config_js_1.clearApiKey)();
|
|
163
|
-
console.log(chalk_1.default.green("✓ Logged out. API key removed."));
|
|
181
|
+
console.log(chalk_1.default.green("✓ Logged out. Every stored API key removed."));
|
|
164
182
|
}
|
|
165
|
-
async function whoamiCommand() {
|
|
183
|
+
async function whoamiCommand(options = {}) {
|
|
166
184
|
const key = (0, config_js_1.getApiKey)();
|
|
167
185
|
if (!key) {
|
|
186
|
+
if (options.json) {
|
|
187
|
+
console.log(JSON.stringify({ authenticated: false }, null, 2));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
168
190
|
console.log(chalk_1.default.yellow("Not authenticated"));
|
|
169
|
-
console.log(chalk_1.default.gray(
|
|
191
|
+
console.log(chalk_1.default.gray(`Run '${(0, utils_js_1.cliName)()} login' to authenticate`));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const keyHint = `${key.slice(0, 15)}...${key.slice(-4)}`;
|
|
195
|
+
const source = process.env.ORTHOGONAL_API_KEY ? "environment" : "config file";
|
|
196
|
+
// The team whose stored key is in use; a key from the environment has none.
|
|
197
|
+
const team = process.env.ORTHOGONAL_API_KEY
|
|
198
|
+
? undefined
|
|
199
|
+
: (0, config_js_1.getKeyTeams)().find((stored) => stored.active);
|
|
200
|
+
if (options.json) {
|
|
201
|
+
// /v1/me's answer as it is, plus the key's hint and where it came from.
|
|
202
|
+
// A 404 means the API predates /me; anything else fails the command.
|
|
203
|
+
let me;
|
|
204
|
+
try {
|
|
205
|
+
me = await (0, api_js_1.getMe)();
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
if (error.status !== 404)
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
console.log(JSON.stringify({ authenticated: true, ...me, ...(team && { team: { id: team.id, name: team.name } }), keyHint, source }, null, 2));
|
|
170
212
|
return;
|
|
171
213
|
}
|
|
172
214
|
console.log(chalk_1.default.green("✓ Authenticated"));
|
|
@@ -198,6 +240,8 @@ async function whoamiCommand() {
|
|
|
198
240
|
console.log(chalk_1.default.yellow(` Could not load account details: ${message}`));
|
|
199
241
|
}
|
|
200
242
|
}
|
|
201
|
-
|
|
202
|
-
|
|
243
|
+
if (team)
|
|
244
|
+
console.log(chalk_1.default.gray(` Team: ${(0, utils_js_1.sanitizeForTerminal)(team.name)} (switch with: ${(0, utils_js_1.cliName)()} team use)`));
|
|
245
|
+
console.log(chalk_1.default.gray(` Key: ${keyHint}`));
|
|
246
|
+
console.log(chalk_1.default.gray(` Source: ${source}`));
|
|
203
247
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type OnboardFlowOptions } from "./shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* orth api-onboarding list - Your organization's onboarding requests
|
|
4
|
+
*/
|
|
5
|
+
export declare function onboardListCommand(options: OnboardFlowOptions): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* orth api-onboarding new <docsUrl> - Ask Orthogonal to list your API
|
|
8
|
+
*/
|
|
9
|
+
export declare function onboardNewCommand(docsUrl: string, options: OnboardFlowOptions): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* orth api-onboarding start [request] - Start (or reply to, or resume) the
|
|
12
|
+
* Agent in the background
|
|
13
|
+
*/
|
|
14
|
+
export declare function onboardStartCommand(given: string | undefined, options: OnboardFlowOptions): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* orth api-onboarding status [request] - Where the onboarding is
|
|
17
|
+
*/
|
|
18
|
+
export declare function onboardStatusCommand(given: string | undefined, options: OnboardFlowOptions): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* orth api-onboarding stop [request] - Stop the agent's background work
|
|
21
|
+
*/
|
|
22
|
+
export declare function onboardStopCommand(given: string | undefined, options: OnboardFlowOptions): Promise<void>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.onboardListCommand = onboardListCommand;
|
|
7
|
+
exports.onboardNewCommand = onboardNewCommand;
|
|
8
|
+
exports.onboardStartCommand = onboardStartCommand;
|
|
9
|
+
exports.onboardStatusCommand = onboardStatusCommand;
|
|
10
|
+
exports.onboardStopCommand = onboardStopCommand;
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
const ora_1 = __importDefault(require("ora"));
|
|
13
|
+
const organizations_js_1 = require("../../organizations.js");
|
|
14
|
+
const utils_js_1 = require("../../utils.js");
|
|
15
|
+
const progress_js_1 = require("./progress.js");
|
|
16
|
+
const requests_js_1 = require("./requests.js");
|
|
17
|
+
const shared_js_1 = require("./shared.js");
|
|
18
|
+
/**
|
|
19
|
+
* orth api-onboarding list - Your organization's onboarding requests
|
|
20
|
+
*/
|
|
21
|
+
async function onboardListCommand(options) {
|
|
22
|
+
try {
|
|
23
|
+
const org = await (0, organizations_js_1.resolveOrganization)(options.org);
|
|
24
|
+
const spinner = options.json ? null : (0, ora_1.default)("Loading onboarding requests...").start();
|
|
25
|
+
const { requests } = await (0, shared_js_1.runTool)("list_requests", org);
|
|
26
|
+
spinner?.stop();
|
|
27
|
+
if (options.json) {
|
|
28
|
+
console.log(JSON.stringify(requests, null, 2));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!requests.length) {
|
|
32
|
+
console.log(chalk_1.default.gray(`\n No onboarding requests for ${(0, utils_js_1.sanitizeForTerminal)(org.name)} yet. Start one:\n ${(0, shared_js_1.cmd)("new <docsUrl> --name <api>")}\n`));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
console.log(chalk_1.default.bold(`\n API onboarding · ${(0, utils_js_1.sanitizeForTerminal)(org.name)}\n`));
|
|
36
|
+
for (const request of requests) {
|
|
37
|
+
console.log(` ${chalk_1.default.cyan.bold((0, shared_js_1.clean)(request.apiName).padEnd(40))} ${(0, requests_js_1.stateOf)(request)}`);
|
|
38
|
+
}
|
|
39
|
+
console.log(chalk_1.default.gray(`\n Details: ${(0, shared_js_1.cmd)("status")}\n`));
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
(0, shared_js_1.fail)(error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* orth api-onboarding new <docsUrl> - Ask Orthogonal to list your API
|
|
47
|
+
*/
|
|
48
|
+
async function onboardNewCommand(docsUrl, options) {
|
|
49
|
+
try {
|
|
50
|
+
docsUrl = (0, shared_js_1.httpsUrl)(docsUrl, "The documentation URL");
|
|
51
|
+
if (options.website)
|
|
52
|
+
options.website = (0, shared_js_1.httpsUrl)(options.website, "--website");
|
|
53
|
+
const moreDocs = (options.moreDocs ?? []).map((url) => (0, shared_js_1.httpsUrl)(url, "--more-docs"));
|
|
54
|
+
const org = await (0, organizations_js_1.resolveOrganization)(options.org);
|
|
55
|
+
const spinner = options.json ? null : (0, ora_1.default)("Requesting...").start();
|
|
56
|
+
const { request } = await (0, shared_js_1.runTool)("create_request", org, undefined, {
|
|
57
|
+
apiName: options.name,
|
|
58
|
+
documentationUrl: docsUrl,
|
|
59
|
+
...(options.useCase ? { useCase: options.useCase } : {}),
|
|
60
|
+
...(options.website ? { companyWebsite: options.website } : {}),
|
|
61
|
+
...(moreDocs.length ? { supplementalDocumentationUrls: moreDocs } : {}),
|
|
62
|
+
});
|
|
63
|
+
spinner?.stop();
|
|
64
|
+
if (options.json) {
|
|
65
|
+
console.log(JSON.stringify(request, null, 2));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
console.log(chalk_1.default.green(`\n Requested ${(0, utils_js_1.sanitizeForTerminal)(request.apiName)}`) +
|
|
69
|
+
chalk_1.default.gray(` for ${(0, utils_js_1.sanitizeForTerminal)(org.name)}`));
|
|
70
|
+
console.log(`\n Orthogonal reviews the request. Once it is approved, the agent starts setting up the API by itself.\n Follow it: ${chalk_1.default.cyan((0, shared_js_1.cmd)("status --watch"))}\n`);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
(0, shared_js_1.fail)(error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* orth api-onboarding start [request] - Start (or reply to, or resume) the
|
|
78
|
+
* Agent in the background
|
|
79
|
+
*/
|
|
80
|
+
async function onboardStartCommand(given, options) {
|
|
81
|
+
try {
|
|
82
|
+
const org = await (0, organizations_js_1.resolveOrganization)(options.org);
|
|
83
|
+
const request = await (0, requests_js_1.resolveRequest)(org, given, requests_js_1.inProgress, "start");
|
|
84
|
+
const requestId = request.id;
|
|
85
|
+
const spinner = options.json ? null : (0, ora_1.default)("Starting the agent...").start();
|
|
86
|
+
const started = await (0, shared_js_1.runTool)("start_onboarding", org, requestId, options.message ? { message: options.message } : {});
|
|
87
|
+
spinner?.stop();
|
|
88
|
+
if (options.json) {
|
|
89
|
+
console.log(JSON.stringify(started, null, 2));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const api = request.apiName ? (0, shared_js_1.clean)(request.apiName) : "your API";
|
|
93
|
+
const said = {
|
|
94
|
+
started: options.message
|
|
95
|
+
? "The agent has your reply and works on it in the background."
|
|
96
|
+
: `The agent is onboarding ${api} in the background.`,
|
|
97
|
+
queued: "The agent is working; it reads your reply in its next step.",
|
|
98
|
+
running: "The agent is already working on it.",
|
|
99
|
+
}[started.state];
|
|
100
|
+
console.log(chalk_1.default.green(`\n ${said}`));
|
|
101
|
+
console.log(chalk_1.default.gray(" You can close this terminal. Follow it here or in the dashboard:"));
|
|
102
|
+
console.log(` ${chalk_1.default.cyan((0, shared_js_1.cmd)("status --watch"))}`);
|
|
103
|
+
console.log(` ${chalk_1.default.cyan((0, utils_js_1.sanitizeForTerminal)(started.dashboardUrl))}\n`);
|
|
104
|
+
if (options.watch) {
|
|
105
|
+
await (0, progress_js_1.watchProgress)(requestId, org, await (0, progress_js_1.fetchProgress)(requestId, org), 3);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
(0, shared_js_1.fail)(error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* orth api-onboarding status [request] - Where the onboarding is
|
|
114
|
+
*/
|
|
115
|
+
async function onboardStatusCommand(given, options) {
|
|
116
|
+
try {
|
|
117
|
+
const org = await (0, organizations_js_1.resolveOrganization)(options.org);
|
|
118
|
+
const { id: requestId } = await (0, requests_js_1.resolveRequest)(org, given, requests_js_1.inProgress, "check", "status");
|
|
119
|
+
const progress = await (0, progress_js_1.fetchProgress)(requestId, org);
|
|
120
|
+
// With --json, --watch prints once. nextStep.command says `status
|
|
121
|
+
// --watch` while the agent works or Orthogonal approves, and an agent
|
|
122
|
+
// running it with --json checks again later instead of blocking for hours.
|
|
123
|
+
if (options.json) {
|
|
124
|
+
console.log(JSON.stringify(progress, null, 2));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
(0, progress_js_1.printProgress)(progress, org);
|
|
128
|
+
if (options.watch)
|
|
129
|
+
await (0, progress_js_1.watchProgress)(requestId, org, progress);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
(0, shared_js_1.fail)(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* orth api-onboarding stop [request] - Stop the agent's background work
|
|
137
|
+
*/
|
|
138
|
+
async function onboardStopCommand(given, options) {
|
|
139
|
+
try {
|
|
140
|
+
const org = await (0, organizations_js_1.resolveOrganization)(options.org);
|
|
141
|
+
const request = await (0, requests_js_1.resolveRequest)(org, given, requests_js_1.inProgress, "stop");
|
|
142
|
+
const requestId = request.id;
|
|
143
|
+
const { stopped } = await (0, shared_js_1.runTool)("stop_onboarding", org, requestId);
|
|
144
|
+
if (options.json) {
|
|
145
|
+
console.log(JSON.stringify({ stopped }, null, 2));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
console.log(stopped
|
|
149
|
+
? chalk_1.default.green(`\n Stopped${request.apiName ? ` ${(0, shared_js_1.clean)(request.apiName)}` : ""}. Resume any time: ${(0, shared_js_1.cmd)("start")}\n`)
|
|
150
|
+
: chalk_1.default.gray("\n The agent was not working.\n"));
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
(0, shared_js_1.fail)(error);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* orth api-onboarding guide - How listing an API works, for people and agents
|
|
3
|
+
* (--json: the same text as {"guide": ...}, for an agent that adds --json
|
|
4
|
+
* to every command)
|
|
5
|
+
*/
|
|
6
|
+
export declare function onboardGuideCommand(options?: {
|
|
7
|
+
json?: boolean;
|
|
8
|
+
}): void;
|