@decocms/parity 0.33.19 → 0.33.21

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 +131 -2
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -57602,6 +57602,41 @@ async function getContentTypes(cfg, call = callCms) {
57602
57602
  async function getSchemaMeta(cfg, call = callCms) {
57603
57603
  return call(cfg, { path: `${SCHEMAS}/${cfg.account}.${cfg.store}` });
57604
57604
  }
57605
+ var REGISTRY_BASE = "https://api.vtexcommercestable.com.br/api/content-platform/schemas";
57606
+ var callRegistry = async (cfg, path, init = {}) => {
57607
+ const method = init.method ?? "GET";
57608
+ const res = await fetch(`${REGISTRY_BASE}/${path}`, {
57609
+ method,
57610
+ headers: {
57611
+ authorization: `Bearer ${cfg.token}`,
57612
+ accept: "application/json",
57613
+ ...init.body === undefined ? {} : { "content-type": "application/json" }
57614
+ },
57615
+ ...init.body === undefined ? {} : { body: JSON.stringify(init.body) }
57616
+ });
57617
+ const text = await res.text().catch(() => "");
57618
+ if (!res.ok) {
57619
+ throw new Error(`${method} ${path}: HTTP ${res.status} ${text.slice(0, 300)}`);
57620
+ }
57621
+ return text ? JSON.parse(text) : {};
57622
+ };
57623
+ async function listSchemaVersions(cfg, call = callRegistry) {
57624
+ try {
57625
+ const rows = await call(cfg, `${cfg.account}.${cfg.store}/versions`);
57626
+ return Array.isArray(rows) ? rows : [];
57627
+ } catch (err) {
57628
+ if (err instanceof Error && /HTTP 404/.test(err.message))
57629
+ return [];
57630
+ throw err;
57631
+ }
57632
+ }
57633
+ async function publishSchema(cfg, schema, call = callRegistry) {
57634
+ const id = typeof schema.$id === "string" ? schema.$id : "";
57635
+ if (!id.includes("@")) {
57636
+ throw new Error("publishSchema: schema.$id must include an explicit version (account.store@1.0.0).");
57637
+ }
57638
+ await call(cfg, id, { method: "PUT", body: schema });
57639
+ }
57605
57640
 
57606
57641
  // src/cms/authoring.ts
57607
57642
  function unwrapValue(node) {
@@ -57881,6 +57916,22 @@ function propertyDrift(published, repoDir) {
57881
57916
  }
57882
57917
  return drift;
57883
57918
  }
57919
+ var SEMVER = /^(\d+)\.(\d+)\.(\d+)$/;
57920
+ function suggestNextSchemaVersion(versions) {
57921
+ let best = null;
57922
+ for (const row of versions) {
57923
+ const parsed = typeof row.version === "string" ? SEMVER.exec(row.version.split("-")[0] ?? "") : null;
57924
+ const tuple = parsed ? { major: Number(parsed[1]), minor: Number(parsed[2]), patch: Number(parsed[3]) } : row.major !== undefined && row.minor !== undefined && row.patch !== undefined ? { major: row.major, minor: row.minor, patch: row.patch } : null;
57925
+ if (!tuple)
57926
+ continue;
57927
+ if (!best || tuple.major > best.major || tuple.major === best.major && tuple.minor > best.minor || tuple.major === best.major && tuple.minor === best.minor && tuple.patch > best.patch) {
57928
+ best = tuple;
57929
+ }
57930
+ }
57931
+ if (!best)
57932
+ return "1.0.0";
57933
+ return `${best.major}.${best.minor + 1}.0`;
57934
+ }
57884
57935
 
57885
57936
  // src/commands/cms.ts
57886
57937
  var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -57919,6 +57970,21 @@ function writeBackup(version) {
57919
57970
  `);
57920
57971
  return backup;
57921
57972
  }
57973
+ function richTextCombinationRisk(usedKeys) {
57974
+ if (usedKeys.includes("RichText") && usedKeys.length > 1) {
57975
+ return "sections include RichText alongside another section — that combination is known to answer VALIDATION_ERROR on some accounts (see #348). If the commit below fails with an unexplained VALIDATION_ERROR, this is the first thing to bisect.";
57976
+ }
57977
+ return null;
57978
+ }
57979
+ function explainCommitError(err, usedKeys) {
57980
+ if (!(err instanceof Error) || !err.message.includes("VALIDATION_ERROR"))
57981
+ return err;
57982
+ const risk = richTextCombinationRisk(usedKeys);
57983
+ if (!risk)
57984
+ return err;
57985
+ return new Error(`${err.message}
57986
+ ${risk}`);
57987
+ }
57922
57988
  function resolveAuthor(explicit) {
57923
57989
  const author = explicit ?? readVtexSession()?.login;
57924
57990
  if (!author) {
@@ -57998,6 +58064,57 @@ async function cmsDoctorCommand(opts, call = callCms) {
57998
58064
  return fail(err);
57999
58065
  }
58000
58066
  }
58067
+ async function cmsSchemaPushCommand(opts, call = callCms, registryCall = callRegistry) {
58068
+ const cfg = config();
58069
+ if (!cfg)
58070
+ return 1;
58071
+ const schemaPath = join19(opts.repo, "cms", "faststore", "schema.json");
58072
+ if (!existsSync14(schemaPath)) {
58073
+ return fail(new Error(`No such file: ${schemaPath}. Generate it first (\`vtex content generate-schema\`).`));
58074
+ }
58075
+ let schema;
58076
+ try {
58077
+ schema = parseJsonc(readFileSync17(schemaPath, "utf8"));
58078
+ } catch (err) {
58079
+ return fail(new Error(`${schemaPath} is not valid JSON: ${err instanceof Error ? err.message : err}`));
58080
+ }
58081
+ try {
58082
+ const baseSchemaId = `${cfg.account}.${cfg.store}`;
58083
+ const [types, versions] = await Promise.all([
58084
+ getContentTypes(cfg, call),
58085
+ listSchemaVersions(cfg, registryCall)
58086
+ ]);
58087
+ const drift = schemaDrift(types, opts.repo);
58088
+ const propDrift = propertyDrift(types, opts.repo);
58089
+ const version = opts.version ?? suggestNextSchemaVersion(versions);
58090
+ const targetId = `${baseSchemaId}@${version}`;
58091
+ if (opts.json) {
58092
+ console.log(JSON.stringify({ targetId, drift, propDrift }, null, 2));
58093
+ } else {
58094
+ console.log(chalk7.dim(` target: ${targetId}`));
58095
+ for (const d of drift.filter((x) => x.missingOnAccount.length > 0)) {
58096
+ console.log(` + ${d.contentType}: ${d.missingOnAccount.join(", ")}`);
58097
+ }
58098
+ for (const d of propDrift) {
58099
+ if (d.missingProps.length > 0)
58100
+ console.log(` + ${d.contentType}: ${d.componentKey} — ${d.missingProps.join(", ")}`);
58101
+ }
58102
+ if (drift.every((x) => x.missingOnAccount.length === 0) && propDrift.length === 0) {
58103
+ console.log(chalk7.dim(" no drift found by doctor's own check — uploading anyway publishes this exact schema as a new version"));
58104
+ }
58105
+ }
58106
+ if (!opts.yes) {
58107
+ console.log(chalk7.yellow("dry run — nothing uploaded. Pass --yes to publish."));
58108
+ return 0;
58109
+ }
58110
+ schema.$id = targetId;
58111
+ await publishSchema(cfg, schema, registryCall);
58112
+ console.log(`${chalk7.green("✓")} published ${targetId}`);
58113
+ return 0;
58114
+ } catch (err) {
58115
+ return fail(err);
58116
+ }
58117
+ }
58001
58118
  async function cmsLsCommand(opts, call = callCms) {
58002
58119
  const cfg = config();
58003
58120
  if (!cfg)
@@ -58128,6 +58245,9 @@ async function cmsPushCommand(opts, call = callCms) {
58128
58245
  if (remote.baseHash !== local.baseHash) {
58129
58246
  return fail(new Error(`Stale: pulled at ${local.baseHash.slice(0, 12)}, remote is at ${remote.baseHash.slice(0, 12)}. Pull again.`));
58130
58247
  }
58248
+ const richTextRisk = richTextCombinationRisk(used);
58249
+ if (richTextRisk)
58250
+ console.log(`${chalk7.yellow("!")} ${richTextRisk}`);
58131
58251
  if (!opts.yes) {
58132
58252
  console.log(chalk7.yellow("dry run — nothing written. Pass --yes to commit."));
58133
58253
  for (const line of summarizeSections(local.data))
@@ -58150,7 +58270,9 @@ async function cmsPushCommand(opts, call = callCms) {
58150
58270
  author,
58151
58271
  identifierKeys: local.identifierKeys,
58152
58272
  searchKeywords: local.searchKeywords
58153
- }, call);
58273
+ }, call).catch((err) => {
58274
+ throw explainCommitError(err, used);
58275
+ });
58154
58276
  if (opts.json) {
58155
58277
  console.log(JSON.stringify({ commit, backup }, null, 2));
58156
58278
  return 0;
@@ -70852,7 +70974,14 @@ program.command("plan").description("Inspect/update the migration-plan.json comp
70852
70974
  }));
