@decocms/parity 0.29.2 → 0.30.0

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 +182 -3
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -56766,7 +56766,7 @@ async function getLastVersion(cfg, args, call = callCms) {
56766
56766
  }
56767
56767
  }
56768
56768
  async function commitEntry(cfg, input, call = callCms) {
56769
- if (!input.baseHash) {
56769
+ if (input.baseHash === undefined || input.baseHash === "") {
56770
56770
  throw new Error("commitEntry: baseHash is required — it is the lock against clobbering a concurrent edit");
56771
56771
  }
56772
56772
  return call(cfg, {
@@ -56791,6 +56791,25 @@ async function undoEntry(cfg, args, call = callCms) {
56791
56791
  method: "DELETE"
56792
56792
  });
56793
56793
  }
56794
+ async function duplicateEntry(cfg, args, call = callCms) {
56795
+ await call(cfg, {
56796
+ path: `${MANAGE}/${cfg.account}/${cfg.store}/entries/${args.entryId}/duplicate`,
56797
+ method: "POST"
56798
+ });
56799
+ }
56800
+ async function deleteEntry(cfg, args, call = callCms) {
56801
+ await call(cfg, {
56802
+ path: `${MANAGE}/${cfg.account}/${cfg.store}/entries/${args.entryId}`,
56803
+ method: "DELETE"
56804
+ });
56805
+ }
56806
+ async function renameEntry(cfg, args, call = callCms) {
56807
+ await call(cfg, {
56808
+ path: `${MANAGE}/${cfg.account}/${cfg.store}/entries/${args.entryId}/rename`,
56809
+ method: "PUT",
56810
+ body: { name: args.name }
56811
+ });
56812
+ }
56794
56813
  async function getContentTypes(cfg, call = callCms) {
56795
56814
  return call(cfg, {
56796
56815
  path: `${SCHEMAS}/${cfg.account}.${cfg.store}/content-types`
@@ -56798,6 +56817,14 @@ async function getContentTypes(cfg, call = callCms) {
56798
56817
  }
56799
56818
 
56800
56819
  // src/cms/authoring.ts
56820
+ function unwrapValue(node2) {
56821
+ if (node2 && typeof node2 === "object" && !Array.isArray(node2)) {
56822
+ const obj = node2;
56823
+ if (obj.$fnType === "switch" && "defaultCase" in obj)
56824
+ return obj.defaultCase;
56825
+ }
56826
+ return node2;
56827
+ }
56801
56828
  function collectionToArray(node2) {
56802
56829
  if (Array.isArray(node2))
56803
56830
  return node2;
@@ -56828,6 +56855,15 @@ function summarizeSections(data2) {
56828
56855
  return counts.length > 0 ? `${s.componentKey} (${counts.join(", ")})` : s.componentKey;
56829
56856
  });
56830
56857
  }
56858
+ function localeSwitch(value) {
56859
+ return {
56860
+ $fnType: "switch",
56861
+ varyByKeys: ["locale"],
56862
+ cases: null,
56863
+ defaultCase: value,
56864
+ configurationSourceType: "contexts"
56865
+ };
56866
+ }
56831
56867
 
56832
56868
  // src/cms/session.ts
56833
56869
  import { existsSync as existsSync11, readFileSync as readFileSync14 } from "node:fs";
@@ -56992,6 +57028,16 @@ function fail(err) {
56992
57028
  console.error(chalk6.red(err instanceof Error ? err.message : String(err)));
56993
57029
  return 1;
56994
57030
  }
57031
+ function resolveAuthor(explicit) {
57032
+ const author = explicit ?? readVtexSession()?.login;
57033
+ if (!author) {
57034
+ return new Error("Could not tell who is committing. Pass --author <email>.");
57035
+ }
57036
+ if (!author.includes("@")) {
57037
+ return new Error(`--author must be an email address — "${author}" is rejected as invalid request data.`);
57038
+ }
57039
+ return author;
57040
+ }
56995
57041
  function resolveBranch(branch, allowMain) {
56996
57042
  if (!branch)
56997
57043
  return new Error("--branch <id> is required. `parity cms ls --branches` lists them.");
@@ -57169,6 +57215,9 @@ async function cmsPushCommand(opts, call = callCms) {
57169
57215
  console.log(chalk6.dim(` branch ${branch} · entry ${local.entryId} · ${local.contentType}`));
57170
57216
  return 0;
57171
57217
  }
57218
+ const author = resolveAuthor(opts.author);
57219
+ if (author instanceof Error)
57220
+ return fail(author);
57172
57221
  const backup = join18("parity-output", "cms-backups", `${local.entryId}-${remote.baseHash.slice(0, 12)}.json`);
57173
57222
  mkdirSync9(dirname4(backup), { recursive: true });
57174
57223
  writeFileSync12(backup, `${JSON.stringify(remote, null, 2)}
@@ -57181,7 +57230,7 @@ async function cmsPushCommand(opts, call = callCms) {
57181
57230
  baseHash: local.baseHash,
57182
57231
  data: local.data,
57183
57232
  message: opts.message ?? "parity cms push",
57184
- author: opts.author ?? "parity",
57233
+ author,
57185
57234
  identifierKeys: local.identifierKeys,
57186
57235
  searchKeywords: local.searchKeywords
57187
57236
  }, call);
@@ -57216,6 +57265,121 @@ async function cmsUndoCommand(opts, call = callCms) {
57216
57265
  return fail(err);
57217
57266
  }
57218
57267
  }
57268
+ async function hasNoRoute(cfg, contentType, entryId, call) {
57269
+ const version = await getLastVersion(cfg, { contentType, entryId, branchId: "main" }, call).catch(() => null);
57270
+ if (!version)
57271
+ return true;
57272
+ return !unwrapValue(version.data?.slug);
57273
+ }
57274
+ async function cmsCreateCommand(opts, call = callCms) {
57275
+ const cfg = config();
57276
+ if (!cfg)
57277
+ return 1;
57278
+ const branch = resolveBranch(opts.branch, Boolean(opts.allowMain));
57279
+ if (branch instanceof Error)
57280
+ return fail(branch);
57281
+ if (!opts.slug.startsWith("/")) {
57282
+ return fail(new Error(`Slug must start with "/" — got "${opts.slug}".`));
57283
+ }
57284
+ const name = opts.name ?? opts.slug;
57285
+ try {
57286
+ const types = await getContentTypes(cfg, call);
57287
+ const type = types[opts.contentType];
57288
+ if (!type) {
57289
+ return fail(new Error(`No content type "${opts.contentType}" on this store. Known: ${Object.keys(types).sort().join(", ")}.`));
57290
+ }
57291
+ if (type.$singleton) {
57292
+ return fail(new Error(`"${opts.contentType}" is a singleton — its one entry already exists. Edit it with pull/push.`));
57293
+ }
57294
+ const before2 = await listEntries(cfg, { contentType: opts.contentType }, call);
57295
+ if (before2.some((e) => e.name === name)) {
57296
+ return fail(new Error(`An entry named "${name}" already exists. Pick another --name, or edit that one.`));
57297
+ }
57298
+ let template = null;
57299
+ if (opts.from) {
57300
+ if (!await hasNoRoute(cfg, opts.contentType, opts.from, call)) {
57301
+ return fail(new Error(`--from ${opts.from} answers a slug on main. A copy inherits it, so this would put a second entry on the live store at that same route. Point --from at an entry with no slug.`));
57302
+ }
57303
+ template = opts.from;
57304
+ } else {
57305
+ for (const entry of before2) {
57306
+ if (await hasNoRoute(cfg, opts.contentType, entry.id, call)) {
57307
+ template = entry.id;
57308
+ break;
57309
+ }
57310
+ }
57311
+ }
57312
+ if (!template) {
57313
+ return fail(new Error(`No routeless "${opts.contentType}" entry to copy. The platform can only create by duplicating, and a copy inherits the source's slug on main — so copying a live page would put a second entry on that same route. Leave one entry of this type with an empty slug for this to copy from.`));
57314
+ }
57315
+ if (!opts.yes) {
57316
+ console.log(chalk6.yellow("dry run — nothing written. Pass --yes to create."));
57317
+ console.log(` ${opts.contentType} ${chalk6.bold(opts.slug)} named "${name}"`);
57318
+ console.log(chalk6.dim(` copies entry ${template} · content committed on ${branch}`));
57319
+ return 0;
57320
+ }
57321
+ const author = resolveAuthor(opts.author);
57322
+ if (author instanceof Error)
57323
+ return fail(author);
57324
+ await duplicateEntry(cfg, { entryId: template }, call);
57325
+ const after2 = await listEntries(cfg, { contentType: opts.contentType }, call);
57326
+ const known = new Set(before2.map((e) => e.id));
57327
+ const created = after2.filter((e) => !known.has(e.id));
57328
+ if (created.length !== 1) {
57329
+ return fail(new Error(`Duplicated ${template} but found ${created.length} new entries instead of 1 — refusing to guess which is mine. Check the Admin listing.`));
57330
+ }
57331
+ const entryId = created[0].id;
57332
+ try {
57333
+ await renameEntry(cfg, { entryId, name }, call);
57334
+ const head = await getLastVersion(cfg, { contentType: opts.contentType, entryId, branchId: branch }, call).then((v) => v.baseHash).catch(() => null);
57335
+ const commit = await commitEntry(cfg, {
57336
+ branchId: branch,
57337
+ contentTypeId: opts.contentType,
57338
+ entryId,
57339
+ entryName: name,
57340
+ baseHash: head,
57341
+ data: {
57342
+ slug: localeSwitch(opts.slug),
57343
+ seo: { slug: localeSwitch(opts.slug), title: localeSwitch(name), description: localeSwitch("") },
57344
+ sections: { $fnType: "array", values: {} }
57345
+ },
57346
+ message: opts.message ?? `parity cms create ${opts.slug}`,
57347
+ author,
57348
+ identifierKeys: null,
57349
+ searchKeywords: null
57350
+ }, call);
57351
+ if (opts.json) {
57352
+ console.log(JSON.stringify({ entryId, slug: opts.slug, branch, commit }, null, 2));
57353
+ return 0;
57354
+ }
57355
+ console.log(`${chalk6.green("✓")} ${opts.slug} — entry ${entryId}, commit ${commit.id} on ${branch}`);
57356
+ console.log(chalk6.dim(` fill it: parity cms pull --entry ${entryId} --content-type ${opts.contentType} --branch ${branch}`));
57357
+ console.log(chalk6.dim(` undo it: parity cms rm --entry ${entryId} --yes`));
57358
+ return 0;
57359
+ } catch (err) {
57360
+ await deleteEntry(cfg, { entryId }, call).catch(() => {});
57361
+ return fail(err);
57362
+ }
57363
+ } catch (err) {
57364
+ return fail(err);
57365
+ }
57366
+ }
57367
+ async function cmsRmCommand(opts, call = callCms) {
57368
+ const cfg = config();
57369
+ if (!cfg)
57370
+ return 1;
57371
+ if (!opts.yes) {
57372
+ console.log(chalk6.yellow(`dry run — would destroy ${opts.entry} on every branch. Pass --yes.`));
57373
+ return 0;
57374
+ }
57375
+ try {
57376
+ await deleteEntry(cfg, { entryId: opts.entry }, call);
57377
+ console.log(`${chalk6.green("✓")} ${opts.entry} deleted`);
57378
+ return 0;
57379
+ } catch (err) {
57380
+ return fail(err);
57381
+ }
57382
+ }
57219
57383
 
57220
57384
  // src/commands/compare.ts
57221
57385
  import chalk7 from "chalk";
@@ -69817,7 +69981,7 @@ program.command("cms").description("Read and write VTEX Content Platform entries
69817
69981
  }));
69818
69982
  })).addCommand(new Command("diff").description("Compare a pulled file against the branch it came from. Exit 1 when they differ.").requiredOption("--file <path>", "File written by `parity cms pull`").option("--branch <id>", "Compare against a different branch").option("--json", "Emit structured JSON instead of human-readable text", false).action(async (opts) => {
69819
69983
  process.exit(await cmsDiffCommand({ file: opts.file, branch: opts.branch, json: Boolean(opts.json) }));
69820
- })).addCommand(new Command("push").description("Commit a pulled file back. Dry run unless --yes. Refuses main without --allow-main, refuses a stale baseHash, refuses sections the account cannot render, and backs the remote up before writing.").requiredOption("--file <path>", "File written by `parity cms pull`").option("--branch <id>", "Target branch (default: the branch in the file)").option("--message <text>", "Commit message", "parity cms push").option("--author <email>", "Commit author", "parity").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) => {
69984
+ })).addCommand(new Command("push").description("Commit a pulled file back. Dry run unless --yes. Refuses main without --allow-main, refuses a stale baseHash, refuses sections the account cannot render, and backs the remote up before writing.").requiredOption("--file <path>", "File written by `parity cms pull`").option("--branch <id>", "Target branch (default: the branch in the file)").option("--message <text>", "Commit message", "parity cms push").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) => {
69821
69985
  process.exit(await cmsPushCommand({
69822
69986
  file: opts.file,
69823
69987
  branch: opts.branch,
@@ -69827,6 +69991,21 @@ program.command("cms").description("Read and write VTEX Content Platform entries
69827
69991
  allowMain: Boolean(opts.allowMain),
69828
69992
  json: Boolean(opts.json)
69829
69993
  }));
69994
+ })).addCommand(new Command("create").description("Create a page at a slug, with no sections — `pull`/`push` fills it. Dry run unless --yes. The platform has no create endpoint, so this copies an existing entry of the same type and deletes the copy if anything downstream fails.").requiredOption("--content-type <id>", "Content type id, e.g. landingPage").requiredOption("--slug <path>", "Route the page answers on, e.g. /cuida/preguntas-frecuentes").option("--name <text>", "Name in the Admin listing (default: the slug)").option("--branch <id>", "Branch to commit the page on").option("--from <id>", "Entry to copy (default: any entry of the same content type)").option("--message <text>", "Commit message").option("--author <email>", "Commit author (default: the logged-in VTEX user)").option("--yes", "Actually create. 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) => {
69995
+ process.exit(await cmsCreateCommand({
69996
+ contentType: opts.contentType,
69997
+ slug: opts.slug,
69998
+ name: opts.name,
69999
+ branch: opts.branch,
70000
+ from: opts.from,
70001
+ message: opts.message,
70002
+ author: opts.author,
70003
+ yes: Boolean(opts.yes),
70004
+ allowMain: Boolean(opts.allowMain),
70005
+ json: Boolean(opts.json)
70006
+ }));
70007
+ })).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) => {
70008
+ process.exit(await cmsRmCommand({ entry: opts.entry, yes: Boolean(opts.yes) }));
69830
70009
  })).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) => {
69831
70010
  process.exit(await cmsUndoCommand({
69832
70011
  entry: opts.entry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/parity",
3
- "version": "0.29.2",
3
+ "version": "0.30.0",
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",