@decocms/parity 0.33.14 → 0.33.16

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/cli.js +86 -10
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -57812,6 +57812,13 @@ function fail(err) {
57812
57812
  console.error(chalk7.red(err instanceof Error ? err.message : String(err)));
57813
57813
  return 1;
57814
57814
  }
57815
+ function writeBackup(version) {
57816
+ const backup = join19("parity-output", "cms-backups", `${version.entryId}-${version.baseHash.slice(0, 12)}.json`);
57817
+ mkdirSync9(dirname4(backup), { recursive: true });
57818
+ writeFileSync13(backup, `${JSON.stringify(version, null, 2)}
57819
+ `);
57820
+ return backup;
57821
+ }
57815
57822
  function resolveAuthor(explicit) {
57816
57823
  const author = explicit ?? readVtexSession()?.login;
57817
57824
  if (!author) {
@@ -58002,10 +58009,7 @@ async function cmsPushCommand(opts, call = callCms) {
58002
58009
  const author = resolveAuthor(opts.author);
58003
58010
  if (author instanceof Error)
58004
58011
  return fail(author);
58005
- const backup = join19("parity-output", "cms-backups", `${local.entryId}-${remote.baseHash.slice(0, 12)}.json`);
58006
- mkdirSync9(dirname4(backup), { recursive: true });
58007
- writeFileSync13(backup, `${JSON.stringify(remote, null, 2)}
58008
- `);
58012
+ const backup = writeBackup(remote);
58009
58013
  const commit = await commitEntry(cfg, {
58010
58014
  branchId: branch,
58011
58015
  contentTypeId: local.contentType,
@@ -58023,13 +58027,57 @@ async function cmsPushCommand(opts, call = callCms) {
58023
58027
  return 0;
58024
58028
  }
58025
58029
  console.log(`${chalk7.green("✓")} commit ${commit.id} on ${branch}`);
58026
- console.log(chalk7.dim(` rollback: parity cms undo --entry ${local.entryId} --branch ${branch}`));
58030
+ console.log(chalk7.dim(` rollback: parity cms restore --file ${backup} --branch ${branch}${branch === "main" ? " --allow-main" : ""} --yes`));
58027
58031
  console.log(chalk7.dim(` backup: ${backup}`));
58028
58032
  return 0;
58029
58033
  } catch (err) {
58030
58034
  return fail(err);
58031
58035
  }
58032
58036
  }
58037
+ async function cmsRestoreCommand(opts, call = callCms) {
58038
+ const cfg = config();
58039
+ if (!cfg)
58040
+ return 1;
58041
+ const backup = readPulled(opts.file);
58042
+ if (backup instanceof Error)
58043
+ return fail(backup);
58044
+ const branch = resolveBranch(opts.branch ?? backup.branchId, Boolean(opts.allowMain));
58045
+ if (branch instanceof Error)
58046
+ return fail(branch);
58047
+ try {
58048
+ const head = await getLastVersion(cfg, { contentType: backup.contentType, entryId: backup.entryId, branchId: branch }, call);
58049
+ if (!opts.yes) {
58050
+ console.log(chalk7.yellow("dry run — nothing written. Pass --yes to restore."));
58051
+ for (const line of summarizeSections(backup.data))
58052
+ console.log(` ${line}`);
58053
+ console.log(chalk7.dim(` branch ${branch} · entry ${backup.entryId} · ${backup.contentType}`));
58054
+ return 0;
58055
+ }
58056
+ const author = resolveAuthor(opts.author);
58057
+ if (author instanceof Error)
58058
+ return fail(author);
58059
+ const commit = await commitEntry(cfg, {
58060
+ branchId: branch,
58061
+ contentTypeId: backup.contentType,
58062
+ entryId: backup.entryId,
58063
+ entryName: backup.entryName,
58064
+ baseHash: head.baseHash,
58065
+ data: backup.data,
58066
+ message: opts.message ?? `parity cms restore ${opts.file}`,
58067
+ author,
58068
+ identifierKeys: backup.identifierKeys,
58069
+ searchKeywords: backup.searchKeywords
58070
+ }, call);
58071
+ if (opts.json) {
58072
+ console.log(JSON.stringify({ commit }, null, 2));
58073
+ return 0;
58074
+ }
58075
+ console.log(`${chalk7.green("✓")} ${backup.entryId} restored from ${opts.file}, commit ${commit.id} on ${branch}`);
58076
+ return 0;
58077
+ } catch (err) {
58078
+ return fail(err);
58079
+ }
58080
+ }
58033
58081
  async function cmsUndoCommand(opts, call = callCms) {
58034
58082
  const cfg = config();
58035
58083
  if (!cfg)
@@ -58038,12 +58086,21 @@ async function cmsUndoCommand(opts, call = callCms) {
58038
58086
  if (branch instanceof Error)
58039
58087
  return fail(branch);
58040
58088
  if (!opts.yes) {
58041
- console.log(chalk7.yellow(`dry run — would drop ${opts.entry} changes on ${branch}. Pass --yes.`));
58089
+ console.log(chalk7.yellow(`dry run — this DELETES ${opts.entry} (every version, this branch and any other) rather than reverting it. Pass --allow-delete --yes to actually run it.`));
58042
58090
  return 0;
58043
58091
  }
58092
+ if (!opts.allowDelete) {
58093
+ return fail(new Error("cms undo destroys the entry, it does not revert it — pass --allow-delete to confirm, or use `parity cms restore` for a non-destructive rollback."));
58094
+ }
58044
58095
  try {
58096
+ const contentType = opts.contentType ?? (await listEntries(cfg, {}, call)).find((e) => e.id === opts.entry)?.contentTypeId;
58097
+ if (contentType) {
58098
+ const current = await getLastVersion(cfg, { contentType, entryId: opts.entry, branchId: branch }, call).catch(() => null);
58099
+ if (current)
58100
+ console.log(chalk7.dim(` backup: ${writeBackup(current)}`));
58101
+ }
58045
58102
  await undoEntry(cfg, { branchId: branch, entryId: opts.entry }, call);
58046
- console.log(`${chalk7.green("✓")} ${opts.entry} reverted on ${branch}`);
58103
+ console.log(`${chalk7.green("✓")} ${opts.entry} deleted on ${branch}`);
58047
58104
  return 0;
58048
58105
  } catch (err) {
58049
58106
  return fail(err);
@@ -65030,8 +65087,9 @@ function themeLink(target) {
65030
65087
 
65031
65088
  // src/migrate/sources/classify.ts
65032
65089
  var has2 = (re, text) => re.test(text);
65090
+ var ISLAND_BUNDLE = /\bisland-[a-z0-9_.-]+\.js\b/i;
65033
65091
  function isDeco(html) {
65034
- return /deco\.cx|__DECO\b|data-deco\b/i.test(html) || /__FRSH|_frsh/.test(html) || html.includes("/live/invoke");
65092
+ return /deco\.cx|__DECO\b|data-deco\b/i.test(html) || /__FRSH|_frsh/.test(html) || ISLAND_BUNDLE.test(html) || html.includes("/live/invoke");
65035
65093
  }
65036
65094
  function detectHtmx(html) {
65037
65095
  return /\bhx-(get|post|target|swap|trigger)\b/i.test(html) || /htmx(\.org|\.min)?\b/i.test(html);
@@ -65065,6 +65123,8 @@ function classifyLiveStack(html, cookies = "") {
65065
65123
  evidence.push("deco.cx");
65066
65124
  if (/__FRSH|_frsh/.test(html))
65067
65125
  evidence.push("fresh-runtime");
65126
+ if (ISLAND_BUNDLE.test(html))
65127
+ evidence.push("island-*.js");
65068
65128
  if (html.includes("/live/invoke"))
65069
65129
  evidence.push("/live/invoke");
65070
65130
  const htmx = detectHtmx(html);
@@ -66265,6 +66325,10 @@ async function migrateCommand(opts) {
66265
66325
  const cookieNames = await ctx.cookies().then((cs) => cs.map((c) => c.name).join("; ")).catch(() => "");
66266
66326
  stack = classifyLiveStack(pageHtml, cookieNames);
66267
66327
  console.log(chalk19.dim(` stack: ${describeStack(stack)}`));
66328
+ if (!opts.source && stack.frontend !== "unknown") {
66329
+ console.warn(chalk19.red(` ! live-only capture, but the live HTML is ${stack.frontend} (${stack.evidence.join(", ")}) — a source repo exists.
66330
+ Re-run with --source <repo> for structural porting (real class strings, not measured pixels).`));
66331
+ }
66268
66332
  const rawAssets = await collectSiteAssets(page);
66269
66333
  const fetchBytes = async (url) => await browserFetchBytes(page, url) ?? await nodeFetchBytes(url);
66270
66334
  assetsResolved = await downloadSiteAssets(rawAssets, runDir, fetchBytes);
@@ -70700,12 +70764,24 @@ program.command("cms").description("Read and write VTEX Content Platform entries
70700
70764
  }));
70701
70765
  })).addCommand(new Command("rm").description("Destroy an entry and every version of it, on every branch. Dry run unless --yes.").requiredOption("--entry <id>", "Entry id").option("--yes", "Actually delete. Without it, this is a dry run.", false).action(async (opts) => {
70702
70766
  process.exit(await cmsRmCommand({ entry: opts.entry, yes: Boolean(opts.yes) }));
70703
- })).addCommand(new Command("undo").description("Drop an entry's changes on a branch — the platform's own rollback. Dry run unless --yes.").requiredOption("--entry <id>", "Entry id").requiredOption("--branch <id>", "Branch id").option("--yes", "Actually revert. Without it, this is a dry run.", false).option("--allow-main", "Permit reverting on main", false).action(async (opts) => {
70767
+ })).addCommand(new Command("undo").description("Delete an entry outright via the platform's `undo` endpoint — NOT a revert, since an entry with one version (every entry `create` makes) has nothing to drop but itself. Use `restore` for a non-destructive rollback. Dry run unless --yes and --allow-delete.").requiredOption("--entry <id>", "Entry id").requiredOption("--branch <id>", "Branch id").option("--content-type <name>", "Skip the entry lookup used to back it up before deleting").option("--yes", "Actually delete. Without it, this is a dry run.", false).option("--allow-main", "Permit deleting on main", false).option("--allow-delete", "Confirm this destroys the entry, it does not revert it", false).action(async (opts) => {
70704
70768
  process.exit(await cmsUndoCommand({
70705
70769
  entry: opts.entry,
70706
70770
  branch: opts.branch,
70771
+ contentType: opts.contentType,
70772
+ yes: Boolean(opts.yes),
70773
+ allowMain: Boolean(opts.allowMain),
70774
+ allowDelete: Boolean(opts.allowDelete)
70775
+ }));
70776
+ })).addCommand(new Command("restore").description("Re-commit a backup file (from `push` or `undo`, in parity-output/cms-backups/) against the entry's current head — the actual non-destructive rollback. Dry run unless --yes.").requiredOption("--file <path>", "Backup file written by `push` or `undo`").option("--branch <id>", "Target branch (default: the branch in the file)").option("--message <text>", "Commit message").option("--author <email>", "Commit author (default: the logged-in VTEX user)").option("--yes", "Actually write. Without it, this is a dry run.", false).option("--allow-main", "Permit committing straight to main", false).option("--json", "Emit structured JSON instead of human-readable text", false).action(async (opts) => {
70777
+ process.exit(await cmsRestoreCommand({
70778
+ file: opts.file,
70779
+ branch: opts.branch,
70780
+ message: opts.message,
70781
+ author: opts.author,
70707
70782
  yes: Boolean(opts.yes),
70708
- allowMain: Boolean(opts.allowMain)
70783
+ allowMain: Boolean(opts.allowMain),
70784
+ json: Boolean(opts.json)
70709
70785
  }));
70710
70786
  }));
70711
70787
  program.command("serve").argument("<runId>", "Run ID to serve").description("Spawns a local HTTP server that serves the report and proxies external iframes (strips X-Frame-Options/CSP), making the Side-by-side tab functional for any site.").option("--output <dir>", "Output directory where runs live", "./parity-output").option("--port <n>", "Fixed port (default: auto-pick free port)", (v) => Number(v)).option("--no-open", "Don't open the browser automatically").action(async (runId, opts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/parity",
3
- "version": "0.33.14",
3
+ "version": "0.33.16",
4
4
  "description": "E2E parity validator for site migrations. Compares prod vs cand and reports UI, functional, SEO, visual, and Web Vitals deltas with an LLM-ranked HTML report.",
5
5
  "type": "module",
6
6
  "license": "MIT",