@theholocron/holocron-plugin-cloudflare 5.0.0-alpha.433 → 5.0.0-alpha.435

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 +39 -15
  2. package/package.json +8 -8
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { AuthError, ProviderApiError, connectionProbe, createResolveToken, resolveValue, tokenExpectations } from "@theholocron/cli";
1
+ import { AuthError, DEFAULT_TOKEN_ROTATION, ProviderApiError, connectionProbe, createResolveToken, resolveValue, tokenExpectations, tokenRotationRows } from "@theholocron/cli";
2
2
  import { PREFIX } from "@theholocron/env-utils/lookup";
3
3
  import { errorMessage } from "@theholocron/misc-utils";
4
4
  import { createCloudflareClient } from "@theholocron/cloudflare-client";
@@ -18,18 +18,24 @@ const EVERYTHING = {
18
18
  * token is only reported. This is the plugin's `tokens` declaration, read through `tokenExpectations()`; change it and
19
19
  * that table together.
20
20
  */
21
- const EXPECTED = { permissions: {
22
- local: EVERYTHING,
23
- dev: EVERYTHING,
24
- ci: {
25
- zone: "absent",
26
- dns: "absent",
27
- routes: "absent",
28
- scripts: "absent",
29
- pages: "required",
30
- tunnels: "absent"
31
- }
32
- } };
21
+ const EXPECTED = {
22
+ rotation: {
23
+ maxAgeDays: 90,
24
+ warnDays: 14
25
+ },
26
+ permissions: {
27
+ local: EVERYTHING,
28
+ dev: EVERYTHING,
29
+ ci: {
30
+ zone: "absent",
31
+ dns: "absent",
32
+ routes: "absent",
33
+ scripts: "absent",
34
+ pages: "required",
35
+ tunnels: "absent"
36
+ }
37
+ }
38
+ };
33
39
  // src/auth.ts
34
40
  /** Resolves the Cloudflare API token from `--token`, `HOLOCRON_CLOUDFLARE_TOKEN`, `CLOUDFLARE_API_TOKEN` or the keyring, and throws an `AuthError` when none is set. */
35
41
  const resolveToken = createResolveToken({
@@ -511,15 +517,19 @@ function tokenProbe(ctx) {
511
517
  probe.secret(token);
512
518
  const client = ctx.client();
513
519
  const { layer, tokenName, zones: wanted } = parseTokenArgs(probe.args ?? []);
514
- const rules = layer ? tokenExpectations(tokens, {
520
+ const expectation = layer ? tokenExpectations(tokens, {
515
521
  layer,
516
522
  ...tokenName ? { envName: tokenName } : {}
517
- })[0]?.rules : void 0;
523
+ })[0] : void 0;
524
+ const rules = expectation?.rules;
518
525
  if (layer && !rules) probe.say({
519
526
  status: "info",
520
527
  label: layer,
521
528
  detail: "no expectations are declared for it, so the token is only described"
522
529
  });
530
+ const now = (ctx.now ?? (() => /* @__PURE__ */ new Date()))();
531
+ const rotation = expectation?.rotation ?? DEFAULT_TOKEN_ROTATION;
532
+ let lifetime;
523
533
  try {
524
534
  const verified = await client.tokens.verify();
525
535
  probe.say({
@@ -527,7 +537,19 @@ function tokenProbe(ctx) {
527
537
  label: "token",
528
538
  detail: `${verified.id} (${verified.status})`
529
539
  });
540
+ lifetime = {
541
+ ...verified.not_before ? { createdAt: verified.not_before } : {},
542
+ ...verified.expires_on ? { expiresAt: verified.expires_on } : {}
543
+ };
530
544
  } catch {}
545
+ const rotationRows = tokenRotationRows(lifetime, rotation, now);
546
+ const sayRotation = () => {
547
+ probe.say({
548
+ status: "heading",
549
+ label: "Rotation"
550
+ });
551
+ for (const row of rotationRows) probe.say(row);
552
+ };
531
553
  const tried = [];
532
554
  let zones = [];
533
555
  const zoneOutcome = await reach(async () => {
@@ -577,6 +599,7 @@ function tokenProbe(ctx) {
577
599
  }
578
600
  if (!rules) {
579
601
  for (const t of tried) probe.say(rowFor(t, void 0));
602
+ sayRotation();
580
603
  return;
581
604
  }
582
605
  for (const [heading, rule] of [["Should have", "required"], ["Should not have", "absent"]]) {
@@ -588,6 +611,7 @@ function tokenProbe(ctx) {
588
611
  });
589
612
  for (const t of inGroup) probe.say(rowFor(t, rule));
590
613
  }
614
+ sayRotation();
591
615
  }
592
616
  };
593
617
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-cloudflare",
3
- "version": "5.0.0-alpha.433",
3
+ "version": "5.0.0-alpha.435",
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",
@@ -44,20 +44,20 @@
44
44
  "tsx": "4.23.15",
45
45
  "typescript": "^5.9.3",
46
46
  "vitest": "^5.1.0",
47
+ "@theholocron/cloudflare-client": "^1.58.0-alpha.31",
47
48
  "@theholocron/eslint-config": "^8.9.0-alpha.17",
48
- "@theholocron/cli": "5.0.0-alpha.433",
49
- "@theholocron/http-client": "^1.58.0-alpha.29",
49
+ "@theholocron/cli": "5.0.0-alpha.435",
50
+ "@theholocron/http-client": "^1.58.0-alpha.31",
51
+ "@theholocron/kyber": "5.0.0-alpha.435",
50
52
  "@theholocron/misc-utils": "^1.17.0-alpha.4",
51
- "@theholocron/cloudflare-client": "^1.58.0-alpha.29",
52
- "@theholocron/kyber": "5.0.0-alpha.433",
53
53
  "@theholocron/tsdown-config": "^8.9.0-alpha.17",
54
- "@theholocron/vitest-config": "^8.9.0-alpha.17",
55
- "@theholocron/tsconfig": "^8.9.0-alpha.17"
54
+ "@theholocron/tsconfig": "^8.9.0-alpha.17",
55
+ "@theholocron/vitest-config": "^8.9.0-alpha.17"
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.433"
60
+ "@theholocron/cli": "5.0.0-alpha.435"
61
61
  },
62
62
  "peerDependenciesMeta": {
63
63
  "@theholocron/cloudflare-client": {}