@decocms/parity 0.33.15 → 0.33.17

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 +171 -16
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -57639,6 +57639,18 @@ function summarizeSections(data) {
57639
57639
  return counts.length > 0 ? `${s.componentKey} (${counts.join(", ")})` : s.componentKey;
57640
57640
  });
57641
57641
  }
57642
+ function toDataPlaneShape(node) {
57643
+ if (Array.isArray(node))
57644
+ return node.map(toDataPlaneShape);
57645
+ if (node && typeof node === "object") {
57646
+ const obj = node;
57647
+ if (obj.values && typeof obj.values === "object") {
57648
+ return collectionToArray(obj).sort((a, b) => (a.$position ?? 0) - (b.$position ?? 0)).map(({ id, $position, ...rest }) => toDataPlaneShape(rest));
57649
+ }
57650
+ return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, toDataPlaneShape(v)]));
57651
+ }
57652
+ return node;
57653
+ }
57642
57654
  function localeSwitch(value) {
57643
57655
  return {
57644
57656
  $fnType: "switch",
@@ -57787,9 +57799,73 @@ function unrenderableSections(usedKeys, contentType) {
57787
57799
  return [];
57788
57800
  return [...new Set(usedKeys.filter((k) => !allowed.includes(k)))];
57789
57801
  }
57802
+ function parseJsonc(raw) {
57803
+ const withoutComments = raw.replace(/\/\/.*$/gm, "");
57804
+ const withoutTrailingCommas = withoutComments.replace(/,(\s*[}\]])/g, "$1");
57805
+ return JSON.parse(withoutTrailingCommas);
57806
+ }
57807
+ function localComponentSchemas(repoDir) {
57808
+ const dir = join18(repoDir, "cms", "faststore", "components");
57809
+ if (!existsSync13(dir))
57810
+ return {};
57811
+ const out = {};
57812
+ for (const file of readdirSync3(dir)) {
57813
+ if (!file.endsWith(".jsonc"))
57814
+ continue;
57815
+ try {
57816
+ const parsed = parseJsonc(readFileSync16(join18(dir, file), "utf8"));
57817
+ if (!parsed.$componentKey)
57818
+ continue;
57819
+ out[parsed.$componentKey] = {
57820
+ properties: Object.keys(parsed.properties ?? {}),
57821
+ required: parsed.required ?? []
57822
+ };
57823
+ } catch {}
57824
+ }
57825
+ return out;
57826
+ }
57827
+ function publishedComponentSchemas(contentType) {
57828
+ const items = contentType?.properties?.sections?.items;
57829
+ const anyOf = items?.anyOf ?? [];
57830
+ const out = {};
57831
+ for (const s of anyOf) {
57832
+ const key = String(s.$componentKey ?? "");
57833
+ if (!key)
57834
+ continue;
57835
+ out[key] = {
57836
+ properties: Object.keys(s.properties ?? {}),
57837
+ required: s.required ?? []
57838
+ };
57839
+ }
57840
+ return out;
57841
+ }
57842
+ function propertyDrift(published, repoDir) {
57843
+ const local = localComponentSchemas(repoDir);
57844
+ const drift = [];
57845
+ for (const [contentType, schema] of Object.entries(published)) {
57846
+ const remote = publishedComponentSchemas(schema);
57847
+ for (const [componentKey, localShape] of Object.entries(local)) {
57848
+ const remoteShape = remote[componentKey];
57849
+ if (!remoteShape)
57850
+ continue;
57851
+ const missingProps = localShape.properties.filter((p) => !remoteShape.properties.includes(p));
57852
+ const newlyRequiredProps = localShape.required.filter((p) => remoteShape.properties.includes(p) && !remoteShape.required.includes(p));
57853
+ if (missingProps.length > 0 || newlyRequiredProps.length > 0) {
57854
+ drift.push({ contentType, componentKey, missingProps, newlyRequiredProps });
57855
+ }
57856
+ }
57857
+ }
57858
+ return drift;
57859
+ }
57790
57860
 
