@openma/cli 0.1.0-beta.1 → 0.1.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +15 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ function loadConfig() {
|
|
|
43
43
|
const stored = readCredentials();
|
|
44
44
|
if (envKey) {
|
|
45
45
|
return {
|
|
46
|
-
baseUrl: envBase || stored?.base_url || "
|
|
46
|
+
baseUrl: envBase || stored?.base_url || "https://openma.dev",
|
|
47
47
|
apiKey: envKey,
|
|
48
48
|
json: false,
|
|
49
49
|
source: "env"
|
|
@@ -67,12 +67,12 @@ function loadConfigOptional() {
|
|
|
67
67
|
const envKey = process.env.OMA_API_KEY;
|
|
68
68
|
const stored = readCredentials();
|
|
69
69
|
if (envKey) {
|
|
70
|
-
return { baseUrl: envBase || stored?.base_url || "
|
|
70
|
+
return { baseUrl: envBase || stored?.base_url || "https://openma.dev", apiKey: envKey, json: false, source: "env" };
|
|
71
71
|
}
|
|
72
72
|
if (stored) {
|
|
73
73
|
return { baseUrl: envBase || stored.base_url, apiKey: stored.token, json: false, source: "stored" };
|
|
74
74
|
}
|
|
75
|
-
return { baseUrl: envBase || "
|
|
75
|
+
return { baseUrl: envBase || "https://openma.dev", apiKey: "", json: false, source: "missing" };
|
|
76
76
|
}
|
|
77
77
|
async function apiFetch(config, path, init) {
|
|
78
78
|
const url = `${config.baseUrl}${path}`;
|
|
@@ -175,6 +175,9 @@ async function authLogin(baseUrl, requestedTenant) {
|
|
|
175
175
|
res.writeHead(200, { "Content-Type": "text/html" }).end(approvalPage("Signed in", "You can close this tab and return to your terminal."));
|
|
176
176
|
clearTimeout(timeout);
|
|
177
177
|
server.close();
|
|
178
|
+
if (typeof server.closeAllConnections === "function") {
|
|
179
|
+
server.closeAllConnections();
|
|
180
|
+
}
|
|
178
181
|
resolve({ token, tenant, user, key_id });
|
|
179
182
|
} catch (err) {
|
|
180
183
|
res.writeHead(500).end();
|
|
@@ -203,12 +206,17 @@ async function authLogin(baseUrl, requestedTenant) {
|
|
|
203
206
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
204
207
|
});
|
|
205
208
|
console.log(`\u2713 Signed in as ${me.user?.email ?? me.user?.id}`);
|
|
206
|
-
console.log(` Tenant : ${me.tenant
|
|
209
|
+
console.log(` Tenant : ${displayTenantName(me.tenant)} (${me.tenant.id})`);
|
|
207
210
|
console.log(` Stored : ${credentialsPath()}`);
|
|
208
211
|
if (me.tenants.length > 1) {
|
|
209
212
|
console.log(` ${me.tenants.length} tenants available \u2014 switch with: oma auth tenant use <id>`);
|
|
210
213
|
}
|
|
211
214
|
}
|
|
215
|
+
function displayTenantName(t) {
|
|
216
|
+
const trimmed = (t.name ?? "").trim();
|
|
217
|
+
if (!trimmed || trimmed === "'s workspace" || trimmed.startsWith("'s ")) return t.id;
|
|
218
|
+
return trimmed;
|
|
219
|
+
}
|
|
212
220
|
function openBrowser(url) {
|
|
213
221
|
try {
|
|
214
222
|
const p = process.platform;
|
|
@@ -234,7 +242,7 @@ var commands = [
|
|
|
234
242
|
desc: "Open browser to authenticate; stores ~/.config/oma/credentials.json",
|
|
235
243
|
http: "POST /v1/me/cli-tokens (browser handoff via /cli/login)",
|
|
236
244
|
async run(_config, args) {
|
|
237
|
-
const baseUrl = (flag(args, "--base-url") ?? process.env.OMA_BASE_URL ?? "https://
|
|
245
|
+
const baseUrl = (flag(args, "--base-url") ?? process.env.OMA_BASE_URL ?? "https://openma.dev").replace(/\/+$/, "");
|
|
238
246
|
await authLogin(baseUrl);
|
|
239
247
|
}
|
|
240
248
|
},
|
|
@@ -265,7 +273,7 @@ var commands = [
|
|
|
265
273
|
console.log(`Base URL : ${config.baseUrl}`);
|
|
266
274
|
console.log(`Source : ${config.source === "env" ? "OMA_API_KEY env var" : "stored credentials"}`);
|
|
267
275
|
console.log(`User : ${me.user?.email ?? me.user?.id ?? "(unknown \u2014 legacy key without user_id)"}`);
|
|
268
|
-
console.log(`Tenant : ${me.tenant
|
|
276
|
+
console.log(`Tenant : ${displayTenantName(me.tenant)} (${me.tenant.id})`);
|
|
269
277
|
if (me.tenants.length > 1) {
|
|
270
278
|
console.log(`Available: ${me.tenants.map((t) => t.id).join(", ")}`);
|
|
271
279
|
}
|
|
@@ -1667,7 +1675,7 @@ Usage:`);
|
|
|
1667
1675
|
oma api <resource> Show endpoints for a resource
|
|
1668
1676
|
|
|
1669
1677
|
Environment:
|
|
1670
|
-
OMA_BASE_URL API base (default:
|
|
1678
|
+
OMA_BASE_URL API base (default: https://openma.dev)
|
|
1671
1679
|
OMA_API_KEY API key \u2014 overrides stored credentials when set
|
|
1672
1680
|
XDG_CONFIG_HOME Base dir for credentials (default: ~/.config)
|
|
1673
1681
|
|