@theholocron/cli 5.0.0-alpha.344 → 5.0.0-alpha.345

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/README.md CHANGED
@@ -679,7 +679,7 @@ holocron auth list # show all stored providers
679
679
  holocron auth export # tokens as NAME=value lines in a private .credentials, to import into a credentials environment
680
680
  holocron auth export --only HOLOCRON_SENTRY_TOKEN # one token, to the clipboard
681
681
  holocron auth export --blank --vendor-names --file --only VERCEL_TOKEN --only HOLOCRON_RELEASE_TOKEN # the stored ones filled, the rest empty
682
- holocron github-app create --name "My App - dev" --webhook-url https://<tunnel>/api/webhook --manifest apps/sentinel/github-app.manifest.json # a GitHub App from a manifest; its id, key and webhook secret to a private .credentials
682
+ holocron github-app create --name "My App - dev" --webhook-url https://<tunnel>/api/webhook --manifest apps/sentinel/github-app.manifest.json # a GitHub App from a manifest (the flow is in @theholocron/dagobah); its id, key and webhook secret to a private .credentials
683
683
  holocron tunnel up --name sentinel-dev --hostname sentinel-dev.example.dev --port 3000 --run # a named tunnel with a stable hostname to a local port
684
684
  holocron project list # the org's project boards (also: create [template], close <number-or-name>, setup)
685
685
  holocron project move v4 v5 --dry-run # preview carrying the open items of one project board to another; without --dry-run it asks first (--yes skips)
package/dist/cli.mjs CHANGED
@@ -28,7 +28,7 @@ import { Separator, checkbox, confirm, input, select } from "@inquirer/prompts";
28
28
  import { execFileSync, spawn, spawnSync } from "node:child_process";
29
29
  import { stringifyJson } from "@theholocron/json-utils";
30
30
  import { findRootSync, isWorkspaceRoot, walkFilesSync } from "@theholocron/fs-utils";
