@decocms/parity 0.33.22 → 0.33.23

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 +159 -27
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -41674,12 +41674,10 @@ var ExpectedDivergence = z.object({
41674
41674
  note: z.string()
41675
41675
  });
41676
41676
  var ParityIgnore = z.object({
41677
- ignoreSelectorsVisual: z.array(z.string()).default([]),
41678
41677
  expectedDivergences: z.array(ExpectedDivergence).optional(),
41679
41678
  ignoreRequestPatterns: z.array(z.string()).default([]),
41680
41679
  ignoreConsolePatterns: z.array(z.string()).default([]),
41681
- ignoreMetaKeys: z.array(z.string()).default([]),
41682
- toleratedDomDrift: z.record(z.string(), z.number()).default({})
41680
+ ignoreMetaKeys: z.array(z.string()).default([])
41683
41681
  });
41684
41682
 
41685
41683
  // src/storage/fs.ts
@@ -56337,11 +56335,9 @@ async function cacheCommand(opts) {
56337
56335
  }
56338
56336
  const rc = { cep: "01310-100", selectors: {}, skipSteps: [] };
56339
56337
  const ignore = {
56340
- ignoreSelectorsVisual: [],
56341
56338
  ignoreRequestPatterns: [],
56342
56339
  ignoreConsolePatterns: [],
56343
- ignoreMetaKeys: [],
56344
- toleratedDomDrift: {}
56340
+ ignoreMetaKeys: []
56345
56341
  };
56346
56342
  const checkCtx = {
56347
56343
  prodPages: allPageCaptures.filter((p) => p.side === "prod"),
@@ -57494,6 +57490,7 @@ import { join as join16 } from "node:path";
57494
57490
  import { readFileSync as readFileSync14 } from "node:fs";
57495
57491
  var MANAGE = "api/content-platform/manage";
57496
57492
  var SCHEMAS = "api/content-platform/schemas";
57493
+ var DATA = "api/content-platform/data";
57497
57494
  function tokenFromVtexSession(home = homedir2()) {
57498
57495
  try {
57499
57496
  const raw = readFileSync14(join16(home, ".config", "configstore", "vtex.json"), "utf8");
@@ -57648,6 +57645,20 @@ async function publishSchema(cfg, schema, call = callRegistry) {
57648
57645
  }
57649
57646
  await call(cfg, id, { method: "PUT", body: schema });
57650
57647
  }
57648
+ var callDelivery = async (cfg, path) => {
57649
+ const res = await fetch(`https://${cfg.account}.vtexcommercestable.com.br/${path}`, {
57650
+ headers: { accept: "application/json" }
57651
+ });
57652
+ const text = await res.text().catch(() => "");
57653
+ if (!res.ok) {
57654
+ throw new Error(`GET ${path}: HTTP ${res.status} ${text.slice(0, 300)}`);
57655
+ }
57656
+ return text ? JSON.parse(text) : {};
57657
+ };
57658
+ async function getDeliveryEntry(cfg, args, call = callDelivery) {
57659
+ const slug = args.slug.replace(/^\//, "");
57660
+ return call(cfg, `${DATA}/${cfg.account}/${cfg.store}/${args.contentType}/entries/slug/${slug}`);
57661
+ }
57651
57662
 
57652
57663
  // src/cms/authoring.ts
57653
57664
  function unwrapValue(node) {
@@ -57870,9 +57881,46 @@ function unrenderableSections(usedKeys, contentType) {
57870
57881
  return [...new Set(usedKeys.filter((k) => !allowed.includes(k)))];
57871
57882
  }
57872
57883
  function parseJsonc(raw) {
57873
- const withoutComments = raw.replace(/\/\/.*$/gm, "");
57874
- const withoutTrailingCommas = withoutComments.replace(/,(\s*[}\]])/g, "$1");
57875
- return JSON.parse(withoutTrailingCommas);
57884
+ let out = "";
57885
+ let inString = false;
57886
+ let escaped = false;
57887
+ for (let i = 0;i < raw.length; i++) {
57888
+ const ch = raw[i];
57889
+ if (inString) {
57890
+ out += ch;
57891
+ if (escaped)
57892
+ escaped = false;
57893
+ else if (ch === "\\")
57894
+ escaped = true;
57895
+ else if (ch === '"')
57896
+ inString = false;
57897
+ continue;
57898
+ }
57899
+ if (ch === '"') {
57900
+ inString = true;
57901
+ out += ch;
57902
+ continue;
57903
+ }
57904
+ if (ch === "/" && raw[i + 1] === "/") {
57905
+ while (i < raw.length && raw[i] !== `
57906
+ `)
57907
+ i++;
57908
+ out += `
57909
+ `;
57910
+ continue;
57911
+ }
57912
+ if (ch === "/" && raw[i + 1] === "*") {
57913
+ i += 2;
57914
+ while (i < raw.length && !(raw[i] === "*" && raw[i + 1] === "/"))
57915
+ i++;
57916
+ i++;
57917
+ continue;
57918
+ }
57919
+ if (ch === "}" || ch === "]")
57920
+ out = out.replace(/,\s*$/, "");
57921
+ out += ch;
57922
+ }
57923
+ return JSON.parse(out);
57876
57924
  }
57877
57925
  function localComponentSchemas(repoDir) {
57878
57926
  const dir = join18(repoDir, "cms", "faststore", "components");
@@ -57890,7 +57938,9 @@ function localComponentSchemas(repoDir) {
57890
57938
  properties: Object.keys(parsed.properties ?? {}),
57891
57939
  required: parsed.required ?? []
57892
57940
  };
57893
- } catch {}
57941
+ } catch (err) {
57942
+ console.warn(` ! could not read ${file}: ${err instanceof Error ? err.message : err} — its properties are NOT being checked`);
57943
+ }
57894
57944
  }
