@orth/cli 0.3.1 → 0.4.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +113 -109
  3. package/dist/analytics.d.ts +36 -8
  4. package/dist/analytics.js +247 -47
  5. package/dist/api.d.ts +28 -2
  6. package/dist/api.js +67 -13
  7. package/dist/command-actions.d.ts +10 -0
  8. package/dist/command-actions.js +42 -0
  9. package/dist/commands/account.d.ts +9 -1
  10. package/dist/commands/account.js +26 -10
  11. package/dist/commands/api.d.ts +3 -0
  12. package/dist/commands/api.js +104 -114
  13. package/dist/commands/auth.d.ts +3 -1
  14. package/dist/commands/auth.js +53 -9
  15. package/dist/commands/onboard/flow.d.ts +22 -0
  16. package/dist/commands/onboard/flow.js +155 -0
  17. package/dist/commands/onboard/guide.d.ts +8 -0
  18. package/dist/commands/onboard/guide.js +73 -0
  19. package/dist/commands/onboard/listing.d.ts +18 -0
  20. package/dist/commands/onboard/listing.js +166 -0
  21. package/dist/commands/onboard/progress.d.ts +44 -0
  22. package/dist/commands/onboard/progress.js +108 -0
  23. package/dist/commands/onboard/register.d.ts +2 -0
  24. package/dist/commands/onboard/register.js +261 -0
  25. package/dist/commands/onboard/requests.d.ts +24 -0
  26. package/dist/commands/onboard/requests.js +96 -0
  27. package/dist/commands/onboard/review.d.ts +31 -0
  28. package/dist/commands/onboard/review.js +228 -0
  29. package/dist/commands/onboard/setup.d.ts +68 -0
  30. package/dist/commands/onboard/setup.js +215 -0
  31. package/dist/commands/onboard/shared.d.ts +41 -0
  32. package/dist/commands/onboard/shared.js +97 -0
  33. package/dist/commands/onboard/tools.d.ts +19 -0
  34. package/dist/commands/onboard/tools.js +104 -0
  35. package/dist/commands/org.d.ts +21 -0
  36. package/dist/commands/org.js +126 -0
  37. package/dist/commands/payouts.d.ts +44 -0
  38. package/dist/commands/payouts.js +125 -0
  39. package/dist/commands/run.d.ts +1 -1
  40. package/dist/commands/run.js +18 -26
  41. package/dist/commands/search.d.ts +8 -1
  42. package/dist/commands/search.js +26 -4
  43. package/dist/commands/skills/browse.d.ts +15 -0
  44. package/dist/commands/skills/browse.js +194 -0
  45. package/dist/commands/skills/create.d.ts +5 -0
  46. package/dist/commands/skills/create.js +62 -0
  47. package/dist/commands/skills/init.d.ts +4 -0
  48. package/dist/commands/skills/init.js +123 -0
  49. package/dist/commands/skills/install.d.ts +6 -0
  50. package/dist/commands/skills/install.js +191 -0
  51. package/dist/commands/skills/local-files.d.ts +15 -0
  52. package/dist/commands/skills/local-files.js +110 -0
  53. package/dist/commands/skills/register.d.ts +2 -0
  54. package/dist/commands/skills/register.js +130 -0
  55. package/dist/commands/skills/shared.d.ts +43 -0
  56. package/dist/commands/skills/shared.js +69 -0
  57. package/dist/commands/skills/upload.d.ts +9 -0
  58. package/dist/commands/skills/upload.js +223 -0
  59. package/dist/commands/skills/verification.d.ts +5 -0
  60. package/dist/commands/skills/verification.js +74 -0
  61. package/dist/commands/telemetry.d.ts +3 -0
  62. package/dist/commands/telemetry.js +38 -0
  63. package/dist/config.d.ts +48 -1
  64. package/dist/config.js +99 -3
  65. package/dist/http.d.ts +15 -0
  66. package/dist/http.js +41 -0
  67. package/dist/index.js +131 -162
  68. package/dist/organizations.d.ts +14 -0
  69. package/dist/organizations.js +77 -0
  70. package/dist/urls.d.ts +3 -0
  71. package/dist/urls.js +34 -0
  72. package/dist/utils.d.ts +20 -0
  73. package/dist/utils.js +112 -0
  74. package/dist/version.d.ts +5 -0
  75. package/dist/version.js +21 -0
  76. package/dist/x402.d.ts +7 -0
  77. package/dist/x402.js +27 -0
  78. package/package.json +23 -22
  79. package/dist/commands/skills.d.ts +0 -66
  80. package/dist/commands/skills.js +0 -821