70853
70975
  program.command("cms").description("Read and write VTEX Content Platform entries — the CMS behind FastStore v4. Every write is a commit on a branch carrying the baseHash it was read at, so a concurrent edit fails the commit instead of silently winning. Needs PARITY_CMS_ACCOUNT + PARITY_CMS_STORE and a `vtex login` session (or PARITY_CMS_TOKEN).").addCommand(new Command("doctor").description("Compare the sections the repo declares against the ones published on the account. A section that exists in code but was never uploaded commits fine and renders nothing — this is the check that catches it.").option("--repo <path>", "Repo holding cms/faststore/pages/", ".").option("--json", "Emit structured JSON instead of human-readable text", false).action(async (opts) => {
70854
70976
  process.exit(await cmsDoctorCommand({ repo: opts.repo, json: Boolean(opts.json) }));
70855
- })).addCommand(new Command("ls").description("List entries, or branches with --branches. Branch ids are what every write needs.").option("--content-type <name>", "Filter by content type (home, landingPage, plp, ...)").option("--branches", "List branches instead of entries", false).option("--json", "Emit structured JSON instead of human-readable text", false).action(async (opts) => {
70977
+ })).addCommand(new Command("schema").description("Manage the published schema registry.").addCommand(new Command("push").description("Upload cms/faststore/schema.json to the registry as a new version. Dry run unless --yes; never deletes the local file.").option("--repo <path>", "Repo holding cms/faststore/schema.json", ".").option("--version <semver>", "Version to publish (default: next minor bump)").option("--yes", "Actually publish. Without it, this is a dry run.", false).option("--json", "Emit structured JSON instead of human-readable text", false).action(async (opts) => {
70978
+ process.exit(await cmsSchemaPushCommand({
70979
+ repo: opts.repo,
70980
+ version: opts.version,
70981
+ yes: Boolean(opts.yes),
70982
+ json: Boolean(opts.json)
70983
+ }));
70984
+ }))).addCommand(new Command("ls").description("List entries, or branches with --branches. Branch ids are what every write needs.").option("--content-type <name>", "Filter by content type (home, landingPage, plp, ...)").option("--branches", "List branches instead of entries", false).option("--json", "Emit structured JSON instead of human-readable text", false).action(async (opts) => {
70856
70985
  process.exit(await cmsLsCommand({
70857
70986
  contentType: opts.contentType,
70858
70987
  branches: Boolean(opts.branches),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/parity",
3
- "version": "0.33.19",
3
+ "version": "0.33.21",
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",