57895
57945
  return out;
57896
57946
  }
@@ -57974,6 +58024,33 @@ function fail(err) {
57974
58024
  console.error(chalk7.red(err instanceof Error ? err.message : String(err)));
57975
58025
  return 1;
57976
58026
  }
58027
+ function leafLike(existing, value) {
58028
+ const isSwitch = existing !== null && typeof existing === "object" && !Array.isArray(existing) && existing.$fnType === "switch";
58029
+ return isSwitch ? localeSwitch(value) : value;
58030
+ }
58031
+ function newPageData(template, page) {
58032
+ const base = template ? { ...template } : {};
58033
+ const seoSource = base.seo ?? {};
58034
+ const sections = base.sections;
58035
+ const emptySections = sections && typeof sections === "object" && !Array.isArray(sections) ? { ...sections, values: {} } : { $fnType: "array", values: {} };
58036
+ return {
58037
+ ...base,
58038
+ slug: leafLike(base.slug, page.slug),
58039
+ seo: {
58040
+ ...seoSource,
58041
+ slug: leafLike(seoSource.slug, page.slug),
58042
+ title: leafLike(seoSource.title, page.name)
58043
+ },
58044
+ sections: emptySections
58045
+ };
58046
+ }
58047
+ function writeRejectedPayload(entryId, body) {
58048
+ const out = join19("parity-output", "cms-backups", `${entryId}-rejected.json`);
58049
+ mkdirSync9(dirname4(out), { recursive: true });
58050
+ writeFileSync13(out, `${JSON.stringify(body, null, 2)}
58051
+ `);
58052
+ return out;
58053
+ }
57977
58054
  function writeBackup(version) {
57978
58055
  const backup = join19("parity-output", "cms-backups", `${version.entryId}-${version.baseHash.slice(0, 12)}.json`);
57979
58056
  mkdirSync9(dirname4(backup), { recursive: true });
@@ -57987,6 +58064,41 @@ function richTextCombinationRisk(usedKeys) {
57987
58064
  }
57988
58065
  return null;
57989
58066
  }
