@tokenoftrust/cli 7.2.0 → 7.2.2

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.2.0",
3
+ "version": "7.2.2",
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,16 +1892,28 @@ 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
  }
1908
+ if (showQr && (status?.previewUrl || previewPrUrl)) {
1909
+ emitGitOp("preview_qr", true, { command: verb });
1910
+ }
1911
+ if (args.page) {
1912
+ emitGitOp("preview_subpage", true, { command: verb });
1913
+ }
1914
+ if (args.revoke) {
1915
+ emitGitOp("preview_revoke", true, { command: verb });
1916
+ }
1895
1917
  const ok = previewSubmitSucceeded(status);
1896
1918
  const degradation = invocationDegradedResult();
1897
1919
  if (degradation.degraded && !args.json) {
@@ -1899,7 +1921,7 @@ export async function run(argv, ctx, {
1899
1921
  }
1900
1922
  emitJson(args, buildJsonResult({
1901
1923
  ok, ref, commit, changeId, candidate, status,
1902
- previewPrUrl, noChanges, ...degradation,
1924
+ previewPrUrl, noChanges, revokedShareLinks: args.revoke, ...degradation,
1903
1925
  }));
1904
1926
  return ok ? 0 : 1;
1905
1927
  } catch (e) {
@@ -2098,6 +2120,42 @@ function reportComplianceCheck(c) {
2098
2120
  if (c.hint) console.log(` → fix: ${c.hint}`);
2099
2121
  }
2100
2122
 
2123
+ /**
2124
+ * Append a sub-page path (e.g. `/products/blue-mug`) onto a shareable preview URL
2125
+ * before any query string or hash so the printed URL and terminal QR code open
2126
+ * directly on the exact page under review. Pure — unit-tested.
2127
+ * @param {string|null|undefined} url
2128
+ * @param {string|null|undefined} page
2129
+ * @returns {string}
2130
+ */
2131
+ export function applyPreviewSubpage(url, page) {
2132
+ const base = String(url ?? "").trim();
2133
+ if (!base) return "";
2134
+ const rawPage = String(page ?? "").trim();
2135
+ if (!rawPage || rawPage === "/") return base;
2136
+ const normalized = rawPage.startsWith("/") ? rawPage : `/${rawPage}`;
2137
+ const qIdx = base.indexOf("?");
2138
+ const hIdx = base.indexOf("#");
2139
+ const splitAt = qIdx >= 0 && hIdx >= 0 ? Math.min(qIdx, hIdx) : qIdx >= 0 ? qIdx : hIdx;
2140
+ const pathPart = (splitAt >= 0 ? base.slice(0, splitAt) : base).replace(/\/+$/, "");
2141
+ const tail = splitAt >= 0 ? base.slice(splitAt) : "";
2142
+ if (pathPart.endsWith(normalized)) return base;
2143
+ return `${pathPart}${normalized}${tail}`;
2144
+ }
2145
+
2146
+ /**
2147
+ * Format the console notice when `--revoke` invalidates prior shared preview links.
2148
+ * Pure — unit-tested.
2149
+ * @param {boolean} [revoked]
2150
+ * @param {string} [tenant]
2151
+ * @returns {string[]}
2152
+ */
2153
+ export function formatRevokeNotice(revoked = false, tenant = "") {
2154
+ if (!revoked) return [];
2155
+ const scope = tenant ? ` for ${tenant}` : "";
2156
+ return [` ✓ Revoked prior shared preview links${scope} — only fresh preview links remain active.`];
2157
+ }
2158
+
2101
2159
  /**
2102
2160
  * The IMMEDIATE shareable preview URL (Vercel-style: "the URL exists before the
2103
2161
  * build does") — composed client-side, deterministically, from the tenant + PR
@@ -2116,10 +2174,12 @@ function reportComplianceCheck(c) {
2116
2174
  * @param {string} base storefront origin, e.g. https://storefront.tokenoftrust.store
2117
2175
  * @param {string} tenant
2118
2176
  * @param {number} prNumber
2177
+ * @param {string|null} [page]
2119
2178
  * @returns {string}
2120
2179
  */
2121
- export function shareablePrUrl(base, tenant, prNumber) {
2122
- return previewPrUrl(base, tenant, prNumber) ?? "";
2180
+ export function shareablePrUrl(base, tenant, prNumber, page = null) {
2181
+ const raw = previewPrUrl(base, tenant, prNumber) ?? "";
2182
+ return page ? applyPreviewSubpage(raw, page) : raw;
2123
2183
  }
2124
2184
 
2125
2185
  /**
@@ -2166,22 +2226,28 @@ export function describeReadbackError(e) {
2166
2226
  * crash or a silent blank. Pure — unit-tested.
2167
2227
  * @param {{ previewUrl?: string|null, status?: string }|null} s
2168
2228
  * @param {string} tenant
2229
+ * @param {{ qr?: boolean, page?: string|null, revoked?: boolean }} [opts]
2169
2230
  * @returns {string[]}
2170
2231
  */
2171
- export function formatShareableUrlBlock(s, tenant, { qr = false } = {}) {
2232
+ export function formatShareableUrlBlock(s, tenant, { qr = false, page = null, revoked = false } = {}) {
2172
2233
  if (s?.previewUrl) {
2234
+ const targetUrl = page ? applyPreviewSubpage(s.previewUrl, page) : s.previewUrl;
2173
2235
  const lines = [
2236
+ ...formatRevokeNotice(revoked, tenant),
2174
2237
  `\n ✓ Preview ready — share this with your reviewer:`,
2175
- ` ${s.previewUrl}`,
2238
+ ` ${targetUrl}`,
2176
2239
  ` ℹ your reviewer needs store access (a member/staff of ${tenant}) to view it — it's not a public link.`,
2177
2240
  ];
2178
- if (qr) lines.push(formatTerminalQrBlock(s.previewUrl));
2241
+ if (qr) lines.push(formatTerminalQrBlock(targetUrl));
2179
2242
  return lines;
2180
2243
  }
2181
2244
  if (s?.status === "reconciled") {
2182
- return [`\n ~ reconciled, but no shareable preview URL yet — it'll show up here once available.`];
2245
+ return [
2246
+ ...formatRevokeNotice(revoked, tenant),
2247
+ `\n ~ reconciled, but no shareable preview URL yet — it'll show up here once available.`,
2248
+ ];
2183
2249
  }
2184
- return [];
2250
+ return formatRevokeNotice(revoked, tenant);
2185
2251
  }
2186
2252
 
2187
2253
  /**
@@ -2292,9 +2358,9 @@ export function formatShipLine(s) {
2292
2358
 
2293
2359
  /**
2294
2360
  * @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]
2361
+ * @param {{ open?: boolean, quiet?: boolean, qr?: boolean, page?: string|null, revoked?: boolean, commit?: string|null, ref?: string|null, verb?: string, noChanges?: boolean }} [opts]
2296
2362
  */
2297
- function reportStatus(s, tenant, { open = true, quiet = false, qr = false, commit = null, ref = null, verb = "preview", noChanges = false } = {}) {
2363
+ function reportStatus(s, tenant, { open = true, quiet = false, qr = false, page = null, revoked = false, commit = null, ref = null, verb = "preview", noChanges = false } = {}) {
2298
2364
  if (!quiet) for (const line of formatVerdictBlock(s?.verdict, s?.supportBundleText)) console.log(line);
2299
2365
  if (!s || s.status === "unknown") {
2300
2366
  if (!quiet) {
@@ -2347,9 +2413,10 @@ function reportStatus(s, tenant, { open = true, quiet = false, qr = false, commi
2347
2413
  }
2348
2414
  const shipLine = formatShipLine(s);
2349
2415
  if (shipLine) console.log(shipLine);
2350
- for (const line of formatShareableUrlBlock(s, tenant, { qr })) console.log(line);
2416
+ for (const line of formatShareableUrlBlock(s, tenant, { qr, page, revoked })) console.log(line);
2351
2417
  }
2352
- if (s.previewUrl && open && s.status === "reconciled" && openBrowser(s.previewUrl)) {
2418
+ const browserUrl = s.previewUrl ? (page ? applyPreviewSubpage(s.previewUrl, page) : s.previewUrl) : null;
2419
+ if (browserUrl && open && s.status === "reconciled" && openBrowser(browserUrl)) {
2353
2420
  if (!quiet) console.log(" (opened in your browser)");
2354
2421
  }
2355
2422
  }