package/dist/index.js CHANGED
@@ -8,38 +8,21 @@ const api_js_1 = require("./commands/api.js");
8
8
  const auth_js_1 = require("./commands/auth.js");
9
9
  const account_js_1 = require("./commands/account.js");
10
10
  const code_js_1 = require("./commands/code.js");
11
- const skills_js_1 = require("./commands/skills.js");
12
11
  const apiRequest_js_1 = require("./commands/apiRequest.js");
12
+ const register_js_1 = require("./commands/onboard/register.js");
13
+ const register_js_2 = require("./commands/skills/register.js");
14
+ const org_js_1 = require("./commands/org.js");
15
+ const payouts_js_1 = require("./commands/payouts.js");
16
+ const telemetry_js_1 = require("./commands/telemetry.js");
17
+ const command_actions_js_1 = require("./command-actions.js");
13
18
  const analytics_js_1 = require("./analytics.js");
14
- /**
15
- * Wraps an async action callback so that rejected promises are caught,
16
- * logged, and set the process exit code to 1. Without this,
17
- * Commander.js silently swallows unhandled rejections from async actions.
18
- */
19
- function asyncAction(fn) {
20
- return (...args) => {
21
- fn(...args).catch((err) => {
22
- console.error(err instanceof Error ? err.message : "Unknown error");
23
- // Avoid a hard exit so fire-and-forget failure analytics can flush.
24
- process.exitCode = 1;
25
- });
26
- };
27
- }
28
- async function runTrackedSearch(command, query, operation) {
29
- try {
30
- const response = await operation();
31
- (0, analytics_js_1.trackEvent)(command, { query }, response);
32
- }
33
- catch (error) {
34
- (0, analytics_js_1.trackEvent)(command, { query }, (0, analytics_js_1.getSearchFailureResponse)(error));
35
- throw error;
36
- }
37
- }
19
+ const utils_js_1 = require("./utils.js");
20
+ const version_js_1 = require("./version.js");
38
21
  const program = new commander_1.Command();
39
22
  program
40
- .name("orth")
23
+ .name((0, utils_js_1.cliName)())
41
24
  .description("CLI to access all APIs and skills on the Orthogonal platform")
42
- .version("0.2.0");
25
+ .version(version_js_1.CLI_VERSION);
43
26
  // ─────────────────────────────────────────────────────────────────────────────
44
27
  // Auth commands (top-level)
45
28
  // ─────────────────────────────────────────────────────────────────────────────
@@ -47,40 +30,44 @@ program
47
30
  .command("login")
48
31
  .description("Authenticate with your Orthogonal API key")
49
32
  .option("-k, --key <key>", "API key (or set ORTHOGONAL_API_KEY env var)")