31
- import { serveHandler, superviseProcesses } from "@theholocron/dagobah";
31
+ import { appManifestPage, buildAppManifest, convertAppManifest, serveAppManifest, serveHandler, superviseProcesses } from "@theholocron/dagobah";
32
32
  import { access, copyFile, lstat, mkdir, open, readFile, readdir, realpath, rename, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
33
33
  import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
34
34
  import { createServer } from "node:http";
@@ -8308,7 +8308,7 @@ const FIELD_TYPES = [
8308
8308
  "iteration"
8309
8309
  ];
8310
8310
  const LAYOUTS = ["board", "table"];
8311
- function isRecord$1(value) {
8311
+ function isRecord(value) {
8312
8312
  return typeof value === "object" && value !== null && !Array.isArray(value);
8313
8313
  }
8314
8314
  function isText(value) {
@@ -8321,7 +8321,7 @@ function namedList(label, value, check) {
8321
8321
  const seen = /* @__PURE__ */ new Set();
8322
8322
  value.forEach((entry, i) => {
8323
8323
  const where = `${label}[${i}]`;
8324
- if (!isRecord$1(entry)) {
8324
+ if (!isRecord(entry)) {
8325
8325
  problems.push(`${where} must be an object`);
8326
8326
  return;
8327
8327
  }
@@ -8338,7 +8338,7 @@ function namedList(label, value, check) {
8338
8338
  * status, the fields and the views). Returns the file typed, or every problem found, so one run lists them all.
8339
8339
  */
8340
8340
  function validateTemplateFile(value) {
8341
- if (!isRecord$1(value)) return {
8341
+ if (!isRecord(value)) return {
8342
8342
  ok: false,
8343
8343
  problems: ["a template must be an object"]
8344
8344
  };
@@ -8357,7 +8357,7 @@ function validateTemplateFile(value) {
8357
8357
  if (value.views !== void 0) problems.push(...namedList("views", value.views, (v, where) => typeof v.layout === "string" && LAYOUTS.includes(v.layout) ? [] : [`${where} needs a layout: ${LAYOUTS.join(", ")}`]));
8358
8358
  if (value.extends === void 0) {
8359
8359
  if (!Array.isArray(value.statuses) || value.statuses.length === 0) problems.push("a template without extends must list its statuses");
8360
- else if (!value.statuses.some((s) => isRecord$1(s) && s.category === "done")) problems.push("statuses need one in the done category");
8360
+ else if (!value.statuses.some((s) => isRecord(s) && s.category === "done")) problems.push("statuses need one in the done category");
8361
8361
  if (value.fields === void 0) problems.push("a template without extends must list its fields (an empty list is fine)");
8362
8362
  if (!Array.isArray(value.views) || value.views.length === 0) problems.push("a template without extends must list its views");
8363
8363
  }
@@ -10355,142 +10355,6 @@ const doctorCommand = {
10355
10355
  })).summary.fail > 0) process.exitCode = 1;
10356
10356
  }
10357
10357
  };
10358
- // src/commands/app-manifest-page/app-manifest-page.ts
10359
- const ESCAPES = {
10360
- "&": "&amp;",
10361
- "<": "&lt;",
10362
- ">": "&gt;",
10363
- "\"": "&quot;",
10364
- "'": "&#39;"
10365
- };
10366
- const escapeHtml = (text) => text.replace(/[&<>"']/g, (c) => ESCAPES[c]);
10367
- /**
10368
- * The page the local server shows: a form that posts the manifest to GitHub on load (the manifest flow takes a form
10369
- * post, not a link), with a button for a browser that blocks the script.
10370
- */
10371
- function appManifestPage(action, manifest) {
10372
- return `<!doctype html>
10373
- <html lang="en">
10374
- <head><meta charset="utf-8"><title>Create ${escapeHtml(manifest.name)}</title></head>
10375
- <body>
10376
- <form id="form" method="post" action="${escapeHtml(action)}">
10377
- <input type="hidden" name="manifest" value="${escapeHtml(JSON.stringify(manifest))}">
10378
- <p>Sending the manifest to GitHub. If nothing happens, <button type="submit">continue</button>.</p>
10379
- </form>
10380
- <script>document.getElementById("form").submit();<\/script>
10381
- </body>
10382
- </html>
10383
- `;
10384
- }
10385
- // src/commands/build-app-manifest/build-app-manifest.ts
10386
- const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
10387
- /**
10388
- * The manifest to post to GitHub: the shared part read from a file, with this instance's name, webhook and redirect.
10389
- * Throws a message that names the problem when the file or the webhook URL is not usable, so nothing reaches GitHub.
10390
- */
10391
- function buildAppManifest(input) {
10392
- const { base } = input;
10393
- if (!isRecord(base)) throw new Error("the manifest file must hold a JSON object");
10394
- const permissions = base["default_permissions"];
10395
- if (!isRecord(permissions) || !Object.values(permissions).every((access) => typeof access === "string")) throw new Error("the manifest file needs a default_permissions object of permission name to access");
10396
- const events = base["default_events"];
10397
- if (!Array.isArray(events) || !events.every((event) => typeof event === "string")) throw new Error("the manifest file needs a default_events list of event names");
10398
- let webhook;
10399
- try {
10400
- webhook = new URL(input.webhookUrl);
10401
- } catch {
10402
- throw new Error(`the webhook URL is not a URL: ${input.webhookUrl}`);
10403
- }
10404
- if (webhook.protocol !== "https:") throw new Error("the webhook URL must be https: GitHub only delivers to one");
10405
- return {
10406
- name: input.name,
10407
- ...typeof base["description"] === "string" ? { description: base["description"] } : {},
10408
- ...typeof base["url"] === "string" ? { url: base["url"] } : {},
10409
- public: base["public"] === true,
10410
- redirect_url: input.redirectUrl,
10411
- hook_attributes: {
10412
- url: webhook.href,
10413
- active: true
10414
- },
10415
- default_permissions: permissions,
10416
- default_events: events
10417
- };
10418
- }
10419
- // src/commands/convert-app-manifest/convert-app-manifest.ts
10420
- /**
10421
- * Exchanges the one-time code from the manifest flow for the App's id, private key and webhook secret
10422
- * (`POST /app-manifests/{code}/conversions`, which takes no token). The code works once, and GitHub shows the key
10423
- * once. An error names the status, never the body: the body of a success is the secrets.
10424
- */
10425
- async function convertAppManifest(code, fetchImpl = fetch) {
10426
- const response = await fetchImpl(`https://api.github.com/app-manifests/${encodeURIComponent(code)}/conversions`, {
10427
- method: "POST",
10428
- headers: {
10429
- accept: "application/vnd.github+json",
10430
- "x-github-api-version": "2022-11-28"
10431
- }
10432
- });
10433
- if (!response.ok) throw new Error(`GitHub did not convert the manifest (HTTP ${response.status})`);
10434
- const { id, slug, html_url: htmlUrl, pem, webhook_secret: webhookSecret } = await response.json();
10435
- if (typeof id !== "number" || typeof slug !== "string" || typeof htmlUrl !== "string" || typeof pem !== "string" || typeof webhookSecret !== "string") throw new Error("GitHub's answer did not hold the App id, private key and webhook secret");
10436
- return {
10437
- id,
10438
- slug,
10439
- htmlUrl,
10440
- pem,
10441
- webhookSecret
10442
- };
10443
- }
10444
- // src/commands/serve-app-manifest/serve-app-manifest.ts
10445
- const LOOPBACK = "127.0.0.1";
10446
- const FIVE_MINUTES = 3e5;
10447
- /**
10448
- * A one-shot server on a random loopback port: `/` shows the page that posts the manifest to GitHub, `/callback` takes
10449
- * the one-time code GitHub redirects back with. The code is only accepted with the `state` it was started with, and a
10450
- * request that does not name this server's own address (a DNS-rebinding page) is refused.
10451
- */
10452
- async function serveAppManifest(input) {
10453
- let resolveCode;
10454
- let rejectCode;
10455
- const code = new Promise((resolve, reject) => {
10456
- resolveCode = resolve;
10457
- rejectCode = reject;
10458
- });
10459
- code.catch(() => {});
10460
- const server = createServer((req, res) => {
10461
- const reply = (status, type, body) => {
10462
- res.writeHead(status, {
10463
- "content-type": `${type}; charset=utf-8`,
10464
- "cache-control": "no-store"
10465
- });
10466
- res.end(body);
10467
- };
10468
- const { port } = server.address();
10469
- if (req.headers.host !== `${LOOPBACK}:${port}`) return reply(403, "text/plain", "forbidden");
10470
- const url = new URL(req.url, `http://${LOOPBACK}:${port}`);
10471
- if (url.pathname === "/") return reply(200, "text/html", input.page(`http://${LOOPBACK}:${port}/callback`));
10472
- if (url.pathname === "/callback") {
10473
- const got = url.searchParams.get("code");
10474
- if (url.searchParams.get("state") !== input.state || !got) return reply(400, "text/plain", "bad request");
10475
- reply(200, "text/plain", "Done. You can close this tab and go back to the terminal.");
10476
- resolveCode(got);
10477
- return;
10478
- }
10479
- reply(404, "text/plain", "not found");
10480
- });
10481
- await new Promise((resolve) => server.listen(0, LOOPBACK, resolve));
10482
- const timer = setTimeout(() => rejectCode(/* @__PURE__ */ new Error("timed out waiting for GitHub: the App was not created")), input.timeoutMs ?? FIVE_MINUTES);
10483
- const close = () => {
10484
- clearTimeout(timer);
10485
- server.close();
10486
- server.closeAllConnections();
10487
- };
10488
- return {
10489
- url: `http://${LOOPBACK}:${server.address().port}/`,
10490
- code,
10491
- close
10492
- };
10493
- }
10494
10358
  // src/commands/github-app-create/github-app-create.ts
10495
10359
  /**
10496
10360
  * `holocron github-app create` — create a GitHub App from a manifest (GitHub's manifest flow), and keep its