58067
+ async function verifyRendered(cfg, args, call = callDelivery) {
58068
+ const pushedSections = sectionsOf(args.data).length;
58069
+ if (pushedSections === 0) {
58070
+ return { ok: null, reason: "nothing to verify — the pushed entry has no sections" };
58071
+ }
58072
+ if (args.branch !== "main") {
58073
+ return { ok: null, reason: `branch ${args.branch} is not published, so the data plane cannot see it yet` };
58074
+ }
58075
+ const slug = unwrapValue(args.data.slug);
58076
+ if (typeof slug !== "string" || !slug) {
58077
+ return { ok: null, reason: "the entry has no slug to resolve by" };
58078
+ }
58079
+ let entry;
58080
+ try {
58081
+ entry = await getDeliveryEntry(cfg, { contentType: args.contentType, slug }, call);
58082
+ } catch (err) {
58083
+ return {
58084
+ ok: null,
58085
+ reason: `could not read ${slug} back from the data plane (${err instanceof Error ? err.message : err})`
58086
+ };
58087
+ }
58088
+ if (!Array.isArray(entry.sections)) {
58089
+ return {
58090
+ ok: false,
58091
+ reason: `${slug} came back from the data plane with sections as ${entry.sections === undefined ? "undefined" : typeof entry.sections}, not an array — the storefront will render it as zero sections (#349)`
58092
+ };
58093
+ }
58094
+ if (entry.sections.length === 0) {
58095
+ return {
58096
+ ok: false,
58097
+ reason: `${slug} came back from the data plane with an empty sections array, but ${pushedSections} section(s) were pushed (#349)`
58098
+ };
58099
+ }
58100
+ return { ok: true, reason: "", sections: entry.sections.length };
58101
+ }
57990
58102
  function explainCommitError(err, usedKeys) {
57991
58103
  if (!(err instanceof Error) || !err.message.includes("VALIDATION_ERROR"))
57992
58104
  return err;
@@ -58085,7 +58197,7 @@ async function cmsSchemaPushCommand(opts, call = callCms, registryCall = callReg
58085
58197
  }
58086
58198
  let schema;
58087
58199
  try {
58088
- schema = parseJsonc(readFileSync17(schemaPath, "utf8"));
58200
+ schema = JSON.parse(readFileSync17(schemaPath, "utf8"));
58089
58201
  } catch (err) {
58090
58202
  return fail(new Error(`${schemaPath} is not valid JSON: ${err instanceof Error ? err.message : err}`));
58091
58203
  }
@@ -58235,7 +58347,7 @@ async function cmsDiffCommand(opts, call = callCms) {
58235
58347
  return fail(err);
58236
58348
  }
58237
58349
  }
