@tokenoftrust/cli 4.4.1 → 4.5.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "4.4.1",
3
+ "version": "4.5.0",
4
4
  "description": "Token of Trust developer CLI — clone a tenant store, run it locally with save→reload, and submit it for preview. Installs the `tot` command.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Token of Trust",
@@ -39,7 +39,7 @@ import { openBrowser } from "../open.mjs";
39
39
  import { missingGrantsOf, refusalHint } from "../admission-hint.mjs";
40
40
  // Reuse `tot ship`'s operator-secret precedence + live-url derivation verbatim so
41
41
  // ship + hotfix speak ONE operator-auth contract.
42
- import { resolveOperatorSecret, liveUrlFor, normalizeLiveDrift } from "./ship.mjs";
42
+ import { resolveOperatorSecret, normalizeLiveDrift } from "./ship.mjs";
43
43
 
44
44
  const DEFAULT_STOREFRONT_URL = "https://storefront.tokenoftrust.store";
45
45
 
@@ -127,6 +127,7 @@ export function normalizeHotfixPlan(data) {
127
127
  bypassedPrs: Array.isArray(o.bypassedPrs) ? o.bypassedPrs : [],
128
128
  rollbackTarget: o.rollbackTarget && typeof o.rollbackTarget === "object" ? o.rollbackTarget : null,
129
129
  warning: normalizeLiveDrift(o.warning),
130
+ liveUrl: typeof o.liveUrl === "string" && o.liveUrl ? o.liveUrl : null,
130
131
  paywall:
131
132
  o.paywall && typeof o.paywall === "object"
132
133
  ? { allowed: o.paywall.allowed === true, message: typeof o.paywall.message === "string" ? o.paywall.message : null }
@@ -277,7 +278,7 @@ export async function runHotfix(
277
278
 
278
279
  // 2. Print the EXACT plan — including the unshipped preview work it BYPASSES —
279
280
  // then require ONE explicit confirm (default NO).
280
- const liveUrl = liveUrlFor(tenant);
281
+ const liveUrl = plan.liveUrl;
281
282
  const planLines = planForAction({
282
283
  action: "hotfix",
283
284
  tenant,
@@ -223,14 +223,6 @@ export async function pollChangeShipped(scoped, { id }, { attempts = 6, delayMs
223
223
  return last;
224
224
  }
225
225
 
226
- // ─── URL derivation (pure) ─────────────────────────────────────────────────────
227
-
228
- /** The live site URL for a tenant (the tenant IS its apex domain, e.g. tokenoftrust.com). Pure. */
229
- export function liveUrlFor(tenant) {
230
- const t = (tenant || "").trim();
231
- return t ? `https://${t}` : null;
232
- }
233
-
234
226
  // ─── Response normalisation (defensive — one endpoint, but shapes may vary) ─────
235
227
 
236
228
  /**
@@ -242,7 +234,8 @@ export function liveUrlFor(tenant) {
242
234
  * includedPrs:Array<{prNumber?:number|null,changeId?:string|null,headSha?:string|null}>,
243
235
  * integrationRunId:string|null, receiptId:string|null,
244
236
  * rollbackTarget:{receiptId:string,aggregateSha:string,artifactDigest?:string}|null,
245
- * paywall:{allowed:boolean,message:string|null}, alreadyShipped:boolean} |
237
+ * paywall:{allowed:boolean,message:string|null}, alreadyShipped:boolean,
238
+ * provedAt:string|null, liveUrl:string|null} |
246
239
  * {ok:false, reason:string, message:string}}
247
240
  */
248
241
  /** The plan CDN drift warning, or null when the ledger and the CDN name the same release. */
@@ -283,6 +276,8 @@ export function normalizeShipPlan(data) {
283
276
  }
284
277
  : { allowed: true, message: null },
285
278
  alreadyShipped: o.alreadyShipped === true,
279
+ provedAt: typeof o.provedAt === "string" && o.provedAt ? o.provedAt : null,
280
+ liveUrl: typeof o.liveUrl === "string" && o.liveUrl ? o.liveUrl : null,
286
281
  };
287
282
  }
288
283
  return {
@@ -553,9 +548,22 @@ export async function runShip(
553
548
  return 1;
554
549
  }
555
550
 
551
+ // The pinned release is already what live serves and nothing else is pending: there is nothing
552
+ // to confirm or POST. A CDN-drift warning means live is not what the ledger says, so that
553
+ // still goes through the plan.
554
+ if (plan.ok && plan.alreadyShipped && !plan.warning && !spaces.ready.length) {
555
+ const detail = [
556
+ plan.receiptId ? `receipt ${plan.receiptId}` : null,
557
+ plan.provedAt ? `proved ${plan.provedAt}` : null,
558
+ ].filter(Boolean).join(", ");
559
+ console.log(` Already live: ${plan.pinnedSha}${detail ? ` (${detail})` : ""} — nothing to ship`);
560
+ return 0;
561
+ }
562
+
556
563
  // 2. Print the EXACT plan via the shared affordance, then require ONE
557
564
  // explicit confirm (`--yes` non-interactive; a non-TTY without it refuses).
558
- const liveUrl = liveUrlFor(tenant);
565
+ // The live URL is the server's served truth; the client derives none.
566
+ const liveUrl = plan.ok ? plan.liveUrl : null;
559
567
  const planLines = plan.ok
560
568
  ? planForAction({
561
569
  action: "ship",
@@ -68,6 +68,9 @@ export interface NicotineWarningPresentation {
68
68
  textTransform: "uppercase" | "none";
69
69
  fontWeight: number;
70
70
  fontSizePx: number;
71
+ borderWidthPx?: number;
72
+ paddingYPx?: number;
73
+ letterSpacingPx?: number;
71
74
  }
72
75
  export interface ResolvedNicotineWarning {
73
76
  enabled: boolean;
@@ -79,6 +82,8 @@ export interface ResolvedNicotineWarning {
79
82
  export const NICOTINE_WARNING_TEXT: string;
80
83
  export const CONSPICUITY_FLOOR: Readonly<{ contrast: number; fontSizePx: number; fontWeight: number }>;
81
84
  export const DEFAULT_NICOTINE_WARNING_PRESET: string;
85
+ export const NICOTINE_WARNING_BOX_BOUNDS: Readonly<Record<"borderWidthPx" | "paddingYPx" | "letterSpacingPx", Readonly<{ min: number; max: number; integer: boolean }>>>;
86
+ export const MEDIUM_WEIGHT_REQUIREMENTS: Readonly<{ fontSizePx: number; contrast: number; borderWidthPx: number }>;
82
87
  export const NICOTINE_WARNING_PRESETS: Readonly<Record<string, Readonly<NicotineWarningPresentation>>>;
83
88
  export const NICOTINE_WARNING_KEYS: readonly string[];
84
89
  export const NICOTINE_WARNING_STYLE_KEYS: readonly string[];
@@ -782,6 +782,16 @@ export const CONSPICUITY_FLOOR = Object.freeze({ contrast: 7, fontSizePx: 12, fo
782
782
  /** Bounds on the size a custom style may declare, so the bar cannot swallow the header. */
783
783
  const MAX_FONT_SIZE_PX = 24;
784
784
 
785
+ /** Bounds on the optional box and spacing keys; an unset key renders the preset's own frame. */
786
+ export const NICOTINE_WARNING_BOX_BOUNDS = Object.freeze({
787
+ borderWidthPx: Object.freeze({ min: 0, max: 8, integer: true }),
788
+ paddingYPx: Object.freeze({ min: 0, max: 24, integer: true }),
789
+ letterSpacingPx: Object.freeze({ min: 0, max: 4, integer: false }),
790
+ });
791
+
792
+ /** Weight 500 is allowed only on a boxed bar that is at least this large, contrasty and bordered. */
793
+ export const MEDIUM_WEIGHT_REQUIREMENTS = Object.freeze({ fontSizePx: 16, contrast: 7, borderWidthPx: 2 });
794
+
785
795
  export const DEFAULT_NICOTINE_WARNING_PRESET = "dark";
786
796
 
787
797
  /**
@@ -816,6 +826,9 @@ export const NICOTINE_WARNING_PRESETS = Object.freeze({
816
826
  * textTransform: "uppercase" | "none",
817
827
  * fontWeight: number,
818
828
  * fontSizePx: number,
829
+ * borderWidthPx?: number,
830
+ * paddingYPx?: number,
831
+ * letterSpacingPx?: number,
819
832
  * }} NicotineWarningPresentation
820
833
  */
821
834
 
@@ -824,9 +837,10 @@ export const NICOTINE_WARNING_KEYS = Object.freeze(["preset", "style", "checkWid
824
837
 
825
838
  export const NICOTINE_WARNING_STYLE_KEYS = Object.freeze([
826
839
  "background", "text", "border", "textTransform", "fontWeight", "fontSizePx",
840
+ "borderWidthPx", "paddingYPx", "letterSpacingPx",
827
841
  ]);
828
842
  const TEXT_TRANSFORMS = ["uppercase", "none"];
829
- const FONT_WEIGHTS = [600, 700, 800, 900];
843
+ const FONT_WEIGHTS = [500, 600, 700, 800, 900];
830
844
  const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
831
845
 
832
846
  /** `#abc` / `#AABBCC` → `#aabbcc`. */
@@ -865,7 +879,15 @@ export function conspicuityProblems(p) {
865
879
  out.push(`font size ${p.fontSizePx}px is below the ${CONSPICUITY_FLOOR.fontSizePx}px floor`);
866
880
  }
867
881
  if (p.fontWeight < CONSPICUITY_FLOOR.fontWeight) {
868
- out.push(`font weight ${p.fontWeight} is below the ${CONSPICUITY_FLOOR.fontWeight} floor`);
882
+ const need = MEDIUM_WEIGHT_REQUIREMENTS;
883
+ const medium = p.fontWeight === 500 && p.fontSizePx >= need.fontSizePx && ratio >= need.contrast
884
+ && (p.borderWidthPx ?? 0) >= need.borderWidthPx;
885
+ if (!medium) {
886
+ out.push(`font weight ${p.fontWeight} is below the ${CONSPICUITY_FLOOR.fontWeight} floor` +
887
+ (p.fontWeight === 500
888
+ ? ` (500 needs font size >= ${need.fontSizePx}px, contrast >= ${need.contrast}:1 and borderWidthPx >= ${need.borderWidthPx})`
889
+ : ""));
890
+ }
869
891
  }
870
892
  return out;
871
893
  }
@@ -885,6 +907,14 @@ function styleValueProblem(key, value) {
885
907
  return typeof value === "number" && Number.isFinite(value) && value >= CONSPICUITY_FLOOR.fontSizePx && value <= MAX_FONT_SIZE_PX
886
908
  ? null
887
909
  : `\`fontSizePx\` must be a number from ${CONSPICUITY_FLOOR.fontSizePx} to ${MAX_FONT_SIZE_PX}`;
910
+ case "borderWidthPx":
911
+ case "paddingYPx":
912
+ case "letterSpacingPx": {
913
+ const { min, max, integer } = NICOTINE_WARNING_BOX_BOUNDS[key];
914
+ return typeof value === "number" && Number.isFinite(value) && value >= min && value <= max && (!integer || Number.isInteger(value))
915
+ ? null
916
+ : `\`${key}\` must be ${integer ? "a whole number" : "a number"} from ${min} to ${max}`;
917
+ }
888
918
  default:
889
919
  return `\`${key}\` is not a nicotine-warning style key (allowed: ${NICOTINE_WARNING_STYLE_KEYS.join(", ")})`;
890
920
  }
@@ -993,7 +1023,10 @@ export function nicotineWarningCheckWidths(declaration) {
993
1023
  */
994
1024
  export function describeNicotineWarningPresentation(p) {
995
1025
  return `background ${p.background}, text ${p.text}, border ${p.border}, ` +
996
- `${p.textTransform === "uppercase" ? "uppercase" : "normal case"}, weight ${p.fontWeight}, ${p.fontSizePx}px`;
1026
+ `${p.textTransform === "uppercase" ? "uppercase" : "normal case"}, weight ${p.fontWeight}, ${p.fontSizePx}px` +
1027
+ (p.borderWidthPx === undefined ? "" : `, border width ${p.borderWidthPx}px`) +
1028
+ (p.paddingYPx === undefined ? "" : `, vertical padding ${p.paddingYPx}px`) +
1029
+ (p.letterSpacingPx === undefined ? "" : `, letter spacing ${p.letterSpacingPx}px`);
997
1030
  }
998
1031
 
999
1032
  /**
@@ -1017,11 +1050,12 @@ export function describeNicotineWarningPresentation(p) {
1017
1050
  */
1018
1051
  export function nicotineWarningHtml(declaration, variant) {
1019
1052
  const { presentation, preset } = resolveNicotineWarning(declaration);
1053
+ const barPadding = presentation.paddingYPx === undefined ? "0.5rem" : `${presentation.paddingYPx}px`;
1020
1054
  const attrs = `style="${nicotineWarningStyle(presentation, variant)}" role="note" aria-label="Health warning" ` +
1021
1055
  `data-compliance="nicotine-warning" data-nicotine-warning-preset="${preset ?? "custom"}"`;
1022
1056
  const text = NICOTINE_WARNING_TEXT_LOCK;
1023
1057
  return variant === "bar"
1024
- ? `<div ${attrs}><p class="container-prose" style="margin-block:0;padding-block:0.5rem;text-align:center;${text}">${NICOTINE_WARNING_TEXT}</p></div>`
1058
+ ? `<div ${attrs}><p class="container-prose" style="margin-block:0;padding-block:${barPadding};text-align:center;${text}">${NICOTINE_WARNING_TEXT}</p></div>`
1025
1059
  : `<div ${attrs}><p style="margin:0;${text}">${NICOTINE_WARNING_TEXT}</p></div>`;
1026
1060
  }
1027
1061
 
@@ -1061,15 +1095,17 @@ const NICOTINE_WARNING_TEXT_LOCK = [
1061
1095
  */
1062
1096
  export function nicotineWarningStyle(p, variant) {
1063
1097
  const size = variant === "block" ? Math.max(p.fontSizePx, 14) : p.fontSizePx;
1098
+ const boxed = `${p.borderWidthPx ?? 2}px`;
1064
1099
  const frame = variant === "bar"
1065
- ? [`border-bottom:2px solid ${p.border}`]
1066
- : [`border:2px solid ${p.border}`, "border-radius:var(--radius-md)", "padding:0.75rem 1rem"];
1100
+ ? [p.borderWidthPx === undefined ? `border-bottom:2px solid ${p.border}` : `border:${boxed} solid ${p.border}`]
1101
+ : [`border:${boxed} solid ${p.border}`, "border-radius:var(--radius-md)",
1102
+ `padding:${p.paddingYPx === undefined ? "0.75rem" : `${p.paddingYPx}px`} 1rem`];
1067
1103
  return [
1068
1104
  ...frame,
1069
1105
  `background-color:${p.background}`,
1070
1106
  `color:${p.text}`,
1071
1107
  `text-transform:${p.textTransform}`,
1072
- `letter-spacing:${p.textTransform === "uppercase" ? "0.06em" : "normal"}`,
1108
+ `letter-spacing:${p.letterSpacingPx !== undefined ? `${p.letterSpacingPx}px` : p.textTransform === "uppercase" ? "0.06em" : "normal"}`,
1073
1109
  `font-weight:${p.fontWeight}`,
1074
1110
  `font-size:${size}px`,
1075
1111
  "line-height:1.4",