@orth/cli 0.2.27 → 0.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +8 -0
- package/dist/api.js +19 -2
- package/dist/commands/auth.js +29 -0
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -151,3 +151,11 @@ export declare function run(api: string, path: string, options?: {
|
|
|
151
151
|
dryRun?: boolean;
|
|
152
152
|
}): Promise<RunResponse>;
|
|
153
153
|
export declare function integrate(api: string, path: string, format?: string): Promise<IntegrateResponse>;
|
|
154
|
+
export interface MeResponse {
|
|
155
|
+
type: "user" | "organization";
|
|
156
|
+
name?: string | null;
|
|
157
|
+
email?: string | null;
|
|
158
|
+
organizationId?: string;
|
|
159
|
+
apiKeyName?: string;
|
|
160
|
+
}
|
|
161
|
+
export declare function getMe(): Promise<MeResponse>;
|
package/dist/api.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.getApiBySlug = getApiBySlug;
|
|
|
7
7
|
exports.getDetails = getDetails;
|
|
8
8
|
exports.run = run;
|
|
9
9
|
exports.integrate = integrate;
|
|
10
|
+
exports.getMe = getMe;
|
|
10
11
|
const config_js_1 = require("./config.js");
|
|
11
12
|
const BASE_URL = process.env.ORTH_API_URL || "https://api.orthogonal.com/v1";
|
|
12
13
|
async function apiRequest(endpoint, options = {}) {
|
|
@@ -20,7 +21,16 @@ async function apiRequest(endpoint, options = {}) {
|
|
|
20
21
|
},
|
|
21
22
|
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
22
23
|
});
|
|
23
|
-
|
|
24
|
+
// Parse defensively: error responses (e.g. a bare 404) may return an empty
|
|
25
|
+
// or non-JSON body, which would otherwise throw here and lose the status.
|
|
26
|
+
const rawBody = await res.text();
|
|
27
|
+
let data;
|
|
28
|
+
try {
|
|
29
|
+
data = (rawBody ? JSON.parse(rawBody) : {});
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
data = {};
|
|
33
|
+
}
|
|
24
34
|
if (!res.ok || data.success === false) {
|
|
25
35
|
// Include more details in error message
|
|
26
36
|
let errorMsg = data.error || `API request failed with status ${res.status}`;
|
|
@@ -50,7 +60,11 @@ async function apiRequest(endpoint, options = {}) {
|
|
|
50
60
|
if (data.details) {
|
|
51
61
|
errorMsg += `\n Details: ${JSON.stringify(data.details)}`;
|
|
52
62
|
}
|
|
53
|
-
|
|
63
|
+
// Attach the HTTP status so callers can branch on it reliably instead of
|
|
64
|
+
// string-matching the message (e.g. whoami treating 404 as "no /me").
|
|
65
|
+
const err = new Error(errorMsg);
|
|
66
|
+
err.status = res.status;
|
|
67
|
+
throw err;
|
|
54
68
|
}
|
|
55
69
|
// Return the whole response, not just data field
|
|
56
70
|
return data;
|
|
@@ -92,3 +106,6 @@ async function integrate(api, path, format = "orth-sdk") {
|
|
|
92
106
|
body: { api, path, format },
|
|
93
107
|
});
|
|
94
108
|
}
|
|
109
|
+
async function getMe() {
|
|
110
|
+
return apiRequest("/me");
|
|
111
|
+
}
|
package/dist/commands/auth.js
CHANGED
|
@@ -10,6 +10,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
10
10
|
const crypto_1 = __importDefault(require("crypto"));
|
|
11
11
|
const http_1 = __importDefault(require("http"));
|
|
12
12
|
const config_js_1 = require("../config.js");
|
|
13
|
+
const api_js_1 = require("../api.js");
|
|
13
14
|
const WEB_BASE = process.env.ORTH_WEB_URL || "https://orthogonal.sh";
|
|
14
15
|
function escapeHtml(str) {
|
|
15
16
|
return str
|
|
@@ -169,6 +170,34 @@ async function whoamiCommand() {
|
|
|
169
170
|
return;
|
|
170
171
|
}
|
|
171
172
|
console.log(chalk_1.default.green("✓ Authenticated"));
|
|
173
|
+
// Resolve the account behind the key. A 404 means the API predates the
|
|
174
|
+
// /me endpoint — fall back silently to the key-only output. Any other
|
|
175
|
+
// failure (auth, network, 5xx) is surfaced so it isn't hidden.
|
|
176
|
+
try {
|
|
177
|
+
const me = await (0, api_js_1.getMe)();
|
|
178
|
+
if (me.type === "organization") {
|
|
179
|
+
const label = me.apiKeyName ? `organization (${me.apiKeyName})` : "organization";
|
|
180
|
+
console.log(chalk_1.default.gray(` Account: ${label}`));
|
|
181
|
+
if (me.organizationId) {
|
|
182
|
+
console.log(chalk_1.default.gray(` Org ID: ${me.organizationId}`));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
if (me.name)
|
|
187
|
+
console.log(chalk_1.default.gray(` Name: ${me.name}`));
|
|
188
|
+
if (me.email)
|
|
189
|
+
console.log(chalk_1.default.gray(` Email: ${me.email}`));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
// A 404 means the API predates /me — fall back silently to key-only
|
|
194
|
+
// output. Surface anything else (auth, network, 5xx) so it isn't hidden.
|
|
195
|
+
const status = error.status;
|
|
196
|
+
if (status !== 404) {
|
|
197
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
198
|
+
console.log(chalk_1.default.yellow(` Could not load account details: ${message}`));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
172
201
|
console.log(chalk_1.default.gray(` Key: ${key.slice(0, 15)}...${key.slice(-4)}`));
|
|
173
202
|
console.log(chalk_1.default.gray(` Source: ${process.env.ORTHOGONAL_API_KEY ? "environment" : "config file"}`));
|
|
174
203
|
}
|