@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.
Files changed (2) hide show
  1. package/cli.mjs +302 -267
  2. 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 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";
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 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");
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 I(e, t, n) {
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 L() {
24
- return pe(process.stdin);
23
+ async function R() {
24
+ return fe(process.stdin);
25
25
  }
26
- function me({ stdin: e, stderr: t }, n, r = {}) {
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") > P) return c(() => a(Error(i)));
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 he = (e, t) => me({
41
+ var me = (e, t) => pe({
42
42
  stdin: process.stdin,
43
43
  stderr: process.stderr
44
44
  }, e, t);
45
- async function ge(e) {
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 R = (e) => /* @__PURE__ */ Error(`The password file ${e}.`);
72
- async function z(e) {
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 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");
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 R("is not a regular file");
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 R("is owned by another user");
86
- if (e.mode & 63) throw R("is readable by others; restrict it with chmod 600");
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 > P) throw R("is too long to be a password");
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 I(r.createReadStream({
91
+ let e = await L(r.createReadStream({
92
92
  autoClose: !1,
93
93
  highWaterMark: 4097
94
- }), P, "The password file is too long to be a password.");
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 ? R("is not valid UTF-8 text") : R("cannot be read");
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 _e(e, r) {
104
+ async function ge(e, r) {
105
105
  let a = "The data is larger than 1 MiB.";
106
- if (e === "-") return I(process.stdin, F, a);
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 > F) throw Error(a);
117
- return await I(l.createReadStream({
116
+ if (e.size > I) throw Error(a);
117
+ return await L(l.createReadStream({
118
118
  autoClose: !1,
119
119
  highWaterMark: 65536
120
- }), F, a);
120
+ }), I, a);
121
121
  } finally {
122
122
  await l.close();
123
123
  }
124
124
  }
125
- function ve(e = process.env) {
125
+ function _e(e = process.env) {
126
126
  let t = l(e);
127
127
  return {
128
128
  context: t,
129
- readData: (e) => _e(e, t.store.directory),
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: he,
141
- readPasswordFile: z,
142
- createSecretFile: ge,
143
- readStdin: L,
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 > P) throw Error("File is too large to be a key.");
148
+ if (e.size > F) throw Error("File is too large to be a key.");
149
149
  return {
150
- text: await pe(t.createReadStream({
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
- // src/jq.ts
164
- var ye = {
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, B = (e) => new a("bad-input", 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 = A(e, t, {
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(B("jq took too long and was stopped.")), i.timeoutMs);
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(B("jq printed too much; stopped.")) : c.push(e);
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(B("jq could not be run."));
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(B(`jq: ${Buffer.concat(l).toString("utf8").slice(0, be).trim() || `exited with ${e}`}`));
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 (!j(e)) throw B("The jq expression is not valid (or not supported).");
244
+ if (!M(e)) throw V("The jq expression is not valid (or not supported).");
210
245
  let n;
211
246
  try {
212
- n = M(JSON.parse(t), e);
247
+ n = N(JSON.parse(t), e);
213
248
  } catch (e) {
214
- throw B(`jq: ${e instanceof Error ? e.message.slice(0, 200) : "failed"}`);
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 B("The jq expression must be 1 to 4096 characters.");
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 (!j(t)) throw B("The jq expression is not valid (or not supported).");
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 B("The jq expression must be 1 to 4096 characters.");
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 B("The response is not JSON, so --jq cannot be applied.");
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 V = {
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
- }, H = class extends Error {
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 U(e) {
380
- if (e instanceof x) return {
381
- exitCode: V.usage,
414
+ function W(e) {
415
+ if (e instanceof S) return {
416
+ exitCode: H.usage,
382
417
  code: "usage",
383
- message: _(e.message.replace(/^error: /, ""))
418
+ message: v(e.message.replace(/^error: /, ""))
384
419
  };
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.` : "";
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: _(`${e.title}${n}`),
425
+ message: v(`${e.title}${n}`),
391
426
  status: e.status
392
427
  };
393
428
  }
394
- if (e instanceof T) return {
395
- exitCode: V.transport,
429
+ if (e instanceof E) return {
430
+ exitCode: H.transport,
396
431
  code: e.reason,
397
- message: _(e.message)
432
+ message: v(e.message)
398
433
  };
399
- if (e instanceof w) return {
400
- exitCode: V.usage,
434
+ if (e instanceof T) return {
435
+ exitCode: H.usage,
401
436
  code: "bad-input",
402
- message: _(e.message)
437
+ message: v(e.message)
403
438
  };
404
439
  if (e instanceof a) return {
405
- exitCode: e.code === "not-logged-in" ? V.unauthorized : e.code === "bad-input" ? V.usage : V.local,
440
+ exitCode: e.code === "not-logged-in" ? H.unauthorized : e.code === "bad-input" ? H.usage : H.local,
406
441
  code: e.code,
407
- message: _(e.message)
442
+ message: v(e.message)
408
443
  };
409
444
  let t = e instanceof Error ? e.message : String(e);
410
445
  return {
411
- exitCode: V.failure,
446
+ exitCode: H.failure,
412
447
  code: "failure",
413
- message: _(t)
448
+ message: v(t)
414
449
  };
415
450
  }
416
- var W = (e) => new a("bad-input", e);
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 W(e instanceof Error ? e.message : "The password file cannot be read.");
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(V.interrupted) : e instanceof Error && /^Input is too long/.test(e.message) ? W(e.message) : e;
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 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.");
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 = O({
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 = O({
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 O({
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 (${U(e).message}). It ends on its own, at most 7 days after its last use.`);
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} (${U(n).message}). The session ends on its own, at most 7 days after its last use.`);
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 H(n.flow.interruptedWith));
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 H(n.flow.interruptedWith);
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 G(e, t = "--email") {
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 = k(t.controller), i = null;
620
+ let e = A(t.controller), i = null;
586
621
  if (t.profile) {
587
622
  let n = await r(t.profile);
588
- k(n.controller) === e && (i = n.organizationId);
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: k(e.env.LAUNCHPAD_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: k(i.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 : G(e.email), o = await Ue(n.context, {
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 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;
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 H(r.interruptedWith);
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 H || e.err("Interrupted."), new H(r.interruptedWith));
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, 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) => {
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: ${[...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.");
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 K(`${e} needs --session.`);
734
- o.email !== void 0 && G(o.email);
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 (!ue.has(h)) throw K("The method must be GET, HEAD, POST, PUT, PATCH or DELETE.");
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 || 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.");
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 ne = /* @__PURE__ */ new Set();
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)) 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);
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
- })(), se = async () => {
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 ?? y.config?.profile,
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 K("The organization list was not a list.");
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 K("{org} has no value: with --session select an organization with `launchpad org use`, launchpad.json or LAUNCHPAD_ORG.");
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
- }, b = /* @__PURE__ */ new Map();
787
- if (ne.has("org")) {
788
- let e = await oe(), t = y.config?.organization;
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
- b.set("org", n.id);
793
- } else b.set("org", e.organizationId ?? await e.ownOrganization());
827
+ x.set("org", n.id);
828
+ } else x.set("org", e.organizationId ?? await e.ownOrganization());
794
829
  }
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);
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 ce = (e, t) => e.replace(tt, (e, n) => {
801
- let r = b.get(n);
802
- if (!r) throw K(`{${n}} has no value here.`);
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 K(`{${n}} is not a valid path segment.`);
839
+ if (r === "." || r === "..") throw q(`{${n}} is not a valid path segment.`);
805
840
  return encodeURIComponent(r);
806
- }), x = { value: !1 }, S = async (e) => {
841
+ }), S = { value: !1 }, C = async (e) => {
807
842
  if (e === "-") {
808
- if (x.value) throw K("Standard input can be read only once.");
809
- x.value = !0;
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 K(e === "-" ? `Could not read standard input: ${n}` : `Could not read the data file: ${/ENOENT/.test(n) ? "not found" : n}`);
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
- }, C = async (e) => {
852
+ }, w = async (e) => {
818
853
  try {
819
- return new TextDecoder("utf-8", { fatal: !0 }).decode(await S(e));
854
+ return new TextDecoder("utf-8", { fatal: !0 }).decode(await C(e));
820
855
  } catch (e) {
821
- throw e instanceof a ? e : K("A field value read from a file or stdin must be UTF-8 text.");
856
+ throw e instanceof a ? e : q("A field value read from a file or stdin must be UTF-8 text.");
822
857
  }
823
- }, w = await te(r, {
824
- readFile: C,
825
- readStdin: () => C("-"),
826
- fill: (e) => ce(e, !1)
827
- }), [E = "", D = ""] = (() => {
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
- })(), 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 = {};
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 K("A header is written name:value.");
836
- M[e.slice(0, t).trim()] = e.slice(t + 1).trim();
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 (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));
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 K("The request body is not valid JSON; set a content-type with -H to send it anyway.");
876
+ throw q("The request body is not valid JSON; set a content-type with -H to send it anyway.");
842
877
  }
843
- let fe = async (e) => {
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
- }, N = await oe(), P = (e) => {
886
+ }, P = await ae(), F = (e) => {
852
887
  if (!o.verbose) return;
853
- let n = new URL(`${k(N.controller)}/api/v1${e}`);
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 N.credentialLines) t.err(e);
856
- for (let [e, n] of Object.entries(M)) {
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}: ${le.has(r) ? "[redacted]" : n}`);
893
+ t.err(`> ${r}: ${ce.has(r) ? "[redacted]" : n}`);
859
894
  }
860
895
  o.idempotencyKey && t.err(`> idempotency-key: ${o.idempotencyKey}`);
861
- }, F = (e) => {
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
- }, pe = (e) => `${de}${e.length ? `?${new URLSearchParams(e)}` : ""}`, I = (e, t) => (P(pe(e)), N.raw(h, de, {
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: j,
869
- headers: M,
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 I(A), r = e.body;
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
- F(e), o.include && t.out([
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 fe(r));
934
+ ].join("\n")), !o.silent && r.length > 0 && t.out(await de(r));
900
935
  return;
901
936
  }
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);
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 I(he, z.signal);
944
+ e = await L(me, B.signal);
910
945
  } catch (e) {
911
- throw z.signal.aborted ? new T("timeout", "--paginate took longer than 5 minutes; stopped.") : e;
946
+ throw B.signal.aborted ? new E("timeout", "--paginate took longer than 5 minutes; stopped.") : e;
912
947
  }
913
- F(e);
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 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.");
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 (me.has(n) || L.length >= Ye) throw K("The controller's paging did not end; stopped.");
926
- me.add(n), he = e.next;
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(_e);
964
+ clearTimeout(ge);
930
965
  }
931
966
  if (!o.silent) {
932
- let e = o.slurp ? `[${L.map((e) => `[${e.join(",")}]`).join(",")}]` : `[${L.flat().join(",")}]`;
933
- t.out(await fe(e));
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 b(t, {
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
- v(t.confirm);
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 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);
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 ne(d), { client: h, organizationId: ee } = await c(u), te = new Blob([new Uint8Array(m.archive)]);
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
- v(t.confirm);
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
- v(n.confirm);
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
- v(t.confirm);
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 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"}.`);
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 ut(e, t) {
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 dt(e) {
1025
- if (!D.includes(e)) throw q(`--role must be one of ${D.join(", ")}.`);
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 ft(e, t = []) {
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 pt = "Use the organization's ID: find it in the dashboard or with `launchpad api --session organizations`.";
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 && v(r.confirm), n.validate?.();
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 re(a.workingDir ?? process.cwd());
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 && !Y(c.value)) throw q(`${c.source} must be an organization ID (a UUID), not a slug. ${pt}`);
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 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}`);
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 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(", ")})`), {
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 = G(e.to, "--to"), a = dt(e.role);
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(J("List the organization's pending invitations (owner or admin).", "GET /organizations/:org/invitations")), {
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(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"), {
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 lt(e, "invitation-id", !0)
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), ht = "The key may exist: run \"launchpad key list\" and revoke it.";
1155
- function gt(e, t) {
1156
- return e instanceof C ? new C({
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} ${ht}`,
1194
+ title: `${e.title} ${gt}`,
1160
1195
  retryAfterSeconds: e.retryAfterSeconds ?? void 0
1161
- }) : e instanceof T ? new T(e.reason, `${e.message} ${ht}`) : (t.err(ht), e);
1196
+ }) : e instanceof E ? new E(e.reason, `${e.message} ${gt}`) : (t.err(gt), e);
1162
1197
  }
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")), {
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(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"), {
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 (${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).");
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 T("invalid-response", "The controller's answer had no secret.");
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 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);
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(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"), {
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 lt(e, "key-id", !0)
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 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"), {
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 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");
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(J("List the organization's members; their user IDs are what `member remove` takes.", "GET /organizations/:org/members")), {
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(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(", ")})`), {
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 = G(e.userEmail, "--user-email"), i = dt(e.role);
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(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"), {
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 lt(e, "user-id", !1)
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 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);
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 Ct(e, t, n) {
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 O({
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 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.`));
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 wt(e, t) {
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 x(V.usage, "commander.interactiveStdin", "error: --key-stdin requires redirected input; omit it to use the hidden terminal prompt");
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 x(V.usage, "commander.missingKey", "error: provide the key with --key-file <path> or --key-stdin, or run in a terminal");
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 x(V.usage, "commander.emptyKey", "error: the API key is empty");
1443
+ if (!r) throw new S(H.usage, "commander.emptyKey", "error: the API key is empty");
1409
1444
  return r;
1410
1445
  }
1411
- function Tt(e, t = /* @__PURE__ */ new Set()) {
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(y(t, n())),
1429
- err: (t) => e.err(y(t, n())),
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 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({
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 x(V.usage, "commander.mixedLogin", "error: --session cannot be combined with --key-file or --key-stdin");
1445
- return St(r, {
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 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, {
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 Ct(r, {
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 x(V.usage, "commander.needsSession", `error: ${t} needs --session`);
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 se(r.context, o(t).profile);
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 oe(r.context, e);
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 ae(r.context, e, o(n).profile);
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), bt(a, l, {
1569
+ }), at(a, r, i), xt(a, l, {
1535
1570
  io: r,
1536
1571
  remember: i
1537
- }, o), mt(a, {
1572
+ }, o), ht(a, {
1538
1573
  io: r,
1539
1574
  remember: i
1540
- }, o), vt(a, {
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 Et(e, t) {
1546
- let n = /* @__PURE__ */ new Set(), r = Tt(t, n);
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" }), V.ok;
1583
+ return await r.parseAsync(e, { from: "user" }), H.ok;
1549
1584
  } 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: {
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 Et(process.argv.slice(2), ve());
1596
+ process.exitCode = await Dt(process.argv.slice(2), _e());