58238
- async function cmsPushCommand(opts, call = callCms) {
58350
+ async function cmsPushCommand(opts, call = callCms, deliveryCall = callDelivery) {
58239
58351
  const cfg = config();
58240
58352
  if (!cfg)
58241
58353
  return 1;
@@ -58284,13 +58396,24 @@ async function cmsPushCommand(opts, call = callCms) {
58284
58396
  }, call).catch((err) => {
58285
58397
  throw explainCommitError(err, used);
58286
58398
  });
58399
+ const rendered = await verifyRendered(cfg, { contentType: local.contentType, data: local.data, branch }, deliveryCall);
58287
58400
  if (opts.json) {
58288
- console.log(JSON.stringify({ commit, backup }, null, 2));
58289
- return 0;
58401
+ console.log(JSON.stringify({ commit, backup, rendered }, null, 2));
58402
+ return rendered.ok === false ? 1 : 0;
58290
58403
  }
58291
58404
  console.log(`${chalk7.green("✓")} commit ${commit.id} on ${branch}`);
58292
58405
  console.log(chalk7.dim(` rollback: parity cms restore --file ${backup} --branch ${branch}${branch === "main" ? " --allow-main" : ""} --yes`));
58293
58406
  console.log(chalk7.dim(` backup: ${backup}`));
58407
+ if (rendered.ok === false) {
58408
+ return fail(new Error(`${rendered.reason}
58409
+ The commit succeeded — this content is live and renders as nothing. Restore with:
58410
+ parity cms restore --file ${backup} --branch ${branch}${branch === "main" ? " --allow-main" : ""} --yes`));
58411
+ }
58412
+ if (rendered.ok === true) {
58413
+ console.log(chalk7.dim(` verified: ${rendered.sections} section(s) live on the data plane`));
58414
+ } else {
58415
+ console.log(chalk7.dim(` not verified: ${rendered.reason}`));
58416
+ }
58294
58417
  return 0;
58295
58418
  } catch (err) {
58296
58419
  return fail(err);
@@ -58434,23 +58557,24 @@ async function cmsCreateCommand(opts, call = callCms) {
58434
58557
  const entryId = created[0].id;
58435
58558
  try {
58436
58559
  await renameEntry(cfg, { entryId, name }, call);
58437
- const head = await getLastVersion(cfg, { contentType: opts.contentType, entryId, branchId: branch }, call).then((v) => v.baseHash).catch(() => null);
58438
- const commit = await commitEntry(cfg, {
58560
+ const copyHead = await getLastVersion(cfg, { contentType: opts.contentType, entryId, branchId: branch }, call).catch(() => null);
58561
+ const head = copyHead?.baseHash ?? null;
58562
+ const commitInput = {
58439
58563
  branchId: branch,
58440
58564
  contentTypeId: opts.contentType,
58441
58565
  entryId,
58442
58566
  entryName: name,
58443
58567
  baseHash: head,
58444
- data: withDataPlaneShape(opts.contentType, {
58445
- slug: localeSwitch(opts.slug),
58446
- seo: { slug: localeSwitch(opts.slug), title: localeSwitch(name), description: localeSwitch("") },
58447
- sections: { $fnType: "array", values: {} }
58448
- }),
58568
+ data: newPageData(copyHead?.data, { slug: opts.slug, name }),
58449
58569
  message: opts.message ?? `parity cms create ${opts.slug}`,
58450
58570
  author,
58451
58571
  identifierKeys: null,
58452
58572
  searchKeywords: null
58453
- }, call);
58573
+ };
58574
+ const commit = await commitEntry(cfg, commitInput, call).catch((err) => {
58575
+ throw new Error(`${err instanceof Error ? err.message : err}
58576
+ rejected payload: ${writeRejectedPayload(entryId, commitInput)}`);
58577
+ });
58454
58578
  if (opts.json) {
58455
58579
  console.log(JSON.stringify({ entryId, slug: opts.slug, branch, commit }, null, 2));
58456
58580
  return 0;
@@ -68410,6 +68534,12 @@ var PRESETS = {
68410
68534
  only: "e2e,html,console"
68411
68535
  }
68412
68536
  };
68537
+ function resolveScopedFlows(args) {
68538
+ const needed = Array.from(args.selectionFlows);
68539
+ const flows = args.explicitFlows.length > 0 ? Array.from(new Set(args.explicitFlows)) : Array.from(new Set(needed));
68540
+ const starved = needed.filter((f) => !flows.includes(f));
68541
+ return { flows, starved };
68542
+ }
68413
68543
  function pagesFlowsScopeWarning(opts, flows) {
68414
68544
  if (!opts.pages && !opts.pagesFile)
68415
68545
  return null;
@@ -68583,8 +68713,12 @@ async function runCommand(rawOpts) {
68583
68713
  let flows;
68584
68714
  if (hasSelection) {
68585
68715
  const explicitFlows = userSetFlows ? opts.flows.split(",").map((s) => s.trim()).filter(Boolean) : [];
68586
- flows = Array.from(new Set([...explicitFlows, ...selection.flows]));
68587
- console.log(chalk22.dim(` modules: ${selection.modules.join(", ") || "(none)"} → flows: ${flows.join(",")}`));
68716
+ const scoped = resolveScopedFlows({ explicitFlows, selectionFlows: selection.flows });
68717
+ flows = scoped.flows;
68718
+ console.log(chalk22.dim(` modules: ${selection.modules.join(", ") || "(none)"} → flows: ${flows.join(",")}${explicitFlows.length > 0 ? " (scoped by --flows)" : ""}`));
68719
+ if (scoped.starved.length > 0) {
68720
+ console.log(chalk22.yellow(` ! --flows leaves out ${scoped.starved.join(",")}, which the selected modules capture from — those checks may have nothing to analyze`));
68721
+ }
68588
68722
  } else {
68589
68723
  flows = opts.flows.split(",").map((s) => s.trim());
68590
68724
  if (!interactivePromptShown) {
@@ -70728,11 +70862,9 @@ async function vitalsCommand(opts) {
70728
70862
  }
70729
70863
  const rc = { cep: "01310-100", selectors: {}, skipSteps: [] };
70730
70864
  const ignore = {
70731
- ignoreSelectorsVisual: [],
70732
70865
  ignoreRequestPatterns: [],
70733
70866
  ignoreConsolePatterns: [],
70734
- ignoreMetaKeys: [],
70735
- toleratedDomDrift: {}
70867
+ ignoreMetaKeys: []
70736
70868
  };
70737
70869
  const checkCtx = {
70738
70870
  prodPages: allPageCaptures.filter((p) => p.side === "prod"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/parity",
3
- "version": "0.33.22",
3
+ "version": "0.33.23",
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",