@launchpad-kit/cli 0.0.0-bootstrap.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/LICENSE +202 -0
- package/README.md +351 -0
- package/cli.mjs +1561 -0
- package/package.json +34 -0
package/cli.mjs
ADDED
|
@@ -0,0 +1,1561 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { accessSync as e, constants as t, promises as n, statSync as r } from "node:fs";
|
|
3
|
+
import i from "node:path";
|
|
4
|
+
import { ClientCoreError as a, appClient as o, checkLocation as s, clientFor as c, createContext as l, fieldsToQuery as u, listOrganizations as d, listProfiles as f, listProjects as p, login as m, logout as h, normalizeEmail as ee, packDirectory as g, parseFields as te, readArchive as ne, readWorkspace as re, redact as _, requireConfirmation as v, resolve as ie, safeOutput as y, useOrganization as ae, useProfile as oe, whoami as se, workspaceContext as b } from "@launchpad-kit/client-core";
|
|
5
|
+
import { Command as ce, CommanderError as x } from "@commander-js/extra-typings";
|
|
6
|
+
import { API_KEY_SCOPES as S, FORBIDDEN_RAW_HEADERS as le, LaunchpadApiError as C, LaunchpadConfigError as w, LaunchpadTransportError as T, MAX_KEY_LIFETIME_DAYS as E, ORGANIZATION_ROLES as D, RAW_METHODS as ue, createSessionClient as O, normalizeBaseUrl as k, slugSchema as de } from "@launchpad-kit/sdk";
|
|
7
|
+
import { spawn as A } from "node:child_process";
|
|
8
|
+
import { checkScript as j, executeScript as M } from "@elastic/micro-jq";
|
|
9
|
+
import { lstat as fe, realpath as N } from "node:fs/promises";
|
|
10
|
+
// src/io.ts
|
|
11
|
+
var P = 4096, F = 1048576;
|
|
12
|
+
async function pe(e, t = P, n = "Input is too long to be a key.") {
|
|
13
|
+
return Buffer.from(await I(e, t, n)).toString("utf8");
|
|
14
|
+
}
|
|
15
|
+
async function I(e, t, n) {
|
|
16
|
+
let r = [], i = 0;
|
|
17
|
+
for await (let a of e) {
|
|
18
|
+
if (i += a.byteLength, i > t) throw Error(n);
|
|
19
|
+
r.push(a);
|
|
20
|
+
}
|
|
21
|
+
return Buffer.concat(r);
|
|
22
|
+
}
|
|
23
|
+
async function L() {
|
|
24
|
+
return pe(process.stdin);
|
|
25
|
+
}
|
|
26
|
+
function me({ stdin: e, stderr: t }, n, r = {}) {
|
|
27
|
+
let i = `Input is too long to be a ${r.kind ?? "key"}.`;
|
|
28
|
+
return r.signal?.aborted ? Promise.reject(/* @__PURE__ */ Error("Cancelled.")) : (t.write(n), e.setRawMode(!0), e.resume(), e.setEncoding("utf8"), new Promise((n, a) => {
|
|
29
|
+
let o = "", s = !1, c = (n) => {
|
|
30
|
+
s || (s = !0, r.signal?.removeEventListener("abort", l), e.off("data", u), e.setRawMode(!1), e.pause(), t.write("\n"), n());
|
|
31
|
+
}, l = () => c(() => a(/* @__PURE__ */ Error("Cancelled."))), u = (e) => {
|
|
32
|
+
for (let t of e) {
|
|
33
|
+
if (t === "\r" || t === "\n") return c(() => n(o));
|
|
34
|
+
if (t === "") return c(() => a(/* @__PURE__ */ Error("Cancelled.")));
|
|
35
|
+
if (t === "" || t === "\b" ? o = o.slice(0, -1) : o += t, Buffer.byteLength(o, "utf8") > P) return c(() => a(Error(i)));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
r.signal?.addEventListener("abort", l, { once: !0 }), e.on("data", u);
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
var he = (e, t) => me({
|
|
42
|
+
stdin: process.stdin,
|
|
43
|
+
stderr: process.stderr
|
|
44
|
+
}, e, t);
|
|
45
|
+
async function ge(e) {
|
|
46
|
+
let t;
|
|
47
|
+
try {
|
|
48
|
+
t = await n.open(e, "wx", 384);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
let t = e.code;
|
|
51
|
+
throw Error(t === "EEXIST" ? "The secret file already exists; choose a path that does not exist." : t === "ENOENT" ? "The secret file's directory does not exist." : "The secret file cannot be created.");
|
|
52
|
+
}
|
|
53
|
+
let r = !1, i = !1, a = await t.stat();
|
|
54
|
+
return {
|
|
55
|
+
async write(e) {
|
|
56
|
+
try {
|
|
57
|
+
await t.writeFile(e), await t.sync();
|
|
58
|
+
} finally {
|
|
59
|
+
i = !0, await t.close();
|
|
60
|
+
}
|
|
61
|
+
r = !0;
|
|
62
|
+
},
|
|
63
|
+
async remove() {
|
|
64
|
+
if (r) return;
|
|
65
|
+
i || await t.close().catch(() => {}), i = !0;
|
|
66
|
+
let o = await n.lstat(e).catch(() => null);
|
|
67
|
+
o && o.dev === a.dev && o.ino === a.ino && await n.rm(e, { force: !0 });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
var R = (e) => /* @__PURE__ */ Error(`The password file ${e}.`);
|
|
72
|
+
async function z(e) {
|
|
73
|
+
let r;
|
|
74
|
+
try {
|
|
75
|
+
r = await n.open(e, t.O_RDONLY | (t.O_NOFOLLOW ?? 0) | (t.O_NONBLOCK ?? 0));
|
|
76
|
+
} catch (e) {
|
|
77
|
+
let t = e.code;
|
|
78
|
+
throw R(t === "ELOOP" ? "is a symbolic link; it is not read" : t === "ENOENT" ? "was not found" : t === "EACCES" ? "is not readable by you" : "cannot be opened");
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
let e = await r.stat();
|
|
82
|
+
if (!e.isFile()) throw R("is not a regular file");
|
|
83
|
+
if (process.platform !== "win32") {
|
|
84
|
+
let t = process.getuid?.();
|
|
85
|
+
if (t !== void 0 && e.uid !== t) throw R("is owned by another user");
|
|
86
|
+
if (e.mode & 63) throw R("is readable by others; restrict it with chmod 600");
|
|
87
|
+
}
|
|
88
|
+
if (e.size > P) throw R("is too long to be a password");
|
|
89
|
+
let t;
|
|
90
|
+
try {
|
|
91
|
+
let e = await I(r.createReadStream({
|
|
92
|
+
autoClose: !1,
|
|
93
|
+
highWaterMark: 4097
|
|
94
|
+
}), P, "The password file is too long to be a password.");
|
|
95
|
+
t = new TextDecoder("utf-8", { fatal: !0 }).decode(e);
|
|
96
|
+
} catch (e) {
|
|
97
|
+
throw e instanceof Error && /too long/.test(e.message) ? e : e instanceof TypeError ? R("is not valid UTF-8 text") : R("cannot be read");
|
|
98
|
+
}
|
|
99
|
+
return t.endsWith("\r\n") ? t.slice(0, -2) : t.endsWith("\n") ? t.slice(0, -1) : t;
|
|
100
|
+
} finally {
|
|
101
|
+
await r.close();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function _e(e, r) {
|
|
105
|
+
let a = "The data is larger than 1 MiB.";
|
|
106
|
+
if (e === "-") return I(process.stdin, F, a);
|
|
107
|
+
let o = await n.realpath(e);
|
|
108
|
+
if (process.platform === "linux" && /^\/(?:proc|sys)(?:\/|$)/.test(o)) throw Error("Files under /proc and /sys are not sent.");
|
|
109
|
+
let s = await n.realpath(r).catch(() => i.resolve(r)), c = i.relative(s, o);
|
|
110
|
+
if (c !== ".." && !c.startsWith(`..${i.sep}`) && !i.isAbsolute(c)) throw Error("That file is inside this client's credential store and is not sent.");
|
|
111
|
+
if (!(await n.stat(o)).isFile()) throw Error("The data source is not a regular file.");
|
|
112
|
+
let l = await n.open(o, t.O_RDONLY | (t.O_NONBLOCK ?? 0));
|
|
113
|
+
try {
|
|
114
|
+
let e = await l.stat();
|
|
115
|
+
if (!e.isFile()) throw Error("The data source is not a regular file.");
|
|
116
|
+
if (e.size > F) throw Error(a);
|
|
117
|
+
return await I(l.createReadStream({
|
|
118
|
+
autoClose: !1,
|
|
119
|
+
highWaterMark: 65536
|
|
120
|
+
}), F, a);
|
|
121
|
+
} finally {
|
|
122
|
+
await l.close();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function ve(e = process.env) {
|
|
126
|
+
let t = l(e);
|
|
127
|
+
return {
|
|
128
|
+
context: t,
|
|
129
|
+
readData: (e) => _e(e, t.store.directory),
|
|
130
|
+
signals: {
|
|
131
|
+
on: (e, t) => void process.on(e, t),
|
|
132
|
+
off: (e, t) => void process.off(e, t),
|
|
133
|
+
exit: (e) => process.exit(e)
|
|
134
|
+
},
|
|
135
|
+
workingDir: process.cwd(),
|
|
136
|
+
out: (e) => void process.stdout.write(e + "\n"),
|
|
137
|
+
err: (e) => void process.stderr.write(e + "\n"),
|
|
138
|
+
interactive: !!(process.stdin.isTTY && process.stderr.isTTY),
|
|
139
|
+
stdinIsTTY: !!process.stdin.isTTY,
|
|
140
|
+
readSecret: he,
|
|
141
|
+
readPasswordFile: z,
|
|
142
|
+
createSecretFile: ge,
|
|
143
|
+
readStdin: L,
|
|
144
|
+
readFile: async (e) => {
|
|
145
|
+
let t = await n.open(e, "r");
|
|
146
|
+
try {
|
|
147
|
+
let e = await t.stat();
|
|
148
|
+
if (e.size > P) throw Error("File is too large to be a key.");
|
|
149
|
+
return {
|
|
150
|
+
text: await pe(t.createReadStream({
|
|
151
|
+
autoClose: !1,
|
|
152
|
+
highWaterMark: 4097
|
|
153
|
+
})),
|
|
154
|
+
mode: e.mode,
|
|
155
|
+
regular: e.isFile()
|
|
156
|
+
};
|
|
157
|
+
} finally {
|
|
158
|
+
await t.close();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
// src/jq.ts
|
|
164
|
+
var ye = {
|
|
165
|
+
timeoutMs: 1e4,
|
|
166
|
+
maxOutputBytes: 8388608
|
|
167
|
+
}, be = 4096, xe = 4096, Se = (e, t = process.platform) => t === "win32" ? [e, `${e}.exe`] : [e];
|
|
168
|
+
function Ce(n, a, o = process.platform) {
|
|
169
|
+
for (let s of (a ?? "").split(i.delimiter)) if (s && i.isAbsolute(s)) for (let a of Se(n, o)) {
|
|
170
|
+
let n = i.join(s, a);
|
|
171
|
+
try {
|
|
172
|
+
if (!r(n).isFile()) continue;
|
|
173
|
+
return e(n, t.X_OK), n;
|
|
174
|
+
} catch {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
var we = (e) => e.startsWith("-") ? ` ${e}` : e, B = (e) => new a("bad-input", e);
|
|
181
|
+
function Te(e, t, n, r = [0], i = ye) {
|
|
182
|
+
return new Promise((a, o) => {
|
|
183
|
+
let s = A(e, t, {
|
|
184
|
+
env: {},
|
|
185
|
+
stdio: [
|
|
186
|
+
"pipe",
|
|
187
|
+
"pipe",
|
|
188
|
+
"pipe"
|
|
189
|
+
],
|
|
190
|
+
shell: !1
|
|
191
|
+
}), c = [], l = [], u = 0, d = 0, f, p = (e) => {
|
|
192
|
+
f ??= e, s.kill("SIGKILL"), s.stdout.destroy(), s.stderr.destroy(), clearTimeout(m), o(f);
|
|
193
|
+
}, m = setTimeout(() => p(B("jq took too long and was stopped.")), i.timeoutMs);
|
|
194
|
+
s.stdout.on("data", (e) => {
|
|
195
|
+
u += e.length, u > i.maxOutputBytes ? p(B("jq printed too much; stopped.")) : c.push(e);
|
|
196
|
+
}), s.stderr.on("data", (e) => {
|
|
197
|
+
d < be && l.push(e), d += e.length;
|
|
198
|
+
}), s.stdin.on("error", () => {}), s.on("error", () => {
|
|
199
|
+
clearTimeout(m), o(B("jq could not be run."));
|
|
200
|
+
}), s.on("close", (e) => {
|
|
201
|
+
if (clearTimeout(m), f) return o(f);
|
|
202
|
+
if (e === null || !r.includes(e)) return o(B(`jq: ${Buffer.concat(l).toString("utf8").slice(0, be).trim() || `exited with ${e}`}`));
|
|
203
|
+
a(Buffer.concat(c).toString("utf8").replace(/\n$/, ""));
|
|
204
|
+
}), s.stdin.end(n);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
var Ee = (e) => typeof e == "string" ? e : JSON.stringify(e, null, 2) ?? "null";
|
|
208
|
+
function De(e, t) {
|
|
209
|
+
if (!j(e)) throw B("The jq expression is not valid (or not supported).");
|
|
210
|
+
let n;
|
|
211
|
+
try {
|
|
212
|
+
n = M(JSON.parse(t), e);
|
|
213
|
+
} catch (e) {
|
|
214
|
+
throw B(`jq: ${e instanceof Error ? e.message.slice(0, 200) : "failed"}`);
|
|
215
|
+
}
|
|
216
|
+
return (Array.isArray(n) && !e.trimStart().startsWith("[") && /[\w\].)"]\[\]/.test(e) ? n : [n]).map(Ee).join("\n");
|
|
217
|
+
}
|
|
218
|
+
function Oe(e, t = Ce) {
|
|
219
|
+
let n = t("jq", e);
|
|
220
|
+
return n ? {
|
|
221
|
+
kind: "system",
|
|
222
|
+
file: n
|
|
223
|
+
} : { kind: "builtin" };
|
|
224
|
+
}
|
|
225
|
+
async function ke(e, t) {
|
|
226
|
+
if (t.length === 0 || t.length > xe) throw B("The jq expression must be 1 to 4096 characters.");
|
|
227
|
+
if (e.kind === "builtin") {
|
|
228
|
+
if (!j(t)) throw B("The jq expression is not valid (or not supported).");
|
|
229
|
+
} else await Te(e.file, [
|
|
230
|
+
"-n",
|
|
231
|
+
"-r",
|
|
232
|
+
we(t)
|
|
233
|
+
], "", [
|
|
234
|
+
0,
|
|
235
|
+
1,
|
|
236
|
+
5
|
|
237
|
+
]);
|
|
238
|
+
}
|
|
239
|
+
async function Ae(e, t, n, r = ye) {
|
|
240
|
+
if (t.length === 0 || t.length > xe) throw B("The jq expression must be 1 to 4096 characters.");
|
|
241
|
+
try {
|
|
242
|
+
JSON.parse(n);
|
|
243
|
+
} catch {
|
|
244
|
+
throw B("The response is not JSON, so --jq cannot be applied.");
|
|
245
|
+
}
|
|
246
|
+
return e.kind === "system" ? Te(e.file, ["-r", we(t)], n, [0], r) : De(t, n);
|
|
247
|
+
}
|
|
248
|
+
// src/json-text.ts
|
|
249
|
+
var je = 512, Me = /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/y;
|
|
250
|
+
function Ne(e) {
|
|
251
|
+
let t = 0, n = () => /* @__PURE__ */ SyntaxError("Invalid JSON"), r = () => {
|
|
252
|
+
for (; t < e.length && " \n\r".includes(e[t]);) t++;
|
|
253
|
+
}, i = () => {
|
|
254
|
+
let r = t++;
|
|
255
|
+
for (;;) {
|
|
256
|
+
let i = e[t];
|
|
257
|
+
if (i === void 0 || i < " ") throw n();
|
|
258
|
+
if (i === "\"") return {
|
|
259
|
+
kind: "scalar",
|
|
260
|
+
start: r,
|
|
261
|
+
end: ++t
|
|
262
|
+
};
|
|
263
|
+
if (i === "\\") {
|
|
264
|
+
let r = e[t + 1];
|
|
265
|
+
if (r === "u") {
|
|
266
|
+
if (!/^[0-9a-fA-F]{4}$/.test(e.slice(t + 2, t + 6))) throw n();
|
|
267
|
+
t += 6;
|
|
268
|
+
} else if (r !== void 0 && "\"\\/bfnrt".includes(r)) t += 2;
|
|
269
|
+
else throw n();
|
|
270
|
+
} else t++;
|
|
271
|
+
}
|
|
272
|
+
}, a = (o) => {
|
|
273
|
+
if (o >= je) throw n();
|
|
274
|
+
r();
|
|
275
|
+
let s = e[t], c = t;
|
|
276
|
+
if (s === "\"") return i();
|
|
277
|
+
if (s === "[") {
|
|
278
|
+
t++;
|
|
279
|
+
let i = [];
|
|
280
|
+
if (r(), e[t] === "]") return {
|
|
281
|
+
kind: "array",
|
|
282
|
+
start: c,
|
|
283
|
+
end: ++t,
|
|
284
|
+
items: i
|
|
285
|
+
};
|
|
286
|
+
for (;;) if (i.push(a(o + 1)), r(), e[t] === ",") t++;
|
|
287
|
+
else if (e[t] === "]") return {
|
|
288
|
+
kind: "array",
|
|
289
|
+
start: c,
|
|
290
|
+
end: ++t,
|
|
291
|
+
items: i
|
|
292
|
+
};
|
|
293
|
+
else throw n();
|
|
294
|
+
}
|
|
295
|
+
if (s === "{") {
|
|
296
|
+
t++;
|
|
297
|
+
let s = [];
|
|
298
|
+
if (r(), e[t] === "}") return {
|
|
299
|
+
kind: "object",
|
|
300
|
+
start: c,
|
|
301
|
+
end: ++t,
|
|
302
|
+
entries: s
|
|
303
|
+
};
|
|
304
|
+
for (;;) {
|
|
305
|
+
if (r(), e[t] !== "\"") throw n();
|
|
306
|
+
let l = i();
|
|
307
|
+
if (r(), e[t++] !== ":") throw n();
|
|
308
|
+
if (s.push([l, a(o + 1)]), r(), e[t] === ",") t++;
|
|
309
|
+
else if (e[t] === "}") return {
|
|
310
|
+
kind: "object",
|
|
311
|
+
start: c,
|
|
312
|
+
end: ++t,
|
|
313
|
+
entries: s
|
|
314
|
+
};
|
|
315
|
+
else throw n();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
for (let n of [
|
|
319
|
+
"true",
|
|
320
|
+
"false",
|
|
321
|
+
"null"
|
|
322
|
+
]) if (e.startsWith(n, t)) return t += n.length, {
|
|
323
|
+
kind: "scalar",
|
|
324
|
+
start: c,
|
|
325
|
+
end: t
|
|
326
|
+
};
|
|
327
|
+
Me.lastIndex = t;
|
|
328
|
+
let l = Me.exec(e);
|
|
329
|
+
if (!l) throw n();
|
|
330
|
+
return t += l[0].length, {
|
|
331
|
+
kind: "scalar",
|
|
332
|
+
start: c,
|
|
333
|
+
end: t
|
|
334
|
+
};
|
|
335
|
+
}, o = a(0);
|
|
336
|
+
if (r(), t !== e.length) throw n();
|
|
337
|
+
return o;
|
|
338
|
+
}
|
|
339
|
+
function Pe(e) {
|
|
340
|
+
let t = Ne(e);
|
|
341
|
+
return t.kind === "array" ? t.items.map((t) => e.slice(t.start, t.end)) : null;
|
|
342
|
+
}
|
|
343
|
+
function Fe(e) {
|
|
344
|
+
let t = Ne(e), n = [], r = (t, i) => {
|
|
345
|
+
let a = " ".repeat(i + 1), o = " ".repeat(i);
|
|
346
|
+
if (t.kind === "scalar") n.push(e.slice(t.start, t.end));
|
|
347
|
+
else if (t.kind === "array") {
|
|
348
|
+
if (t.items.length === 0) return void n.push("[]");
|
|
349
|
+
n.push("[\n"), t.items.forEach((e, o) => {
|
|
350
|
+
n.push(a), r(e, i + 1), n.push(o < t.items.length - 1 ? ",\n" : "\n");
|
|
351
|
+
}), n.push(`${o}]`);
|
|
352
|
+
} else {
|
|
353
|
+
if (t.entries.length === 0) return void n.push("{}");
|
|
354
|
+
n.push("{\n"), t.entries.forEach(([o, s], c) => {
|
|
355
|
+
n.push(a, e.slice(o.start, o.end), ": "), r(s, i + 1), n.push(c < t.entries.length - 1 ? ",\n" : "\n");
|
|
356
|
+
}), n.push(`${o}}`);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
return r(t, 0), n.join("");
|
|
360
|
+
}
|
|
361
|
+
// src/errors.ts
|
|
362
|
+
var V = {
|
|
363
|
+
ok: 0,
|
|
364
|
+
failure: 1,
|
|
365
|
+
usage: 2,
|
|
366
|
+
unauthorized: 3,
|
|
367
|
+
notFound: 4,
|
|
368
|
+
transport: 5,
|
|
369
|
+
local: 6,
|
|
370
|
+
deployment: 7,
|
|
371
|
+
waiting: 8,
|
|
372
|
+
interrupted: 130
|
|
373
|
+
}, H = class extends Error {
|
|
374
|
+
exitCode;
|
|
375
|
+
constructor(e) {
|
|
376
|
+
super(`exit ${e}`), this.exitCode = e, this.name = "ExitWith";
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
function U(e) {
|
|
380
|
+
if (e instanceof x) return {
|
|
381
|
+
exitCode: V.usage,
|
|
382
|
+
code: "usage",
|
|
383
|
+
message: _(e.message.replace(/^error: /, ""))
|
|
384
|
+
};
|
|
385
|
+
if (e instanceof C) {
|
|
386
|
+
let t = e.status === 401 || e.status === 403 ? V.unauthorized : e.status === 404 ? V.notFound : V.failure, n = e.status === 429 && e.retryAfterSeconds ? ` Try again in ${e.retryAfterSeconds} seconds.` : "";
|
|
387
|
+
return {
|
|
388
|
+
exitCode: t,
|
|
389
|
+
code: e.code,
|
|
390
|
+
message: _(`${e.title}${n}`),
|
|
391
|
+
status: e.status
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
if (e instanceof T) return {
|
|
395
|
+
exitCode: V.transport,
|
|
396
|
+
code: e.reason,
|
|
397
|
+
message: _(e.message)
|
|
398
|
+
};
|
|
399
|
+
if (e instanceof w) return {
|
|
400
|
+
exitCode: V.usage,
|
|
401
|
+
code: "bad-input",
|
|
402
|
+
message: _(e.message)
|
|
403
|
+
};
|
|
404
|
+
if (e instanceof a) return {
|
|
405
|
+
exitCode: e.code === "not-logged-in" ? V.unauthorized : e.code === "bad-input" ? V.usage : V.local,
|
|
406
|
+
code: e.code,
|
|
407
|
+
message: _(e.message)
|
|
408
|
+
};
|
|
409
|
+
let t = e instanceof Error ? e.message : String(e);
|
|
410
|
+
return {
|
|
411
|
+
exitCode: V.failure,
|
|
412
|
+
code: "failure",
|
|
413
|
+
message: _(t)
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
var W = (e) => new a("bad-input", e);
|
|
417
|
+
async function Ie(e, t) {
|
|
418
|
+
let n;
|
|
419
|
+
if (t.passwordFile !== void 0) try {
|
|
420
|
+
n = await e.readPasswordFile(t.passwordFile);
|
|
421
|
+
} catch (e) {
|
|
422
|
+
throw W(e instanceof Error ? e.message : "The password file cannot be read.");
|
|
423
|
+
}
|
|
424
|
+
else if (e.interactive) try {
|
|
425
|
+
n = await e.readSecret(t.prompt, {
|
|
426
|
+
kind: "password",
|
|
427
|
+
signal: t.signal
|
|
428
|
+
});
|
|
429
|
+
} catch (e) {
|
|
430
|
+
throw e instanceof Error && e.message === "Cancelled." ? new H(V.interrupted) : e instanceof Error && /^Input is too long/.test(e.message) ? W(e.message) : e;
|
|
431
|
+
}
|
|
432
|
+
else throw W("There is no terminal to ask for the password: provide --password-file <path> or run in a terminal.");
|
|
433
|
+
if (n.length === 0) throw W("The password is empty.");
|
|
434
|
+
if (n.length < 12 || n.length > 128) throw W("The password must be 12 to 128 characters.");
|
|
435
|
+
return n;
|
|
436
|
+
}
|
|
437
|
+
// src/session-flow.ts
|
|
438
|
+
var Le = {
|
|
439
|
+
SIGHUP: 129,
|
|
440
|
+
SIGINT: 130,
|
|
441
|
+
SIGTERM: 143
|
|
442
|
+
}, Re = class {
|
|
443
|
+
io;
|
|
444
|
+
abort = new AbortController();
|
|
445
|
+
listeners = [];
|
|
446
|
+
interruptedWith = null;
|
|
447
|
+
constructor(e) {
|
|
448
|
+
this.io = e;
|
|
449
|
+
}
|
|
450
|
+
get signal() {
|
|
451
|
+
return this.abort.signal;
|
|
452
|
+
}
|
|
453
|
+
install() {
|
|
454
|
+
let e = this.io.signals;
|
|
455
|
+
if (!(!e || this.listeners.length > 0)) for (let [t, n] of Object.entries(Le)) {
|
|
456
|
+
let r = () => {
|
|
457
|
+
if (this.interruptedWith !== null) return e.exit(n);
|
|
458
|
+
this.interruptedWith = n, this.abort.abort();
|
|
459
|
+
};
|
|
460
|
+
e.on(t, r), this.listeners.push([t, r]);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
uninstall() {
|
|
464
|
+
for (let [e, t] of this.listeners) this.io.signals?.off(e, t);
|
|
465
|
+
this.listeners = [];
|
|
466
|
+
}
|
|
467
|
+
}, ze = class {
|
|
468
|
+
options;
|
|
469
|
+
guard;
|
|
470
|
+
ownsGuard;
|
|
471
|
+
client = null;
|
|
472
|
+
signingIn = null;
|
|
473
|
+
kept = !1;
|
|
474
|
+
constructor(e) {
|
|
475
|
+
this.options = e, this.guard = e.guard ?? new Re(e.io), this.ownsGuard = e.guard === void 0;
|
|
476
|
+
}
|
|
477
|
+
get interruptedWith() {
|
|
478
|
+
return this.guard.interruptedWith;
|
|
479
|
+
}
|
|
480
|
+
get controller() {
|
|
481
|
+
return this.options.controller;
|
|
482
|
+
}
|
|
483
|
+
get signal() {
|
|
484
|
+
return this.guard.signal;
|
|
485
|
+
}
|
|
486
|
+
attach(e) {
|
|
487
|
+
let t = O({
|
|
488
|
+
baseUrl: this.options.controller,
|
|
489
|
+
cookie: e,
|
|
490
|
+
fetch: this.options.io.context.fetch
|
|
491
|
+
});
|
|
492
|
+
return this.options.remember(e), this.options.remember(e.slice(e.indexOf("=") + 1)), this.client = t, this.kept = !0, this.signingIn = Promise.resolve(t), t;
|
|
493
|
+
}
|
|
494
|
+
signIn() {
|
|
495
|
+
return this.signingIn ??= this.start(), this.signingIn;
|
|
496
|
+
}
|
|
497
|
+
async start() {
|
|
498
|
+
let { io: e, controller: t, email: n } = this.options;
|
|
499
|
+
this.guard.install(), e.err(`Signing in to ${t} as ${n}.`);
|
|
500
|
+
let r = await Ie(e, {
|
|
501
|
+
passwordFile: this.options.passwordFile,
|
|
502
|
+
prompt: `Password for ${n}: `,
|
|
503
|
+
signal: this.guard.signal
|
|
504
|
+
});
|
|
505
|
+
this.options.remember(r);
|
|
506
|
+
let i = O({
|
|
507
|
+
baseUrl: t,
|
|
508
|
+
fetch: e.context.fetch
|
|
509
|
+
});
|
|
510
|
+
this.client = i, this.options.verbose && e.err("> POST /api/auth/sign-in/email (the email and password are not shown)");
|
|
511
|
+
let a;
|
|
512
|
+
try {
|
|
513
|
+
({cookie: a} = await i.signIn(n, r, { signal: this.guard.signal }));
|
|
514
|
+
} catch (e) {
|
|
515
|
+
let t = i.cookie();
|
|
516
|
+
throw t && (this.options.remember(t), this.options.remember(t.slice(t.indexOf("=") + 1))), e;
|
|
517
|
+
}
|
|
518
|
+
return this.options.remember(a), this.options.remember(a.slice(a.indexOf("=") + 1)), this.options.keep && await this.keep(a), i;
|
|
519
|
+
}
|
|
520
|
+
async keep(e) {
|
|
521
|
+
let { io: t, controller: n, email: r } = this.options, i = await t.context.sessions.put({
|
|
522
|
+
controller: n,
|
|
523
|
+
email: r,
|
|
524
|
+
cookie: e
|
|
525
|
+
});
|
|
526
|
+
if (this.kept = !0, t.err("Session saved. It lasts until `launchpad logout --session`, or 7 days after its last use."), i) {
|
|
527
|
+
this.options.remember(i.cookie);
|
|
528
|
+
try {
|
|
529
|
+
await O({
|
|
530
|
+
baseUrl: n,
|
|
531
|
+
cookie: i.cookie,
|
|
532
|
+
fetch: t.context.fetch
|
|
533
|
+
}).signOut();
|
|
534
|
+
} catch (e) {
|
|
535
|
+
t.err(`Warning: could not sign the previous session out (${U(e).message}). It ends on its own, at most 7 days after its last use.`);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
async close() {
|
|
540
|
+
let { io: e, controller: t } = this.options;
|
|
541
|
+
try {
|
|
542
|
+
let n = this.client;
|
|
543
|
+
if (this.client = null, n?.cookie() && !this.kept) {
|
|
544
|
+
this.options.verbose && e.err("> POST /api/auth/sign-out");
|
|
545
|
+
try {
|
|
546
|
+
await n.signOut();
|
|
547
|
+
} catch (n) {
|
|
548
|
+
e.err(`Warning: could not sign out of ${t} (${U(n).message}). The session ends on its own, at most 7 days after its last use.`);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
} finally {
|
|
552
|
+
this.ownsGuard && this.guard.uninstall();
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
async function Be(e, t) {
|
|
557
|
+
let n = {};
|
|
558
|
+
try {
|
|
559
|
+
await t(n);
|
|
560
|
+
} catch (t) {
|
|
561
|
+
throw await n.flow?.close(), n.flow?.interruptedWith == null ? t : (e.err("Interrupted."), new H(n.flow.interruptedWith));
|
|
562
|
+
}
|
|
563
|
+
if (await n.flow?.close(), n.flow?.interruptedWith != null) throw new H(n.flow.interruptedWith);
|
|
564
|
+
}
|
|
565
|
+
// src/session-target.ts
|
|
566
|
+
var Ve = (e) => new a("bad-input", e);
|
|
567
|
+
function He(e, t) {
|
|
568
|
+
if (e.env.LAUNCHPAD_API_KEY !== void 0) throw Ve(`${t} cannot be used while LAUNCHPAD_API_KEY is set. Unset it to use your own account.`);
|
|
569
|
+
}
|
|
570
|
+
function G(e, t = "--email") {
|
|
571
|
+
let n = ee(e);
|
|
572
|
+
if (n.length > 254 || !/^[^\s@\p{Cc}]+@[^\s@\p{Cc}]+$/u.test(n)) throw Ve(`${t} must be an email address.`);
|
|
573
|
+
return n;
|
|
574
|
+
}
|
|
575
|
+
async function Ue(e, t) {
|
|
576
|
+
let n = e.env.LAUNCHPAD_ORG || null, r = async (t) => {
|
|
577
|
+
let n = await e.store.load(), r = t ?? e.env.LAUNCHPAD_PROFILE ?? n.currentProfile, i = r && Object.hasOwn(n.profiles, r) ? n.profiles[r] : void 0;
|
|
578
|
+
if (!r || !i) throw new a("not-logged-in", r ? `No profile named "${r}". Run: launchpad login` : "No controller: use --controller, --profile or LAUNCHPAD_CONTROLLER.");
|
|
579
|
+
return {
|
|
580
|
+
controller: i.controller,
|
|
581
|
+
organizationId: i.organizationId
|
|
582
|
+
};
|
|
583
|
+
};
|
|
584
|
+
if (t.controller !== void 0) {
|
|
585
|
+
let e = k(t.controller), i = null;
|
|
586
|
+
if (t.profile) {
|
|
587
|
+
let n = await r(t.profile);
|
|
588
|
+
k(n.controller) === e && (i = n.organizationId);
|
|
589
|
+
}
|
|
590
|
+
return {
|
|
591
|
+
controller: e,
|
|
592
|
+
organizationId: n ?? i
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
if (t.profile === void 0 && e.env.LAUNCHPAD_CONTROLLER) return {
|
|
596
|
+
controller: k(e.env.LAUNCHPAD_CONTROLLER),
|
|
597
|
+
organizationId: n
|
|
598
|
+
};
|
|
599
|
+
let i = await r(t.profile);
|
|
600
|
+
return {
|
|
601
|
+
controller: k(i.controller),
|
|
602
|
+
organizationId: n ?? i.organizationId
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
// src/session-run.ts
|
|
606
|
+
var We = 9e5, Ge = (e) => new a("bad-input", e);
|
|
607
|
+
async function Ke(e, t) {
|
|
608
|
+
let { io: n, guard: r } = e, i = e.email === void 0 ? null : G(e.email), o = await Ue(n.context, {
|
|
609
|
+
controller: e.controller,
|
|
610
|
+
profile: e.profile
|
|
611
|
+
}), s = e.keep ? null : await n.context.sessions.get(o.controller);
|
|
612
|
+
if (s && i !== null && i !== s.email) throw Ge("--email differs from the saved session's account. Use `launchpad login --session` to switch, or `launchpad logout --session` first.");
|
|
613
|
+
if (!s && i === null) throw Ge(e.missingEmail ?? "--session needs --email <address> to sign in.");
|
|
614
|
+
let c = e.chooseOrganization ? e.chooseOrganization(o.organizationId) : null, l = s?.email ?? i, u = new ze({
|
|
615
|
+
io: n,
|
|
616
|
+
controller: o.controller,
|
|
617
|
+
email: l,
|
|
618
|
+
passwordFile: e.passwordFile,
|
|
619
|
+
verbose: e.verbose,
|
|
620
|
+
keep: e.keep,
|
|
621
|
+
guard: r,
|
|
622
|
+
remember: e.remember
|
|
623
|
+
});
|
|
624
|
+
t.flow = u, s && u.attach(s.cookie);
|
|
625
|
+
let d = !1, f = async (t, r) => {
|
|
626
|
+
let i = await u.signIn();
|
|
627
|
+
e.acting && !d && (d = !0, n.err(`Acting as ${l} on ${o.controller}${c === null ? "" : `, organization ${c}`}`));
|
|
628
|
+
let a = typeof e.needsFresh == "function" ? e.needsFresh(t, r) : e.needsFresh;
|
|
629
|
+
return s && a && Date.now() - Date.parse(s.savedAt) > We && n.err("Warning: this saved session is older than 15 minutes, and issuing a key needs a sign-in from the last 15 minutes. Run `launchpad login --session` again if the controller refuses."), i;
|
|
630
|
+
}, p = async (e) => {
|
|
631
|
+
try {
|
|
632
|
+
return await e();
|
|
633
|
+
} catch (e) {
|
|
634
|
+
throw s && e instanceof C && e.status === 401 ? (await n.context.sessions.remove(o.controller, s.cookie), new a("not-logged-in", "The saved session is no longer valid and was removed. Sign in again with `launchpad login --session`.")) : e;
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
return {
|
|
638
|
+
caller: {
|
|
639
|
+
raw: async (e, t, n) => {
|
|
640
|
+
let r = await f(e, t);
|
|
641
|
+
return p(() => r.raw(e, t, {
|
|
642
|
+
...n,
|
|
643
|
+
signal: n.signal ? AbortSignal.any([u.signal, n.signal]) : u.signal
|
|
644
|
+
}));
|
|
645
|
+
},
|
|
646
|
+
use: async (e, t, n) => {
|
|
647
|
+
let r = await f(e, t);
|
|
648
|
+
return p(() => n(r, u.signal));
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
controller: o.controller,
|
|
652
|
+
email: l,
|
|
653
|
+
organization: c,
|
|
654
|
+
organizationId: o.organizationId
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function qe(e, t) {
|
|
658
|
+
let n;
|
|
659
|
+
return Be(e.io, async (r) => {
|
|
660
|
+
let i = await Ke(e, r);
|
|
661
|
+
n = await t({
|
|
662
|
+
client: i.caller,
|
|
663
|
+
email: i.email,
|
|
664
|
+
controller: i.controller,
|
|
665
|
+
organization: i.organization
|
|
666
|
+
});
|
|
667
|
+
}).then(() => n);
|
|
668
|
+
}
|
|
669
|
+
async function Je(e, t, n) {
|
|
670
|
+
let r = t === void 0 ? void 0 : new Re(e);
|
|
671
|
+
r?.install();
|
|
672
|
+
let i;
|
|
673
|
+
try {
|
|
674
|
+
if (t !== void 0) try {
|
|
675
|
+
i = await e.createSecretFile(t);
|
|
676
|
+
} catch (e) {
|
|
677
|
+
throw Ge(e instanceof Error ? e.message : "The secret file cannot be created.");
|
|
678
|
+
}
|
|
679
|
+
if (await n({
|
|
680
|
+
guard: r,
|
|
681
|
+
secretFile: i
|
|
682
|
+
}), r?.interruptedWith != null) throw new H(r.interruptedWith);
|
|
683
|
+
} catch (t) {
|
|
684
|
+
throw await i?.remove().catch(() => {}), r?.interruptedWith == null ? t : (t instanceof H || e.err("Interrupted."), new H(r.interruptedWith));
|
|
685
|
+
} finally {
|
|
686
|
+
r?.uninstall();
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
// src/api-command.ts
|
|
690
|
+
var Ye = 1e3, Xe = 1e5, Ze = 16777216, Qe = 3e5;
|
|
691
|
+
function $e(e, t) {
|
|
692
|
+
return t ? t.aborted ? Promise.reject(/* @__PURE__ */ Error("Interrupted.")) : new Promise((n, r) => {
|
|
693
|
+
let i = () => r(/* @__PURE__ */ Error("Interrupted."));
|
|
694
|
+
t.addEventListener("abort", i, { once: !0 });
|
|
695
|
+
let a;
|
|
696
|
+
try {
|
|
697
|
+
a = e();
|
|
698
|
+
} catch (e) {
|
|
699
|
+
a = Promise.reject(e);
|
|
700
|
+
}
|
|
701
|
+
a.then(n, r).finally(() => t.removeEventListener("abort", i));
|
|
702
|
+
}) : e();
|
|
703
|
+
}
|
|
704
|
+
var et = (e, t) => e === "POST" && /^\/organizations\/[^/]+\/api-keys\/?$/.test(t), tt = /\{(org|project)\}/g, K = (e) => new a("bad-input", e), nt = /* @__PURE__ */ new Set(["set-cookie", "set-cookie2"]), rt = (e) => [...e.entries()].map(([e, t]) => `${e}: ${nt.has(e) ? "[redacted]" : t}`), it = (e) => {
|
|
705
|
+
try {
|
|
706
|
+
return Fe(e);
|
|
707
|
+
} catch {
|
|
708
|
+
return e.replace(/\n$/, "");
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
function at(e, t, n = () => {}) {
|
|
712
|
+
let r = [], i = [];
|
|
713
|
+
e.command("api").description("Call any /api/v1 endpoint of the controller with the current key and print the response (modeled on `gh api`).").argument("<endpoint>", "path under /api/v1, e.g. organizations/{org}/apps").option("-X, --method <method>", "HTTP method (GET, or POST when fields are given)").option("-f, --raw-field <key=value>", "add a string parameter (repeatable; a[b]=c nests, a[]=x builds an array)", (e) => void r.push({
|
|
714
|
+
typed: !1,
|
|
715
|
+
text: e
|
|
716
|
+
})).option("-F, --field <key=value>", "add a typed parameter: true, false, null and integers convert; @file and @- read a file or stdin", (e) => void r.push({
|
|
717
|
+
typed: !0,
|
|
718
|
+
text: e
|
|
719
|
+
})).option("--input <file>", "send this file (or - for stdin) as the body, byte for byte (JSON unless -H sets a content-type)").option("-H, --header <name:value>", `add a request header (refused: ${[...le].join(", ")})`, (e) => void i.push(e)).option("-i, --include", "print the status line and response headers first").option("--silent", "do not print the response body").option("--verbose", "print the request and response (the key and cookies are redacted)").option("--paginate", "follow same-origin rel=\"next\" links of a list and merge the arrays").option("--slurp", "with --paginate, print an array of the pages instead of merging them").option("-q, --jq <expression>", "filter the JSON response with jq (the system jq if found, else a built-in subset)").option("--idempotency-key <key>", "send this Idempotency-Key header (1 to 128 printable ASCII)").option("--confirm", "confirm a request that is not GET or HEAD").option("--session", "use your own account (an email and password sign-in) instead of a key, for the organization, member and key endpoints a key cannot reach. The session lives only for this command and is signed out at the end (best effort). Each call is a new sign-in, and sign-ins are throttled per account and address: more than 5 a minute are refused and also block that account's dashboard sign-in. Use occasionally.").option("--email <address>", "with --session, the account's email address").option("--password-file <path>", "with --session, read the password from this private file instead of the prompt").option("--controller <url>", "with --session, the controller (else the selected profile's, else LAUNCHPAD_CONTROLLER)").option("--secret-file <path>", "create this new file (mode 0600) before the request and write the response's `secret` (a new API key) to it; the screen shows it redacted").option("--keep", "with --session, save the session (session.json, owner-only) instead of signing out; later calls reuse it until `launchpad logout --session`").action(async (e, n, r) => {
|
|
720
|
+
if (n.secretFile !== void 0 && n.paginate) throw K("--secret-file cannot be combined with --paginate.");
|
|
721
|
+
await Je(t, n.secretFile, ({ guard: i, secretFile: a }) => Be(t, (t) => o(e, n, r, t, a, i)));
|
|
722
|
+
});
|
|
723
|
+
async function o(e, o, s, l, d, f) {
|
|
724
|
+
let p = f?.signal;
|
|
725
|
+
{
|
|
726
|
+
let { profile: m } = s.optsWithGlobals();
|
|
727
|
+
if (o.session) He(t.context, "--session");
|
|
728
|
+
else for (let [e, t] of [
|
|
729
|
+
["--email", o.email],
|
|
730
|
+
["--password-file", o.passwordFile],
|
|
731
|
+
["--controller", o.controller],
|
|
732
|
+
["--keep", o.keep]
|
|
733
|
+
]) if (t !== void 0) throw K(`${e} needs --session.`);
|
|
734
|
+
o.email !== void 0 && G(o.email);
|
|
735
|
+
let h = (o.method ?? (r.length > 0 || o.input ? "POST" : "GET")).toUpperCase();
|
|
736
|
+
if (!ue.has(h)) throw K("The method must be GET, HEAD, POST, PUT, PATCH or DELETE.");
|
|
737
|
+
let ee = h === "GET" || h === "HEAD";
|
|
738
|
+
if (ee || v(o.confirm), o.paginate && h !== "GET") throw K("--paginate needs the GET method.");
|
|
739
|
+
if (o.slurp && !o.paginate) throw K("--slurp needs --paginate.");
|
|
740
|
+
if (o.paginate && o.include) throw K("--include cannot be combined with --paginate.");
|
|
741
|
+
if (e.includes("#")) throw K("The endpoint must not contain a fragment.");
|
|
742
|
+
let g = o.jq === void 0 ? void 0 : Oe(t.context.env.PATH, (e, n) => t.findExecutable?.(e) ?? Ce(e, n));
|
|
743
|
+
g && await ke(g, o.jq), g && o.verbose && t.err(`> jq: ${g.kind === "system" ? g.file : "built-in micro-jq subset"}`);
|
|
744
|
+
let ne = /* @__PURE__ */ new Set();
|
|
745
|
+
for (let t of [e, ...r.map((e) => ({
|
|
746
|
+
typed: e.typed,
|
|
747
|
+
value: e.text.slice(e.text.indexOf("=") + 1)
|
|
748
|
+
})).filter((e) => !(e.typed && e.value.startsWith("@"))).map((e) => e.value)]) for (let e of t.matchAll(tt)) ne.add(e[1]);
|
|
749
|
+
let _ = t.workingDir ?? process.cwd(), y = await re(_), ae, oe = () => ae ??= o.session ? se() : (async () => {
|
|
750
|
+
let e = await ie(t.context, m ?? y.config?.profile), n = c(t.context, e);
|
|
751
|
+
return {
|
|
752
|
+
controller: e.controller,
|
|
753
|
+
organizationId: e.organizationId,
|
|
754
|
+
organizations: () => n.organizations.list(),
|
|
755
|
+
ownOrganization: async () => (await n.key.get()).organizationId,
|
|
756
|
+
raw: (e, t, r) => n.raw(e, t, r),
|
|
757
|
+
credentialLines: ["> authorization: [redacted]"]
|
|
758
|
+
};
|
|
759
|
+
})(), se = async () => {
|
|
760
|
+
let e = await Ke({
|
|
761
|
+
io: t,
|
|
762
|
+
remember: n,
|
|
763
|
+
guard: f,
|
|
764
|
+
controller: o.controller,
|
|
765
|
+
profile: m ?? y.config?.profile,
|
|
766
|
+
email: o.email,
|
|
767
|
+
passwordFile: o.passwordFile,
|
|
768
|
+
verbose: o.verbose,
|
|
769
|
+
keep: o.keep,
|
|
770
|
+
needsFresh: et
|
|
771
|
+
}, l);
|
|
772
|
+
return {
|
|
773
|
+
controller: e.controller,
|
|
774
|
+
organizationId: e.organizationId,
|
|
775
|
+
organizations: async () => {
|
|
776
|
+
let t = await e.caller.raw("GET", "/organizations", {}), n = JSON.parse(t.body);
|
|
777
|
+
if (!Array.isArray(n)) throw K("The organization list was not a list.");
|
|
778
|
+
return n.filter((e) => typeof e?.id == "string" && typeof e?.slug == "string");
|
|
779
|
+
},
|
|
780
|
+
ownOrganization: async () => {
|
|
781
|
+
throw K("{org} has no value: with --session select an organization with `launchpad org use`, launchpad.json or LAUNCHPAD_ORG.");
|
|
782
|
+
},
|
|
783
|
+
raw: e.caller.raw,
|
|
784
|
+
credentialLines: ["> cookie: [redacted]", `> origin: ${new URL(e.controller).origin}`]
|
|
785
|
+
};
|
|
786
|
+
}, b = /* @__PURE__ */ new Map();
|
|
787
|
+
if (ne.has("org")) {
|
|
788
|
+
let e = await oe(), t = y.config?.organization;
|
|
789
|
+
if (t) {
|
|
790
|
+
let n = (await e.organizations()).find((e) => e.id === t || e.slug === t);
|
|
791
|
+
if (!n) throw new a("no-organization", "This key cannot see the selected organization.");
|
|
792
|
+
b.set("org", n.id);
|
|
793
|
+
} else b.set("org", e.organizationId ?? await e.ownOrganization());
|
|
794
|
+
}
|
|
795
|
+
if (ne.has("project")) {
|
|
796
|
+
let e = y.config?.project;
|
|
797
|
+
if (!e) throw K("{project} needs a launchpad.json with a project.");
|
|
798
|
+
b.set("project", e);
|
|
799
|
+
}
|
|
800
|
+
let ce = (e, t) => e.replace(tt, (e, n) => {
|
|
801
|
+
let r = b.get(n);
|
|
802
|
+
if (!r) throw K(`{${n}} has no value here.`);
|
|
803
|
+
if (!t) return r;
|
|
804
|
+
if (r === "." || r === "..") throw K(`{${n}} is not a valid path segment.`);
|
|
805
|
+
return encodeURIComponent(r);
|
|
806
|
+
}), x = { value: !1 }, S = async (e) => {
|
|
807
|
+
if (e === "-") {
|
|
808
|
+
if (x.value) throw K("Standard input can be read only once.");
|
|
809
|
+
x.value = !0;
|
|
810
|
+
}
|
|
811
|
+
try {
|
|
812
|
+
return await $e(() => t.readData(e), p);
|
|
813
|
+
} catch (t) {
|
|
814
|
+
let n = t instanceof Error ? t.message : "unreadable";
|
|
815
|
+
throw K(e === "-" ? `Could not read standard input: ${n}` : `Could not read the data file: ${/ENOENT/.test(n) ? "not found" : n}`);
|
|
816
|
+
}
|
|
817
|
+
}, C = async (e) => {
|
|
818
|
+
try {
|
|
819
|
+
return new TextDecoder("utf-8", { fatal: !0 }).decode(await S(e));
|
|
820
|
+
} catch (e) {
|
|
821
|
+
throw e instanceof a ? e : K("A field value read from a file or stdin must be UTF-8 text.");
|
|
822
|
+
}
|
|
823
|
+
}, w = await te(r, {
|
|
824
|
+
readFile: C,
|
|
825
|
+
readStdin: () => C("-"),
|
|
826
|
+
fill: (e) => ce(e, !1)
|
|
827
|
+
}), [E = "", D = ""] = (() => {
|
|
828
|
+
let t = e.indexOf("?");
|
|
829
|
+
return t === -1 ? [e] : [e.slice(0, t), e.slice(t + 1)];
|
|
830
|
+
})(), O = ce(E, !0), de = O.startsWith("/") ? O : `/${O}`, A = [...new URLSearchParams(D).entries()].map(([e, t]) => [e, ce(t, !1)]), j;
|
|
831
|
+
o.input === void 0 ? ee ? A.push(...u(w)) : Object.keys(w).length > 0 && (j = JSON.stringify(w)) : (j = await S(o.input), A.push(...u(w)));
|
|
832
|
+
let M = {};
|
|
833
|
+
for (let e of i) {
|
|
834
|
+
let t = e.indexOf(":");
|
|
835
|
+
if (t < 1) throw K("A header is written name:value.");
|
|
836
|
+
M[e.slice(0, t).trim()] = e.slice(t + 1).trim();
|
|
837
|
+
}
|
|
838
|
+
if (j !== void 0 && !Object.keys(M).some((e) => e.toLowerCase() === "content-type")) try {
|
|
839
|
+
JSON.parse(typeof j == "string" ? j : new TextDecoder("utf-8", { fatal: !0 }).decode(j));
|
|
840
|
+
} catch {
|
|
841
|
+
throw K("The request body is not valid JSON; set a content-type with -H to send it anyway.");
|
|
842
|
+
}
|
|
843
|
+
let fe = async (e) => {
|
|
844
|
+
if (!g) return it(e);
|
|
845
|
+
try {
|
|
846
|
+
return await Ae(g, o.jq, e);
|
|
847
|
+
} catch (e) {
|
|
848
|
+
let t = e instanceof Error ? e.message : "failed";
|
|
849
|
+
throw Error(`The request succeeded; the --jq filter failed: ${t}`);
|
|
850
|
+
}
|
|
851
|
+
}, N = await oe(), P = (e) => {
|
|
852
|
+
if (!o.verbose) return;
|
|
853
|
+
let n = new URL(`${k(N.controller)}/api/v1${e}`);
|
|
854
|
+
t.err(`> ${h} ${n.pathname}${n.search}`), t.err(`> host: ${n.host}`);
|
|
855
|
+
for (let e of N.credentialLines) t.err(e);
|
|
856
|
+
for (let [e, n] of Object.entries(M)) {
|
|
857
|
+
let r = e.toLowerCase();
|
|
858
|
+
t.err(`> ${r}: ${le.has(r) ? "[redacted]" : n}`);
|
|
859
|
+
}
|
|
860
|
+
o.idempotencyKey && t.err(`> idempotency-key: ${o.idempotencyKey}`);
|
|
861
|
+
}, F = (e) => {
|
|
862
|
+
if (o.verbose) {
|
|
863
|
+
t.err(`< HTTP ${e.status}`);
|
|
864
|
+
for (let n of rt(e.headers)) t.err(`< ${n}`);
|
|
865
|
+
}
|
|
866
|
+
}, pe = (e) => `${de}${e.length ? `?${new URLSearchParams(e)}` : ""}`, I = (e, t) => (P(pe(e)), N.raw(h, de, {
|
|
867
|
+
query: e,
|
|
868
|
+
body: j,
|
|
869
|
+
headers: M,
|
|
870
|
+
idempotencyKey: o.idempotencyKey,
|
|
871
|
+
signal: t ?? p
|
|
872
|
+
}));
|
|
873
|
+
if (!o.paginate) {
|
|
874
|
+
let e = await I(A), r = e.body;
|
|
875
|
+
if (d) {
|
|
876
|
+
let t, i;
|
|
877
|
+
try {
|
|
878
|
+
i = JSON.parse(e.body), t = i?.secret;
|
|
879
|
+
} catch {
|
|
880
|
+
t = void 0;
|
|
881
|
+
}
|
|
882
|
+
if (typeof t != "string" || t.length === 0) throw Error("The response had no secret to save, so the --secret-file was removed.");
|
|
883
|
+
t.startsWith("lp_") || n(t);
|
|
884
|
+
let s = t.startsWith("lp_") ? "lp_[redacted]" : "[redacted]", c = (e) => typeof e == "string" ? e.split(t).join(s) : Array.isArray(e) ? e.map(c) : e && typeof e == "object" ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, c(t)])) : e;
|
|
885
|
+
r = JSON.stringify({
|
|
886
|
+
...c(i),
|
|
887
|
+
secret: s
|
|
888
|
+
});
|
|
889
|
+
try {
|
|
890
|
+
await d.write(`${t}\n`);
|
|
891
|
+
} catch {
|
|
892
|
+
throw new a("store-unavailable", `The key was created but could not be written to ${o.secretFile}. It exists: revoke it in the dashboard or with \`launchpad api\`.`);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
F(e), o.include && t.out([
|
|
896
|
+
`HTTP ${e.status}`,
|
|
897
|
+
...rt(e.headers),
|
|
898
|
+
""
|
|
899
|
+
].join("\n")), !o.silent && r.length > 0 && t.out(await fe(r));
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
let L = [], me = /* @__PURE__ */ new Set(), he = A;
|
|
903
|
+
me.add(new URLSearchParams(A).toString());
|
|
904
|
+
let ge = 0, R = 0, z = new AbortController(), _e = setTimeout(() => z.abort(), Qe);
|
|
905
|
+
try {
|
|
906
|
+
for (;;) {
|
|
907
|
+
let e;
|
|
908
|
+
try {
|
|
909
|
+
e = await I(he, z.signal);
|
|
910
|
+
} catch (e) {
|
|
911
|
+
throw z.signal.aborted ? new T("timeout", "--paginate took longer than 5 minutes; stopped.") : e;
|
|
912
|
+
}
|
|
913
|
+
F(e);
|
|
914
|
+
let t;
|
|
915
|
+
try {
|
|
916
|
+
t = Pe(e.body);
|
|
917
|
+
} catch {
|
|
918
|
+
t = null;
|
|
919
|
+
}
|
|
920
|
+
if (!t) throw K("--paginate needs an endpoint that returns a list.");
|
|
921
|
+
if (R += Buffer.byteLength(e.body), R > Ze) throw K("The list is larger than --paginate will collect (16 MiB).");
|
|
922
|
+
if (L.push(t), ge += t.length, ge > Xe) throw K("The list is longer than --paginate will collect.");
|
|
923
|
+
if (!e.next) break;
|
|
924
|
+
let n = new URLSearchParams(e.next).toString();
|
|
925
|
+
if (me.has(n) || L.length >= Ye) throw K("The controller's paging did not end; stopped.");
|
|
926
|
+
me.add(n), he = e.next;
|
|
927
|
+
}
|
|
928
|
+
} finally {
|
|
929
|
+
clearTimeout(_e);
|
|
930
|
+
}
|
|
931
|
+
if (!o.silent) {
|
|
932
|
+
let e = o.slurp ? `[${L.map((e) => `[${e.join(",")}]`).join(",")}]` : `[${L.flat().join(",")}]`;
|
|
933
|
+
t.out(await fe(e));
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
// src/app-commands.ts
|
|
939
|
+
function ot(e, t, n, r) {
|
|
940
|
+
let c = async (e) => {
|
|
941
|
+
let { profile: r } = e.optsWithGlobals(), i = await b(t, {
|
|
942
|
+
workingDir: n,
|
|
943
|
+
profile: r
|
|
944
|
+
});
|
|
945
|
+
return o(i.context, i.profile);
|
|
946
|
+
}, l = (e) => r(JSON.stringify(e, null, 2)), u = e.command("app").description("Manage apps and immutable deployments.");
|
|
947
|
+
u.command("list").action(async (e, t) => {
|
|
948
|
+
let { client: n, organizationId: r } = await c(t);
|
|
949
|
+
l(await n.apps.list(r));
|
|
950
|
+
}), u.command("create <project-id> <slug>").action(async (e, t, n, r) => {
|
|
951
|
+
let { client: i, organizationId: a } = await c(r);
|
|
952
|
+
l(await i.apps.create(a, e, { slug: t }));
|
|
953
|
+
}), u.command("deploy <app-id>").description("Deploy an uploaded archive to its own URL. Never promotes.").requiredOption("--artifact <id>", "uploaded artifact ID").option("--spa", "enable single-page application fallback").option("--ttl <duration>", "retention deadline, such as 7d").action(async (e, t, n) => {
|
|
954
|
+
let { client: r, organizationId: i } = await c(n);
|
|
955
|
+
l(await r.deployments.create(i, e, {
|
|
956
|
+
artifactId: t.artifact,
|
|
957
|
+
spa: t.spa,
|
|
958
|
+
ttl: t.ttl
|
|
959
|
+
}));
|
|
960
|
+
}), u.command("deployments <app-id>").action(async (e, t, n) => {
|
|
961
|
+
let { client: r, organizationId: i } = await c(n);
|
|
962
|
+
l(await r.deployments.list(i, e));
|
|
963
|
+
}), u.command("shutdown <app-id>").description("Withdraw all aliases before deleting the app's deployments; repeat to resume.").option("--confirm", "confirm destructive shutdown").action(async (e, t, n) => {
|
|
964
|
+
v(t.confirm);
|
|
965
|
+
let { client: r, organizationId: i } = await c(n);
|
|
966
|
+
l(await r.apps.shutdown(i, e));
|
|
967
|
+
}), e.command("artifact").description("Upload static site archives.").command("upload <project-id> <path>").description("Upload a .tar.gz file or pack a static output directory.").option("--directory", "pack the given directory rather than reading a .tar.gz").action(async (e, r, o, u) => {
|
|
968
|
+
let d = i.resolve(n, r);
|
|
969
|
+
if (o.directory && (await fe(d)).isSymbolicLink()) throw new a("bad-input", "The output directory must not be a symlink.");
|
|
970
|
+
let f = await N(t.store.directory).catch(() => t.store.directory), p = await N(d);
|
|
971
|
+
s(p, [f]);
|
|
972
|
+
let m = o.directory ? await g(p, void 0, {
|
|
973
|
+
include: ["**/*"],
|
|
974
|
+
exclude: ["**/launchpad.json"],
|
|
975
|
+
prefix: "",
|
|
976
|
+
protectedPaths: [f]
|
|
977
|
+
}) : await ne(d), { client: h, organizationId: ee } = await c(u), te = new Blob([new Uint8Array(m.archive)]);
|
|
978
|
+
l(await h.artifacts.upload(ee, e, te));
|
|
979
|
+
});
|
|
980
|
+
let d = e.command("deployment").description("Inspect or delete deployments.");
|
|
981
|
+
d.command("get <deployment-id>").action(async (e, t, n) => {
|
|
982
|
+
let { client: r, organizationId: i } = await c(n);
|
|
983
|
+
l(await r.deployments.get(i, e));
|
|
984
|
+
}), d.command("events <deployment-id>").option("--after <seq>", "read after this event sequence").action(async (e, t, n) => {
|
|
985
|
+
let { client: r, organizationId: i } = await c(n);
|
|
986
|
+
l(await r.deployments.events(i, e, { after: t.after }));
|
|
987
|
+
}), d.command("delete <deployment-id>").option("--confirm", "confirm deletion").action(async (e, t, n) => {
|
|
988
|
+
v(t.confirm);
|
|
989
|
+
let { client: r, organizationId: i } = await c(n);
|
|
990
|
+
l(await r.deployments.delete(i, e));
|
|
991
|
+
});
|
|
992
|
+
let f = e.command("alias").description("Read and explicitly change stable aliases.");
|
|
993
|
+
f.command("list <app-id>").action(async (e, t, n) => {
|
|
994
|
+
let { client: r, organizationId: i } = await c(n);
|
|
995
|
+
l(await r.aliases.list(i, e));
|
|
996
|
+
}), f.command("create <app-id> <slug>").action(async (e, t, n, r) => {
|
|
997
|
+
let { client: i, organizationId: a } = await c(r);
|
|
998
|
+
l(await i.aliases.create(a, e, { slug: t }));
|
|
999
|
+
}), f.command("operations <alias-id>").action(async (e, t, n) => {
|
|
1000
|
+
let { client: r, organizationId: i } = await c(n);
|
|
1001
|
+
l(await r.aliases.operations(i, e));
|
|
1002
|
+
}), f.command("promote <alias-id> <deployment-id>").description("Point an alias at a deployment, including rollback to a retained deployment.").requiredOption("--expected-generation <generation>", "alias's last read reserved generation").requiredOption("--idempotency-key <key>", "reuse the same key when retrying this exact request").option("--confirm", "confirm changing the live alias target").action(async (e, t, n, r) => {
|
|
1003
|
+
v(n.confirm);
|
|
1004
|
+
let { client: i, organizationId: a } = await c(r);
|
|
1005
|
+
l(await i.aliases.promote(a, e, {
|
|
1006
|
+
targetDeploymentId: t,
|
|
1007
|
+
expectedGeneration: n.expectedGeneration
|
|
1008
|
+
}, { idempotencyKey: n.idempotencyKey }));
|
|
1009
|
+
}), f.command("withdraw <alias-id>").description("Permanently withdraw an alias hostname.").requiredOption("--expected-generation <generation>", "alias's last read reserved generation").requiredOption("--idempotency-key <key>", "reuse the same key when retrying this exact request").option("--confirm", "confirm permanent withdrawal").action(async (e, t, n) => {
|
|
1010
|
+
v(t.confirm);
|
|
1011
|
+
let { client: r, organizationId: i } = await c(n);
|
|
1012
|
+
l(await r.aliases.withdraw(i, e, { expectedGeneration: t.expectedGeneration }, { idempotencyKey: t.idempotencyKey }));
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
// src/session-actions.ts
|
|
1016
|
+
var q = (e) => new a("bad-input", e), st = "Every run without --keep or a saved session is a new sign-in, and sign-ins are throttled: more than 5 a minute are refused and also block that account's dashboard sign-in. For batches use --keep, then `launchpad logout --session`. A kept session goes stale for `key issue` after 15 minutes (sign in again then).", J = (e, t, n = "") => `${e} Calls ${t}, with your own account's session (an email and password sign-in). ${n}${st}`, ct = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, Y = (e) => ct.test(e);
|
|
1017
|
+
function lt(e, t, n) {
|
|
1018
|
+
if (e.length === 0 || e.length > 256 || e === "." || e === ".." || /[\u0000-\u001f\u007f]/.test(e) || n && !Y(e)) throw q(`<${t}> must be ${n ? "an ID (a UUID) as the list command prints it" : "a valid ID"}.`);
|
|
1019
|
+
return e;
|
|
1020
|
+
}
|
|
1021
|
+
function ut(e, t) {
|
|
1022
|
+
return (n, r, i) => e.out(t(n).json ? JSON.stringify(r, null, 2) : i());
|
|
1023
|
+
}
|
|
1024
|
+
function dt(e) {
|
|
1025
|
+
if (!D.includes(e)) throw q(`--role must be one of ${D.join(", ")}.`);
|
|
1026
|
+
return e;
|
|
1027
|
+
}
|
|
1028
|
+
function ft(e, t = []) {
|
|
1029
|
+
return [...t, e];
|
|
1030
|
+
}
|
|
1031
|
+
function X(e, t) {
|
|
1032
|
+
return e.option("--email <address>", "the account that signs in (optional with a saved session; a different one is refused)").option("--password-file <path>", "read the password from this private file, not the prompt").option("--keep", "save the session (session.json, owner-only) instead of signing out; later commands reuse it until `launchpad logout --session`").option("--controller <url>", "the controller (else the selected profile's, else LAUNCHPAD_CONTROLLER)"), t.org && e.option("--org <id>", "the organization's ID (a UUID, not a slug; else launchpad.json, LAUNCHPAD_ORG, the profile)"), t.write && e.option("--confirm", "confirm this change"), e;
|
|
1033
|
+
}
|
|
1034
|
+
var pt = "Use the organization's ID: find it in the dashboard or with `launchpad api --session organizations`.";
|
|
1035
|
+
async function Z(e, t, n, r, i) {
|
|
1036
|
+
let { io: a, remember: o } = e;
|
|
1037
|
+
He(a.context, "This command"), n.write && v(r.confirm), n.validate?.();
|
|
1038
|
+
let { profile: s } = t.optsWithGlobals(), c = null, l;
|
|
1039
|
+
if (n.org) {
|
|
1040
|
+
r.org !== void 0 && (c = {
|
|
1041
|
+
value: r.org,
|
|
1042
|
+
source: "--org"
|
|
1043
|
+
});
|
|
1044
|
+
let e = await re(a.workingDir ?? process.cwd());
|
|
1045
|
+
if (l = e.config?.profile, !c && e.config?.organization && (c = {
|
|
1046
|
+
value: e.config.organization,
|
|
1047
|
+
source: "launchpad.json"
|
|
1048
|
+
}), c && !Y(c.value)) throw q(`${c.source} must be an organization ID (a UUID), not a slug. ${pt}`);
|
|
1049
|
+
}
|
|
1050
|
+
await Je(a, n.secretFile, ({ guard: e, secretFile: t }) => qe({
|
|
1051
|
+
io: a,
|
|
1052
|
+
remember: o,
|
|
1053
|
+
guard: e,
|
|
1054
|
+
controller: r.controller,
|
|
1055
|
+
profile: s ?? l,
|
|
1056
|
+
email: r.email,
|
|
1057
|
+
passwordFile: r.passwordFile,
|
|
1058
|
+
keep: r.keep,
|
|
1059
|
+
needsFresh: n.needsFresh,
|
|
1060
|
+
acting: !0,
|
|
1061
|
+
missingEmail: "--email <address> is needed to sign in (no saved session).",
|
|
1062
|
+
chooseOrganization: n.org ? (e) => {
|
|
1063
|
+
if (c) return c.value;
|
|
1064
|
+
if (e === null) throw q("No organization: use --org <id>, launchpad.json, LAUNCHPAD_ORG or a profile's organization.");
|
|
1065
|
+
if (!Y(e)) throw q(`The organization from LAUNCHPAD_ORG or the profile must be an organization ID (a UUID), not a slug. ${pt}`);
|
|
1066
|
+
return e;
|
|
1067
|
+
} : void 0
|
|
1068
|
+
}, ({ client: n, email: r, controller: a, organization: o }) => i({
|
|
1069
|
+
client: n,
|
|
1070
|
+
email: r,
|
|
1071
|
+
controller: a,
|
|
1072
|
+
organization: o ?? "",
|
|
1073
|
+
secretFile: t,
|
|
1074
|
+
guard: e
|
|
1075
|
+
})));
|
|
1076
|
+
}
|
|
1077
|
+
// src/table.ts
|
|
1078
|
+
var Q = (e) => {
|
|
1079
|
+
let t = e[0].map((t, n) => Math.max(...e.map((e) => (e[n] ?? "").length)));
|
|
1080
|
+
return e.map((e) => e.map((e, n) => e.padEnd(t[n])).join(" ").trimEnd()).join("\n");
|
|
1081
|
+
};
|
|
1082
|
+
// src/invite-commands.ts
|
|
1083
|
+
function mt(e, t, n) {
|
|
1084
|
+
let r = ut(t.io, n), i = e.command("invite").description("Email invitations to an organization (your own account's session, not a key).");
|
|
1085
|
+
X(i.command("create").description(J("Invite someone by email (owner or admin). Needs invitation enrollment and SMTP on the controller (else 404 \"Invitations are not enabled.\"); if the mail cannot be sent the controller answers 502 and has already revoked the invitation. The token is emailed and never shown.", "POST /organizations/:org/invitations")).requiredOption("--to <address>", "the address to invite").requiredOption("--role <role>", `their role (${D.join(", ")})`), {
|
|
1086
|
+
org: !0,
|
|
1087
|
+
write: !0
|
|
1088
|
+
}).action(async (e, n) => {
|
|
1089
|
+
let i = "", a = "viewer";
|
|
1090
|
+
await Z(t, n, {
|
|
1091
|
+
write: !0,
|
|
1092
|
+
org: !0,
|
|
1093
|
+
needsFresh: !1,
|
|
1094
|
+
validate: () => {
|
|
1095
|
+
i = G(e.to, "--to"), a = dt(e.role);
|
|
1096
|
+
}
|
|
1097
|
+
}, e, async ({ client: e, organization: t }) => {
|
|
1098
|
+
let o = await e.use("POST", "/invitations", (e, n) => e.invitations.create(t, {
|
|
1099
|
+
email: i,
|
|
1100
|
+
role: a
|
|
1101
|
+
}, { signal: n })), s = {
|
|
1102
|
+
id: o.id,
|
|
1103
|
+
email: o.email,
|
|
1104
|
+
role: o.role
|
|
1105
|
+
};
|
|
1106
|
+
r(n, s, () => `Invited ${s.email} as ${s.role} (${s.id}). The invitation was emailed.`);
|
|
1107
|
+
});
|
|
1108
|
+
}), X(i.command("list").description(J("List the organization's pending invitations (owner or admin).", "GET /organizations/:org/invitations")), {
|
|
1109
|
+
org: !0,
|
|
1110
|
+
write: !1
|
|
1111
|
+
}).action(async (e, n) => {
|
|
1112
|
+
await Z(t, n, {
|
|
1113
|
+
write: !1,
|
|
1114
|
+
org: !0,
|
|
1115
|
+
needsFresh: !1
|
|
1116
|
+
}, e, async ({ client: e, organization: t }) => {
|
|
1117
|
+
let i = (await e.use("GET", "/invitations", (e, n) => e.invitations.list(t, { signal: n }))).map((e) => ({
|
|
1118
|
+
id: e.id,
|
|
1119
|
+
email: e.email,
|
|
1120
|
+
role: e.role,
|
|
1121
|
+
createdAt: e.createdAt,
|
|
1122
|
+
expiresAt: e.expiresAt
|
|
1123
|
+
}));
|
|
1124
|
+
r(n, i, () => i.length === 0 ? "No invitations." : Q([[
|
|
1125
|
+
"ID",
|
|
1126
|
+
"EMAIL",
|
|
1127
|
+
"ROLE",
|
|
1128
|
+
"CREATED",
|
|
1129
|
+
"EXPIRES"
|
|
1130
|
+
], ...i.map((e) => [
|
|
1131
|
+
e.id,
|
|
1132
|
+
e.email,
|
|
1133
|
+
e.role,
|
|
1134
|
+
e.createdAt,
|
|
1135
|
+
e.expiresAt
|
|
1136
|
+
])]));
|
|
1137
|
+
});
|
|
1138
|
+
}), X(i.command("revoke").description(J("Revoke a pending invitation (owner or admin).", "DELETE /organizations/:org/invitations/:id")).argument("<invitation-id>", "the invitation's ID, as `invite list` prints it"), {
|
|
1139
|
+
org: !0,
|
|
1140
|
+
write: !0
|
|
1141
|
+
}).action(async (e, n, i) => {
|
|
1142
|
+
await Z(t, i, {
|
|
1143
|
+
write: !0,
|
|
1144
|
+
org: !0,
|
|
1145
|
+
needsFresh: !1,
|
|
1146
|
+
validate: () => void lt(e, "invitation-id", !0)
|
|
1147
|
+
}, n, async ({ client: t, organization: n }) => {
|
|
1148
|
+
let a = await t.use("DELETE", "/invitations/:id", (t, r) => t.invitations.revoke(n, e, { signal: r }));
|
|
1149
|
+
r(i, a, () => `Revoked invitation ${e}.`);
|
|
1150
|
+
});
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
// src/key-commands.ts
|
|
1154
|
+
var $ = (e) => new a("bad-input", e), ht = "The key may exist: run \"launchpad key list\" and revoke it.";
|
|
1155
|
+
function gt(e, t) {
|
|
1156
|
+
return e instanceof C ? new C({
|
|
1157
|
+
status: e.status,
|
|
1158
|
+
code: e.code,
|
|
1159
|
+
title: `${e.title} ${ht}`,
|
|
1160
|
+
retryAfterSeconds: e.retryAfterSeconds ?? void 0
|
|
1161
|
+
}) : e instanceof T ? new T(e.reason, `${e.message} ${ht}`) : (t.err(ht), e);
|
|
1162
|
+
}
|
|
1163
|
+
var _t = (e) => e instanceof C && e.status >= 400 && e.status < 500 && e.status !== 408 && e.status !== 429;
|
|
1164
|
+
function vt(e, t, n) {
|
|
1165
|
+
let { io: r, remember: i } = t, o = ut(r, n), s = e.command("key").description("API keys of an organization (your own account's session, not a key).");
|
|
1166
|
+
X(s.command("list").description(J("List the organization's API keys, never their secrets.", "GET /organizations/:org/api-keys")), {
|
|
1167
|
+
org: !0,
|
|
1168
|
+
write: !1
|
|
1169
|
+
}).action(async (e, n) => {
|
|
1170
|
+
await Z(t, n, {
|
|
1171
|
+
write: !1,
|
|
1172
|
+
org: !0,
|
|
1173
|
+
needsFresh: !1
|
|
1174
|
+
}, e, async ({ client: e, organization: t }) => {
|
|
1175
|
+
let r = await e.use("GET", "/api-keys", (e, n) => e.apiKeys.list(t, { signal: n }));
|
|
1176
|
+
o(n, r, () => r.length === 0 ? "No API keys." : Q([[
|
|
1177
|
+
"ID",
|
|
1178
|
+
"NAME",
|
|
1179
|
+
"PREFIX",
|
|
1180
|
+
"STATUS",
|
|
1181
|
+
"SCOPES",
|
|
1182
|
+
"PROJECTS",
|
|
1183
|
+
"EXPIRES",
|
|
1184
|
+
"LAST USED"
|
|
1185
|
+
], ...r.map((e) => [
|
|
1186
|
+
e.id,
|
|
1187
|
+
e.name,
|
|
1188
|
+
e.prefix,
|
|
1189
|
+
e.status,
|
|
1190
|
+
e.scopes.join(","),
|
|
1191
|
+
e.projectIds ? e.projectIds.join(",") : "all",
|
|
1192
|
+
e.expiresAt,
|
|
1193
|
+
e.lastUsedAt ?? "never"
|
|
1194
|
+
])]));
|
|
1195
|
+
});
|
|
1196
|
+
}), X(s.command("issue").description(J("Issue an API key and write its secret to a new file; the screen never shows it.", "POST /organizations/:org/api-keys", "Needs an owner or admin signed in within the last 15 minutes. If the request fails without a clear answer the key may exist: run `launchpad key list` and revoke it. ")).requiredOption("--name <name>", "the key's name").option("--scope <scope>", `a scope to grant (repeatable; one of ${S.join(", ")})`, ft, []).option("--project <id>", "limit the key to this project (repeatable; not with project:create)", ft, []).requiredOption("--expires-in-days <n>", `lifetime in days, 1 to ${E}`).requiredOption("--secret-file <path>", "create this new file (mode 0600) before the request and write the secret to it"), {
|
|
1197
|
+
org: !0,
|
|
1198
|
+
write: !0
|
|
1199
|
+
}).action(async (e, n) => {
|
|
1200
|
+
let s = [], c = 0;
|
|
1201
|
+
await Z(t, n, {
|
|
1202
|
+
write: !0,
|
|
1203
|
+
org: !0,
|
|
1204
|
+
needsFresh: !0,
|
|
1205
|
+
secretFile: e.secretFile,
|
|
1206
|
+
validate: () => {
|
|
1207
|
+
if (e.name.trim().length === 0) throw $("--name must not be empty.");
|
|
1208
|
+
if (e.scope.length === 0) throw $(`Give at least one --scope (${S.join(", ")}).`);
|
|
1209
|
+
for (let t of e.scope) if (!S.includes(t)) throw $(`--scope must be one of ${S.join(", ")}.`);
|
|
1210
|
+
if (s = e.scope, !/^\d{1,4}$/.test(e.expiresInDays) || (c = Number(e.expiresInDays), c < 1 || c > E)) throw $(`--expires-in-days must be a whole number from 1 to ${E}.`);
|
|
1211
|
+
for (let t of e.project) if (!Y(t)) throw $("--project must be a project ID (a UUID).");
|
|
1212
|
+
if (e.project.length > 0 && s.includes("project:create")) throw $("A project-limited API key cannot create projects.");
|
|
1213
|
+
}
|
|
1214
|
+
}, e, async ({ client: t, organization: l, secretFile: u }) => {
|
|
1215
|
+
let d = !1, f = !1;
|
|
1216
|
+
try {
|
|
1217
|
+
let r = await t.use("POST", "/api-keys", (t, n) => (d = !0, t.apiKeys.issue(l, {
|
|
1218
|
+
name: e.name,
|
|
1219
|
+
scopes: s,
|
|
1220
|
+
...e.project.length > 0 ? { projectIds: e.project } : {},
|
|
1221
|
+
expiresInDays: c
|
|
1222
|
+
}, {
|
|
1223
|
+
signal: n,
|
|
1224
|
+
onSecret: async (t) => {
|
|
1225
|
+
t.startsWith("lp_") || i(t), f = !0;
|
|
1226
|
+
try {
|
|
1227
|
+
await u.write(`${t}\n`);
|
|
1228
|
+
} catch {
|
|
1229
|
+
throw new a("store-unavailable", `The key was created but could not be written to ${e.secretFile}. It exists: run "launchpad key list" and revoke it.`);
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
})));
|
|
1233
|
+
if (!f) throw new T("invalid-response", "The controller's answer had no secret.");
|
|
1234
|
+
o(n, {
|
|
1235
|
+
...r,
|
|
1236
|
+
secret: `[written to ${e.secretFile}]`
|
|
1237
|
+
}, () => `Issued key ${r.name} (${r.id}), expires ${r.expiresAt}. The secret is in ${e.secretFile}.`);
|
|
1238
|
+
} catch (t) {
|
|
1239
|
+
throw !d || t instanceof w ? t : f ? (t instanceof a || r.err(`Warning: the key was issued and its secret is in ${e.secretFile}, but the controller's answer could not be read. Run "launchpad key list" to see it.`), t) : _t(t) || t instanceof a && t.code === "not-logged-in" ? t : gt(t, r);
|
|
1240
|
+
}
|
|
1241
|
+
});
|
|
1242
|
+
}), X(s.command("revoke").description(J("Revoke an API key (revoking it again is fine).", "DELETE /organizations/:org/api-keys/:id")).argument("<key-id>", "the key's ID, as `key list` prints it"), {
|
|
1243
|
+
org: !0,
|
|
1244
|
+
write: !0
|
|
1245
|
+
}).action(async (e, n, r) => {
|
|
1246
|
+
await Z(t, r, {
|
|
1247
|
+
write: !0,
|
|
1248
|
+
org: !0,
|
|
1249
|
+
needsFresh: !1,
|
|
1250
|
+
validate: () => void lt(e, "key-id", !0)
|
|
1251
|
+
}, n, async ({ client: t, organization: n }) => {
|
|
1252
|
+
let i = await t.use("DELETE", "/api-keys/:id", (t, r) => t.apiKeys.revoke(n, e, { signal: r }));
|
|
1253
|
+
o(r, i, () => `Revoked key ${e}.`);
|
|
1254
|
+
});
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
// src/org-commands.ts
|
|
1258
|
+
var yt = (e) => new a("bad-input", e);
|
|
1259
|
+
function bt(e, t, n, r) {
|
|
1260
|
+
let { io: i } = n, a = ut(i, r);
|
|
1261
|
+
X(t.command("create").description(J("Create an organization with an existing user as its first owner (the instance operator only; the operator gets no membership).", "POST /organizations")).requiredOption("--name <name>", "the organization's name").requiredOption("--slug <slug>", "the organization's slug").requiredOption("--owner-email <address>", "the existing user who becomes the owner"), {
|
|
1262
|
+
org: !1,
|
|
1263
|
+
write: !0
|
|
1264
|
+
}).action(async (e, t) => {
|
|
1265
|
+
let r = "";
|
|
1266
|
+
await Z(n, t, {
|
|
1267
|
+
write: !0,
|
|
1268
|
+
org: !1,
|
|
1269
|
+
needsFresh: !1,
|
|
1270
|
+
validate: () => {
|
|
1271
|
+
if (e.name.trim().length === 0) throw yt("--name must not be empty.");
|
|
1272
|
+
if (!de.safeParse(e.slug).success) throw yt("--slug must be a valid slug (lowercase letters, digits and hyphens).");
|
|
1273
|
+
r = G(e.ownerEmail, "--owner-email");
|
|
1274
|
+
}
|
|
1275
|
+
}, e, async ({ client: n }) => {
|
|
1276
|
+
let i = await n.use("POST", "/organizations", (t, n) => t.organizations.create({
|
|
1277
|
+
name: e.name,
|
|
1278
|
+
slug: e.slug,
|
|
1279
|
+
ownerEmail: r
|
|
1280
|
+
}, { signal: n }));
|
|
1281
|
+
a(t, i, () => `Created organization ${i.slug} (${i.id}) with owner ${r}.`);
|
|
1282
|
+
});
|
|
1283
|
+
});
|
|
1284
|
+
let o = e.command("member").description("Members of an organization (your own account's session, not a key).");
|
|
1285
|
+
X(o.command("list").description(J("List the organization's members; their user IDs are what `member remove` takes.", "GET /organizations/:org/members")), {
|
|
1286
|
+
org: !0,
|
|
1287
|
+
write: !1
|
|
1288
|
+
}).action(async (e, t) => {
|
|
1289
|
+
await Z(n, t, {
|
|
1290
|
+
write: !1,
|
|
1291
|
+
org: !0,
|
|
1292
|
+
needsFresh: !1
|
|
1293
|
+
}, e, async ({ client: e, organization: n }) => {
|
|
1294
|
+
let r = await e.use("GET", "/members", (e, t) => e.members.list(n, { signal: t }));
|
|
1295
|
+
a(t, r, () => r.length === 0 ? "No members." : Q([[
|
|
1296
|
+
"USER ID",
|
|
1297
|
+
"EMAIL",
|
|
1298
|
+
"NAME",
|
|
1299
|
+
"ROLE"
|
|
1300
|
+
], ...r.map((e) => [
|
|
1301
|
+
e.userId,
|
|
1302
|
+
e.email,
|
|
1303
|
+
e.name,
|
|
1304
|
+
e.role
|
|
1305
|
+
])]));
|
|
1306
|
+
});
|
|
1307
|
+
}), X(o.command("add").description(J("Add an existing user to the organization (owner or admin; an admin may assign only deployer and viewer, which the controller decides).", "POST /organizations/:org/members")).requiredOption("--user-email <address>", "the existing user to add").requiredOption("--role <role>", `their role (${D.join(", ")})`), {
|
|
1308
|
+
org: !0,
|
|
1309
|
+
write: !0
|
|
1310
|
+
}).action(async (e, t) => {
|
|
1311
|
+
let r = "", i = "viewer";
|
|
1312
|
+
await Z(n, t, {
|
|
1313
|
+
write: !0,
|
|
1314
|
+
org: !0,
|
|
1315
|
+
needsFresh: !1,
|
|
1316
|
+
validate: () => {
|
|
1317
|
+
r = G(e.userEmail, "--user-email"), i = dt(e.role);
|
|
1318
|
+
}
|
|
1319
|
+
}, e, async ({ client: e, organization: n }) => {
|
|
1320
|
+
let o = await e.use("POST", "/members", (e, t) => e.members.add(n, {
|
|
1321
|
+
email: r,
|
|
1322
|
+
role: i
|
|
1323
|
+
}, { signal: t }));
|
|
1324
|
+
a(t, o, () => `Added ${r} to ${n} as ${o.role}.`);
|
|
1325
|
+
});
|
|
1326
|
+
}), X(o.command("remove").description(J("Remove a member, or leave by removing yourself (owner or admin; the last owner cannot be removed).", "DELETE /organizations/:org/members/:userId")).argument("<user-id>", "the user ID, as `member list` prints it"), {
|
|
1327
|
+
org: !0,
|
|
1328
|
+
write: !0
|
|
1329
|
+
}).action(async (e, t, r) => {
|
|
1330
|
+
await Z(n, r, {
|
|
1331
|
+
write: !0,
|
|
1332
|
+
org: !0,
|
|
1333
|
+
needsFresh: !1,
|
|
1334
|
+
validate: () => void lt(e, "user-id", !1)
|
|
1335
|
+
}, t, async ({ client: t, organization: n }) => {
|
|
1336
|
+
let i = await t.use("DELETE", "/members/:userId", (t, r) => t.members.remove(n, e, { signal: r }));
|
|
1337
|
+
a(r, i, () => `Removed ${e} from ${n}.`);
|
|
1338
|
+
});
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
// src/session-commands.ts
|
|
1342
|
+
var xt = (e) => new a("bad-input", e);
|
|
1343
|
+
async function St(e, t, n) {
|
|
1344
|
+
if (He(e.context, "--session"), t.email === void 0) throw xt("--session needs --email <address> to sign in.");
|
|
1345
|
+
let r = G(t.email);
|
|
1346
|
+
await Be(e, async (i) => {
|
|
1347
|
+
let a = await Ue(e.context, {
|
|
1348
|
+
controller: t.controller,
|
|
1349
|
+
profile: t.profile
|
|
1350
|
+
}), o = new ze({
|
|
1351
|
+
io: e,
|
|
1352
|
+
controller: a.controller,
|
|
1353
|
+
email: r,
|
|
1354
|
+
passwordFile: t.passwordFile,
|
|
1355
|
+
keep: !0,
|
|
1356
|
+
remember: n
|
|
1357
|
+
});
|
|
1358
|
+
i.flow = o, await o.signIn(), e.out(t.json ? JSON.stringify({
|
|
1359
|
+
controller: a.controller,
|
|
1360
|
+
email: r
|
|
1361
|
+
}, null, 2) : `Signed in to ${a.controller} as ${r}.`);
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1364
|
+
async function Ct(e, t, n) {
|
|
1365
|
+
He(e.context, "--session");
|
|
1366
|
+
let r = await Ue(e.context, {
|
|
1367
|
+
controller: t.controller,
|
|
1368
|
+
profile: t.profile
|
|
1369
|
+
}), i = await e.context.sessions.get(r.controller);
|
|
1370
|
+
if (!i) {
|
|
1371
|
+
e.out(t.json ? JSON.stringify({
|
|
1372
|
+
controller: r.controller,
|
|
1373
|
+
signedOut: !1,
|
|
1374
|
+
localEntryRemoved: !1
|
|
1375
|
+
}, null, 2) : `No saved session for ${r.controller}.`);
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1378
|
+
n(i.cookie), n(i.cookie.slice(i.cookie.indexOf("=") + 1));
|
|
1379
|
+
let a = !0;
|
|
1380
|
+
try {
|
|
1381
|
+
await O({
|
|
1382
|
+
baseUrl: r.controller,
|
|
1383
|
+
cookie: i.cookie,
|
|
1384
|
+
fetch: e.context.fetch
|
|
1385
|
+
}).signOut();
|
|
1386
|
+
} catch (t) {
|
|
1387
|
+
t instanceof C && t.status === 401 || (a = !1, e.err(`Warning: could not sign out of ${r.controller} (${U(t).message}). The session ends on its own, at most 7 days after its last use.`));
|
|
1388
|
+
}
|
|
1389
|
+
await e.context.sessions.remove(r.controller, i.cookie), e.out(t.json ? JSON.stringify({
|
|
1390
|
+
controller: r.controller,
|
|
1391
|
+
email: i.email,
|
|
1392
|
+
signedOut: a,
|
|
1393
|
+
localEntryRemoved: !0
|
|
1394
|
+
}, null, 2) : a ? `Signed ${i.email} out of ${r.controller} and removed the saved session.` : `Removed the saved session for ${i.email} at ${r.controller}, but the controller did not confirm the sign-out: it may still accept the old cookie until it expires (at most 7 days after its last use).`);
|
|
1395
|
+
}
|
|
1396
|
+
// src/program.ts
|
|
1397
|
+
async function wt(e, t) {
|
|
1398
|
+
let n;
|
|
1399
|
+
if (t.keyFile) {
|
|
1400
|
+
let r = await e.readFile(t.keyFile);
|
|
1401
|
+
r.regular !== !1 && process.platform !== "win32" && r.mode & 63 && e.err(`Warning: ${t.keyFile} is readable by others; restrict it with chmod 600.`), n = r.text;
|
|
1402
|
+
} else if (t.keyStdin) {
|
|
1403
|
+
if (e.stdinIsTTY ?? e.interactive) throw new x(V.usage, "commander.interactiveStdin", "error: --key-stdin requires redirected input; omit it to use the hidden terminal prompt");
|
|
1404
|
+
n = await e.readStdin();
|
|
1405
|
+
} else if (e.interactive) n = await e.readSecret("API key: ");
|
|
1406
|
+
else throw new x(V.usage, "commander.missingKey", "error: provide the key with --key-file <path> or --key-stdin, or run in a terminal");
|
|
1407
|
+
let r = n.trim();
|
|
1408
|
+
if (!r) throw new x(V.usage, "commander.emptyKey", "error: the API key is empty");
|
|
1409
|
+
return r;
|
|
1410
|
+
}
|
|
1411
|
+
function Tt(e, t = /* @__PURE__ */ new Set()) {
|
|
1412
|
+
let n = () => [...t, ...e.context.secrets ?? []], r = {
|
|
1413
|
+
get workingDir() {
|
|
1414
|
+
return e.workingDir;
|
|
1415
|
+
},
|
|
1416
|
+
get context() {
|
|
1417
|
+
return e.context;
|
|
1418
|
+
},
|
|
1419
|
+
get interactive() {
|
|
1420
|
+
return e.interactive;
|
|
1421
|
+
},
|
|
1422
|
+
get stdinIsTTY() {
|
|
1423
|
+
return e.stdinIsTTY;
|
|
1424
|
+
},
|
|
1425
|
+
get signals() {
|
|
1426
|
+
return e.signals;
|
|
1427
|
+
},
|
|
1428
|
+
out: (t) => e.out(y(t, n())),
|
|
1429
|
+
err: (t) => e.err(y(t, n())),
|
|
1430
|
+
readStdin: () => e.readStdin(),
|
|
1431
|
+
readSecret: (t, n) => e.readSecret(t, n),
|
|
1432
|
+
readPasswordFile: (t) => e.readPasswordFile(t),
|
|
1433
|
+
createSecretFile: (t) => e.createSecretFile(t),
|
|
1434
|
+
readFile: (t) => e.readFile(t),
|
|
1435
|
+
readData: (t) => e.readData(t),
|
|
1436
|
+
findExecutable: e.findExecutable?.bind(e)
|
|
1437
|
+
}, i = (e) => void t.add(e), a = new ce().name("launchpad").description("Work with a Launchpad controller using an organization API key.").version("0.0.0-bootstrap.0").option("--json", "print machine-readable JSON").option("--profile <name>", "use this saved profile instead of the current one").showHelpAfterError(!1).configureOutput({
|
|
1438
|
+
writeOut: (e) => r.out(e.replace(/\n$/, "")),
|
|
1439
|
+
writeErr: () => {}
|
|
1440
|
+
}).exitOverride(), o = (e) => e.optsWithGlobals(), s = (e, t, n) => r.out(o(e).json ? JSON.stringify(t, null, 2) : n());
|
|
1441
|
+
a.command("login").description("Save an API key for a controller. The key is read from a file, stdin or the terminal, never an argument.").option("--controller <url>", "the controller's address, e.g. https://control.example.com").option("--key-file <path>", "read the key from this file").option("--key-stdin", "read the key from standard input").option("--session", "instead of a key, sign in with your own account and keep the session (session.json, owner-only) for `api --session`; it replaces a saved session for the controller").option("--email <address>", "with --session, the account's email address").option("--password-file <path>", "with --session, read the password from this private file").action(async (e, t) => {
|
|
1442
|
+
let { profile: n, json: a } = o(t);
|
|
1443
|
+
if (e.session) {
|
|
1444
|
+
if (e.keyFile !== void 0 || e.keyStdin) throw new x(V.usage, "commander.mixedLogin", "error: --session cannot be combined with --key-file or --key-stdin");
|
|
1445
|
+
return St(r, {
|
|
1446
|
+
...e,
|
|
1447
|
+
profile: n,
|
|
1448
|
+
json: a
|
|
1449
|
+
}, i);
|
|
1450
|
+
}
|
|
1451
|
+
for (let [t, n] of [["--email", e.email], ["--password-file", e.passwordFile]]) if (n !== void 0) throw new x(V.usage, "commander.needsSession", `error: ${t} needs --session`);
|
|
1452
|
+
if (e.controller === void 0) throw new x(V.usage, "commander.missingControllerOption", "error: required option '--controller <url>' not specified");
|
|
1453
|
+
let s = await wt(r, e), c = await m(r.context, {
|
|
1454
|
+
controller: e.controller,
|
|
1455
|
+
apiKey: s,
|
|
1456
|
+
profile: n
|
|
1457
|
+
}), l = {
|
|
1458
|
+
profile: c.profile,
|
|
1459
|
+
controller: c.controller,
|
|
1460
|
+
organizationId: c.key.organizationId,
|
|
1461
|
+
key: {
|
|
1462
|
+
id: c.key.id,
|
|
1463
|
+
name: c.key.name,
|
|
1464
|
+
expiresAt: c.key.expiresAt
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
r.out(a ? JSON.stringify(l, null, 2) : `Logged in as profile "${c.profile}" (key "${c.key.name}", expires ${c.key.expiresAt}).`);
|
|
1468
|
+
}), a.command("logout").description("Forget a saved profile, or with --session revoke and forget the saved session.").option("--session", "revoke and delete the session saved by `login --session` or `--keep`").option("--controller <url>", "with --session, the controller (else the selected profile's)").option("--email <address>", "accepted with --session and ignored").action(async (e, t) => {
|
|
1469
|
+
if (e.session) {
|
|
1470
|
+
let { profile: n, json: a } = o(t);
|
|
1471
|
+
return Ct(r, {
|
|
1472
|
+
controller: e.controller,
|
|
1473
|
+
profile: n,
|
|
1474
|
+
json: a
|
|
1475
|
+
}, i);
|
|
1476
|
+
}
|
|
1477
|
+
for (let [t, n] of [["--controller", e.controller], ["--email", e.email]]) if (n !== void 0) throw new x(V.usage, "commander.needsSession", `error: ${t} needs --session`);
|
|
1478
|
+
let n = await h(r.context, o(t).profile);
|
|
1479
|
+
s(t, n, () => `Logged out of profile "${n.profile}".`);
|
|
1480
|
+
}), a.command("whoami").description("Show the controller, organization and permissions of the current key.").action(async (e, t) => {
|
|
1481
|
+
let n = await se(r.context, o(t).profile);
|
|
1482
|
+
s(t, n, () => [
|
|
1483
|
+
`Controller: ${n.controller}`,
|
|
1484
|
+
`Profile: ${n.profile ?? "(environment)"}`,
|
|
1485
|
+
`Key: ${n.key.name}`,
|
|
1486
|
+
`Organization: ${n.key.organizationId}`,
|
|
1487
|
+
`Scopes: ${n.key.scopes.join(", ")}`,
|
|
1488
|
+
`Projects: ${n.key.projectIds ? n.key.projectIds.join(", ") : "all"}`,
|
|
1489
|
+
`Expires: ${n.key.expiresAt}`
|
|
1490
|
+
].join("\n"));
|
|
1491
|
+
});
|
|
1492
|
+
let c = a.command("profile").description("Saved profiles.");
|
|
1493
|
+
c.command("list").description("List saved profiles.").action(async (e, t) => {
|
|
1494
|
+
let n = await f(r.context);
|
|
1495
|
+
s(t, n, () => n.profiles.length === 0 ? "No profiles. Run: launchpad login" : Q([[
|
|
1496
|
+
"",
|
|
1497
|
+
"PROFILE",
|
|
1498
|
+
"CONTROLLER"
|
|
1499
|
+
], ...n.profiles.map((e) => [
|
|
1500
|
+
e.name === n.current ? "*" : "",
|
|
1501
|
+
e.name,
|
|
1502
|
+
e.controller
|
|
1503
|
+
])]));
|
|
1504
|
+
}), c.command("use").argument("<name>", "the profile to make current").description("Make a saved profile the current one.").action(async (e, t, n) => {
|
|
1505
|
+
let i = await oe(r.context, e);
|
|
1506
|
+
s(n, i, () => `Using profile "${i.profile}".`);
|
|
1507
|
+
});
|
|
1508
|
+
let l = a.command("org").description("Organizations: `list` and `use` need a key, `create` your own account's session.");
|
|
1509
|
+
return l.command("list").description("List organizations the key can see.").action(async (e, t) => {
|
|
1510
|
+
let n = await d(r.context, o(t).profile);
|
|
1511
|
+
s(t, n, () => Q([[
|
|
1512
|
+
"ID",
|
|
1513
|
+
"SLUG",
|
|
1514
|
+
"NAME"
|
|
1515
|
+
], ...n.map((e) => [
|
|
1516
|
+
e.id,
|
|
1517
|
+
e.slug,
|
|
1518
|
+
e.name
|
|
1519
|
+
])]));
|
|
1520
|
+
}), l.command("use").argument("<organization>", "slug or id").description("Select the organization for later commands.").action(async (e, t, n) => {
|
|
1521
|
+
let i = await ae(r.context, e, o(n).profile);
|
|
1522
|
+
s(n, i, () => `Using organization ${i.organization.slug}.`);
|
|
1523
|
+
}), a.command("projects").description("Projects of the selected organization.").command("list").description("List projects the key can see.").action(async (e, t) => {
|
|
1524
|
+
let n = await p(r.context, o(t).profile);
|
|
1525
|
+
s(t, n, () => n.length === 0 ? "No projects." : Q([[
|
|
1526
|
+
"ID",
|
|
1527
|
+
"SLUG",
|
|
1528
|
+
"NAME"
|
|
1529
|
+
], ...n.map((e) => [
|
|
1530
|
+
e.id,
|
|
1531
|
+
e.slug,
|
|
1532
|
+
e.name
|
|
1533
|
+
])]));
|
|
1534
|
+
}), at(a, r, i), bt(a, l, {
|
|
1535
|
+
io: r,
|
|
1536
|
+
remember: i
|
|
1537
|
+
}, o), mt(a, {
|
|
1538
|
+
io: r,
|
|
1539
|
+
remember: i
|
|
1540
|
+
}, o), vt(a, {
|
|
1541
|
+
io: r,
|
|
1542
|
+
remember: i
|
|
1543
|
+
}, o), ot(a, r.context, r.workingDir ?? process.cwd(), r.out), a;
|
|
1544
|
+
}
|
|
1545
|
+
async function Et(e, t) {
|
|
1546
|
+
let n = /* @__PURE__ */ new Set(), r = Tt(t, n);
|
|
1547
|
+
try {
|
|
1548
|
+
return await r.parseAsync(e, { from: "user" }), V.ok;
|
|
1549
|
+
} catch (r) {
|
|
1550
|
+
if (r instanceof x && r.exitCode === 0) return V.ok;
|
|
1551
|
+
if (r instanceof H) return r.exitCode;
|
|
1552
|
+
let i = U(r), a = e.includes("--json");
|
|
1553
|
+
return t.err(y(a ? JSON.stringify({ error: {
|
|
1554
|
+
code: i.code,
|
|
1555
|
+
message: i.message,
|
|
1556
|
+
...i.status ? { status: i.status } : {}
|
|
1557
|
+
} }) : `Error: ${i.message}`, [...n, ...t.context.secrets ?? []])), i.exitCode;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
// src/index.ts
|
|
1561
|
+
process.exitCode = await Et(process.argv.slice(2), ve());
|