@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
|
@@ -0,0 +1,126 @@
|
|
|
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.orgCommand = orgCommand;
|
|
7
|
+
exports.orgUseCommand = orgUseCommand;
|
|
8
|
+
exports.teamCommand = teamCommand;
|
|
9
|
+
exports.teamUseCommand = teamUseCommand;
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const ora_1 = __importDefault(require("ora"));
|
|
12
|
+
const config_js_1 = require("../config.js");
|
|
13
|
+
const organizations_js_1 = require("../organizations.js");
|
|
14
|
+
const urls_js_1 = require("../urls.js");
|
|
15
|
+
const utils_js_1 = require("../utils.js");
|
|
16
|
+
function fail(error) {
|
|
17
|
+
(0, utils_js_1.printError)(error);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* orth org - The organizations you sell APIs with, and the default one for
|
|
22
|
+
* api-onboarding and payouts
|
|
23
|
+
*/
|
|
24
|
+
async function orgCommand(options) {
|
|
25
|
+
const spinner = options.json ? null : (0, ora_1.default)("Loading your organizations...").start();
|
|
26
|
+
try {
|
|
27
|
+
const orgs = await (0, organizations_js_1.listOrganizations)();
|
|
28
|
+
spinner?.stop();
|
|
29
|
+
const current = (0, config_js_1.getDefaultOrganization)((0, urls_js_1.apiBaseUrl)());
|
|
30
|
+
if (options.json) {
|
|
31
|
+
console.log(JSON.stringify({ current: current ?? null, organizations: orgs }, null, 2));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!orgs.length) {
|
|
35
|
+
console.log(chalk_1.default.gray("\n You don't administer an organization that sells APIs yet.\n"));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
console.log(chalk_1.default.bold("\n Your organizations\n"));
|
|
39
|
+
for (const org of orgs) {
|
|
40
|
+
const used = current?.id === org.id || (!current && orgs.length === 1);
|
|
41
|
+
console.log(` ${used ? chalk_1.default.green("●") : " "} ${(0, utils_js_1.sanitizeForTerminal)(org.name).padEnd(36)}` +
|
|
42
|
+
chalk_1.default.gray((0, utils_js_1.sanitizeForTerminal)(org.id)));
|
|
43
|
+
}
|
|
44
|
+
console.log(chalk_1.default.gray(current || orgs.length === 1
|
|
45
|
+
? `\n ● is the default for api-onboarding and payouts. Change it with: ${(0, utils_js_1.cliName)()} org use\n`
|
|
46
|
+
: `\n Choose the default for api-onboarding and payouts: ${(0, utils_js_1.cliName)()} org use\n`));
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
spinner?.stop();
|
|
50
|
+
fail(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* orth org use [name] - Choose the default organization for api-onboarding
|
|
55
|
+
* and payouts (who pays for calls follows the key)
|
|
56
|
+
*/
|
|
57
|
+
async function orgUseCommand(query) {
|
|
58
|
+
try {
|
|
59
|
+
const orgs = await (0, organizations_js_1.listOrganizations)();
|
|
60
|
+
if (!orgs.length)
|
|
61
|
+
throw new Error("You don't administer an organization that sells APIs.");
|
|
62
|
+
if (!query) {
|
|
63
|
+
if (!(0, utils_js_1.isInteractive)())
|
|
64
|
+
throw new Error(`Name the organization: ${(0, utils_js_1.cliName)()} org use "<name>"`);
|
|
65
|
+
await (0, organizations_js_1.pickOrganization)(orgs);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const org = (0, organizations_js_1.matchOrganization)(orgs, query);
|
|
69
|
+
if (!org) {
|
|
70
|
+
throw new Error(`No organization of yours matches "${(0, utils_js_1.sanitizeForTerminal)(query)}". Run ${(0, utils_js_1.cliName)()} org to see them.`);
|
|
71
|
+
}
|
|
72
|
+
(0, config_js_1.setDefaultOrganization)((0, urls_js_1.apiBaseUrl)(), org);
|
|
73
|
+
console.log(chalk_1.default.green(`\n Saved ${(0, utils_js_1.sanitizeForTerminal)(org.name)} as the default for api-onboarding and payouts.\n`));
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
fail(error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* orth team - The teams this machine holds a key for (one per team, from
|
|
81
|
+
* `orth login`), and the active one: its key is the one every command sends
|
|
82
|
+
*/
|
|
83
|
+
async function teamCommand(options) {
|
|
84
|
+
const teams = (0, config_js_1.getKeyTeams)();
|
|
85
|
+
if (options.json) {
|
|
86
|
+
console.log(JSON.stringify({ teams }, null, 2));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!teams.length) {
|
|
90
|
+
console.log(chalk_1.default.gray(`\n No team yet. Sign in with: ${(0, utils_js_1.cliName)()} login\n`));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
console.log(chalk_1.default.bold("\n Your teams\n"));
|
|
94
|
+
for (const team of teams) {
|
|
95
|
+
console.log(` ${team.active ? chalk_1.default.green("●") : " "} ${(0, utils_js_1.sanitizeForTerminal)(team.name).padEnd(36)}` +
|
|
96
|
+
chalk_1.default.gray((0, utils_js_1.sanitizeForTerminal)(team.id)));
|
|
97
|
+
}
|
|
98
|
+
console.log(chalk_1.default.gray(`\n ● pays for your calls. Switch with: ${(0, utils_js_1.cliName)()} team use. Add a team with: ${(0, utils_js_1.cliName)()} login\n`));
|
|
99
|
+
if (process.env.ORTHOGONAL_API_KEY) {
|
|
100
|
+
console.log(chalk_1.default.yellow(" ORTHOGONAL_API_KEY is set in this shell and overrides every stored key.\n"));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** orth team use [name] - Switch the active team to another one signed in to */
|
|
104
|
+
async function teamUseCommand(query) {
|
|
105
|
+
try {
|
|
106
|
+
const teams = (0, config_js_1.getKeyTeams)();
|
|
107
|
+
if (!teams.length)
|
|
108
|
+
throw new Error(`No team yet. Sign in with: ${(0, utils_js_1.cliName)()} login`);
|
|
109
|
+
let team;
|
|
110
|
+
if (query) {
|
|
111
|
+
team = (0, organizations_js_1.matchOrganization)(teams, query);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
if (!(0, utils_js_1.isInteractive)())
|
|
115
|
+
throw new Error(`Name the team: ${(0, utils_js_1.cliName)()} team use "<name>"`);
|
|
116
|
+
team = teams[await (0, utils_js_1.choose)("Which team?", teams.map((candidate) => candidate.name))];
|
|
117
|
+
}
|
|
118
|
+
if (!team || !(0, config_js_1.switchKeyTeam)(team.id)) {
|
|
119
|
+
throw new Error(`No team signed in to matches "${(0, utils_js_1.sanitizeForTerminal)(query ?? "")}". Run ${(0, utils_js_1.cliName)()} team to see them, or ${(0, utils_js_1.cliName)()} login to add one.`);
|
|
120
|
+
}
|
|
121
|
+
console.log(chalk_1.default.green(`\n ${(0, utils_js_1.sanitizeForTerminal)(team.name)} is now the active team.\n`));
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
fail(error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
interface Payout {
|
|
2
|
+
id: string;
|
|
3
|
+
/** Ledger units (100,000 = $1). */
|
|
4
|
+
amountCents: number;
|
|
5
|
+
status: "PENDING" | "COMPLETED" | "FAILED" | "CANCELLED";
|
|
6
|
+
createdAt: string;
|
|
7
|
+
completedAt: string | null;
|
|
8
|
+
}
|
|
9
|
+
interface PayoutsResponse {
|
|
10
|
+
organizationId: string;
|
|
11
|
+
available: boolean;
|
|
12
|
+
account: {
|
|
13
|
+
ready: boolean;
|
|
14
|
+
requirementsDue: number;
|
|
15
|
+
} | null;
|
|
16
|
+
/** Ledger units owed now (100,000 = $1). */
|
|
17
|
+
owedCents: number;
|
|
18
|
+
/** What the organization's APIs earned, in ledger units; absent on older servers. */
|
|
19
|
+
earnings?: {
|
|
20
|
+
earnedCents: number;
|
|
21
|
+
earnedThisMonthCents: number;
|
|
22
|
+
paidCalls: number;
|
|
23
|
+
};
|
|
24
|
+
setupUrl: string;
|
|
25
|
+
payouts: Payout[];
|
|
26
|
+
}
|
|
27
|
+
export interface PayoutsOptions {
|
|
28
|
+
/** A name, part of one, or an id; default: the one `org use` chose. */
|
|
29
|
+
org?: string;
|
|
30
|
+
json?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** Ledger units as dollars, as the web shows them. */
|
|
33
|
+
export declare function formatUnits(units: number): string;
|
|
34
|
+
/** The account's state in the web's words (/account/payouts). */
|
|
35
|
+
export declare function payoutsSummary(data: PayoutsResponse): string[];
|
|
36
|
+
/**
|
|
37
|
+
* orth payouts - A provider org's payout status, what it is owed and what it earned
|
|
38
|
+
*/
|
|
39
|
+
export declare function payoutsCommand(options: PayoutsOptions): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* orth payouts history - The payouts made to a provider org, newest first
|
|
42
|
+
*/
|
|
43
|
+
export declare function payoutsHistoryCommand(options: PayoutsOptions): Promise<void>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
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.formatUnits = formatUnits;
|
|
7
|
+
exports.payoutsSummary = payoutsSummary;
|
|
8
|
+
exports.payoutsCommand = payoutsCommand;
|
|
9
|
+
exports.payoutsHistoryCommand = payoutsHistoryCommand;
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const ora_1 = __importDefault(require("ora"));
|
|
12
|
+
const api_js_1 = require("../api.js");
|
|
13
|
+
const organizations_js_1 = require("../organizations.js");
|
|
14
|
+
const utils_js_1 = require("../utils.js");
|
|
15
|
+
const UNITS_PER_DOLLAR = 100_000;
|
|
16
|
+
/** Ledger units as dollars, as the web shows them. */
|
|
17
|
+
function formatUnits(units) {
|
|
18
|
+
return `$${(units / UNITS_PER_DOLLAR).toFixed(2)}`;
|
|
19
|
+
}
|
|
20
|
+
const STATUS_COLORS = {
|
|
21
|
+
PENDING: chalk_1.default.yellow,
|
|
22
|
+
COMPLETED: chalk_1.default.green,
|
|
23
|
+
FAILED: chalk_1.default.red,
|
|
24
|
+
CANCELLED: chalk_1.default.gray,
|
|
25
|
+
};
|
|
26
|
+
async function fetchPayouts(options, label) {
|
|
27
|
+
let spinner = null;
|
|
28
|
+
try {
|
|
29
|
+
const org = await (0, organizations_js_1.resolveOrganization)(options.org);
|
|
30
|
+
spinner = options.json ? null : (0, ora_1.default)(label).start();
|
|
31
|
+
const data = await (0, api_js_1.apiRequest)(`/payouts?org=${encodeURIComponent(org.id)}`);
|
|
32
|
+
spinner?.stop();
|
|
33
|
+
if (options.json) {
|
|
34
|
+
console.log(JSON.stringify(data, null, 2));
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return { ...data, organizationName: org.name };
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
spinner?.stop();
|
|
41
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
42
|
+
if (message.includes("401") || message.includes("Authentication")) {
|
|
43
|
+
console.error(chalk_1.default.red(`\n Authentication failed. Check your API key with: ${(0, utils_js_1.cliName)()} login\n`));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.error(chalk_1.default.red(`\n Failed to fetch payouts: ${message}\n`));
|
|
47
|
+
}
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** The account's state in the web's words (/account/payouts). */
|
|
52
|
+
function payoutsSummary(data) {
|
|
53
|
+
const setupUrl = (0, utils_js_1.sanitizeForTerminal)(data.setupUrl);
|
|
54
|
+
const lines = [];
|
|
55
|
+
if (!data.available) {
|
|
56
|
+
lines.push(` ${chalk_1.default.gray("Stripe".padEnd(10))}${chalk_1.default.yellow("Not available for this organization yet")}`);
|
|
57
|
+
}
|
|
58
|
+
else if (data.account?.ready) {
|
|
59
|
+
lines.push(` ${chalk_1.default.gray("Stripe".padEnd(10))}${chalk_1.default.green("Ready to receive payouts")}`);
|
|
60
|
+
}
|
|
61
|
+
else if (data.account) {
|
|
62
|
+
const due = data.account.requirementsDue;
|
|
63
|
+
lines.push(` ${chalk_1.default.gray("Stripe".padEnd(10))}${chalk_1.default.yellow(`Setup unfinished${due ? ` (${due} requirement${due === 1 ? "" : "s"} due)` : ""}`)}`);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
lines.push(` ${chalk_1.default.gray("Stripe".padEnd(10))}${chalk_1.default.yellow("Not set up")}`);
|
|
67
|
+
}
|
|
68
|
+
lines.push(` ${chalk_1.default.gray("Owed".padEnd(10))}${chalk_1.default.green.bold(formatUnits(data.owedCents))}`);
|
|
69
|
+
if (data.earnings) {
|
|
70
|
+
const { earnedCents, earnedThisMonthCents, paidCalls } = data.earnings;
|
|
71
|
+
lines.push(` ${chalk_1.default.gray("Earned".padEnd(10))}${formatUnits(earnedCents)} lifetime` +
|
|
72
|
+
chalk_1.default.gray(` · ${formatUnits(earnedThisMonthCents)} this month · ` +
|
|
73
|
+
`${paidCalls.toLocaleString("en-US")} paid call${paidCalls === 1 ? "" : "s"}`));
|
|
74
|
+
}
|
|
75
|
+
if (!data.available) {
|
|
76
|
+
lines.push("", chalk_1.default.gray(" Your earnings remain recorded. Contact Orthogonal to check availability."));
|
|
77
|
+
}
|
|
78
|
+
else if (!data.account?.ready) {
|
|
79
|
+
lines.push("", ` ${data.account ? "Finish" : "Set up"} payouts in your browser, with this organization selected:`, ` ${chalk_1.default.cyan(setupUrl)}`);
|
|
80
|
+
}
|
|
81
|
+
return lines;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* orth payouts - A provider org's payout status, what it is owed and what it earned
|
|
85
|
+
*/
|
|
86
|
+
async function payoutsCommand(options) {
|
|
87
|
+
const data = await fetchPayouts(options, "Fetching payouts...");
|
|
88
|
+
if (!data)
|
|
89
|
+
return;
|
|
90
|
+
console.log(chalk_1.default.bold(`\n Payouts · ${(0, utils_js_1.sanitizeForTerminal)(data.organizationName)}\n`));
|
|
91
|
+
for (const line of payoutsSummary(data))
|
|
92
|
+
console.log(line);
|
|
93
|
+
console.log();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* orth payouts history - The payouts made to a provider org, newest first
|
|
97
|
+
*/
|
|
98
|
+
async function payoutsHistoryCommand(options) {
|
|
99
|
+
const data = await fetchPayouts(options, "Fetching payout history...");
|
|
100
|
+
if (!data)
|
|
101
|
+
return;
|
|
102
|
+
console.log(chalk_1.default.bold(`\n Payouts · ${(0, utils_js_1.sanitizeForTerminal)(data.organizationName)}\n`));
|
|
103
|
+
if (data.payouts.length === 0) {
|
|
104
|
+
console.log(chalk_1.default.gray(" No payouts yet.\n"));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
console.log(chalk_1.default.gray(" " + "Date".padEnd(22) + "Amount".padStart(12) + " " + "Status"));
|
|
108
|
+
console.log(chalk_1.default.gray(" " + "─".repeat(48)));
|
|
109
|
+
for (const payout of data.payouts) {
|
|
110
|
+
const date = new Date(payout.createdAt).toLocaleDateString("en-US", {
|
|
111
|
+
year: "numeric",
|
|
112
|
+
month: "short",
|
|
113
|
+
day: "numeric",
|
|
114
|
+
hour: "2-digit",
|
|
115
|
+
minute: "2-digit",
|
|
116
|
+
});
|
|
117
|
+
const color = STATUS_COLORS[payout.status] ?? chalk_1.default.white;
|
|
118
|
+
console.log(" " +
|
|
119
|
+
chalk_1.default.gray(date.padEnd(22)) +
|
|
120
|
+
chalk_1.default.green(formatUnits(payout.amountCents).padStart(12)) +
|
|
121
|
+
" " +
|
|
122
|
+
color((0, utils_js_1.sanitizeForTerminal)(payout.status.toLowerCase())));
|
|
123
|
+
}
|
|
124
|
+
console.log();
|
|
125
|
+
}
|
package/dist/commands/run.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export declare function runCommand(api: string, path: string, options: {
|
|
2
|
-
method
|
|
2
|
+
method?: string;
|
|
3
3
|
query?: string[];
|
|
4
4
|
body?: string;
|
|
5
5
|
data?: string;
|
|
6
6
|
raw?: boolean;
|
|
7
7
|
output?: string;
|
|
8
8
|
dryRun?: boolean;
|
|
9
|
+
searchId?: string;
|
|
9
10
|
}): Promise<void>;
|
package/dist/commands/run.js
CHANGED
|
@@ -9,6 +9,8 @@ const ora_1 = __importDefault(require("ora"));
|
|
|
9
9
|
const fs_1 = require("fs");
|
|
10
10
|
const path_1 = require("path");
|
|
11
11
|
const api_js_1 = require("../api.js");
|
|
12
|
+
const last_search_js_1 = require("../last-search.js");
|
|
13
|
+
const utils_js_1 = require("../utils.js");
|
|
12
14
|
// Map content-type to file extension
|
|
13
15
|
const CONTENT_TYPE_EXT = {
|
|
14
16
|
"image/jpeg": "jpg",
|
|
@@ -134,9 +136,9 @@ function printFailureHint(body) {
|
|
|
134
136
|
}
|
|
135
137
|
function formatCost(result) {
|
|
136
138
|
if (result.price)
|
|
137
|
-
return result.price;
|
|
139
|
+
return /^\$?0(\.0+)?$/.test(result.price) ? "Free" : result.price;
|
|
138
140
|
if (result.priceCents != null && result.priceCents > 0) {
|
|
139
|
-
return `$${parseFloat((result.priceCents / 100).toFixed(
|
|
141
|
+
return `$${parseFloat((result.priceCents / 100).toFixed(6))}`;
|
|
140
142
|
}
|
|
141
143
|
return null;
|
|
142
144
|
}
|
|
@@ -164,42 +166,34 @@ async function runCommand(api, path, options) {
|
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
|
-
//
|
|
169
|
+
// The body: JSON, or "-" to read it from stdin. Stdin is read only when
|
|
170
|
+
// asked, so a caller whose stdin never closes (an agent's shell) can't hang.
|
|
168
171
|
let body = undefined;
|
|
169
|
-
|
|
172
|
+
let bodyJson = options.body ?? options.data;
|
|
173
|
+
if (bodyJson === "-") {
|
|
174
|
+
const chunks = [];
|
|
175
|
+
for await (const chunk of process.stdin)
|
|
176
|
+
chunks.push(chunk);
|
|
177
|
+
bodyJson = Buffer.concat(chunks).toString().trim();
|
|
178
|
+
}
|
|
170
179
|
if (bodyJson) {
|
|
171
180
|
try {
|
|
172
181
|
body = JSON.parse(bodyJson);
|
|
173
182
|
}
|
|
174
183
|
catch {
|
|
175
184
|
spinner.stop();
|
|
176
|
-
console.error(chalk_1.default.red("Error:
|
|
185
|
+
console.error(chalk_1.default.red("Error: --body is not valid JSON"));
|
|
177
186
|
process.exit(1);
|
|
178
187
|
}
|
|
179
188
|
}
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
const chunks = [];
|
|
183
|
-
for await (const chunk of process.stdin) {
|
|
184
|
-
chunks.push(chunk);
|
|
185
|
-
}
|
|
186
|
-
const input = Buffer.concat(chunks).toString().trim();
|
|
187
|
-
if (input) {
|
|
188
|
-
try {
|
|
189
|
-
body = JSON.parse(input);
|
|
190
|
-
}
|
|
191
|
-
catch {
|
|
192
|
-
spinner.stop();
|
|
193
|
-
console.error(chalk_1.default.red("Error: Invalid JSON from stdin"));
|
|
194
|
-
process.exit(1);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
189
|
+
// A body means POST, as curl's -d does; an explicit -X always wins.
|
|
190
|
+
const method = (options.method ?? (body === undefined ? "GET" : "POST")).toUpperCase();
|
|
198
191
|
const result = await (0, api_js_1.run)(api, path, {
|
|
199
|
-
method
|
|
192
|
+
method,
|
|
200
193
|
query: Object.keys(query).length > 0 ? query : undefined,
|
|
201
194
|
body,
|
|
202
195
|
dryRun: options.dryRun,
|
|
196
|
+
searchId: options.searchId ?? (0, last_search_js_1.searchIdFor)(api, path),
|
|
203
197
|
});
|
|
204
198
|
spinner.stop();
|
|
205
199
|
// Handle dry-run response
|
|
@@ -210,7 +204,7 @@ async function runCommand(api, path, options) {
|
|
|
210
204
|
: null) ||
|
|
211
205
|
result.price ||
|
|
212
206
|
"unknown";
|
|
213
|
-
console.log(chalk_1.default.bold("\
|
|
207
|
+
console.log(chalk_1.default.bold("\nThis request: ") + chalk_1.default.yellow(estimatedCost));
|
|
214
208
|
console.log(chalk_1.default.gray("(Use without --dry-run to execute)"));
|
|
215
209
|
return;
|
|
216
210
|
}
|
|
@@ -218,11 +212,11 @@ async function runCommand(api, path, options) {
|
|
|
218
212
|
if (isBinaryEnvelope(result.data)) {
|
|
219
213
|
if (!options.output) {
|
|
220
214
|
const ext = extFromContentType(result.data.contentType);
|
|
221
|
-
const methodHint = options.method
|
|
215
|
+
const methodHint = options.method ? ` -X ${options.method}` : "";
|
|
222
216
|
const bodyHint = options.body || options.data ? " --body '...'" : "";
|
|
223
217
|
const queryHint = options.query?.length ? " -q '...'" : "";
|
|
224
218
|
console.log(chalk_1.default.yellow(`\nResponse contains binary ${ext.toUpperCase()} data (${result.data.size} bytes).` +
|
|
225
|
-
`\nUse -o to save it:
|
|
219
|
+
`\nUse -o to save it: ${(0, utils_js_1.cliName)()} api run ${api} ${path}${methodHint}${queryHint}${bodyHint} -o output.${ext}`));
|
|
226
220
|
const cost0 = formatCost(result);
|
|
227
221
|
if (cost0)
|
|
228
222
|
console.log(chalk_1.default.dim(`\nCost: ${cost0}`));
|
|
@@ -260,10 +254,10 @@ async function runCommand(api, path, options) {
|
|
|
260
254
|
console.log(chalk_1.default.bold("\nResponse:\n"));
|
|
261
255
|
console.log(JSON.stringify(result.data, null, 2));
|
|
262
256
|
}
|
|
263
|
-
// Show price if returned
|
|
257
|
+
// Show price if returned; with --raw on stderr, so stdout is only the body.
|
|
264
258
|
const cost3 = formatCost(result);
|
|
265
259
|
if (cost3) {
|
|
266
|
-
console.log(chalk_1.default.dim(`\nCost: ${cost3}`));
|
|
260
|
+
(options.raw ? console.error : console.log)(chalk_1.default.dim(`\nCost: ${cost3}`));
|
|
267
261
|
}
|
|
268
262
|
}
|
|
269
263
|
catch (error) {
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { SearchResponse } from "../api.js";
|
|
1
|
+
import { SearchResponse, EndpointQuality } from "../api.js";
|
|
2
|
+
/**
|
|
3
|
+
* "99.6%", "83.9% degraded" or "99.6% · API-wide": a hit's 30-day success
|
|
4
|
+
* rate, the website's warning word and whose calls; null below 100 calls.
|
|
5
|
+
* The rate rounds down, as the website shows it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function qualityMarker(quality: Pick<EndpointQuality, "tier" | "scope" | "successRate30d">): string | null;
|
|
2
8
|
export declare function searchCommand(query: string, options: {
|
|
3
9
|
limit: string;
|
|
10
|
+
json?: boolean;
|
|
4
11
|
}): Promise<SearchResponse>;
|
package/dist/commands/search.js
CHANGED
|
@@ -3,23 +3,45 @@ 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.qualityMarker = qualityMarker;
|
|
6
7
|
exports.searchCommand = searchCommand;
|
|
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 api_js_2 = require("./api.js");
|
|
13
|
+
const last_search_js_1 = require("../last-search.js");
|
|
14
|
+
/**
|
|
15
|
+
* "99.6%", "83.9% degraded" or "99.6% · API-wide": a hit's 30-day success
|
|
16
|
+
* rate, the website's warning word and whose calls; null below 100 calls.
|
|
17
|
+
* The rate rounds down, as the website shows it.
|
|
18
|
+
*/
|
|
19
|
+
function qualityMarker(quality) {
|
|
20
|
+
if (quality.successRate30d == null)
|
|
21
|
+
return null;
|
|
22
|
+
const percent = Math.floor(quality.successRate30d * 1000 + 1e-9) / 10;
|
|
23
|
+
const warning = api_js_2.TIER_WARNING[quality.tier];
|
|
24
|
+
return `${percent}%${warning ? ` ${warning}` : ""}` +
|
|
25
|
+
(quality.scope === "api" ? " · API-wide" : "");
|
|
26
|
+
}
|
|
11
27
|
async function searchCommand(query, options) {
|
|
12
28
|
const spinner = (0, ora_1.default)("Searching APIs...").start();
|
|
13
29
|
try {
|
|
14
30
|
const data = await (0, api_js_1.search)(query, parseInt(options.limit, 10));
|
|
15
31
|
spinner.stop();
|
|
32
|
+
(0, last_search_js_1.rememberSearch)(data);
|
|
33
|
+
if (options.json) {
|
|
34
|
+
console.log(JSON.stringify(data, null, 2));
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
16
37
|
if (!data.results || data.results.length === 0) {
|
|
17
38
|
console.log(chalk_1.default.yellow("No APIs found matching your query."));
|
|
18
39
|
return data;
|
|
19
40
|
}
|
|
20
41
|
console.log(chalk_1.default.bold(`\nFound ${data.apisCount} APIs with ${data.count} matching endpoints:\n`));
|
|
21
42
|
for (const api of data.results) {
|
|
22
|
-
|
|
43
|
+
const integration = api.kind === "integration" ? chalk_1.default.gray(" · OAuth integration, free per call") : "";
|
|
44
|
+
console.log(chalk_1.default.cyan.bold(`${api.name}`) + chalk_1.default.gray(` (${api.slug})`) + integration);
|
|
23
45
|
for (const endpoint of api.endpoints.slice(0, 3)) {
|
|
24
46
|
const method = endpoint.method.padEnd(6);
|
|
25
47
|
// Group members commonly collide on the same upstream path (e.g.
|
|
@@ -29,10 +51,12 @@ async function searchCommand(query, options) {
|
|
|
29
51
|
const memberTag = endpoint.apiSlug && endpoint.apiSlug !== api.slug
|
|
30
52
|
? chalk_1.default.dim(` [${(0, utils_js_1.sanitizeForTerminal)(endpoint.apiSlug)}]`)
|
|
31
53
|
: "";
|
|
54
|
+
const marker = endpoint.quality && qualityMarker(endpoint.quality);
|
|
32
55
|
console.log(chalk_1.default.gray(" ") +
|
|
33
56
|
chalk_1.default.yellow(method) +
|
|
34
57
|
chalk_1.default.white(endpoint.path) +
|
|
35
|
-
memberTag
|
|
58
|
+
memberTag +
|
|
59
|
+
(marker ? chalk_1.default.gray(` ${marker}`) : ""));
|
|
36
60
|
if (endpoint.description) {
|
|
37
61
|
console.log(chalk_1.default.gray(` ${endpoint.description.slice(0, 80)}${endpoint.description.length > 80 ? "..." : ""}`));
|
|
38
62
|
}
|
|
@@ -42,8 +66,8 @@ async function searchCommand(query, options) {
|
|
|
42
66
|
}
|
|
43
67
|
console.log();
|
|
44
68
|
}
|
|
45
|
-
console.log(chalk_1.default.gray(`Run '
|
|
46
|
-
console.log(chalk_1.default.gray(`Run '
|
|
69
|
+
console.log(chalk_1.default.gray(`Run '${(0, utils_js_1.cliName)()} api show <slug>' to see all endpoints for an API`));
|
|
70
|
+
console.log(chalk_1.default.gray(`Run '${(0, utils_js_1.cliName)()} run <slug> <path>' to call an endpoint`));
|
|
47
71
|
return data;
|
|
48
72
|
}
|
|
49
73
|
catch (error) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SkillSearchResponse } from "./shared.js";
|
|
2
|
+
export declare function skillsListCommand(options: {
|
|
3
|
+
limit: string;
|
|
4
|
+
json?: boolean;
|
|
5
|
+
}): Promise<void>;
|
|
6
|
+
export declare function skillsMineCommand(options: {
|
|
7
|
+
limit: string;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function skillsSearchCommand(query: string, options: {
|
|
10
|
+
limit: string;
|
|
11
|
+
json?: boolean;
|
|
12
|
+
}): Promise<SkillSearchResponse>;
|
|
13
|
+
export declare function skillsShowCommand(slug: string, options?: {
|
|
14
|
+
json?: boolean;
|
|
15
|
+
}): Promise<void>;
|