57791
57861
  // src/commands/cms.ts
57792
57862
  var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
57863
+ var DICT_SHAPE_CONTENT_TYPES = new Set(["globalSections"]);
57864
+ function withDataPlaneShape(contentType, data) {
57865
+ if (DICT_SHAPE_CONTENT_TYPES.has(contentType))
57866
+ return data;
57867
+ return toDataPlaneShape(data);
57868
+ }
57793
57869
  function config() {
57794
57870
  const account = process.env.PARITY_CMS_ACCOUNT;
57795
57871
  const store = process.env.PARITY_CMS_STORE;
@@ -57812,6 +57888,13 @@ function fail(err) {
57812
57888
  console.error(chalk7.red(err instanceof Error ? err.message : String(err)));
57813
57889
  return 1;
57814
57890
  }
57891
+ function writeBackup(version) {
57892
+ const backup = join19("parity-output", "cms-backups", `${version.entryId}-${version.baseHash.slice(0, 12)}.json`);
57893
+ mkdirSync9(dirname4(backup), { recursive: true });
57894
+ writeFileSync13(backup, `${JSON.stringify(version, null, 2)}
57895
+ `);
57896
+ return backup;
57897
+ }
57815
57898
  function resolveAuthor(explicit) {
57816
57899
  const author = explicit ?? readVtexSession()?.login;
57817
57900
  if (!author) {
@@ -57841,23 +57924,33 @@ async function cmsDoctorCommand(opts, call = callCms) {
57841
57924
  try {
57842
57925
  const types = await getContentTypes(cfg, call);
57843
57926
  const drift = schemaDrift(types, opts.repo);
57927
+ const propDrift = propertyDrift(types, opts.repo);
57928
+ const blockingProps = propDrift.filter((d) => d.missingProps.length > 0);
57844
57929
  if (opts.json) {
57845
- console.log(JSON.stringify({ session, contentTypes: Object.keys(types), drift }, null, 2));
57846
- return drift.some((d) => d.missingOnAccount.length > 0) ? 1 : 0;
57930
+ console.log(JSON.stringify({ session, contentTypes: Object.keys(types), drift, propDrift }, null, 2));
57931
+ return drift.some((d) => d.missingOnAccount.length > 0) || blockingProps.length > 0 ? 1 : 0;
57847
57932
  }
57848
57933
  if (session)
57849
57934
  console.log(`${chalk7.green("✓")} ${session}`);
57850
57935
  const blocking = drift.filter((d) => d.missingOnAccount.length > 0);
57851
- if (blocking.length === 0) {
57936
+ if (blocking.length === 0 && propDrift.length === 0) {
57852
57937
  console.log(`${chalk7.green("✓")} every section the repo declares is published on the account`);
57853
57938
  }
57854
57939
  for (const d of blocking) {
57855
57940
  console.log(`${chalk7.red("✗")} ${d.contentType}: ${d.missingOnAccount.join(", ")} ${chalk7.dim("— in the repo, not on the account. Upload the schema (`faststore cms-sync`) or it renders nothing.")}`);
57856
57941
  }
57942
+ for (const d of propDrift) {
57943
+ if (d.missingProps.length > 0) {
57944
+ console.log(`${chalk7.red("✗")} ${d.contentType}: ${d.componentKey} — property ${d.missingProps.join(", ")} ${chalk7.dim("in the repo, not on the account. Upload the schema or it renders nothing.")}`);
57945
+ }
57946
+ if (d.newlyRequiredProps.length > 0) {
57947
+ console.log(`${chalk7.yellow("!")} ${d.contentType}: ${d.componentKey} — ${d.newlyRequiredProps.join(", ")} ${chalk7.dim("now required locally but optional on the account. Entries authored before this change may not have it.")}`);
57948
+ }
57949
+ }
57857
57950
  for (const d of drift.filter((x) => x.missingInRepo.length > 0)) {
57858
57951
  console.log(`${chalk7.gray("·")} ${d.contentType}: ${d.missingInRepo.length} section(s) published but not in the repo ${chalk7.dim("(usually core components the repo never overrode)")}`);
57859
57952
  }
57860
- return blocking.length > 0 ? 1 : 0;
57953
+ return blocking.length > 0 || blockingProps.length > 0 ? 1 : 0;
57861
57954
  } catch (err) {
57862
57955
  return fail(err);
57863
57956
  }
@@ -58002,17 +58095,14 @@ async function cmsPushCommand(opts, call = callCms) {
58002
58095
  const author = resolveAuthor(opts.author);
58003
58096
  if (author instanceof Error)
58004
58097
  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
- `);
58098
+ const backup = writeBackup(remote);
58009
58099
  const commit = await commitEntry(cfg, {
58010
58100
  branchId: branch,
58011
58101
  contentTypeId: local.contentType,
58012
58102
  entryId: local.entryId,
58013
58103
  entryName: local.entryName,
58014
58104
  baseHash: local.baseHash,
58015
- data: local.data,
58105
+ data: withDataPlaneShape(local.contentType, local.data),
58016
58106
  message: opts.message ?? "parity cms push",
58017
58107
  author,
58018
58108
  identifierKeys: local.identifierKeys,
@@ -58023,13 +58113,57 @@ async function cmsPushCommand(opts, call = callCms) {
58023
58113
  return 0;
58024
58114
  }
58025
58115
  console.log(`${chalk7.green("✓")} commit ${commit.id} on ${branch}`);
58026
- console.log(chalk7.dim(` rollback: parity cms undo --entry ${local.entryId} --branch ${branch}`));
58116
+ console.log(chalk7.dim(` rollback: parity cms restore --file ${backup} --branch ${branch}${branch === "main" ? " --allow-main" : ""} --yes`));
58027
58117
  console.log(chalk7.dim(` backup: ${backup}`));
58028
58118
  return 0;
58029
58119
  } catch (err) {
58030
58120
  return fail(err);
58031
58121
  }
58032
58122
  }
58123
+ async function cmsRestoreCommand(opts, call = callCms) {
58124
+ const cfg = config();
58125
+ if (!cfg)
58126
+ return 1;
58127
+ const backup = readPulled(opts.file);
58128
+ if (backup instanceof Error)
58129
+ return fail(backup);
58130
+ const branch = resolveBranch(opts.branch ?? backup.branchId, Boolean(opts.allowMain));
58131
+ if (branch instanceof Error)
58132
+ return fail(branch);
58133
+ try {
58134
+ const head = await getLastVersion(cfg, { contentType: backup.contentType, entryId: backup.entryId, branchId: branch }, call);
58135
+ if (!opts.yes) {
58136
+ console.log(chalk7.yellow("dry run — nothing written. Pass --yes to restore."));
58137
+ for (const line of summarizeSections(backup.data))
58138
+ console.log(` ${line}`);
58139
+ console.log(chalk7.dim(` branch ${branch} · entry ${backup.entryId} · ${backup.contentType}`));
58140
+ return 0;
58141
+ }
58142
+ const author = resolveAuthor(opts.author);
58143
+ if (author instanceof Error)
58144
+ return fail(author);
58145
+ const commit = await commitEntry(cfg, {
58146
+ branchId: branch,
58147
+ contentTypeId: backup.contentType,
58148
+ entryId: backup.entryId,
58149
+ entryName: backup.entryName,
58150
+ baseHash: head.baseHash,
58151
+ data: backup.data,
58152
+ message: opts.message ?? `parity cms restore ${opts.file}`,
58153
+ author,
58154
+ identifierKeys: backup.identifierKeys,
58155
+ searchKeywords: backup.searchKeywords
58156
+ }, call);
58157
+ if (opts.json) {
58158
+ console.log(JSON.stringify({ commit }, null, 2));
58159
+ return 0;
58160
+ }
58161
+ console.log(`${chalk7.green("✓")} ${backup.entryId} restored from ${opts.file}, commit ${commit.id} on ${branch}`);
58162
+ return 0;
58163
+ } catch (err) {
58164
+ return fail(err);
58165
+ }
58166
+ }
58033
58167
  async function cmsUndoCommand(opts, call = callCms) {
58034
58168
  const cfg = config();
58035
58169
  if (!cfg)
@@ -58038,12 +58172,21 @@ async function cmsUndoCommand(opts, call = callCms) {
58038
58172
  if (branch instanceof Error)
58039
58173
  return fail(branch);
58040
58174
  if (!opts.yes) {
58041
- console.log(chalk7.yellow(`dry run — would drop ${opts.entry} changes on ${branch}. Pass --yes.`));
58175
+ 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
58176
  return 0;
58043
58177
  }
58178
+ if (!opts.allowDelete) {
58179
+ 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."));
58180
+ }
58044
58181
  try {
58182
+ const contentType = opts.contentType ?? (await listEntries(cfg, {}, call)).find((e) => e.id === opts.entry)?.contentTypeId;
58183
+ if (contentType) {
58184
+ const current = await getLastVersion(cfg, { contentType, entryId: opts.entry, branchId: branch }, call).catch(() => null);
58185
+ if (current)
58186
+ console.log(chalk7.dim(` backup: ${writeBackup(current)}`));
58187
+ }
58045
58188
  await undoEntry(cfg, { branchId: branch, entryId: opts.entry }, call);
58046
- console.log(`${chalk7.green("✓")} ${opts.entry} reverted on ${branch}`);
58189
+ console.log(`${chalk7.green("✓")} ${opts.entry} deleted on ${branch}`);
58047
58190
  return 0;
58048
58191
  } catch (err) {
58049
58192
  return fail(err);
@@ -58122,11 +58265,11 @@ async function cmsCreateCommand(opts, call = callCms) {
58122
58265
  entryId,
58123
58266
  entryName: name,
58124
58267
  baseHash: head,
58125
- data: {
58268
+ data: withDataPlaneShape(opts.contentType, {
58126
58269
  slug: localeSwitch(opts.slug),
58127
58270
  seo: { slug: localeSwitch(opts.slug), title: localeSwitch(name), description: localeSwitch("") },
58128
58271
  sections: { $fnType: "array", values: {} }
58129
- },
58272
+ }),
58130
58273
  message: opts.message ?? `parity cms create ${opts.slug}`,
58131
58274
  author,
58132
58275
  identifierKeys: null,
@@ -70707,12 +70850,24 @@ program.command("cms").description("Read and write VTEX Content Platform entries
70707
70850
  }));
70708
70851
  })).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) => {
70709
70852
  process.exit(await cmsRmCommand({ entry: opts.entry, yes: Boolean(opts.yes) }));
70710
- })).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) => {
70853
+ })).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) => {
70711
70854
  process.exit(await cmsUndoCommand({
70712
70855
  entry: opts.entry,
70713
70856
  branch: opts.branch,
70857
+ contentType: opts.contentType,
70858
+ yes: Boolean(opts.yes),
70859
+ allowMain: Boolean(opts.allowMain),
70860
+ allowDelete: Boolean(opts.allowDelete)
70861
+ }));
70862
+ })).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) => {
70863
+ process.exit(await cmsRestoreCommand({
70864
+ file: opts.file,
70865
+ branch: opts.branch,
70866
+ message: opts.message,
70867
+ author: opts.author,
70714
70868
  yes: Boolean(opts.yes),
70715
- allowMain: Boolean(opts.allowMain)
70869
+ allowMain: Boolean(opts.allowMain),
70870
+ json: Boolean(opts.json)
70716
70871
  }));
70717
70872
  }));
70718
70873
  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.15",
3
+ "version": "0.33.17",
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",