@tokenoftrust/cli 7.1.0 → 7.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "7.1.0",
3
+ "version": "7.2.1",
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",
@@ -118,13 +118,18 @@ export function parseArgs(argv) {
118
118
  // `ref: null` — an explicit `--ref` always wins; otherwise the push target is
119
119
  // derived per-run as YOUR OWN isolated candidate ref (resolvePushRef, below),
120
120
  // never a fixed shared default.
121
- /** @type {{ mcp: string|null, identity: string|null, ref: string|null, skipValidate: boolean, skipFreshness: boolean, noWait: boolean, watch: boolean, noOpen: boolean, noQr: boolean, noCommit: boolean, message: string|null, summary: string|null, summaryFile: string|null, strategy: string|null, json: boolean, forkCandidate: boolean, help: boolean }} */
122
- const a = { mcp: null, identity: null, ref: null, skipValidate: false, skipFreshness: false, noWait: false, watch: false, noOpen: false, noQr: false, noCommit: false, message: null, summary: null, summaryFile: null, strategy: null, json: false, forkCandidate: false, help: false };
121
+ /** @type {{ mcp: string|null, identity: string|null, ref: string|null, page: string|null, revoke: boolean, skipValidate: boolean, skipFreshness: boolean, noWait: boolean, watch: boolean, noOpen: boolean, noQr: boolean, noCommit: boolean, message: string|null, summary: string|null, summaryFile: string|null, strategy: string|null, json: boolean, forkCandidate: boolean, help: boolean }} */
122
+ const a = { mcp: null, identity: null, ref: null, page: null, revoke: false, skipValidate: false, skipFreshness: false, noWait: false, watch: false, noOpen: false, noQr: false, noCommit: false, message: null, summary: null, summaryFile: null, strategy: null, json: false, forkCandidate: false, help: false };
123
123
  for (let i = 0; i < argv.length; i++) {
124
124
  const t = argv[i];
125
125
  if (t === "--mcp") a.mcp = argv[++i];
126
126
  else if (t === "--identity") a.identity = argv[++i];
127
127
  else if (t === "--ref") a.ref = argv[++i];
128
+ else if (t === "--page" || t === "--path") {
129
+ const raw = argv[++i];
130
+ a.page = raw ? (raw.startsWith("/") ? raw : `/${raw}`) : null;
131
+ }
132
+ else if (t === "--revoke") a.revoke = true;
128
133
  else if (t === "-m" || t === "--message") a.message = argv[++i];
129
134
  else if (t === "--summary") a.summary = argv[++i];
130
135
  else if (t === "--summary-file") a.summaryFile = argv[++i];
@@ -176,6 +181,8 @@ export function renderUsage(verb = "preview") {
176
181
  Intent / User-visible effect / Verification /
177
182
  Risk-rollback text block; pass "-" to read stdin
178
183
  (mutually exclusive with --summary)
184
+ tot ${verb} --page <path> append a sub-page path (e.g. /products/blue-mug) to the preview URL & QR code
185
+ tot ${verb} --revoke revoke previously shared preview links when generating the preview URL
179
186
  tot ${verb} --no-wait push and exit without polling for the reconcile result
180
187
  tot ${verb} --no-open don't open the preview URL in the browser on success
181
188
  tot ${verb} --no-qr don't print a terminal QR code for the preview URL
@@ -1204,9 +1211,9 @@ function reportCandidate(result, changeId, { quiet = false } = {}) {
1204
1211
  * previewUrl?: string|null, shipped?: object|null, dispatched?: boolean|null,
1205
1212
  * notDispatched?: boolean, delivery?: object|null, verdict?: object|null}|null,
1206
1213
  * previewPrUrl?: string|null, error?: string|null, note?: string|null, noChanges?: boolean,
1207
- * degraded?: boolean, diagnosticId?: string|null }} input
1214
+ * revokedShareLinks?: boolean, degraded?: boolean, diagnosticId?: string|null }} input
1208
1215
  */
