@launchpad-kit/cli 0.0.0-bootstrap.0 → 0.1.0-rc.1
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/cli.mjs +302 -267
- package/package.json +3 -3
package/cli.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { accessSync as e, constants as t, promises as n, statSync as r } from "node:fs";
|
|
3
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
|
|
5
|
-
import { Command as
|
|
6
|
-
import { API_KEY_SCOPES as
|
|
7
|
-
import { spawn as
|
|
8
|
-
import { checkScript as
|
|
9
|
-
import { lstat as
|
|
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 _, readWorkspace as ne, redact as v, requireConfirmation as y, resolve as re, safeOutput as b, useOrganization as ie, useProfile as ae, whoami as oe, workspaceContext as x } from "@launchpad-kit/client-core";
|
|
5
|
+
import { Command as se, CommanderError as S } from "@commander-js/extra-typings";
|
|
6
|
+
import { API_KEY_SCOPES as C, FORBIDDEN_RAW_HEADERS as ce, LaunchpadApiError as w, LaunchpadConfigError as T, LaunchpadTransportError as E, MAX_KEY_LIFETIME_DAYS as D, ORGANIZATION_ROLES as O, RAW_METHODS as le, createSessionClient as k, normalizeBaseUrl as A, slugSchema as ue } from "@launchpad-kit/sdk";
|
|
7
|
+
import { spawn as j } from "node:child_process";
|
|
8
|
+
import { checkScript as M, executeScript as N } from "@elastic/micro-jq";
|
|
9
|
+
import { lstat as de, realpath as P } from "node:fs/promises";
|
|
10
10
|
// src/io.ts
|
|
11
|
-
var
|
|
12
|
-
async function
|
|
13
|
-
return Buffer.from(await
|
|
11
|
+
var F = 4096, I = 1048576;
|
|
12
|
+
async function fe(e, t = F, n = "Input is too long to be a key.") {
|
|
13
|
+
return Buffer.from(await L(e, t, n)).toString("utf8");
|
|
14
14
|
}
|
|
15
|
-
async function
|
|
15
|
+
async function L(e, t, n) {
|
|
16
16
|
let r = [], i = 0;
|
|
17
17
|
for await (let a of e) {
|
|
18
18
|
if (i += a.byteLength, i > t) throw Error(n);
|
|
@@ -20,10 +20,10 @@ async function I(e, t, n) {
|
|
|
20
20
|
}
|
|
21
21
|
return Buffer.concat(r);
|
|
22
22
|
}
|
|
23
|
-
async function
|
|
24
|
-
return
|
|
23
|
+
async function R() {
|
|
24
|
+
return fe(process.stdin);
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function pe({ stdin: e, stderr: t }, n, r = {}) {
|
|
27
27
|
let i = `Input is too long to be a ${r.kind ?? "key"}.`;
|
|
28
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
29
|
let o = "", s = !1, c = (n) => {
|
|
@@ -32,17 +32,17 @@ function me({ stdin: e, stderr: t }, n, r = {}) {
|
|
|
32
32
|
for (let t of e) {
|
|
33
33
|
if (t === "\r" || t === "\n") return c(() => n(o));
|
|
34
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") >
|
|
35
|
+
if (t === "" || t === "\b" ? o = o.slice(0, -1) : o += t, Buffer.byteLength(o, "utf8") > F) return c(() => a(Error(i)));
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
r.signal?.addEventListener("abort", l, { once: !0 }), e.on("data", u);
|
|
39
39
|
}));
|
|
40
40
|
}
|
|
41
|
-
var
|
|
41
|
+
var me = (e, t) => pe({
|
|
42
42
|
stdin: process.stdin,
|
|
43
43
|
stderr: process.stderr
|
|
44
44
|
}, e, t);
|
|
45
|
-
async function
|
|
45
|
+
async function he(e) {
|
|
46
46
|
let t;
|
|
47
47
|
try {
|
|
48
48
|
t = await n.open(e, "wx", 384);
|
|
@@ -68,42 +68,42 @@ async function ge(e) {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
var
|
|
72
|
-
async function
|
|
71
|
+
var z = (e) => /* @__PURE__ */ Error(`The password file ${e}.`);
|
|
72
|
+
async function B(e) {
|
|
73
73
|
let r;
|
|
74
74
|
try {
|
|
75
75
|
r = await n.open(e, t.O_RDONLY | (t.O_NOFOLLOW ?? 0) | (t.O_NONBLOCK ?? 0));
|
|
76
76
|
} catch (e) {
|
|
77
77
|
let t = e.code;
|
|
78
|
-
throw
|
|
78
|
+
throw z(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
79
|
}
|
|
80
80
|
try {
|
|
81
81
|
let e = await r.stat();
|
|
82
|
-
if (!e.isFile()) throw
|
|
82
|
+
if (!e.isFile()) throw z("is not a regular file");
|
|
83
83
|
if (process.platform !== "win32") {
|
|
84
84
|
let t = process.getuid?.();
|
|
85
|
-
if (t !== void 0 && e.uid !== t) throw
|
|
86
|
-
if (e.mode & 63) throw
|
|
85
|
+
if (t !== void 0 && e.uid !== t) throw z("is owned by another user");
|
|
86
|
+
if (e.mode & 63) throw z("is readable by others; restrict it with chmod 600");
|
|
87
87
|
}
|
|
88
|
-
if (e.size >
|
|
88
|
+
if (e.size > F) throw z("is too long to be a password");
|
|
89
89
|
let t;
|
|
90
90
|
try {
|
|
91
|
-
let e = await
|
|
91
|
+
let e = await L(r.createReadStream({
|
|
92
92
|
autoClose: !1,
|
|
93
93
|
highWaterMark: 4097
|
|
94
|
-
}),
|
|
94
|
+
}), F, "The password file is too long to be a password.");
|
|
95
95
|
t = new TextDecoder("utf-8", { fatal: !0 }).decode(e);
|
|
96
96
|
} catch (e) {
|
|
97
|
-
throw e instanceof Error && /too long/.test(e.message) ? e : e instanceof TypeError ?
|
|
97
|
+
throw e instanceof Error && /too long/.test(e.message) ? e : e instanceof TypeError ? z("is not valid UTF-8 text") : z("cannot be read");
|
|
98
98
|
}
|
|
99
99
|
return t.endsWith("\r\n") ? t.slice(0, -2) : t.endsWith("\n") ? t.slice(0, -1) : t;
|
|
100
100
|
} finally {
|
|
101
101
|
await r.close();
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
async function
|
|
104
|
+
async function ge(e, r) {
|
|
105
105
|
let a = "The data is larger than 1 MiB.";
|
|
106
|
-
if (e === "-") return
|
|
106
|
+
if (e === "-") return L(process.stdin, I, a);
|
|
107
107
|
let o = await n.realpath(e);
|
|
108
108
|
if (process.platform === "linux" && /^\/(?:proc|sys)(?:\/|$)/.test(o)) throw Error("Files under /proc and /sys are not sent.");
|
|
109
109
|
let s = await n.realpath(r).catch(() => i.resolve(r)), c = i.relative(s, o);
|
|
@@ -113,20 +113,20 @@ async function _e(e, r) {
|
|
|
113
113
|
try {
|
|
114
114
|
let e = await l.stat();
|
|
115
115
|
if (!e.isFile()) throw Error("The data source is not a regular file.");
|
|
116
|
-
if (e.size >
|
|
117
|
-
return await
|
|
116
|
+
if (e.size > I) throw Error(a);
|
|
117
|
+
return await L(l.createReadStream({
|
|
118
118
|
autoClose: !1,
|
|
119
119
|
highWaterMark: 65536
|
|
120
|
-
}),
|
|
120
|
+
}), I, a);
|
|
121
121
|
} finally {
|
|
122
122
|
await l.close();
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function _e(e = process.env) {
|
|
126
126
|
let t = l(e);
|
|
127
127
|
return {
|
|
128
128
|
context: t,
|
|
129
|
-
readData: (e) =>
|
|
129
|
+
readData: (e) => ge(e, t.store.directory),
|
|
130
130
|
signals: {
|
|
131
131
|
on: (e, t) => void process.on(e, t),
|
|
132
132
|
off: (e, t) => void process.off(e, t),
|
|
@@ -137,17 +137,17 @@ function ve(e = process.env) {
|
|
|
137
137
|
err: (e) => void process.stderr.write(e + "\n"),
|
|
138
138
|
interactive: !!(process.stdin.isTTY && process.stderr.isTTY),
|
|
139
139
|
stdinIsTTY: !!process.stdin.isTTY,
|
|
140
|
-
readSecret:
|
|
141
|
-
readPasswordFile:
|
|
142
|
-
createSecretFile:
|
|
143
|
-
readStdin:
|
|
140
|
+
readSecret: me,
|
|
141
|
+
readPasswordFile: B,
|
|
142
|
+
createSecretFile: he,
|
|
143
|
+
readStdin: R,
|
|
144
144
|
readFile: async (e) => {
|
|
145
145
|
let t = await n.open(e, "r");
|
|
146
146
|
try {
|
|
147
147
|
let e = await t.stat();
|
|
148
|
-
if (e.size >
|
|
148
|
+
if (e.size > F) throw Error("File is too large to be a key.");
|
|
149
149
|
return {
|
|
150
|
-
text: await
|
|
150
|
+
text: await fe(t.createReadStream({
|
|
151
151
|
autoClose: !1,
|
|
152
152
|
highWaterMark: 4097
|
|
153
153
|
})),
|
|
@@ -160,8 +160,43 @@ function ve(e = process.env) {
|
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
var ve = {
|
|
164
|
+
name: "@launchpad-kit/cli",
|
|
165
|
+
version: "0.1.0-rc.1",
|
|
166
|
+
private: !0,
|
|
167
|
+
description: "The launchpad command-line client",
|
|
168
|
+
homepage: "https://github.com/launchpad-kit/launchpad#readme",
|
|
169
|
+
bugs: { url: "https://github.com/launchpad-kit/launchpad/issues" },
|
|
170
|
+
license: "Apache-2.0",
|
|
171
|
+
repository: {
|
|
172
|
+
type: "git",
|
|
173
|
+
url: "git+https://github.com/launchpad-kit/launchpad.git",
|
|
174
|
+
directory: "apps/cli"
|
|
175
|
+
},
|
|
176
|
+
bin: { launchpad: "./dist/cli.mjs" },
|
|
177
|
+
type: "module",
|
|
178
|
+
scripts: {
|
|
179
|
+
build: "vite build",
|
|
180
|
+
"check:types": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.node.json",
|
|
181
|
+
"test:unit": "bun --bun vitest run --config vitest.config.unit.ts"
|
|
182
|
+
},
|
|
183
|
+
dependencies: {
|
|
184
|
+
"@commander-js/extra-typings": "catalog:",
|
|
185
|
+
"@elastic/micro-jq": "catalog:",
|
|
186
|
+
"@launchpad-kit/client-core": "workspace:^",
|
|
187
|
+
"@launchpad-kit/sdk": "workspace:^",
|
|
188
|
+
commander: "catalog:"
|
|
189
|
+
},
|
|
190
|
+
devDependencies: {
|
|
191
|
+
"@launchpad-kit/tsconfig": "workspace:^",
|
|
192
|
+
"@launchpad-kit/vite-config": "workspace:^",
|
|
193
|
+
"@launchpad-kit/vitest-config": "workspace:^",
|
|
194
|
+
"@types/node": "catalog:",
|
|
195
|
+
typescript: "catalog:",
|
|
196
|
+
vite: "catalog:",
|
|
197
|
+
vitest: "catalog:"
|
|
198
|
+
}
|
|
199
|
+
}, ye = {
|
|
165
200
|
timeoutMs: 1e4,
|
|
166
201
|
maxOutputBytes: 8388608
|
|
167
202
|
}, be = 4096, xe = 4096, Se = (e, t = process.platform) => t === "win32" ? [e, `${e}.exe`] : [e];
|
|
@@ -177,10 +212,10 @@ function Ce(n, a, o = process.platform) {
|
|
|
177
212
|
}
|
|
178
213
|
return null;
|
|
179
214
|
}
|
|
180
|
-
var we = (e) => e.startsWith("-") ? ` ${e}` : e,
|
|
215
|
+
var we = (e) => e.startsWith("-") ? ` ${e}` : e, V = (e) => new a("bad-input", e);
|
|
181
216
|
function Te(e, t, n, r = [0], i = ye) {
|
|
182
217
|
return new Promise((a, o) => {
|
|
183
|
-
let s =
|
|
218
|
+
let s = j(e, t, {
|
|
184
219
|
env: {},
|
|
185
220
|
stdio: [
|
|
186
221
|
"pipe",
|
|
@@ -190,28 +225,28 @@ function Te(e, t, n, r = [0], i = ye) {
|
|
|
190
225
|
shell: !1
|
|
191
226
|
}), c = [], l = [], u = 0, d = 0, f, p = (e) => {
|
|
192
227
|
f ??= e, s.kill("SIGKILL"), s.stdout.destroy(), s.stderr.destroy(), clearTimeout(m), o(f);
|
|
193
|
-
}, m = setTimeout(() => p(
|
|
228
|
+
}, m = setTimeout(() => p(V("jq took too long and was stopped.")), i.timeoutMs);
|
|
194
229
|
s.stdout.on("data", (e) => {
|
|
195
|
-
u += e.length, u > i.maxOutputBytes ? p(
|
|
230
|
+
u += e.length, u > i.maxOutputBytes ? p(V("jq printed too much; stopped.")) : c.push(e);
|
|
196
231
|
}), s.stderr.on("data", (e) => {
|
|
197
232
|
d < be && l.push(e), d += e.length;
|
|
198
233
|
}), s.stdin.on("error", () => {}), s.on("error", () => {
|
|
199
|
-
clearTimeout(m), o(
|
|
234
|
+
clearTimeout(m), o(V("jq could not be run."));
|
|
200
235
|
}), s.on("close", (e) => {
|
|
201
236
|
if (clearTimeout(m), f) return o(f);
|
|
202
|
-
if (e === null || !r.includes(e)) return o(
|
|
237
|
+
if (e === null || !r.includes(e)) return o(V(`jq: ${Buffer.concat(l).toString("utf8").slice(0, be).trim() || `exited with ${e}`}`));
|
|
203
238
|
a(Buffer.concat(c).toString("utf8").replace(/\n$/, ""));
|
|
204
239
|
}), s.stdin.end(n);
|
|
205
240
|
});
|
|
206
241
|
}
|
|
207
242
|
var Ee = (e) => typeof e == "string" ? e : JSON.stringify(e, null, 2) ?? "null";
|
|
208
243
|
function De(e, t) {
|
|
209
|
-
if (!
|
|
244
|
+
if (!M(e)) throw V("The jq expression is not valid (or not supported).");
|
|
210
245
|
let n;
|
|
211
246
|
try {
|
|
212
|
-
n =
|
|
247
|
+
n = N(JSON.parse(t), e);
|
|
213
248
|
} catch (e) {
|
|
214
|
-
throw
|
|
249
|
+
throw V(`jq: ${e instanceof Error ? e.message.slice(0, 200) : "failed"}`);
|
|
215
250
|
}
|
|
216
251
|
return (Array.isArray(n) && !e.trimStart().startsWith("[") && /[\w\].)"]\[\]/.test(e) ? n : [n]).map(Ee).join("\n");
|
|
217
252
|
}
|
|
@@ -223,9 +258,9 @@ function Oe(e, t = Ce) {
|
|
|
223
258
|
} : { kind: "builtin" };
|
|
224
259
|
}
|
|
225
260
|
async function ke(e, t) {
|
|
226
|
-
if (t.length === 0 || t.length > xe) throw
|
|
261
|
+
if (t.length === 0 || t.length > xe) throw V("The jq expression must be 1 to 4096 characters.");
|
|
227
262
|
if (e.kind === "builtin") {
|
|
228
|
-
if (!
|
|
263
|
+
if (!M(t)) throw V("The jq expression is not valid (or not supported).");
|
|
229
264
|
} else await Te(e.file, [
|
|
230
265
|
"-n",
|
|
231
266
|
"-r",
|
|
@@ -237,11 +272,11 @@ async function ke(e, t) {
|
|
|
237
272
|
]);
|
|
238
273
|
}
|
|
239
274
|
async function Ae(e, t, n, r = ye) {
|
|
240
|
-
if (t.length === 0 || t.length > xe) throw
|
|
275
|
+
if (t.length === 0 || t.length > xe) throw V("The jq expression must be 1 to 4096 characters.");
|
|
241
276
|
try {
|
|
242
277
|
JSON.parse(n);
|
|
243
278
|
} catch {
|
|
244
|
-
throw
|
|
279
|
+
throw V("The response is not JSON, so --jq cannot be applied.");
|
|
245
280
|
}
|
|
246
281
|
return e.kind === "system" ? Te(e.file, ["-r", we(t)], n, [0], r) : De(t, n);
|
|
247
282
|
}
|
|
@@ -359,7 +394,7 @@ function Fe(e) {
|
|
|
359
394
|
return r(t, 0), n.join("");
|
|
360
395
|
}
|
|
361
396
|
// src/errors.ts
|
|
362
|
-
var
|
|
397
|
+
var H = {
|
|
363
398
|
ok: 0,
|
|
364
399
|
failure: 1,
|
|
365
400
|
usage: 2,
|
|
@@ -370,56 +405,56 @@ var V = {
|
|
|
370
405
|
deployment: 7,
|
|
371
406
|
waiting: 8,
|
|
372
407
|
interrupted: 130
|
|
373
|
-
},
|
|
408
|
+
}, U = class extends Error {
|
|
374
409
|
exitCode;
|
|
375
410
|
constructor(e) {
|
|
376
411
|
super(`exit ${e}`), this.exitCode = e, this.name = "ExitWith";
|
|
377
412
|
}
|
|
378
413
|
};
|
|
379
|
-
function
|
|
380
|
-
if (e instanceof
|
|
381
|
-
exitCode:
|
|
414
|
+
function W(e) {
|
|
415
|
+
if (e instanceof S) return {
|
|
416
|
+
exitCode: H.usage,
|
|
382
417
|
code: "usage",
|
|
383
|
-
message:
|
|
418
|
+
message: v(e.message.replace(/^error: /, ""))
|
|
384
419
|
};
|
|
385
|
-
if (e instanceof
|
|
386
|
-
let t = e.status === 401 || e.status === 403 ?
|
|
420
|
+
if (e instanceof w) {
|
|
421
|
+
let t = e.status === 401 || e.status === 403 ? H.unauthorized : e.status === 404 ? H.notFound : H.failure, n = e.status === 429 && e.retryAfterSeconds ? ` Try again in ${e.retryAfterSeconds} seconds.` : "";
|
|
387
422
|
return {
|
|
388
423
|
exitCode: t,
|
|
389
424
|
code: e.code,
|
|
390
|
-
message:
|
|
425
|
+
message: v(`${e.title}${n}`),
|
|
391
426
|
status: e.status
|
|
392
427
|
};
|
|
393
428
|
}
|
|
394
|
-
if (e instanceof
|
|
395
|
-
exitCode:
|
|
429
|
+
if (e instanceof E) return {
|
|
430
|
+
exitCode: H.transport,
|
|
396
431
|
code: e.reason,
|
|
397
|
-
message:
|
|
432
|
+
message: v(e.message)
|
|
398
433
|
};
|
|
399
|
-
if (e instanceof
|
|
400
|
-
exitCode:
|
|
434
|
+
if (e instanceof T) return {
|
|
435
|
+
exitCode: H.usage,
|
|
401
436
|
code: "bad-input",
|
|
402
|
-
message:
|
|
437
|
+
message: v(e.message)
|
|
403
438
|
};
|
|
404
439
|
if (e instanceof a) return {
|
|
405
|
-
exitCode: e.code === "not-logged-in" ?
|
|
440
|
+
exitCode: e.code === "not-logged-in" ? H.unauthorized : e.code === "bad-input" ? H.usage : H.local,
|
|
406
441
|
code: e.code,
|
|
407
|
-
message:
|
|
442
|
+
message: v(e.message)
|
|
408
443
|
};
|
|
409
444
|
let t = e instanceof Error ? e.message : String(e);
|
|
410
445
|
return {
|
|
411
|
-
exitCode:
|
|
446
|
+
exitCode: H.failure,
|
|
412
447
|
code: "failure",
|
|
413
|
-
message:
|
|
448
|
+
message: v(t)
|
|
414
449
|
};
|
|
415
450
|
}
|
|
416
|
-
var
|
|
451
|
+
var G = (e) => new a("bad-input", e);
|
|
417
452
|
async function Ie(e, t) {
|
|
418
453
|
let n;
|
|
419
454
|
if (t.passwordFile !== void 0) try {
|
|
420
455
|
n = await e.readPasswordFile(t.passwordFile);
|
|
421
456
|
} catch (e) {
|
|
422
|
-
throw
|
|
457
|
+
throw G(e instanceof Error ? e.message : "The password file cannot be read.");
|
|
423
458
|
}
|
|
424
459
|
else if (e.interactive) try {
|
|
425
460
|
n = await e.readSecret(t.prompt, {
|
|
@@ -427,11 +462,11 @@ async function Ie(e, t) {
|
|
|
427
462
|
signal: t.signal
|
|
428
463
|
});
|
|
429
464
|
} catch (e) {
|
|
430
|
-
throw e instanceof Error && e.message === "Cancelled." ? new H
|
|
465
|
+
throw e instanceof Error && e.message === "Cancelled." ? new U(H.interrupted) : e instanceof Error && /^Input is too long/.test(e.message) ? G(e.message) : e;
|
|
431
466
|
}
|
|
432
|
-
else throw
|
|
433
|
-
if (n.length === 0) throw
|
|
434
|
-
if (n.length < 12 || n.length > 128) throw
|
|
467
|
+
else throw G("There is no terminal to ask for the password: provide --password-file <path> or run in a terminal.");
|
|
468
|
+
if (n.length === 0) throw G("The password is empty.");
|
|
469
|
+
if (n.length < 12 || n.length > 128) throw G("The password must be 12 to 128 characters.");
|
|
435
470
|
return n;
|
|
436
471
|
}
|
|
437
472
|
// src/session-flow.ts
|
|
@@ -484,7 +519,7 @@ var Le = {
|
|
|
484
519
|
return this.guard.signal;
|
|
485
520
|
}
|
|
486
521
|
attach(e) {
|
|
487
|
-
let t =
|
|
522
|
+
let t = k({
|
|
488
523
|
baseUrl: this.options.controller,
|
|
489
524
|
cookie: e,
|
|
490
525
|
fetch: this.options.io.context.fetch
|
|
@@ -503,7 +538,7 @@ var Le = {
|
|
|
503
538
|
signal: this.guard.signal
|
|
504
539
|
});
|
|
505
540
|
this.options.remember(r);
|
|
506
|
-
let i =
|
|
541
|
+
let i = k({
|
|
507
542
|
baseUrl: t,
|
|
508
543
|
fetch: e.context.fetch
|
|
509
544
|
});
|
|
@@ -526,13 +561,13 @@ var Le = {
|
|
|
526
561
|
if (this.kept = !0, t.err("Session saved. It lasts until `launchpad logout --session`, or 7 days after its last use."), i) {
|
|
527
562
|
this.options.remember(i.cookie);
|
|
528
563
|
try {
|
|
529
|
-
await
|
|
564
|
+
await k({
|
|
530
565
|
baseUrl: n,
|
|
531
566
|
cookie: i.cookie,
|
|
532
567
|
fetch: t.context.fetch
|
|
533
568
|
}).signOut();
|
|
534
569
|
} catch (e) {
|
|
535
|
-
t.err(`Warning: could not sign the previous session out (${
|
|
570
|
+
t.err(`Warning: could not sign the previous session out (${W(e).message}). It ends on its own, at most 7 days after its last use.`);
|
|
536
571
|
}
|
|
537
572
|
}
|
|
538
573
|
}
|
|
@@ -545,7 +580,7 @@ var Le = {
|
|
|
545
580
|
try {
|
|
546
581
|
await n.signOut();
|
|
547
582
|
} catch (n) {
|
|
548
|
-
e.err(`Warning: could not sign out of ${t} (${
|
|
583
|
+
e.err(`Warning: could not sign out of ${t} (${W(n).message}). The session ends on its own, at most 7 days after its last use.`);
|
|
549
584
|
}
|
|
550
585
|
}
|
|
551
586
|
} finally {
|
|
@@ -558,16 +593,16 @@ async function Be(e, t) {
|
|
|
558
593
|
try {
|
|
559
594
|
await t(n);
|
|
560
595
|
} catch (t) {
|
|
561
|
-
throw await n.flow?.close(), n.flow?.interruptedWith == null ? t : (e.err("Interrupted."), new
|
|
596
|
+
throw await n.flow?.close(), n.flow?.interruptedWith == null ? t : (e.err("Interrupted."), new U(n.flow.interruptedWith));
|
|
562
597
|
}
|
|
563
|
-
if (await n.flow?.close(), n.flow?.interruptedWith != null) throw new
|
|
598
|
+
if (await n.flow?.close(), n.flow?.interruptedWith != null) throw new U(n.flow.interruptedWith);
|
|
564
599
|
}
|
|
565
600
|
// src/session-target.ts
|
|
566
601
|
var Ve = (e) => new a("bad-input", e);
|
|
567
602
|
function He(e, t) {
|
|
568
603
|
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
604
|
}
|
|
570
|
-
function
|
|
605
|
+
function K(e, t = "--email") {
|
|
571
606
|
let n = ee(e);
|
|
572
607
|
if (n.length > 254 || !/^[^\s@\p{Cc}]+@[^\s@\p{Cc}]+$/u.test(n)) throw Ve(`${t} must be an email address.`);
|
|
573
608
|
return n;
|
|
@@ -582,10 +617,10 @@ async function Ue(e, t) {
|
|
|
582
617
|
};
|
|
583
618
|
};
|
|
584
619
|
if (t.controller !== void 0) {
|
|
585
|
-
let e =
|
|
620
|
+
let e = A(t.controller), i = null;
|
|
586
621
|
if (t.profile) {
|
|
587
622
|
let n = await r(t.profile);
|
|
588
|
-
|
|
623
|
+
A(n.controller) === e && (i = n.organizationId);
|
|
589
624
|
}
|
|
590
625
|
return {
|
|
591
626
|
controller: e,
|
|
@@ -593,19 +628,19 @@ async function Ue(e, t) {
|
|
|
593
628
|
};
|
|
594
629
|
}
|
|
595
630
|
if (t.profile === void 0 && e.env.LAUNCHPAD_CONTROLLER) return {
|
|
596
|
-
controller:
|
|
631
|
+
controller: A(e.env.LAUNCHPAD_CONTROLLER),
|
|
597
632
|
organizationId: n
|
|
598
633
|
};
|
|
599
634
|
let i = await r(t.profile);
|
|
600
635
|
return {
|
|
601
|
-
controller:
|
|
636
|
+
controller: A(i.controller),
|
|
602
637
|
organizationId: n ?? i.organizationId
|
|
603
638
|
};
|
|
604
639
|
}
|
|
605
640
|
// src/session-run.ts
|
|
606
641
|
var We = 9e5, Ge = (e) => new a("bad-input", e);
|
|
607
642
|
async function Ke(e, t) {
|
|
608
|
-
let { io: n, guard: r } = e, i = e.email === void 0 ? null :
|
|
643
|
+
let { io: n, guard: r } = e, i = e.email === void 0 ? null : K(e.email), o = await Ue(n.context, {
|
|
609
644
|
controller: e.controller,
|
|
610
645
|
profile: e.profile
|
|
611
646
|
}), s = e.keep ? null : await n.context.sessions.get(o.controller);
|
|
@@ -631,7 +666,7 @@ async function Ke(e, t) {
|
|
|
631
666
|
try {
|
|
632
667
|
return await e();
|
|
633
668
|
} catch (e) {
|
|
634
|
-
throw s && e instanceof
|
|
669
|
+
throw s && e instanceof w && 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
670
|
}
|
|
636
671
|
};
|
|
637
672
|
return {
|
|
@@ -679,9 +714,9 @@ async function Je(e, t, n) {
|
|
|
679
714
|
if (await n({
|
|
680
715
|
guard: r,
|
|
681
716
|
secretFile: i
|
|
682
|
-
}), r?.interruptedWith != null) throw new
|
|
717
|
+
}), r?.interruptedWith != null) throw new U(r.interruptedWith);
|
|
683
718
|
} catch (t) {
|
|
684
|
-
throw await i?.remove().catch(() => {}), r?.interruptedWith == null ? t : (t instanceof
|
|
719
|
+
throw await i?.remove().catch(() => {}), r?.interruptedWith == null ? t : (t instanceof U || e.err("Interrupted."), new U(r.interruptedWith));
|
|
685
720
|
} finally {
|
|
686
721
|
r?.uninstall();
|
|
687
722
|
}
|
|
@@ -701,7 +736,7 @@ function $e(e, t) {
|
|
|
701
736
|
a.then(n, r).finally(() => t.removeEventListener("abort", i));
|
|
702
737
|
}) : e();
|
|
703
738
|
}
|
|
704
|
-
var et = (e, t) => e === "POST" && /^\/organizations\/[^/]+\/api-keys\/?$/.test(t), tt = /\{(org|project)\}/g,
|
|
739
|
+
var et = (e, t) => e === "POST" && /^\/organizations\/[^/]+\/api-keys\/?$/.test(t), tt = /\{(org|project)\}/g, q = (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
740
|
try {
|
|
706
741
|
return Fe(e);
|
|
707
742
|
} catch {
|
|
@@ -716,8 +751,8 @@ function at(e, t, n = () => {}) {
|
|
|
716
751
|
})).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
752
|
typed: !0,
|
|
718
753
|
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: ${[...
|
|
720
|
-
if (n.secretFile !== void 0 && n.paginate) throw
|
|
754
|
+
})).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: ${[...ce].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) => {
|
|
755
|
+
if (n.secretFile !== void 0 && n.paginate) throw q("--secret-file cannot be combined with --paginate.");
|
|
721
756
|
await Je(t, n.secretFile, ({ guard: i, secretFile: a }) => Be(t, (t) => o(e, n, r, t, a, i)));
|
|
722
757
|
});
|
|
723
758
|
async function o(e, o, s, l, d, f) {
|
|
@@ -730,24 +765,24 @@ function at(e, t, n = () => {}) {
|
|
|
730
765
|
["--password-file", o.passwordFile],
|
|
731
766
|
["--controller", o.controller],
|
|
732
767
|
["--keep", o.keep]
|
|
733
|
-
]) if (t !== void 0) throw
|
|
734
|
-
o.email !== void 0 &&
|
|
768
|
+
]) if (t !== void 0) throw q(`${e} needs --session.`);
|
|
769
|
+
o.email !== void 0 && K(o.email);
|
|
735
770
|
let h = (o.method ?? (r.length > 0 || o.input ? "POST" : "GET")).toUpperCase();
|
|
736
|
-
if (!
|
|
771
|
+
if (!le.has(h)) throw q("The method must be GET, HEAD, POST, PUT, PATCH or DELETE.");
|
|
737
772
|
let ee = h === "GET" || h === "HEAD";
|
|
738
|
-
if (ee ||
|
|
739
|
-
if (o.slurp && !o.paginate) throw
|
|
740
|
-
if (o.paginate && o.include) throw
|
|
741
|
-
if (e.includes("#")) throw
|
|
773
|
+
if (ee || y(o.confirm), o.paginate && h !== "GET") throw q("--paginate needs the GET method.");
|
|
774
|
+
if (o.slurp && !o.paginate) throw q("--slurp needs --paginate.");
|
|
775
|
+
if (o.paginate && o.include) throw q("--include cannot be combined with --paginate.");
|
|
776
|
+
if (e.includes("#")) throw q("The endpoint must not contain a fragment.");
|
|
742
777
|
let g = o.jq === void 0 ? void 0 : Oe(t.context.env.PATH, (e, n) => t.findExecutable?.(e) ?? Ce(e, n));
|
|
743
778
|
g && await ke(g, o.jq), g && o.verbose && t.err(`> jq: ${g.kind === "system" ? g.file : "built-in micro-jq subset"}`);
|
|
744
|
-
let
|
|
779
|
+
let _ = /* @__PURE__ */ new Set();
|
|
745
780
|
for (let t of [e, ...r.map((e) => ({
|
|
746
781
|
typed: e.typed,
|
|
747
782
|
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))
|
|
749
|
-
let
|
|
750
|
-
let e = await
|
|
783
|
+
})).filter((e) => !(e.typed && e.value.startsWith("@"))).map((e) => e.value)]) for (let e of t.matchAll(tt)) _.add(e[1]);
|
|
784
|
+
let v = t.workingDir ?? process.cwd(), b = await ne(v), ie, ae = () => ie ??= o.session ? oe() : (async () => {
|
|
785
|
+
let e = await re(t.context, m ?? b.config?.profile), n = c(t.context, e);
|
|
751
786
|
return {
|
|
752
787
|
controller: e.controller,
|
|
753
788
|
organizationId: e.organizationId,
|
|
@@ -756,13 +791,13 @@ function at(e, t, n = () => {}) {
|
|
|
756
791
|
raw: (e, t, r) => n.raw(e, t, r),
|
|
757
792
|
credentialLines: ["> authorization: [redacted]"]
|
|
758
793
|
};
|
|
759
|
-
})(),
|
|
794
|
+
})(), oe = async () => {
|
|
760
795
|
let e = await Ke({
|
|
761
796
|
io: t,
|
|
762
797
|
remember: n,
|
|
763
798
|
guard: f,
|
|
764
799
|
controller: o.controller,
|
|
765
|
-
profile: m ??
|
|
800
|
+
profile: m ?? b.config?.profile,
|
|
766
801
|
email: o.email,
|
|
767
802
|
passwordFile: o.passwordFile,
|
|
768
803
|
verbose: o.verbose,
|
|
@@ -774,73 +809,73 @@ function at(e, t, n = () => {}) {
|
|
|
774
809
|
organizationId: e.organizationId,
|
|
775
810
|
organizations: async () => {
|
|
776
811
|
let t = await e.caller.raw("GET", "/organizations", {}), n = JSON.parse(t.body);
|
|
777
|
-
if (!Array.isArray(n)) throw
|
|
812
|
+
if (!Array.isArray(n)) throw q("The organization list was not a list.");
|
|
778
813
|
return n.filter((e) => typeof e?.id == "string" && typeof e?.slug == "string");
|
|
779
814
|
},
|
|
780
815
|
ownOrganization: async () => {
|
|
781
|
-
throw
|
|
816
|
+
throw q("{org} has no value: with --session select an organization with `launchpad org use`, launchpad.json or LAUNCHPAD_ORG.");
|
|
782
817
|
},
|
|
783
818
|
raw: e.caller.raw,
|
|
784
819
|
credentialLines: ["> cookie: [redacted]", `> origin: ${new URL(e.controller).origin}`]
|
|
785
820
|
};
|
|
786
|
-
},
|
|
787
|
-
if (
|
|
788
|
-
let e = await
|
|
821
|
+
}, x = /* @__PURE__ */ new Map();
|
|
822
|
+
if (_.has("org")) {
|
|
823
|
+
let e = await ae(), t = b.config?.organization;
|
|
789
824
|
if (t) {
|
|
790
825
|
let n = (await e.organizations()).find((e) => e.id === t || e.slug === t);
|
|
791
826
|
if (!n) throw new a("no-organization", "This key cannot see the selected organization.");
|
|
792
|
-
|
|
793
|
-
} else
|
|
827
|
+
x.set("org", n.id);
|
|
828
|
+
} else x.set("org", e.organizationId ?? await e.ownOrganization());
|
|
794
829
|
}
|
|
795
|
-
if (
|
|
796
|
-
let e =
|
|
797
|
-
if (!e) throw
|
|
798
|
-
|
|
830
|
+
if (_.has("project")) {
|
|
831
|
+
let e = b.config?.project;
|
|
832
|
+
if (!e) throw q("{project} needs a launchpad.json with a project.");
|
|
833
|
+
x.set("project", e);
|
|
799
834
|
}
|
|
800
|
-
let
|
|
801
|
-
let r =
|
|
802
|
-
if (!r) throw
|
|
835
|
+
let se = (e, t) => e.replace(tt, (e, n) => {
|
|
836
|
+
let r = x.get(n);
|
|
837
|
+
if (!r) throw q(`{${n}} has no value here.`);
|
|
803
838
|
if (!t) return r;
|
|
804
|
-
if (r === "." || r === "..") throw
|
|
839
|
+
if (r === "." || r === "..") throw q(`{${n}} is not a valid path segment.`);
|
|
805
840
|
return encodeURIComponent(r);
|
|
806
|
-
}),
|
|
841
|
+
}), S = { value: !1 }, C = async (e) => {
|
|
807
842
|
if (e === "-") {
|
|
808
|
-
if (
|
|
809
|
-
|
|
843
|
+
if (S.value) throw q("Standard input can be read only once.");
|
|
844
|
+
S.value = !0;
|
|
810
845
|
}
|
|
811
846
|
try {
|
|
812
847
|
return await $e(() => t.readData(e), p);
|
|
813
848
|
} catch (t) {
|
|
814
849
|
let n = t instanceof Error ? t.message : "unreadable";
|
|
815
|
-
throw
|
|
850
|
+
throw q(e === "-" ? `Could not read standard input: ${n}` : `Could not read the data file: ${/ENOENT/.test(n) ? "not found" : n}`);
|
|
816
851
|
}
|
|
817
|
-
},
|
|
852
|
+
}, w = async (e) => {
|
|
818
853
|
try {
|
|
819
|
-
return new TextDecoder("utf-8", { fatal: !0 }).decode(await
|
|
854
|
+
return new TextDecoder("utf-8", { fatal: !0 }).decode(await C(e));
|
|
820
855
|
} catch (e) {
|
|
821
|
-
throw e instanceof a ? e :
|
|
856
|
+
throw e instanceof a ? e : q("A field value read from a file or stdin must be UTF-8 text.");
|
|
822
857
|
}
|
|
823
|
-
},
|
|
824
|
-
readFile:
|
|
825
|
-
readStdin: () =>
|
|
826
|
-
fill: (e) =>
|
|
827
|
-
}), [
|
|
858
|
+
}, T = await te(r, {
|
|
859
|
+
readFile: w,
|
|
860
|
+
readStdin: () => w("-"),
|
|
861
|
+
fill: (e) => se(e, !1)
|
|
862
|
+
}), [D = "", O = ""] = (() => {
|
|
828
863
|
let t = e.indexOf("?");
|
|
829
864
|
return t === -1 ? [e] : [e.slice(0, t), e.slice(t + 1)];
|
|
830
|
-
})(),
|
|
831
|
-
o.input === void 0 ? ee ?
|
|
832
|
-
let
|
|
865
|
+
})(), k = se(D, !0), ue = k.startsWith("/") ? k : `/${k}`, j = [...new URLSearchParams(O).entries()].map(([e, t]) => [e, se(t, !1)]), M;
|
|
866
|
+
o.input === void 0 ? ee ? j.push(...u(T)) : Object.keys(T).length > 0 && (M = JSON.stringify(T)) : (M = await C(o.input), j.push(...u(T)));
|
|
867
|
+
let N = {};
|
|
833
868
|
for (let e of i) {
|
|
834
869
|
let t = e.indexOf(":");
|
|
835
|
-
if (t < 1) throw
|
|
836
|
-
|
|
870
|
+
if (t < 1) throw q("A header is written name:value.");
|
|
871
|
+
N[e.slice(0, t).trim()] = e.slice(t + 1).trim();
|
|
837
872
|
}
|
|
838
|
-
if (
|
|
839
|
-
JSON.parse(typeof
|
|
873
|
+
if (M !== void 0 && !Object.keys(N).some((e) => e.toLowerCase() === "content-type")) try {
|
|
874
|
+
JSON.parse(typeof M == "string" ? M : new TextDecoder("utf-8", { fatal: !0 }).decode(M));
|
|
840
875
|
} catch {
|
|
841
|
-
throw
|
|
876
|
+
throw q("The request body is not valid JSON; set a content-type with -H to send it anyway.");
|
|
842
877
|
}
|
|
843
|
-
let
|
|
878
|
+
let de = async (e) => {
|
|
844
879
|
if (!g) return it(e);
|
|
845
880
|
try {
|
|
846
881
|
return await Ae(g, o.jq, e);
|
|
@@ -848,30 +883,30 @@ function at(e, t, n = () => {}) {
|
|
|
848
883
|
let t = e instanceof Error ? e.message : "failed";
|
|
849
884
|
throw Error(`The request succeeded; the --jq filter failed: ${t}`);
|
|
850
885
|
}
|
|
851
|
-
},
|
|
886
|
+
}, P = await ae(), F = (e) => {
|
|
852
887
|
if (!o.verbose) return;
|
|
853
|
-
let n = new URL(`${
|
|
888
|
+
let n = new URL(`${A(P.controller)}/api/v1${e}`);
|
|
854
889
|
t.err(`> ${h} ${n.pathname}${n.search}`), t.err(`> host: ${n.host}`);
|
|
855
|
-
for (let e of
|
|
856
|
-
for (let [e, n] of Object.entries(
|
|
890
|
+
for (let e of P.credentialLines) t.err(e);
|
|
891
|
+
for (let [e, n] of Object.entries(N)) {
|
|
857
892
|
let r = e.toLowerCase();
|
|
858
|
-
t.err(`> ${r}: ${
|
|
893
|
+
t.err(`> ${r}: ${ce.has(r) ? "[redacted]" : n}`);
|
|
859
894
|
}
|
|
860
895
|
o.idempotencyKey && t.err(`> idempotency-key: ${o.idempotencyKey}`);
|
|
861
|
-
},
|
|
896
|
+
}, I = (e) => {
|
|
862
897
|
if (o.verbose) {
|
|
863
898
|
t.err(`< HTTP ${e.status}`);
|
|
864
899
|
for (let n of rt(e.headers)) t.err(`< ${n}`);
|
|
865
900
|
}
|
|
866
|
-
},
|
|
901
|
+
}, fe = (e) => `${ue}${e.length ? `?${new URLSearchParams(e)}` : ""}`, L = (e, t) => (F(fe(e)), P.raw(h, ue, {
|
|
867
902
|
query: e,
|
|
868
|
-
body:
|
|
869
|
-
headers:
|
|
903
|
+
body: M,
|
|
904
|
+
headers: N,
|
|
870
905
|
idempotencyKey: o.idempotencyKey,
|
|
871
906
|
signal: t ?? p
|
|
872
907
|
}));
|
|
873
908
|
if (!o.paginate) {
|
|
874
|
-
let e = await
|
|
909
|
+
let e = await L(j), r = e.body;
|
|
875
910
|
if (d) {
|
|
876
911
|
let t, i;
|
|
877
912
|
try {
|
|
@@ -892,45 +927,45 @@ function at(e, t, n = () => {}) {
|
|
|
892
927
|
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
928
|
}
|
|
894
929
|
}
|
|
895
|
-
|
|
930
|
+
I(e), o.include && t.out([
|
|
896
931
|
`HTTP ${e.status}`,
|
|
897
932
|
...rt(e.headers),
|
|
898
933
|
""
|
|
899
|
-
].join("\n")), !o.silent && r.length > 0 && t.out(await
|
|
934
|
+
].join("\n")), !o.silent && r.length > 0 && t.out(await de(r));
|
|
900
935
|
return;
|
|
901
936
|
}
|
|
902
|
-
let
|
|
903
|
-
|
|
904
|
-
let
|
|
937
|
+
let R = [], pe = /* @__PURE__ */ new Set(), me = j;
|
|
938
|
+
pe.add(new URLSearchParams(j).toString());
|
|
939
|
+
let he = 0, z = 0, B = new AbortController(), ge = setTimeout(() => B.abort(), Qe);
|
|
905
940
|
try {
|
|
906
941
|
for (;;) {
|
|
907
942
|
let e;
|
|
908
943
|
try {
|
|
909
|
-
e = await
|
|
944
|
+
e = await L(me, B.signal);
|
|
910
945
|
} catch (e) {
|
|
911
|
-
throw
|
|
946
|
+
throw B.signal.aborted ? new E("timeout", "--paginate took longer than 5 minutes; stopped.") : e;
|
|
912
947
|
}
|
|
913
|
-
|
|
948
|
+
I(e);
|
|
914
949
|
let t;
|
|
915
950
|
try {
|
|
916
951
|
t = Pe(e.body);
|
|
917
952
|
} catch {
|
|
918
953
|
t = null;
|
|
919
954
|
}
|
|
920
|
-
if (!t) throw
|
|
921
|
-
if (
|
|
922
|
-
if (
|
|
955
|
+
if (!t) throw q("--paginate needs an endpoint that returns a list.");
|
|
956
|
+
if (z += Buffer.byteLength(e.body), z > Ze) throw q("The list is larger than --paginate will collect (16 MiB).");
|
|
957
|
+
if (R.push(t), he += t.length, he > Xe) throw q("The list is longer than --paginate will collect.");
|
|
923
958
|
if (!e.next) break;
|
|
924
959
|
let n = new URLSearchParams(e.next).toString();
|
|
925
|
-
if (
|
|
926
|
-
|
|
960
|
+
if (pe.has(n) || R.length >= Ye) throw q("The controller's paging did not end; stopped.");
|
|
961
|
+
pe.add(n), me = e.next;
|
|
927
962
|
}
|
|
928
963
|
} finally {
|
|
929
|
-
clearTimeout(
|
|
964
|
+
clearTimeout(ge);
|
|
930
965
|
}
|
|
931
966
|
if (!o.silent) {
|
|
932
|
-
let e = o.slurp ? `[${
|
|
933
|
-
t.out(await
|
|
967
|
+
let e = o.slurp ? `[${R.map((e) => `[${e.join(",")}]`).join(",")}]` : `[${R.flat().join(",")}]`;
|
|
968
|
+
t.out(await de(e));
|
|
934
969
|
}
|
|
935
970
|
}
|
|
936
971
|
}
|
|
@@ -938,7 +973,7 @@ function at(e, t, n = () => {}) {
|
|
|
938
973
|
// src/app-commands.ts
|
|
939
974
|
function ot(e, t, n, r) {
|
|
940
975
|
let c = async (e) => {
|
|
941
|
-
let { profile: r } = e.optsWithGlobals(), i = await
|
|
976
|
+
let { profile: r } = e.optsWithGlobals(), i = await x(t, {
|
|
942
977
|
workingDir: n,
|
|
943
978
|
profile: r
|
|
944
979
|
});
|
|
@@ -961,20 +996,20 @@ function ot(e, t, n, r) {
|
|
|
961
996
|
let { client: r, organizationId: i } = await c(n);
|
|
962
997
|
l(await r.deployments.list(i, e));
|
|
963
998
|
}), 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
|
-
|
|
999
|
+
y(t.confirm);
|
|
965
1000
|
let { client: r, organizationId: i } = await c(n);
|
|
966
1001
|
l(await r.apps.shutdown(i, e));
|
|
967
1002
|
}), 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
1003
|
let d = i.resolve(n, r);
|
|
969
|
-
if (o.directory && (await
|
|
970
|
-
let f = await
|
|
1004
|
+
if (o.directory && (await de(d)).isSymbolicLink()) throw new a("bad-input", "The output directory must not be a symlink.");
|
|
1005
|
+
let f = await P(t.store.directory).catch(() => t.store.directory), p = await P(d);
|
|
971
1006
|
s(p, [f]);
|
|
972
1007
|
let m = o.directory ? await g(p, void 0, {
|
|
973
1008
|
include: ["**/*"],
|
|
974
1009
|
exclude: ["**/launchpad.json"],
|
|
975
1010
|
prefix: "",
|
|
976
1011
|
protectedPaths: [f]
|
|
977
|
-
}) : await
|
|
1012
|
+
}) : await _(d), { client: h, organizationId: ee } = await c(u), te = new Blob([new Uint8Array(m.archive)]);
|
|
978
1013
|
l(await h.artifacts.upload(ee, e, te));
|
|
979
1014
|
});
|
|
980
1015
|
let d = e.command("deployment").description("Inspect or delete deployments.");
|
|
@@ -985,7 +1020,7 @@ function ot(e, t, n, r) {
|
|
|
985
1020
|
let { client: r, organizationId: i } = await c(n);
|
|
986
1021
|
l(await r.deployments.events(i, e, { after: t.after }));
|
|
987
1022
|
}), d.command("delete <deployment-id>").option("--confirm", "confirm deletion").action(async (e, t, n) => {
|
|
988
|
-
|
|
1023
|
+
y(t.confirm);
|
|
989
1024
|
let { client: r, organizationId: i } = await c(n);
|
|
990
1025
|
l(await r.deployments.delete(i, e));
|
|
991
1026
|
});
|
|
@@ -1000,52 +1035,52 @@ function ot(e, t, n, r) {
|
|
|
1000
1035
|
let { client: r, organizationId: i } = await c(n);
|
|
1001
1036
|
l(await r.aliases.operations(i, e));
|
|
1002
1037
|
}), 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
|
-
|
|
1038
|
+
y(n.confirm);
|
|
1004
1039
|
let { client: i, organizationId: a } = await c(r);
|
|
1005
1040
|
l(await i.aliases.promote(a, e, {
|
|
1006
1041
|
targetDeploymentId: t,
|
|
1007
1042
|
expectedGeneration: n.expectedGeneration
|
|
1008
1043
|
}, { idempotencyKey: n.idempotencyKey }));
|
|
1009
1044
|
}), 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
|
-
|
|
1045
|
+
y(t.confirm);
|
|
1011
1046
|
let { client: r, organizationId: i } = await c(n);
|
|
1012
1047
|
l(await r.aliases.withdraw(i, e, { expectedGeneration: t.expectedGeneration }, { idempotencyKey: t.idempotencyKey }));
|
|
1013
1048
|
});
|
|
1014
1049
|
}
|
|
1015
1050
|
// src/session-actions.ts
|
|
1016
|
-
var
|
|
1017
|
-
function
|
|
1018
|
-
if (e.length === 0 || e.length > 256 || e === "." || e === ".." || /[\u0000-\u001f\u007f]/.test(e) || n && !
|
|
1051
|
+
var J = (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).", Y = (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, lt = (e) => ct.test(e);
|
|
1052
|
+
function ut(e, t, n) {
|
|
1053
|
+
if (e.length === 0 || e.length > 256 || e === "." || e === ".." || /[\u0000-\u001f\u007f]/.test(e) || n && !lt(e)) throw J(`<${t}> must be ${n ? "an ID (a UUID) as the list command prints it" : "a valid ID"}.`);
|
|
1019
1054
|
return e;
|
|
1020
1055
|
}
|
|
1021
|
-
function
|
|
1056
|
+
function dt(e, t) {
|
|
1022
1057
|
return (n, r, i) => e.out(t(n).json ? JSON.stringify(r, null, 2) : i());
|
|
1023
1058
|
}
|
|
1024
|
-
function
|
|
1025
|
-
if (!
|
|
1059
|
+
function ft(e) {
|
|
1060
|
+
if (!O.includes(e)) throw J(`--role must be one of ${O.join(", ")}.`);
|
|
1026
1061
|
return e;
|
|
1027
1062
|
}
|
|
1028
|
-
function
|
|
1063
|
+
function pt(e, t = []) {
|
|
1029
1064
|
return [...t, e];
|
|
1030
1065
|
}
|
|
1031
1066
|
function X(e, t) {
|
|
1032
1067
|
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
1068
|
}
|
|
1034
|
-
var
|
|
1069
|
+
var mt = "Use the organization's ID: find it in the dashboard or with `launchpad api --session organizations`.";
|
|
1035
1070
|
async function Z(e, t, n, r, i) {
|
|
1036
1071
|
let { io: a, remember: o } = e;
|
|
1037
|
-
He(a.context, "This command"), n.write &&
|
|
1072
|
+
He(a.context, "This command"), n.write && y(r.confirm), n.validate?.();
|
|
1038
1073
|
let { profile: s } = t.optsWithGlobals(), c = null, l;
|
|
1039
1074
|
if (n.org) {
|
|
1040
1075
|
r.org !== void 0 && (c = {
|
|
1041
1076
|
value: r.org,
|
|
1042
1077
|
source: "--org"
|
|
1043
1078
|
});
|
|
1044
|
-
let e = await
|
|
1079
|
+
let e = await ne(a.workingDir ?? process.cwd());
|
|
1045
1080
|
if (l = e.config?.profile, !c && e.config?.organization && (c = {
|
|
1046
1081
|
value: e.config.organization,
|
|
1047
1082
|
source: "launchpad.json"
|
|
1048
|
-
}), c && !
|
|
1083
|
+
}), c && !lt(c.value)) throw J(`${c.source} must be an organization ID (a UUID), not a slug. ${mt}`);
|
|
1049
1084
|
}
|
|
1050
1085
|
await Je(a, n.secretFile, ({ guard: e, secretFile: t }) => qe({
|
|
1051
1086
|
io: a,
|
|
@@ -1061,8 +1096,8 @@ async function Z(e, t, n, r, i) {
|
|
|
1061
1096
|
missingEmail: "--email <address> is needed to sign in (no saved session).",
|
|
1062
1097
|
chooseOrganization: n.org ? (e) => {
|
|
1063
1098
|
if (c) return c.value;
|
|
1064
|
-
if (e === null) throw
|
|
1065
|
-
if (!
|
|
1099
|
+
if (e === null) throw J("No organization: use --org <id>, launchpad.json, LAUNCHPAD_ORG or a profile's organization.");
|
|
1100
|
+
if (!lt(e)) throw J(`The organization from LAUNCHPAD_ORG or the profile must be an organization ID (a UUID), not a slug. ${mt}`);
|
|
1066
1101
|
return e;
|
|
1067
1102
|
} : void 0
|
|
1068
1103
|
}, ({ client: n, email: r, controller: a, organization: o }) => i({
|
|
@@ -1080,9 +1115,9 @@ var Q = (e) => {
|
|
|
1080
1115
|
return e.map((e) => e.map((e, n) => e.padEnd(t[n])).join(" ").trimEnd()).join("\n");
|
|
1081
1116
|
};
|
|
1082
1117
|
// src/invite-commands.ts
|
|
1083
|
-
function
|
|
1084
|
-
let r =
|
|
1085
|
-
X(i.command("create").description(
|
|
1118
|
+
function ht(e, t, n) {
|
|
1119
|
+
let r = dt(t.io, n), i = e.command("invite").description("Email invitations to an organization (your own account's session, not a key).");
|
|
1120
|
+
X(i.command("create").description(Y("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 (${O.join(", ")})`), {
|
|
1086
1121
|
org: !0,
|
|
1087
1122
|
write: !0
|
|
1088
1123
|
}).action(async (e, n) => {
|
|
@@ -1092,7 +1127,7 @@ function mt(e, t, n) {
|
|
|
1092
1127
|
org: !0,
|
|
1093
1128
|
needsFresh: !1,
|
|
1094
1129
|
validate: () => {
|
|
1095
|
-
i =
|
|
1130
|
+
i = K(e.to, "--to"), a = ft(e.role);
|
|
1096
1131
|
}
|
|
1097
1132
|
}, e, async ({ client: e, organization: t }) => {
|
|
1098
1133
|
let o = await e.use("POST", "/invitations", (e, n) => e.invitations.create(t, {
|
|
@@ -1105,7 +1140,7 @@ function mt(e, t, n) {
|
|
|
1105
1140
|
};
|
|
1106
1141
|
r(n, s, () => `Invited ${s.email} as ${s.role} (${s.id}). The invitation was emailed.`);
|
|
1107
1142
|
});
|
|
1108
|
-
}), X(i.command("list").description(
|
|
1143
|
+
}), X(i.command("list").description(Y("List the organization's pending invitations (owner or admin).", "GET /organizations/:org/invitations")), {
|
|
1109
1144
|
org: !0,
|
|
1110
1145
|
write: !1
|
|
1111
1146
|
}).action(async (e, n) => {
|
|
@@ -1135,7 +1170,7 @@ function mt(e, t, n) {
|
|
|
1135
1170
|
e.expiresAt
|
|
1136
1171
|
])]));
|
|
1137
1172
|
});
|
|
1138
|
-
}), X(i.command("revoke").description(
|
|
1173
|
+
}), X(i.command("revoke").description(Y("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
1174
|
org: !0,
|
|
1140
1175
|
write: !0
|
|
1141
1176
|
}).action(async (e, n, i) => {
|
|
@@ -1143,7 +1178,7 @@ function mt(e, t, n) {
|
|
|
1143
1178
|
write: !0,
|
|
1144
1179
|
org: !0,
|
|
1145
1180
|
needsFresh: !1,
|
|
1146
|
-
validate: () => void
|
|
1181
|
+
validate: () => void ut(e, "invitation-id", !0)
|
|
1147
1182
|
}, n, async ({ client: t, organization: n }) => {
|
|
1148
1183
|
let a = await t.use("DELETE", "/invitations/:id", (t, r) => t.invitations.revoke(n, e, { signal: r }));
|
|
1149
1184
|
r(i, a, () => `Revoked invitation ${e}.`);
|
|
@@ -1151,19 +1186,19 @@ function mt(e, t, n) {
|
|
|
1151
1186
|
});
|
|
1152
1187
|
}
|
|
1153
1188
|
// src/key-commands.ts
|
|
1154
|
-
var $ = (e) => new a("bad-input", e),
|
|
1155
|
-
function
|
|
1156
|
-
return e instanceof
|
|
1189
|
+
var $ = (e) => new a("bad-input", e), gt = "The key may exist: run \"launchpad key list\" and revoke it.";
|
|
1190
|
+
function _t(e, t) {
|
|
1191
|
+
return e instanceof w ? new w({
|
|
1157
1192
|
status: e.status,
|
|
1158
1193
|
code: e.code,
|
|
1159
|
-
title: `${e.title} ${
|
|
1194
|
+
title: `${e.title} ${gt}`,
|
|
1160
1195
|
retryAfterSeconds: e.retryAfterSeconds ?? void 0
|
|
1161
|
-
}) : e instanceof
|
|
1196
|
+
}) : e instanceof E ? new E(e.reason, `${e.message} ${gt}`) : (t.err(gt), e);
|
|
1162
1197
|
}
|
|
1163
|
-
var
|
|
1164
|
-
function
|
|
1165
|
-
let { io: r, remember: i } = t, o =
|
|
1166
|
-
X(s.command("list").description(
|
|
1198
|
+
var vt = (e) => e instanceof w && e.status >= 400 && e.status < 500 && e.status !== 408 && e.status !== 429;
|
|
1199
|
+
function yt(e, t, n) {
|
|
1200
|
+
let { io: r, remember: i } = t, o = dt(r, n), s = e.command("key").description("API keys of an organization (your own account's session, not a key).");
|
|
1201
|
+
X(s.command("list").description(Y("List the organization's API keys, never their secrets.", "GET /organizations/:org/api-keys")), {
|
|
1167
1202
|
org: !0,
|
|
1168
1203
|
write: !1
|
|
1169
1204
|
}).action(async (e, n) => {
|
|
@@ -1193,7 +1228,7 @@ function vt(e, t, n) {
|
|
|
1193
1228
|
e.lastUsedAt ?? "never"
|
|
1194
1229
|
])]));
|
|
1195
1230
|
});
|
|
1196
|
-
}), X(s.command("issue").description(
|
|
1231
|
+
}), X(s.command("issue").description(Y("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 ${C.join(", ")})`, pt, []).option("--project <id>", "limit the key to this project (repeatable; not with project:create)", pt, []).requiredOption("--expires-in-days <n>", `lifetime in days, 1 to ${D}`).requiredOption("--secret-file <path>", "create this new file (mode 0600) before the request and write the secret to it"), {
|
|
1197
1232
|
org: !0,
|
|
1198
1233
|
write: !0
|
|
1199
1234
|
}).action(async (e, n) => {
|
|
@@ -1205,10 +1240,10 @@ function vt(e, t, n) {
|
|
|
1205
1240
|
secretFile: e.secretFile,
|
|
1206
1241
|
validate: () => {
|
|
1207
1242
|
if (e.name.trim().length === 0) throw $("--name must not be empty.");
|
|
1208
|
-
if (e.scope.length === 0) throw $(`Give at least one --scope (${
|
|
1209
|
-
for (let t of e.scope) if (!
|
|
1210
|
-
if (s = e.scope, !/^\d{1,4}$/.test(e.expiresInDays) || (c = Number(e.expiresInDays), c < 1 || c >
|
|
1211
|
-
for (let t of e.project) if (!
|
|
1243
|
+
if (e.scope.length === 0) throw $(`Give at least one --scope (${C.join(", ")}).`);
|
|
1244
|
+
for (let t of e.scope) if (!C.includes(t)) throw $(`--scope must be one of ${C.join(", ")}.`);
|
|
1245
|
+
if (s = e.scope, !/^\d{1,4}$/.test(e.expiresInDays) || (c = Number(e.expiresInDays), c < 1 || c > D)) throw $(`--expires-in-days must be a whole number from 1 to ${D}.`);
|
|
1246
|
+
for (let t of e.project) if (!lt(t)) throw $("--project must be a project ID (a UUID).");
|
|
1212
1247
|
if (e.project.length > 0 && s.includes("project:create")) throw $("A project-limited API key cannot create projects.");
|
|
1213
1248
|
}
|
|
1214
1249
|
}, e, async ({ client: t, organization: l, secretFile: u }) => {
|
|
@@ -1230,16 +1265,16 @@ function vt(e, t, n) {
|
|
|
1230
1265
|
}
|
|
1231
1266
|
}
|
|
1232
1267
|
})));
|
|
1233
|
-
if (!f) throw new
|
|
1268
|
+
if (!f) throw new E("invalid-response", "The controller's answer had no secret.");
|
|
1234
1269
|
o(n, {
|
|
1235
1270
|
...r,
|
|
1236
1271
|
secret: `[written to ${e.secretFile}]`
|
|
1237
1272
|
}, () => `Issued key ${r.name} (${r.id}), expires ${r.expiresAt}. The secret is in ${e.secretFile}.`);
|
|
1238
1273
|
} catch (t) {
|
|
1239
|
-
throw !d || t instanceof
|
|
1274
|
+
throw !d || t instanceof T ? 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) : vt(t) || t instanceof a && t.code === "not-logged-in" ? t : _t(t, r);
|
|
1240
1275
|
}
|
|
1241
1276
|
});
|
|
1242
|
-
}), X(s.command("revoke").description(
|
|
1277
|
+
}), X(s.command("revoke").description(Y("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
1278
|
org: !0,
|
|
1244
1279
|
write: !0
|
|
1245
1280
|
}).action(async (e, n, r) => {
|
|
@@ -1247,7 +1282,7 @@ function vt(e, t, n) {
|
|
|
1247
1282
|
write: !0,
|
|
1248
1283
|
org: !0,
|
|
1249
1284
|
needsFresh: !1,
|
|
1250
|
-
validate: () => void
|
|
1285
|
+
validate: () => void ut(e, "key-id", !0)
|
|
1251
1286
|
}, n, async ({ client: t, organization: n }) => {
|
|
1252
1287
|
let i = await t.use("DELETE", "/api-keys/:id", (t, r) => t.apiKeys.revoke(n, e, { signal: r }));
|
|
1253
1288
|
o(r, i, () => `Revoked key ${e}.`);
|
|
@@ -1255,10 +1290,10 @@ function vt(e, t, n) {
|
|
|
1255
1290
|
});
|
|
1256
1291
|
}
|
|
1257
1292
|
// src/org-commands.ts
|
|
1258
|
-
var
|
|
1259
|
-
function
|
|
1260
|
-
let { io: i } = n, a =
|
|
1261
|
-
X(t.command("create").description(
|
|
1293
|
+
var bt = (e) => new a("bad-input", e);
|
|
1294
|
+
function xt(e, t, n, r) {
|
|
1295
|
+
let { io: i } = n, a = dt(i, r);
|
|
1296
|
+
X(t.command("create").description(Y("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
1297
|
org: !1,
|
|
1263
1298
|
write: !0
|
|
1264
1299
|
}).action(async (e, t) => {
|
|
@@ -1268,9 +1303,9 @@ function bt(e, t, n, r) {
|
|
|
1268
1303
|
org: !1,
|
|
1269
1304
|
needsFresh: !1,
|
|
1270
1305
|
validate: () => {
|
|
1271
|
-
if (e.name.trim().length === 0) throw
|
|
1272
|
-
if (!
|
|
1273
|
-
r =
|
|
1306
|
+
if (e.name.trim().length === 0) throw bt("--name must not be empty.");
|
|
1307
|
+
if (!ue.safeParse(e.slug).success) throw bt("--slug must be a valid slug (lowercase letters, digits and hyphens).");
|
|
1308
|
+
r = K(e.ownerEmail, "--owner-email");
|
|
1274
1309
|
}
|
|
1275
1310
|
}, e, async ({ client: n }) => {
|
|
1276
1311
|
let i = await n.use("POST", "/organizations", (t, n) => t.organizations.create({
|
|
@@ -1282,7 +1317,7 @@ function bt(e, t, n, r) {
|
|
|
1282
1317
|
});
|
|
1283
1318
|
});
|
|
1284
1319
|
let o = e.command("member").description("Members of an organization (your own account's session, not a key).");
|
|
1285
|
-
X(o.command("list").description(
|
|
1320
|
+
X(o.command("list").description(Y("List the organization's members; their user IDs are what `member remove` takes.", "GET /organizations/:org/members")), {
|
|
1286
1321
|
org: !0,
|
|
1287
1322
|
write: !1
|
|
1288
1323
|
}).action(async (e, t) => {
|
|
@@ -1304,7 +1339,7 @@ function bt(e, t, n, r) {
|
|
|
1304
1339
|
e.role
|
|
1305
1340
|
])]));
|
|
1306
1341
|
});
|
|
1307
|
-
}), X(o.command("add").description(
|
|
1342
|
+
}), X(o.command("add").description(Y("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 (${O.join(", ")})`), {
|
|
1308
1343
|
org: !0,
|
|
1309
1344
|
write: !0
|
|
1310
1345
|
}).action(async (e, t) => {
|
|
@@ -1314,7 +1349,7 @@ function bt(e, t, n, r) {
|
|
|
1314
1349
|
org: !0,
|
|
1315
1350
|
needsFresh: !1,
|
|
1316
1351
|
validate: () => {
|
|
1317
|
-
r =
|
|
1352
|
+
r = K(e.userEmail, "--user-email"), i = ft(e.role);
|
|
1318
1353
|
}
|
|
1319
1354
|
}, e, async ({ client: e, organization: n }) => {
|
|
1320
1355
|
let o = await e.use("POST", "/members", (e, t) => e.members.add(n, {
|
|
@@ -1323,7 +1358,7 @@ function bt(e, t, n, r) {
|
|
|
1323
1358
|
}, { signal: t }));
|
|
1324
1359
|
a(t, o, () => `Added ${r} to ${n} as ${o.role}.`);
|
|
1325
1360
|
});
|
|
1326
|
-
}), X(o.command("remove").description(
|
|
1361
|
+
}), X(o.command("remove").description(Y("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
1362
|
org: !0,
|
|
1328
1363
|
write: !0
|
|
1329
1364
|
}).action(async (e, t, r) => {
|
|
@@ -1331,7 +1366,7 @@ function bt(e, t, n, r) {
|
|
|
1331
1366
|
write: !0,
|
|
1332
1367
|
org: !0,
|
|
1333
1368
|
needsFresh: !1,
|
|
1334
|
-
validate: () => void
|
|
1369
|
+
validate: () => void ut(e, "user-id", !1)
|
|
1335
1370
|
}, t, async ({ client: t, organization: n }) => {
|
|
1336
1371
|
let i = await t.use("DELETE", "/members/:userId", (t, r) => t.members.remove(n, e, { signal: r }));
|
|
1337
1372
|
a(r, i, () => `Removed ${e} from ${n}.`);
|
|
@@ -1339,10 +1374,10 @@ function bt(e, t, n, r) {
|
|
|
1339
1374
|
});
|
|
1340
1375
|
}
|
|
1341
1376
|
// src/session-commands.ts
|
|
1342
|
-
var
|
|
1343
|
-
async function
|
|
1344
|
-
if (He(e.context, "--session"), t.email === void 0) throw
|
|
1345
|
-
let r =
|
|
1377
|
+
var St = (e) => new a("bad-input", e);
|
|
1378
|
+
async function Ct(e, t, n) {
|
|
1379
|
+
if (He(e.context, "--session"), t.email === void 0) throw St("--session needs --email <address> to sign in.");
|
|
1380
|
+
let r = K(t.email);
|
|
1346
1381
|
await Be(e, async (i) => {
|
|
1347
1382
|
let a = await Ue(e.context, {
|
|
1348
1383
|
controller: t.controller,
|
|
@@ -1361,7 +1396,7 @@ async function St(e, t, n) {
|
|
|
1361
1396
|
}, null, 2) : `Signed in to ${a.controller} as ${r}.`);
|
|
1362
1397
|
});
|
|
1363
1398
|
}
|
|
1364
|
-
async function
|
|
1399
|
+
async function wt(e, t, n) {
|
|
1365
1400
|
He(e.context, "--session");
|
|
1366
1401
|
let r = await Ue(e.context, {
|
|
1367
1402
|
controller: t.controller,
|
|
@@ -1378,13 +1413,13 @@ async function Ct(e, t, n) {
|
|
|
1378
1413
|
n(i.cookie), n(i.cookie.slice(i.cookie.indexOf("=") + 1));
|
|
1379
1414
|
let a = !0;
|
|
1380
1415
|
try {
|
|
1381
|
-
await
|
|
1416
|
+
await k({
|
|
1382
1417
|
baseUrl: r.controller,
|
|
1383
1418
|
cookie: i.cookie,
|
|
1384
1419
|
fetch: e.context.fetch
|
|
1385
1420
|
}).signOut();
|
|
1386
1421
|
} catch (t) {
|
|
1387
|
-
t instanceof
|
|
1422
|
+
t instanceof w && t.status === 401 || (a = !1, e.err(`Warning: could not sign out of ${r.controller} (${W(t).message}). The session ends on its own, at most 7 days after its last use.`));
|
|
1388
1423
|
}
|
|
1389
1424
|
await e.context.sessions.remove(r.controller, i.cookie), e.out(t.json ? JSON.stringify({
|
|
1390
1425
|
controller: r.controller,
|
|
@@ -1394,21 +1429,21 @@ async function Ct(e, t, n) {
|
|
|
1394
1429
|
}, 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
1430
|
}
|
|
1396
1431
|
// src/program.ts
|
|
1397
|
-
async function
|
|
1432
|
+
async function Tt(e, t) {
|
|
1398
1433
|
let n;
|
|
1399
1434
|
if (t.keyFile) {
|
|
1400
1435
|
let r = await e.readFile(t.keyFile);
|
|
1401
1436
|
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
1437
|
} else if (t.keyStdin) {
|
|
1403
|
-
if (e.stdinIsTTY ?? e.interactive) throw new
|
|
1438
|
+
if (e.stdinIsTTY ?? e.interactive) throw new S(H.usage, "commander.interactiveStdin", "error: --key-stdin requires redirected input; omit it to use the hidden terminal prompt");
|
|
1404
1439
|
n = await e.readStdin();
|
|
1405
1440
|
} else if (e.interactive) n = await e.readSecret("API key: ");
|
|
1406
|
-
else throw new
|
|
1441
|
+
else throw new S(H.usage, "commander.missingKey", "error: provide the key with --key-file <path> or --key-stdin, or run in a terminal");
|
|
1407
1442
|
let r = n.trim();
|
|
1408
|
-
if (!r) throw new
|
|
1443
|
+
if (!r) throw new S(H.usage, "commander.emptyKey", "error: the API key is empty");
|
|
1409
1444
|
return r;
|
|
1410
1445
|
}
|
|
1411
|
-
function
|
|
1446
|
+
function Et(e, t = /* @__PURE__ */ new Set()) {
|
|
1412
1447
|
let n = () => [...t, ...e.context.secrets ?? []], r = {
|
|
1413
1448
|
get workingDir() {
|
|
1414
1449
|
return e.workingDir;
|
|
@@ -1425,8 +1460,8 @@ function Tt(e, t = /* @__PURE__ */ new Set()) {
|
|
|
1425
1460
|
get signals() {
|
|
1426
1461
|
return e.signals;
|
|
1427
1462
|
},
|
|
1428
|
-
out: (t) => e.out(
|
|
1429
|
-
err: (t) => e.err(
|
|
1463
|
+
out: (t) => e.out(b(t, n())),
|
|
1464
|
+
err: (t) => e.err(b(t, n())),
|
|
1430
1465
|
readStdin: () => e.readStdin(),
|
|
1431
1466
|
readSecret: (t, n) => e.readSecret(t, n),
|
|
1432
1467
|
readPasswordFile: (t) => e.readPasswordFile(t),
|
|
@@ -1434,23 +1469,23 @@ function Tt(e, t = /* @__PURE__ */ new Set()) {
|
|
|
1434
1469
|
readFile: (t) => e.readFile(t),
|
|
1435
1470
|
readData: (t) => e.readData(t),
|
|
1436
1471
|
findExecutable: e.findExecutable?.bind(e)
|
|
1437
|
-
}, i = (e) => void t.add(e), a = new
|
|
1472
|
+
}, i = (e) => void t.add(e), a = new se().name("launchpad").description("Work with a Launchpad controller using an organization API key.").version(ve.version).option("--json", "print machine-readable JSON").option("--profile <name>", "use this saved profile instead of the current one").showHelpAfterError(!1).configureOutput({
|
|
1438
1473
|
writeOut: (e) => r.out(e.replace(/\n$/, "")),
|
|
1439
1474
|
writeErr: () => {}
|
|
1440
1475
|
}).exitOverride(), o = (e) => e.optsWithGlobals(), s = (e, t, n) => r.out(o(e).json ? JSON.stringify(t, null, 2) : n());
|
|
1441
1476
|
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
1477
|
let { profile: n, json: a } = o(t);
|
|
1443
1478
|
if (e.session) {
|
|
1444
|
-
if (e.keyFile !== void 0 || e.keyStdin) throw new
|
|
1445
|
-
return
|
|
1479
|
+
if (e.keyFile !== void 0 || e.keyStdin) throw new S(H.usage, "commander.mixedLogin", "error: --session cannot be combined with --key-file or --key-stdin");
|
|
1480
|
+
return Ct(r, {
|
|
1446
1481
|
...e,
|
|
1447
1482
|
profile: n,
|
|
1448
1483
|
json: a
|
|
1449
1484
|
}, i);
|
|
1450
1485
|
}
|
|
1451
|
-
for (let [t, n] of [["--email", e.email], ["--password-file", e.passwordFile]]) if (n !== void 0) throw new
|
|
1452
|
-
if (e.controller === void 0) throw new
|
|
1453
|
-
let s = await
|
|
1486
|
+
for (let [t, n] of [["--email", e.email], ["--password-file", e.passwordFile]]) if (n !== void 0) throw new S(H.usage, "commander.needsSession", `error: ${t} needs --session`);
|
|
1487
|
+
if (e.controller === void 0) throw new S(H.usage, "commander.missingControllerOption", "error: required option '--controller <url>' not specified");
|
|
1488
|
+
let s = await Tt(r, e), c = await m(r.context, {
|
|
1454
1489
|
controller: e.controller,
|
|
1455
1490
|
apiKey: s,
|
|
1456
1491
|
profile: n
|
|
@@ -1468,17 +1503,17 @@ function Tt(e, t = /* @__PURE__ */ new Set()) {
|
|
|
1468
1503
|
}), 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
1504
|
if (e.session) {
|
|
1470
1505
|
let { profile: n, json: a } = o(t);
|
|
1471
|
-
return
|
|
1506
|
+
return wt(r, {
|
|
1472
1507
|
controller: e.controller,
|
|
1473
1508
|
profile: n,
|
|
1474
1509
|
json: a
|
|
1475
1510
|
}, i);
|
|
1476
1511
|
}
|
|
1477
|
-
for (let [t, n] of [["--controller", e.controller], ["--email", e.email]]) if (n !== void 0) throw new
|
|
1512
|
+
for (let [t, n] of [["--controller", e.controller], ["--email", e.email]]) if (n !== void 0) throw new S(H.usage, "commander.needsSession", `error: ${t} needs --session`);
|
|
1478
1513
|
let n = await h(r.context, o(t).profile);
|
|
1479
1514
|
s(t, n, () => `Logged out of profile "${n.profile}".`);
|
|
1480
1515
|
}), a.command("whoami").description("Show the controller, organization and permissions of the current key.").action(async (e, t) => {
|
|
1481
|
-
let n = await
|
|
1516
|
+
let n = await oe(r.context, o(t).profile);
|
|
1482
1517
|
s(t, n, () => [
|
|
1483
1518
|
`Controller: ${n.controller}`,
|
|
1484
1519
|
`Profile: ${n.profile ?? "(environment)"}`,
|
|
@@ -1502,7 +1537,7 @@ function Tt(e, t = /* @__PURE__ */ new Set()) {
|
|
|
1502
1537
|
e.controller
|
|
1503
1538
|
])]));
|
|
1504
1539
|
}), 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
|
|
1540
|
+
let i = await ae(r.context, e);
|
|
1506
1541
|
s(n, i, () => `Using profile "${i.profile}".`);
|
|
1507
1542
|
});
|
|
1508
1543
|
let l = a.command("org").description("Organizations: `list` and `use` need a key, `create` your own account's session.");
|
|
@@ -1518,7 +1553,7 @@ function Tt(e, t = /* @__PURE__ */ new Set()) {
|
|
|
1518
1553
|
e.name
|
|
1519
1554
|
])]));
|
|
1520
1555
|
}), l.command("use").argument("<organization>", "slug or id").description("Select the organization for later commands.").action(async (e, t, n) => {
|
|
1521
|
-
let i = await
|
|
1556
|
+
let i = await ie(r.context, e, o(n).profile);
|
|
1522
1557
|
s(n, i, () => `Using organization ${i.organization.slug}.`);
|
|
1523
1558
|
}), a.command("projects").description("Projects of the selected organization.").command("list").description("List projects the key can see.").action(async (e, t) => {
|
|
1524
1559
|
let n = await p(r.context, o(t).profile);
|
|
@@ -1531,26 +1566,26 @@ function Tt(e, t = /* @__PURE__ */ new Set()) {
|
|
|
1531
1566
|
e.slug,
|
|
1532
1567
|
e.name
|
|
1533
1568
|
])]));
|
|
1534
|
-
}), at(a, r, i),
|
|
1569
|
+
}), at(a, r, i), xt(a, l, {
|
|
1535
1570
|
io: r,
|
|
1536
1571
|
remember: i
|
|
1537
|
-
}, o),
|
|
1572
|
+
}, o), ht(a, {
|
|
1538
1573
|
io: r,
|
|
1539
1574
|
remember: i
|
|
1540
|
-
}, o),
|
|
1575
|
+
}, o), yt(a, {
|
|
1541
1576
|
io: r,
|
|
1542
1577
|
remember: i
|
|
1543
1578
|
}, o), ot(a, r.context, r.workingDir ?? process.cwd(), r.out), a;
|
|
1544
1579
|
}
|
|
1545
|
-
async function
|
|
1546
|
-
let n = /* @__PURE__ */ new Set(), r =
|
|
1580
|
+
async function Dt(e, t) {
|
|
1581
|
+
let n = /* @__PURE__ */ new Set(), r = Et(t, n);
|
|
1547
1582
|
try {
|
|
1548
|
-
return await r.parseAsync(e, { from: "user" }),
|
|
1583
|
+
return await r.parseAsync(e, { from: "user" }), H.ok;
|
|
1549
1584
|
} catch (r) {
|
|
1550
|
-
if (r instanceof
|
|
1551
|
-
if (r instanceof
|
|
1552
|
-
let i =
|
|
1553
|
-
return t.err(
|
|
1585
|
+
if (r instanceof S && r.exitCode === 0) return H.ok;
|
|
1586
|
+
if (r instanceof U) return r.exitCode;
|
|
1587
|
+
let i = W(r), a = e.includes("--json");
|
|
1588
|
+
return t.err(b(a ? JSON.stringify({ error: {
|
|
1554
1589
|
code: i.code,
|
|
1555
1590
|
message: i.message,
|
|
1556
1591
|
...i.status ? { status: i.status } : {}
|
|
@@ -1558,4 +1593,4 @@ async function Et(e, t) {
|
|
|
1558
1593
|
}
|
|
1559
1594
|
}
|
|
1560
1595
|
// src/index.ts
|
|
1561
|
-
process.exitCode = await
|
|
1596
|
+
process.exitCode = await Dt(process.argv.slice(2), _e());
|