@theholocron/holocron-plugin-cloudflare 5.0.0-alpha.426 → 5.0.0-alpha.427

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/dist/index.mjs +71 -40
  2. package/package.json +7 -7
package/dist/index.mjs CHANGED
@@ -452,39 +452,39 @@ async function reach(read, noun) {
452
452
  }
453
453
  }
454
454
  /**
455
- * Reports an outcome. With no rule it only describes (`ok` for access, `info` for none). With the layer's rule it judges:
456
- * a required permission that is missing fails, and a permission the layer must not have fails when the token has it.
455
+ * One row for what was tried. With no rule it only describes (`ok` for access, `info` for none). Under a layer's rule it
456
+ * judges: a required permission the token lacks fails, and one the layer must not have fails when the token has it; a
457
+ * permission that is rightly absent is a bare `ok`.
457
458
  */
458
- function report(probe, label, outcome, rule, layer) {
459
- if (outcome.kind === "error") return probe.say({
459
+ function rowFor({ label, outcome }, rule) {
460
+ if (outcome.kind === "error") return {
460
461
  status: "fail",
461
462
  label,
462
463
  detail: outcome.detail
463
- });
464
+ };
464
465
  const has = outcome.kind === "has";
465
- if (rule === "required") return probe.say(has ? {
466
+ if (rule === "required") return has ? {
466
467
  status: "ok",
467
468
  label,
468
469
  detail: outcome.detail
469
470
  } : {
470
471
  status: "fail",
471
472
  label,
472
- detail: `${outcome.detail}; the ${layer} token needs it`
473
- });
474
- if (rule === "absent") return probe.say(has ? {
473
+ detail: outcome.detail
474
+ };
475
+ if (rule === "absent") return has ? {
475
476
  status: "fail",
476
477
  label,
477
- detail: `${outcome.detail}; the ${layer} token must not have it`
478
+ detail: outcome.detail
478
479
  } : {
479
480
  status: "ok",
480
- label,
481
- detail: `not present, as the ${layer} token should be`
482
- });
483
- probe.say({
481
+ label
482
+ };
483
+ return {
484
484
  status: has ? "ok" : "info",
485
485
  label,
486
486
  detail: outcome.detail
487
- });
487
+ };
488
488
  }
489
489
  /**
490
490
  * The `token` probe: tries each permission Holocron uses with the Cloudflare API token and reports which ones the token
@@ -492,8 +492,9 @@ function report(probe, label, outcome, rule, layer) {
492
492
  * `--token cloudflare=<token>` or `--environment <layer>` checks another one; the account id is the plugin's own.
493
493
  *
494
494
  * A token with no layer is only described. When the CLI passes `--layer` (because `--environment` named `ci`, `dev` or
495
- * `local`), the same results are judged against what that layer's token is meant to carry (`EXPECTED_BY_LAYER`), and a
496
- * missing or extra permission fails. The other words limit the zone checks to those zones; otherwise up to five are read.
495
+ * `local`), the results are judged against what that layer's token is meant to carry (`EXPECTED_BY_LAYER`) and shown in
496
+ * two groups, what it should have and what it should not, where a missing or extra permission fails. The other words
497
+ * limit the zone checks to those zones; otherwise up to five are read. How the token is chosen is in `holocron probe --help`.
497
498
  */
498
499
  function tokenProbe(ctx) {
499
500
  return {
@@ -506,11 +507,10 @@ function tokenProbe(ctx) {
506
507
  const client = ctx.client();
507
508
  const { layer, zones: wanted } = parseTokenArgs(probe.args ?? []);
508
509
  const rules = layer ? EXPECTED_BY_LAYER[layer] : void 0;
509
- const ruleFor = (permission) => rules?.[permission];
510
- if (layer) probe.say({
510
+ if (layer && !rules) probe.say({
511
511
  status: "info",
512
512
  label: layer,
513
- detail: rules ? `checking against what the ${layer} token should carry (docs: tokens, what each Cloudflare token needs)` : `no expectations are declared for ${layer}, so the token is only described`
513
+ detail: "no expectations are declared for it, so the token is only described"
514
514
  });
515
515
  try {
516
516
  const verified = await client.tokens.verify();
@@ -519,36 +519,67 @@ function tokenProbe(ctx) {
519
519
  label: "token",
520
520
  detail: `${verified.id} (${verified.status})`
521
521
  });
522
- } catch {
523
- probe.say({
524
- status: "info",
525
- label: "token",
526
- detail: "not a user-level token, so it is judged by what it can reach below"
527
- });
528
- }
522
+ } catch {}
523
+ const tried = [];
529
524
  let zones = [];
530
525
  const zoneOutcome = await reach(async () => {
531
526
  zones = wanted.length > 0 ? (await Promise.all(wanted.map((name) => client.zones.list({ name })))).flat() : await client.zones.list({ per_page: MAX_ZONES });
532
527
  return zones.map((z) => ({ name: z.name }));
533
528
  }, "zones");
534
- report(probe, "Zone: Read", zoneOutcome, ruleFor("zone"), layer);
535
- if (zoneOutcome.kind === "error") return;
536
- for (const zone of zones.slice(0, MAX_ZONES)) {
537
- report(probe, `DNS: Edit (${zone.name})`, await reach(() => client.dns.list(zone.id), "records"), ruleFor("dns"), layer);
538
- report(probe, `Workers Routes: Edit (${zone.name})`, await reach(async () => (await client.workers.listRoutes(zone.id)).map((r) => ({ name: r.pattern })), "routes"), ruleFor("routes"), layer);
539
- }
540
- const account = ctx.options.accountId;
541
- if (!account) {
542
- probe.say({
543
- status: layer && rules ? "fail" : "info",
529
+ tried.push({
530
+ label: "Zone: Read",
531
+ permission: "zone",
532
+ outcome: zoneOutcome
533
+ });
534
+ if (zoneOutcome.kind !== "error") {
535
+ for (const zone of zones.slice(0, MAX_ZONES)) {
536
+ tried.push({
537
+ label: `DNS: Edit (${zone.name})`,
538
+ permission: "dns",
539
+ outcome: await reach(() => client.dns.list(zone.id), "records")
540
+ });
541
+ tried.push({
542
+ label: `Workers Routes: Edit (${zone.name})`,
543
+ permission: "routes",
544
+ outcome: await reach(async () => (await client.workers.listRoutes(zone.id)).map((r) => ({ name: r.pattern })), "routes")
545
+ });
546
+ }
547
+ const account = ctx.options.accountId;
548
+ if (account) {
549
+ tried.push({
550
+ label: "Workers Scripts: Edit",
551
+ permission: "scripts",
552
+ outcome: await reach(async () => (await client.workers.listScripts(account)).map((s) => ({ name: s.id })), "scripts")
553
+ });
554
+ tried.push({
555
+ label: "Pages: Edit",
556
+ permission: "pages",
557
+ outcome: await reach(() => client.pages.listProjects(account), "projects")
558
+ });
559
+ tried.push({
560
+ label: "Cloudflare Tunnel: Edit",
561
+ permission: "tunnels",
562
+ outcome: await reach(() => client.tunnels.list(account), "tunnels")
563
+ });
564
+ } else probe.say({
565
+ status: rules ? "fail" : "info",
544
566
  label: "account permissions",
545
567
  detail: "no account id: set HOLOCRON_CLOUDFLARE_ACCOUNT_ID or the plugin's accountId option to check them"
546
568
  });
569
+ }
570
+ if (!rules) {
571
+ for (const t of tried) probe.say(rowFor(t, void 0));
547
572
  return;
548
573
  }
549
- report(probe, "Workers Scripts: Edit", await reach(async () => (await client.workers.listScripts(account)).map((s) => ({ name: s.id })), "scripts"), ruleFor("scripts"), layer);
550
- report(probe, "Pages: Edit", await reach(() => client.pages.listProjects(account), "projects"), ruleFor("pages"), layer);
551
- report(probe, "Cloudflare Tunnel: Edit", await reach(() => client.tunnels.list(account), "tunnels"), ruleFor("tunnels"), layer);
574
+ for (const [heading, rule] of [["Should have", "required"], ["Should not have", "absent"]]) {
575
+ const inGroup = tried.filter((t) => rules[t.permission] === rule);
576
+ if (inGroup.length === 0) continue;
577
+ probe.say({
578
+ status: "heading",
579
+ label: heading
580
+ });
581
+ for (const t of inGroup) probe.say(rowFor(t, rule));
582
+ }
552
583
  }
553
584
  };
554
585
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-cloudflare",
3
- "version": "5.0.0-alpha.426",
3
+ "version": "5.0.0-alpha.427",
4
4
  "description": "Holocron plugin for Cloudflare. Implements the dns capability against Cloudflare's REST API — zone resolution, DNS record management.",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -45,19 +45,19 @@
45
45
  "typescript": "^5.9.3",
46
46
  "vitest": "^5.1.0",
47
47
  "@theholocron/cloudflare-client": "^1.58.0-alpha.29",
48
+ "@theholocron/cli": "5.0.0-alpha.427",
49
+ "@theholocron/eslint-config": "^8.9.0-alpha.17",
48
50
  "@theholocron/http-client": "^1.58.0-alpha.29",
51
+ "@theholocron/kyber": "5.0.0-alpha.427",
49
52
  "@theholocron/tsconfig": "^8.9.0-alpha.17",
50
- "@theholocron/eslint-config": "^8.9.0-alpha.17",
51
- "@theholocron/misc-utils": "^1.17.0-alpha.4",
52
- "@theholocron/tsdown-config": "^8.9.0-alpha.17",
53
- "@theholocron/kyber": "5.0.0-alpha.426",
54
53
  "@theholocron/vitest-config": "^8.9.0-alpha.17",
55
- "@theholocron/cli": "5.0.0-alpha.426"
54
+ "@theholocron/tsdown-config": "^8.9.0-alpha.17",
55
+ "@theholocron/misc-utils": "^1.17.0-alpha.4"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@theholocron/cloudflare-client": "^1.53.1",
59
59
  "@theholocron/misc-utils": "^1.16.0",
60
- "@theholocron/cli": "5.0.0-alpha.426"
60
+ "@theholocron/cli": "5.0.0-alpha.427"
61
61
  },
62
62
  "peerDependenciesMeta": {
63
63
  "@theholocron/cloudflare-client": {}