50
- .action(asyncAction(async (options) => {
33
+ .action((0, command_actions_js_1.asyncAction)(async (options) => {
51
34
  (0, analytics_js_1.trackEvent)("login");
52
35
  await (0, auth_js_1.loginCommand)(options);
53
36
  }));
54
37
  program
55
38
  .command("logout")
56
39
  .description("Remove stored API key")
57
- .action(asyncAction(async () => {
40
+ .action((0, command_actions_js_1.asyncAction)(async () => {
58
41
  (0, analytics_js_1.trackEvent)("logout");
59
42
  await (0, auth_js_1.logoutCommand)();
60
43
  }));
61
44
  program
62
45
  .command("whoami")
63
46
  .description("Show current authentication status")
64
- .action(asyncAction(async () => {
47
+ .option("--json", "Print JSON")
48
+ .action((0, command_actions_js_1.asyncAction)(async (options) => {
65
49
  (0, analytics_js_1.trackEvent)("whoami");
66
- await (0, auth_js_1.whoamiCommand)();
50
+ await (0, auth_js_1.whoamiCommand)(options);
67
51
  }));
68
52
  // ─────────────────────────────────────────────────────────────────────────────
69
53
  // Account commands (top-level)
70
54
  // ─────────────────────────────────────────────────────────────────────────────
71
55
  program
72
56
  .command("balance")
73
- .description("Check your credit balance")
74
- .action(asyncAction(async () => {
57
+ .description("Check the credit balance of whoever your key bills (you, or its organization)")
58
+ .option("--json", "Print JSON")
59
+ .action((0, command_actions_js_1.asyncAction)(async (options) => {
75
60
  (0, analytics_js_1.trackEvent)("balance");
76
- await (0, account_js_1.balanceCommand)();
61
+ await (0, account_js_1.balanceCommand)(options);
77
62
  }));
78
63
  program
79
64
  .command("usage")
80
- .description("Show recent API usage")
65
+ .description("Show your recent paid calls and the total spent")
81
66
  .option("-l, --limit <number>", "Number of recent calls", "20")
82
67
  .option("-d, --days <number>", "Number of days to look back", "30")
83
- .action(asyncAction(async (options) => {
68
+ .option("--offset <number>", "Skip this many of the most recent calls")
69
+ .option("--json", "Print JSON")
70
+ .action((0, command_actions_js_1.asyncAction)(async (options) => {
84
71
  (0, analytics_js_1.trackEvent)("usage");
85
72
  await (0, account_js_1.usageCommand)(options);
86
73
  }));
@@ -91,9 +78,10 @@ const apiGroup = program.command("api").description("API marketplace commands");
91
78
  apiGroup
92
79
  .command("list")
93
80
  .description("List available APIs")
94
- .action(asyncAction(async () => {
81
+ .option("--json", "Print JSON")
82
+ .action((0, command_actions_js_1.asyncAction)(async (options) => {
95
83
  (0, analytics_js_1.trackEvent)("api.list");
96
- await (0, api_js_1.apiCommand)(undefined, undefined, {});
84
+ await (0, api_js_1.apiCommand)(undefined, undefined, options);
97
85
  }));
98
86
  apiGroup
99
87
  .command("show <slug> [path]")
@@ -101,7 +89,8 @@ apiGroup
101
89
  .description("Show API endpoints or endpoint details")
102
90
  .option("--x402", "Output x402 payment URL only")
103
91
  .option("--x402-full", "Output full x402 payment details")
104
- .action(asyncAction(async (slug, path, options) => {
92
+ .option("--json", "Print JSON")
93
+ .action((0, command_actions_js_1.asyncAction)(async (slug, path, options) => {
105
94
  (0, analytics_js_1.trackEvent)("api.show", { slug, path });
106
95
  await (0, api_js_1.apiCommand)(slug, path, options);
107
96
  }));
@@ -109,20 +98,21 @@ apiGroup
109
98
  .command("search <query>")
110
99
  .description("Search for APIs using natural language")
111
100
  .option("-l, --limit <number>", "Max results", "10")
112
- .action(asyncAction(async (query, options) => {
113
- await runTrackedSearch("api.search", query, () => (0, search_js_1.searchCommand)(query, options));
101
+ .option("--json", "Print JSON")
102
+ .action((0, command_actions_js_1.asyncAction)(async (query, options) => {
103
+ await (0, command_actions_js_1.runTrackedSearch)("api.search", query, () => (0, search_js_1.searchCommand)(query, options));
114
104
  }));
115
105
  apiGroup
116
106
  .command("run <slug> <path>")
117
107
  .description("Call an API endpoint")
118
- .option("-X, --method <method>", "HTTP method", "GET")
108
+ .option("-X, --method <method>", "HTTP method (default: POST with a body, else GET)")
119
109
  .option("-q, --query <params...>", "Query params (key=value)")
120
- .option("-b, --body <json>", "Request body JSON")
110
+ .option("-b, --body <json>", "Request body JSON ('-' reads stdin)")
121
111
  .option("-d, --data <json>", "Alias for --body")
122
- .option("--raw", "Output raw JSON without formatting")
112
+ .option("--raw", "Print only the response JSON on stdout (the cost goes to stderr)")
123
113
  .option("-o, --output <file>", "Save response to file (auto-detects binary like images)")
124
114
  .option("--dry-run", "Estimate cost without executing the call")
125
- .action(asyncAction(async (slug, path, options) => {
115
+ .action((0, command_actions_js_1.asyncAction)(async (slug, path, options) => {
126
116
  (0, analytics_js_1.trackEvent)("api.run", { slug, path });
127
117
  await (0, run_js_1.runCommand)(slug, path, options);
128
118
  }));
@@ -130,7 +120,7 @@ apiGroup
130
120
  .command("code <slug> <path>")
131
121
  .description("Generate integration code for an endpoint")
132
122
  .option("-l, --lang <language>", "Language: typescript, python, curl", "typescript")
133
- .action(asyncAction(async (slug, path, options) => {
123
+ .action((0, command_actions_js_1.asyncAction)(async (slug, path, options) => {
134
124
  (0, analytics_js_1.trackEvent)("api.code", { slug, path });
135
125
  await (0, code_js_1.codeCommand)(slug, path, options);
136
126
  }));
@@ -138,153 +128,132 @@ apiGroup
138
128
  .command("request <docsUrl>")
139
129
  .description("Request an API to be added to the platform")
140
130
  .option("-d, --description <text>", "Additional notes about the API")
141
- .action(asyncAction(async (docsUrl, options) => {
131
+ .action((0, command_actions_js_1.asyncAction)(async (docsUrl, options) => {
142
132
  (0, analytics_js_1.trackEvent)("api.request", { docsUrl });
143
133
  await (0, apiRequest_js_1.apiRequestCommand)(docsUrl, options);
144
134
  }));
145
135
  // ─────────────────────────────────────────────────────────────────────────────
146
- // orth skills <subcommand> — Skills commands group
136
+ // orth org — which of your selling organizations commands act for
147
137
  // ─────────────────────────────────────────────────────────────────────────────
148
- const skillsGroup = program
149
- .command("skills")
150
- .description("Agent skills library commands");
151
- skillsGroup
152
- .command("list")
153
- .description("List discoverable skills")
154
- .option("-l, --limit <number>", "Max results", "20")
155
- .action(asyncAction(async (options) => {
156
- (0, analytics_js_1.trackEvent)("skills.list");
157
- await (0, skills_js_1.skillsListCommand)(options);
158
- }));
159
- skillsGroup
160
- .command("mine")
161
- .description("List your own skills")
162
- .option("-l, --limit <number>", "Max results", "50")
163
- .action(asyncAction(async (options) => {
164
- (0, analytics_js_1.trackEvent)("skills.mine");
165
- await (0, skills_js_1.skillsMineCommand)(options);
166
- }));
167
- skillsGroup
168
- .command("search <query>")
169
- .description("Search for agent skills")
170
- .option("-l, --limit <number>", "Max results", "20")
171
- .action(asyncAction(async (query, options) => {
172
- await runTrackedSearch("skills.search", query, () => (0, skills_js_1.skillsSearchCommand)(query, options));
173
- }));
174
- skillsGroup
175
- .command("show <slug>")
176
- .description("Show skill details and files")
177
- .action(asyncAction(async (slug) => {
178
- (0, analytics_js_1.trackEvent)("skills.show", { slug });
179
- await (0, skills_js_1.skillsShowCommand)(slug);
180
- }));
181
- skillsGroup
182
- .command("init [name]")
183
- .description("Initialize a new skill directory with SKILL.md template")
184
- .option("--bare", "Only create SKILL.md, skip subdirectories")
185
- .option("--path <dir>", "Output directory")
186
- .action(asyncAction(async (name, options) => {
187
- (0, analytics_js_1.trackEvent)("skills.init", { name });
188
- await (0, skills_js_1.skillsInitCommand)(name, options);
189
- }));
190
- skillsGroup
191
- .command("submit [path]")
192
- .description("Submit a local skill to the Orthogonal platform")
193
- .option("-n, --name <name>", "Override skill name from frontmatter")
194
- .option("-t, --tags <tags>", "Comma-separated tags")
195
- .option("--org <orgId>", "Submit to an organization instead of personal account")
196
- .action(asyncAction(async (inputPath, options) => {
197
- (0, analytics_js_1.trackEvent)("skills.submit", { path: inputPath });
198
- await (0, skills_js_1.skillsSubmitCommand)(inputPath, options);
199
- }));
200
- skillsGroup
201
- .command("update <slug> [path]")
202
- .description("Pull latest skill version from Orthogonal to local directory")
203
- .option("-f, --force", "Overwrite existing files")
204
- .action(asyncAction(async (slug, inputPath, options) => {
205
- (0, analytics_js_1.trackEvent)("skills.update", { slug, path: inputPath });
206
- await (0, skills_js_1.skillsUpdateCommand)(slug, inputPath, options);
138
+ const orgGroup = program
139
+ .command("org")
140
+ .description("Organizations you administer that sell APIs, and your default one")
141
+ .option("--json", "Print JSON")
142
+ .action((0, command_actions_js_1.asyncAction)(async (options) => {
143
+ (0, analytics_js_1.trackEvent)("org");
144
+ await (0, org_js_1.orgCommand)(options);
207
145
  }));
208
- skillsGroup
209
- .command("push <slug> [path]")
210
- .description("Push local skill files to Orthogonal (update remote)")
211
- .option("-n, --name <name>", "Override skill name from frontmatter")
212
- .option("-t, --tags <tags>", "Comma-separated tags")
213
- .action(asyncAction(async (slug, inputPath, options) => {
214
- (0, analytics_js_1.trackEvent)("skills.push", { slug, path: inputPath });
215
- await (0, skills_js_1.skillsPushCommand)(slug, inputPath, options);
146
+ orgGroup
147
+ .command("use [name]")
148
+ .description("Choose the default organization for api-onboarding and payouts (a name, part of one, or an id)")
149
+ .action((0, command_actions_js_1.asyncAction)(async (name) => {
150
+ (0, analytics_js_1.trackEvent)("org.use");
151
+ await (0, org_js_1.orgUseCommand)(name);
216
152
  }));
217
- skillsGroup
218
- .command("request-verification <slug>")
219
- .description("Request verification for your skill (required before discoverability)")
220
- .action(asyncAction(async (slug) => {
221
- (0, analytics_js_1.trackEvent)("skills.request-verification", { slug });
222
- await (0, skills_js_1.skillsRequestVerificationCommand)(slug);
223
- }));
224
- skillsGroup
225
- .command("create <githubRepo>")
226
- .description("Create a skill from a GitHub URL or owner/repo")
227
- .option("-p, --path <path>", "Path to skill within repo")
228
- .option("-r, --ref <ref>", "Git ref (branch/tag)", "main")
229
- .option("-n, --name <name>", "Skill name (auto-detected from SKILL.md)")
230
- .action(asyncAction(async (githubRepo, options) => {
231
- (0, analytics_js_1.trackEvent)("skills.create", { githubRepo });
232
- await (0, skills_js_1.skillsCreateCommand)(githubRepo, options);
153
+ // ─────────────────────────────────────────────────────────────────────────────
154
+ // orth team — the teams signed in to (one key each) and the active one
155
+ // ─────────────────────────────────────────────────────────────────────────────
156
+ const teamGroup = program
157
+ .command("team")
158
+ .description("Teams you are signed in to (one key each, from login), and the active one")
159
+ .option("--json", "Print JSON")
160
+ .action((0, command_actions_js_1.asyncAction)(async (options) => {
161
+ (0, analytics_js_1.trackEvent)("team");
162
+ await (0, org_js_1.teamCommand)(options);
233
163
  }));
234
- skillsGroup
235
- .command("add <slug>")
236
- .alias("install")
237
- .description("Add a skill to your local agent skills directories")
238
- .option("--agent <agent>", "Install for specific agent only (cursor, claude, copilot)")
239
- .action(asyncAction(async (slug, options) => {
240
- (0, analytics_js_1.trackEvent)("skills.add", { slug });
241
- await (0, skills_js_1.skillsInstallCommand)(slug, options);
164
+ teamGroup
165
+ .command("use [name]")
166
+ .description("Switch the active team, whose key pays for calls (a name, part of one, or an id)")
167
+ .action((0, command_actions_js_1.asyncAction)(async (name) => {
168
+ (0, analytics_js_1.trackEvent)("team.use");
169
+ await (0, org_js_1.teamUseCommand)(name);
242
170
  }));
243
- skillsGroup
244
- .command("publish <slug>")
245
- .description("Toggle skill discoverability")
246
- .option("--unpublish", "Make skill private")
247
- .action(asyncAction(async (slug, options) => {
248
- (0, analytics_js_1.trackEvent)("skills.publish", { slug });
249
- await (0, skills_js_1.skillsPublishCommand)(slug, options);
171
+ (0, register_js_1.registerOnboardCommands)(program);
172
+ // ─────────────────────────────────────────────────────────────────────────────
173
+ // orth payouts — a provider org's payouts (set up in the browser)
174
+ // ─────────────────────────────────────────────────────────────────────────────
175
+ const payoutsGroup = program
176
+ .command("payouts")
177
+ .description("Show your organization's payout status, what it is owed and what it earned")
178
+ .option(...command_actions_js_1.orgOption)
179
+ .option("--json", "Output raw JSON")
180
+ .action((0, command_actions_js_1.asyncAction)(async (options) => {
181
+ (0, analytics_js_1.trackEvent)("payouts");
182
+ await (0, payouts_js_1.payoutsCommand)(options);
250
183
  }));
251
- skillsGroup
252
- .command("request <input>")
253
- .description("Request a skill to be added (GitHub URL or description)")
254
- .action(asyncAction(async (input) => {
255
- (0, analytics_js_1.trackEvent)("skills.request", { input });
256
- await (0, skills_js_1.skillsRequestCommand)(input);
184
+ payoutsGroup
185
+ .command("history")
186
+ .description("List the payouts made to your organization, newest first")
187
+ .option(...command_actions_js_1.orgOption)
188
+ .option("--json", "Output raw JSON")
189
+ .action((0, command_actions_js_1.asyncAction)(async (_options, command) => {
190
+ (0, analytics_js_1.trackEvent)("payouts.history");
191
+ await (0, payouts_js_1.payoutsHistoryCommand)(command.optsWithGlobals());
257
192
  }));
193
+ (0, register_js_2.registerSkillsCommands)(program);
194
+ // ─────────────────────────────────────────────────────────────────────────────
195
+ // orth telemetry <subcommand> — usage telemetry opt-out (sends no event)
196
+ // ─────────────────────────────────────────────────────────────────────────────
197
+ const telemetryGroup = program
198
+ .command("telemetry")
199
+ .description("Manage usage telemetry");
200
+ telemetryGroup
201
+ .command("enable")
202
+ .description("Turn usage telemetry on")
203
+ .action(() => (0, telemetry_js_1.telemetryEnableCommand)());
204
+ telemetryGroup
205
+ .command("disable")
206
+ .description("Turn usage telemetry off")
207
+ .action(() => (0, telemetry_js_1.telemetryDisableCommand)());
208
+ telemetryGroup
209
+ .command("status")
210
+ .description("Show whether usage telemetry is on, and why not")
211
+ .action(() => (0, telemetry_js_1.telemetryStatusCommand)());
258
212
  // ─────────────────────────────────────────────────────────────────────────────
259
213
  // Backward-compatible aliases (flat commands)
260
214
  // ─────────────────────────────────────────────────────────────────────────────
261
215
  program
262
216
  .command("search <query>")
263
- .description("Search for APIs (alias for 'orth api search')")
217
+ .description(`Search for APIs (alias for '${(0, utils_js_1.cliName)()} api search')`)
264
218
  .option("-l, --limit <number>", "Max results", "10")
265
- .action(asyncAction(async (query, options) => {
266
- await runTrackedSearch("search", query, () => (0, search_js_1.searchCommand)(query, options));
219
+ .option("--json", "Print JSON")
220
+ .action((0, command_actions_js_1.asyncAction)(async (query, options) => {
221
+ await (0, command_actions_js_1.runTrackedSearch)("search", query, () => (0, search_js_1.searchCommand)(query, options));
267
222
  }));
268
223
  program
269
224
  .command("run <api> <path>")
270
- .description("Call an API endpoint (alias for 'orth api run')")
271
- .option("-X, --method <method>", "HTTP method", "GET")
225
+ .description(`Call an API endpoint (alias for '${(0, utils_js_1.cliName)()} api run')`)
226
+ .option("-X, --method <method>", "HTTP method (default: POST with a body, else GET)")
272
227
  .option("-q, --query <params...>", "Query params (key=value)")
273
- .option("-b, --body <json>", "Request body JSON")
228
+ .option("-b, --body <json>", "Request body JSON ('-' reads stdin)")
274
229
  .option("-d, --data <json>", "Alias for --body")
275
- .option("--raw", "Output raw JSON without formatting")
230
+ .option("--raw", "Print only the response JSON on stdout (the cost goes to stderr)")
276
231
  .option("-o, --output <file>", "Save response to file (auto-detects binary like images)")
277
232
  .option("--dry-run", "Estimate cost without executing the call")
278
- .action(asyncAction(async (api, path, options) => {
233
+ .action((0, command_actions_js_1.asyncAction)(async (api, path, options) => {
279
234
  (0, analytics_js_1.trackEvent)("run", { api, path });
280
235
  await (0, run_js_1.runCommand)(api, path, options);
281
236
  }));
282
237
  program
283
238
  .command("code <api> <path>")
284
- .description("Generate integration code (alias for 'orth api code')")
239
+ .description(`Generate integration code (alias for '${(0, utils_js_1.cliName)()} api code')`)
285
240
  .option("-l, --lang <language>", "Language: typescript, python, curl", "typescript")
286
- .action(asyncAction(async (api, path, options) => {
241
+ .action((0, command_actions_js_1.asyncAction)(async (api, path, options) => {
287
242
  (0, analytics_js_1.trackEvent)("code", { api, path });
288
243
  await (0, code_js_1.codeCommand)(api, path, options);
289
244
  }));
245
+ program.addHelpText("after", () => {
246
+ const orth = (0, utils_js_1.cliName)();
247
+ return `
248
+ Examples:
249
+ ${orth} login # sign in through the browser
250
+ export ORTHOGONAL_API_KEY=orth_live_... # or use a key, no login needed
251
+ ${orth} api search "send an email" --json # find endpoints
252
+ ${orth} api show tavily /search --json # parameters and price
253
+ ${orth} run tavily /search -b '{"query":"AI news"}' --dry-run
254
+ ${orth} run tavily /search -b '{"query":"AI news"}' --raw | jq .results
255
+ ${orth} balance --json
256
+
257
+ Every command exits 1 on failure; --json and --raw print only JSON on stdout.`;
258
+ });
290
259
  program.parse();
@@ -0,0 +1,14 @@
1
+ import { type Organization } from "./config.js";
2
+ /**
3
+ * Which selling organization a command acts for, without anyone knowing an
4
+ * org id: --org takes a name (or part of one) or an id; else the default
5
+ * saved for this server; else the person's only one; else they pick from a
6
+ * numbered list, and that choice is saved (`orth org use` changes it).
7
+ */
8
+ /** The organizations that sell APIs the person administers. */
9
+ export declare function listOrganizations(): Promise<Organization[]>;
10
+ /** An organization by id, exact name, or a part of one name only it has. */
11
+ export declare function matchOrganization(orgs: Organization[], query: string): Organization | undefined;
12
+ /** Ask which organization, save it as this server's default, and say so. */
13
+ export declare function pickOrganization(orgs: Organization[]): Promise<Organization>;
14
+ export declare function resolveOrganization(flag?: string): Promise<Organization>;
@@ -0,0 +1,77 @@
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.listOrganizations = listOrganizations;
7
+ exports.matchOrganization = matchOrganization;
8
+ exports.pickOrganization = pickOrganization;
9
+ exports.resolveOrganization = resolveOrganization;
10
+ const chalk_1 = __importDefault(require("chalk"));
11
+ const api_js_1 = require("./api.js");
12
+ const config_js_1 = require("./config.js");
13
+ const urls_js_1 = require("./urls.js");
14
+ const utils_js_1 = require("./utils.js");
15
+ /**
16
+ * Which selling organization a command acts for, without anyone knowing an
17
+ * org id: --org takes a name (or part of one) or an id; else the default
18
+ * saved for this server; else the person's only one; else they pick from a
19
+ * numbered list, and that choice is saved (`orth org use` changes it).
20
+ */
21
+ /** The organizations that sell APIs the person administers. */
22
+ async function listOrganizations() {
23
+ const res = await (0, api_js_1.apiRequest)("/onboarding", {
24
+ method: "POST",
25
+ body: { tool: "list_organizations" },
26
+ });
27
+ return res.result.organizations;
28
+ }
29
+ const names = (orgs) => orgs.map((org) => `"${(0, utils_js_1.sanitizeForTerminal)(org.name)}"`).join(", ");
30
+ /** An organization by id, exact name, or a part of one name only it has. */
31
+ function matchOrganization(orgs, query) {
32
+ const wanted = query.trim().toLowerCase();
33
+ const partial = orgs.filter((org) => org.name.toLowerCase().includes(wanted));
34
+ return (orgs.find((org) => org.id === query.trim()) ??
35
+ orgs.find((org) => org.name.toLowerCase() === wanted) ??
36
+ (partial.length === 1 ? partial[0] : undefined));
37
+ }
38
+ function noneError() {
39
+ return new Error(`You don't administer an organization that sells APIs. Create your seller organization in Your listings (${(0, urls_js_1.webBaseUrl)()}/account/listings), then try again.`);
40
+ }
41
+ /** Ask which organization, save it as this server's default, and say so. */
42
+ async function pickOrganization(orgs) {
43
+ const org = orgs[await (0, utils_js_1.choose)("Which organization?", orgs.map((candidate) => candidate.name))];
44
+ if (!org)
45
+ throw noneError();
46
+ (0, config_js_1.setDefaultOrganization)((0, urls_js_1.apiBaseUrl)(), org);
47
+ console.log(chalk_1.default.gray(`\n Saved ${(0, utils_js_1.sanitizeForTerminal)(org.name)} as your default organization. Change it with: ${(0, utils_js_1.cliName)()} org use\n`));
48
+ return org;
49
+ }
50
+ async function resolveOrganization(flag) {
51
+ // An org id needs no lookup; the server checks the person administers it.
52
+ if (flag?.startsWith("org_"))
53
+ return { id: flag, name: flag };
54
+ if (!flag) {
55
+ const saved = (0, config_js_1.getDefaultOrganization)((0, urls_js_1.apiBaseUrl)());
56
+ if (saved)
57
+ return saved;
58
+ }
59
+ const orgs = await listOrganizations();
60
+ if (flag) {
61
+ const org = matchOrganization(orgs, flag);
62
+ if (org)
63
+ return org;
64
+ throw new Error(orgs.length
65
+ ? `No organization of yours matches "${(0, utils_js_1.sanitizeForTerminal)(flag)}". Yours: ${names(orgs)}.`
66
+ : noneError().message);
67
+ }
68
+ const [only] = orgs;
69
+ if (!only)
70
+ throw noneError();
71
+ if (orgs.length === 1)
72
+ return only;
73
+ if (!(0, utils_js_1.isInteractive)()) {
74
+ throw new Error(`You administer several organizations that sell APIs: ${names(orgs)}. Choose one with \`${(0, utils_js_1.cliName)()} org use\`, or pass --org "<name>".`);
75
+ }
76
+ return pickOrganization(orgs);
77
+ }
package/dist/urls.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function apiBaseUrl(): string;
2
+ export declare function webBaseUrl(): string;
3
+ export declare function protectionBypass(url: string): Record<string, string>;
package/dist/urls.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiBaseUrl = apiBaseUrl;
4
+ exports.webBaseUrl = webBaseUrl;
5
+ exports.protectionBypass = protectionBypass;
6
+ const DEFAULT_ORIGIN = "https://www.orthogonal.com";
7
+ function apiBaseUrl() {
8
+ return (process.env.ORTH_API_URL || `${DEFAULT_ORIGIN}/v1`).replace(/\/$/, "");
9
+ }
10
+ // Without ORTH_WEB_URL, the site that serves ORTH_API_URL, so `orth login`
11
+ // makes its key on the server the commands then call.
12
+ function webBaseUrl() {
13
+ const apiSite = process.env.ORTH_API_URL?.replace(/\/$/, "").replace(/\/v1$/, "");
14
+ return (process.env.ORTH_WEB_URL || apiSite || DEFAULT_ORIGIN).replace(/\/$/, "");
15
+ }
16
+ // dev.mono sits behind Vercel Authentication. Staff and agents calling it
17
+ // export Vercel's automation bypass secret (README, "Staff builds"), which goes
18
+ // as Vercel's x-vercel-protection-bypass header on each request to the
19
+ // configured API or web origin, and never to another host.
20
+ function protectionBypass(url) {
21
+ const secret = process.env.VERCEL_AUTOMATION_BYPASS_SECRET?.trim();
22
+ const origin = originOf(url);
23
+ return secret && origin && [apiBaseUrl(), webBaseUrl()].some((base) => originOf(base) === origin)
24
+ ? { "x-vercel-protection-bypass": secret }
25
+ : {};
26
+ }
27
+ function originOf(url) {
28
+ try {
29
+ return new URL(url).origin;
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ }
package/dist/utils.d.ts CHANGED
@@ -1 +1,21 @@
1
1
  export declare function sanitizeForTerminal(value: string): string;
2
+ /**
3
+ * The command the person typed: `orth`, or a staff build's `mono-dev` and
4
+ * `mono-prod`, so hints name a command that exists. `npm run cli` runs
5
+ * dist/index.js, which is `orth`.
6
+ */
7
+ export declare function cliName(): string;
8
+ /** Whether a person is at the terminal to answer a question. */
9
+ export declare function isInteractive(): boolean;
10
+ /** A numbered list to pick from; answers the chosen index. */
11
+ export declare function choose(question: string, labels: string[]): Promise<number>;
12
+ /** A failure as people read it: a red ✗ and the message, never a stack. */
13
+ export declare function printError(error: unknown): void;
14
+ /** A yes-or-no question; anything but y/yes is no. */
15
+ export declare function confirmYes(question: string): Promise<boolean>;
16
+ /**
17
+ * A secret typed without echo (an API key), or stdin when piped, so it never
18
+ * shows on screen, in shell history or in `ps`. The prompt goes to stderr,
19
+ * so stdout keeps only the command's output (--json).
20
+ */
21
+ export declare function readSecret(question: string): Promise<string>;