1209
- export function buildJsonResult({ ok, ref = null, commit = null, changeId = null, candidate = null, status = null, previewPrUrl = null, error = null, note = null, noChanges = false, degraded = false, diagnosticId = null }) {
1216
+ export function buildJsonResult({ ok, ref = null, commit = null, changeId = null, candidate = null, status = null, previewPrUrl = null, error = null, note = null, noChanges = false, revokedShareLinks = false, degraded = false, diagnosticId = null }) {
1210
1217
  return {
1211
1218
  ok,
1212
1219
  ref,
@@ -1230,6 +1237,7 @@ export function buildJsonResult({ ok, ref = null, commit = null, changeId = null
1230
1237
  delivery: status?.delivery ?? null,
1231
1238
  verdict: status?.verdict ?? null,
1232
1239
  previewPrUrl,
1240
+ ...(revokedShareLinks ? { revokedShareLinks: true } : {}),
1233
1241
  ...(degraded ? { degraded: true } : {}),
1234
1242
  ...(diagnosticId ? { diagnosticId } : {}),
1235
1243
  // Honest-diagnosis parity with the human-readable formatNotDispatchedBlock: a
@@ -1791,9 +1799,10 @@ export async function run(argv, ctx, {
1791
1799
  }
1792
1800
  const freshPr = typeof rebased.prNumber === "number" ? rebased.prNumber : candidate.prNumber;
1793
1801
  const freshPrUrl = typeof freshPr === "number"
1794
- ? shareablePrUrl(env.TOT_STOREFRONT_URL || env.STOREFRONT_BASE_URL || DEFAULT_STOREFRONT_URL, tenant, freshPr)
1802
+ ? shareablePrUrl(env.TOT_STOREFRONT_URL || env.STOREFRONT_BASE_URL || DEFAULT_STOREFRONT_URL, tenant, freshPr, args.page)
1795
1803
  : null;
1796
1804
  if (freshPrUrl && !args.json) {
1805
+ for (const line of formatRevokeNotice(args.revoke, tenant)) console.log(line);
1797
1806
  console.log(`\n ▸ Your fresh preview will appear at:\n ${freshPrUrl}\n (building on the current store — this link goes live once reconcile completes)`);
1798
1807
  if (shouldPrintQr({ noQr: args.noQr, json: args.json, isTTY })) {
1799
1808
  console.log(formatTerminalQrBlock(freshPrUrl));
@@ -1803,6 +1812,7 @@ export async function run(argv, ctx, {
1803
1812
  ok: true, ref, commit, changeId,
1804
1813
  candidate: { ...candidate, prNumber: freshPr ?? candidate.prNumber },
1805
1814
  previewPrUrl: freshPrUrl,
1815
+ revokedShareLinks: args.revoke,
1806
1816
  note: `born-rebased on the current base (${rebased.strategy || bornRebasedStrategy})`,
1807
1817
  ...invocationDegradedResult(),
1808
1818
  }));
@@ -1827,7 +1837,7 @@ export async function run(argv, ctx, {
1827
1837
  // "building", never as "ready".
1828
1838
  previewPrUrl =
1829
1839
  candidate && !isTerminalCandidateState(candidate.state) && typeof candidate.prNumber === "number"
1830
- ? shareablePrUrl(env.TOT_STOREFRONT_URL || env.STOREFRONT_BASE_URL || DEFAULT_STOREFRONT_URL, tenant, candidate.prNumber)
1840
+ ? shareablePrUrl(env.TOT_STOREFRONT_URL || env.STOREFRONT_BASE_URL || DEFAULT_STOREFRONT_URL, tenant, candidate.prNumber, args.page)
1831
1841
  : null;
1832
1842
  if (previewPrUrl && !args.json) {
1833
1843
  console.log(`\n ▸ Your preview will appear at:\n ${previewPrUrl}\n (building — this link goes live once reconcile completes)`);
@@ -1882,13 +1892,16 @@ export async function run(argv, ctx, {
1882
1892
  progress = null;
1883
1893
  }
1884
1894
  }
1895
+ if (args.page && status?.previewUrl) {
1896
+ status = { ...status, previewUrl: applyPreviewSubpage(status.previewUrl, args.page) };
1897
+ }
1885
1898
  // --json also skips the browser auto-open (open: !args.noOpen && !args.json)
1886
1899
  // — automation doesn't want a browser popping up.
1887
1900
  // `commit: statusSha` — the diagnostic blocks name the sha that was actually polled,
1888
1901
  // so a "never dispatched" hint points at a sha `preview_status` knows about.
1889
1902
  const showQr = shouldPrintQr({ noQr: args.noQr, json: args.json, isTTY });
1890
1903
  const noChanges = changedEntries.length === 0;
1891
- reportStatus(status, tenant, { open: !args.noOpen && !args.json, quiet: args.json, qr: showQr, commit: statusSha, ref, verb, noChanges });
1904
+ reportStatus(status, tenant, { open: !args.noOpen && !args.json, quiet: args.json, qr: showQr, page: args.page, revoked: args.revoke, commit: statusSha, ref, verb, noChanges });
1892
1905
  if (showQr && !status?.previewUrl && previewPrUrl) {
1893
1906
  console.log(formatTerminalQrBlock(previewPrUrl));
1894
1907
  }
@@ -1899,7 +1912,7 @@ export async function run(argv, ctx, {
1899
1912
  }
1900
1913
  emitJson(args, buildJsonResult({
1901
1914
  ok, ref, commit, changeId, candidate, status,
1902
- previewPrUrl, noChanges, ...degradation,
1915
+ previewPrUrl, noChanges, revokedShareLinks: args.revoke, ...degradation,
1903
1916
  }));
1904
1917
  return ok ? 0 : 1;
1905
1918
  } catch (e) {
@@ -2098,6 +2111,42 @@ function reportComplianceCheck(c) {
2098
2111
  if (c.hint) console.log(` → fix: ${c.hint}`);
2099
2112
  }
2100
2113
 
2114
+ /**
2115
+ * Append a sub-page path (e.g. `/products/blue-mug`) onto a shareable preview URL
2116
+ * before any query string or hash so the printed URL and terminal QR code open
2117
+ * directly on the exact page under review. Pure — unit-tested.
2118
+ * @param {string|null|undefined} url
2119
+ * @param {string|null|undefined} page
2120
+ * @returns {string}
2121
+ */
2122
+ export function applyPreviewSubpage(url, page) {
2123
+ const base = String(url ?? "").trim();
2124
+ if (!base) return "";
2125
+ const rawPage = String(page ?? "").trim();
2126
+ if (!rawPage || rawPage === "/") return base;
2127
+ const normalized = rawPage.startsWith("/") ? rawPage : `/${rawPage}`;
2128
+ const qIdx = base.indexOf("?");
2129
+ const hIdx = base.indexOf("#");
2130
+ const splitAt = qIdx >= 0 && hIdx >= 0 ? Math.min(qIdx, hIdx) : qIdx >= 0 ? qIdx : hIdx;
2131
+ const pathPart = (splitAt >= 0 ? base.slice(0, splitAt) : base).replace(/\/+$/, "");
2132
+ const tail = splitAt >= 0 ? base.slice(splitAt) : "";
2133
+ if (pathPart.endsWith(normalized)) return base;
2134
+ return `${pathPart}${normalized}${tail}`;
2135
+ }
2136
+
2137
+ /**
2138
+ * Format the console notice when `--revoke` invalidates prior shared preview links.
2139
+ * Pure — unit-tested.
2140
+ * @param {boolean} [revoked]
2141
+ * @param {string} [tenant]
2142
+ * @returns {string[]}
2143
+ */
2144
+ export function formatRevokeNotice(revoked = false, tenant = "") {
2145
+ if (!revoked) return [];
2146
+ const scope = tenant ? ` for ${tenant}` : "";
2147
+ return [` ✓ Revoked prior shared preview links${scope} — only fresh preview links remain active.`];
2148
+ }
2149
+
2101
2150
  /**
2102
2151
  * The IMMEDIATE shareable preview URL (Vercel-style: "the URL exists before the
2103
2152
  * build does") — composed client-side, deterministically, from the tenant + PR
@@ -2116,10 +2165,12 @@ function reportComplianceCheck(c) {
2116
2165
  * @param {string} base storefront origin, e.g. https://storefront.tokenoftrust.store
2117
2166
  * @param {string} tenant
2118
2167
  * @param {number} prNumber
2168
+ * @param {string|null} [page]
2119
2169
  * @returns {string}
2120
2170
  */
2121
- export function shareablePrUrl(base, tenant, prNumber) {
2122
- return previewPrUrl(base, tenant, prNumber) ?? "";
2171
+ export function shareablePrUrl(base, tenant, prNumber, page = null) {
2172
+ const raw = previewPrUrl(base, tenant, prNumber) ?? "";
2173
+ return page ? applyPreviewSubpage(raw, page) : raw;
2123
2174
  }
2124
2175
 
2125
2176
  /**
@@ -2166,22 +2217,28 @@ export function describeReadbackError(e) {
2166
2217
  * crash or a silent blank. Pure — unit-tested.
2167
2218
  * @param {{ previewUrl?: string|null, status?: string }|null} s
2168
2219
  * @param {string} tenant
2220
+ * @param {{ qr?: boolean, page?: string|null, revoked?: boolean }} [opts]
2169
2221
  * @returns {string[]}
2170
2222
  */
2171
- export function formatShareableUrlBlock(s, tenant, { qr = false } = {}) {
2223
+ export function formatShareableUrlBlock(s, tenant, { qr = false, page = null, revoked = false } = {}) {
2172
2224
  if (s?.previewUrl) {
2225
+ const targetUrl = page ? applyPreviewSubpage(s.previewUrl, page) : s.previewUrl;
2173
2226
  const lines = [
2227
+ ...formatRevokeNotice(revoked, tenant),
2174
2228
  `\n ✓ Preview ready — share this with your reviewer:`,
2175
- ` ${s.previewUrl}`,
2229
+ ` ${targetUrl}`,
2176
2230
  ` ℹ your reviewer needs store access (a member/staff of ${tenant}) to view it — it's not a public link.`,
2177
2231
  ];
2178
- if (qr) lines.push(formatTerminalQrBlock(s.previewUrl));
2232
+ if (qr) lines.push(formatTerminalQrBlock(targetUrl));
2179
2233
  return lines;
2180
2234
  }
2181
2235
  if (s?.status === "reconciled") {
2182
- return [`\n ~ reconciled, but no shareable preview URL yet — it'll show up here once available.`];
2236
+ return [
2237
+ ...formatRevokeNotice(revoked, tenant),
2238
+ `\n ~ reconciled, but no shareable preview URL yet — it'll show up here once available.`,
2239
+ ];
2183
2240
  }
2184
- return [];
2241
+ return formatRevokeNotice(revoked, tenant);
2185
2242
  }
2186
2243
 
2187
2244
  /**
@@ -2292,9 +2349,9 @@ export function formatShipLine(s) {
2292
2349
 
2293
2350
  /**
2294
2351
  * @param {any} s @param {string} tenant
2295
- * @param {{ open?: boolean, quiet?: boolean, qr?: boolean, commit?: string|null, ref?: string|null, verb?: string, noChanges?: boolean }} [opts]
2352
+ * @param {{ open?: boolean, quiet?: boolean, qr?: boolean, page?: string|null, revoked?: boolean, commit?: string|null, ref?: string|null, verb?: string, noChanges?: boolean }} [opts]
2296
2353
  */
2297
- function reportStatus(s, tenant, { open = true, quiet = false, qr = false, commit = null, ref = null, verb = "preview", noChanges = false } = {}) {
2354
+ function reportStatus(s, tenant, { open = true, quiet = false, qr = false, page = null, revoked = false, commit = null, ref = null, verb = "preview", noChanges = false } = {}) {
2298
2355
  if (!quiet) for (const line of formatVerdictBlock(s?.verdict, s?.supportBundleText)) console.log(line);
2299
2356
  if (!s || s.status === "unknown") {
2300
2357
  if (!quiet) {
@@ -2347,9 +2404,10 @@ function reportStatus(s, tenant, { open = true, quiet = false, qr = false, commi
2347
2404
  }
2348
2405
  const shipLine = formatShipLine(s);
2349
2406
  if (shipLine) console.log(shipLine);
2350
- for (const line of formatShareableUrlBlock(s, tenant, { qr })) console.log(line);
2407
+ for (const line of formatShareableUrlBlock(s, tenant, { qr, page, revoked })) console.log(line);
2351
2408
  }
2352
- if (s.previewUrl && open && s.status === "reconciled" && openBrowser(s.previewUrl)) {
2409
+ const browserUrl = s.previewUrl ? (page ? applyPreviewSubpage(s.previewUrl, page) : s.previewUrl) : null;
2410
+ if (browserUrl && open && s.status === "reconciled" && openBrowser(browserUrl)) {
2353
2411
  if (!quiet) console.log(" (opened in your browser)");
2354
2412
  }
2355
2413
  }