@decocms/parity 0.33.16 → 0.33.18
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.
- package/dist/cli.js +117 -7
- 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",
|
|
@@ -57650,6 +57662,7 @@ function localeSwitch(value) {
|
|
|
57650
57662
|
}
|
|
57651
57663
|
|
|
57652
57664
|
// src/cms/session.ts
|
|
57665
|
+
import { execFileSync } from "node:child_process";
|
|
57653
57666
|
import { existsSync as existsSync12, readFileSync as readFileSync15 } from "node:fs";
|
|
57654
57667
|
import { homedir as homedir3 } from "node:os";
|
|
57655
57668
|
import { delimiter, join as join17 } from "node:path";
|
|
@@ -57688,6 +57701,26 @@ function vtexCliInstalled(env = process.env) {
|
|
|
57688
57701
|
const dirs = (env.PATH ?? "").split(delimiter).filter(Boolean);
|
|
57689
57702
|
return dirs.some((dir) => existsSync12(join17(dir, "vtex")));
|
|
57690
57703
|
}
|
|
57704
|
+
function vtexContentPluginAdvice(run = (cmd, args) => execFileSync(cmd, args, { stdio: "pipe" })) {
|
|
57705
|
+
try {
|
|
57706
|
+
run("vtex", ["content", "--help"]);
|
|
57707
|
+
return null;
|
|
57708
|
+
} catch (err) {
|
|
57709
|
+
const output = [
|
|
57710
|
+
err?.stdout,
|
|
57711
|
+
err?.stderr,
|
|
57712
|
+
err instanceof Error ? err.message : ""
|
|
57713
|
+
].map((v) => v?.toString() ?? "").join(`
|
|
57714
|
+
`);
|
|
57715
|
+
if (!/Cannot find module ['"]vtex['"]/.test(output))
|
|
57716
|
+
return null;
|
|
57717
|
+
return [
|
|
57718
|
+
"`vtex content` cannot load — the content plugin resolves `vtex` from the wrong node_modules root (breaks under nvm-managed installs).",
|
|
57719
|
+
' ln -sfn "$(npm root -g)/vtex" ~/.local/share/vtex/node_modules/vtex'
|
|
57720
|
+
].join(`
|
|
57721
|
+
`);
|
|
57722
|
+
}
|
|
57723
|
+
}
|
|
57691
57724
|
function sessionState(expectedAccount, env = process.env, home = homedir3(), now = Date.now()) {
|
|
57692
57725
|
if (env.PARITY_CMS_TOKEN)
|
|
57693
57726
|
return { status: "env-token" };
|
|
@@ -57787,9 +57820,73 @@ function unrenderableSections(usedKeys, contentType) {
|
|
|
57787
57820
|
return [];
|
|
57788
57821
|
return [...new Set(usedKeys.filter((k) => !allowed.includes(k)))];
|
|
57789
57822
|
}
|
|
57823
|
+
function parseJsonc(raw) {
|
|
57824
|
+
const withoutComments = raw.replace(/\/\/.*$/gm, "");
|
|
57825
|
+
const withoutTrailingCommas = withoutComments.replace(/,(\s*[}\]])/g, "$1");
|
|
57826
|
+
return JSON.parse(withoutTrailingCommas);
|
|
57827
|
+
}
|
|
57828
|
+
function localComponentSchemas(repoDir) {
|
|
57829
|
+
const dir = join18(repoDir, "cms", "faststore", "components");
|
|
57830
|
+
if (!existsSync13(dir))
|
|
57831
|
+
return {};
|
|
57832
|
+
const out = {};
|
|
57833
|
+
for (const file of readdirSync3(dir)) {
|
|
57834
|
+
if (!file.endsWith(".jsonc"))
|
|
57835
|
+
continue;
|
|
57836
|
+
try {
|
|
57837
|
+
const parsed = parseJsonc(readFileSync16(join18(dir, file), "utf8"));
|
|
57838
|
+
if (!parsed.$componentKey)
|
|
57839
|
+
continue;
|
|
57840
|
+
out[parsed.$componentKey] = {
|
|
57841
|
+
properties: Object.keys(parsed.properties ?? {}),
|
|
57842
|
+
required: parsed.required ?? []
|
|
57843
|
+
};
|
|
57844
|
+
} catch {}
|
|
57845
|
+
}
|
|
57846
|
+
return out;
|
|
57847
|
+
}
|
|
57848
|
+
function publishedComponentSchemas(contentType) {
|
|
57849
|
+
const items = contentType?.properties?.sections?.items;
|
|
57850
|
+
const anyOf = items?.anyOf ?? [];
|
|
57851
|
+
const out = {};
|
|
57852
|
+
for (const s of anyOf) {
|
|
57853
|
+
const key = String(s.$componentKey ?? "");
|
|
57854
|
+
if (!key)
|
|
57855
|
+
continue;
|
|
57856
|
+
out[key] = {
|
|
57857
|
+
properties: Object.keys(s.properties ?? {}),
|
|
57858
|
+
required: s.required ?? []
|
|
57859
|
+
};
|
|
57860
|
+
}
|
|
57861
|
+
return out;
|
|
57862
|
+
}
|
|
57863
|
+
function propertyDrift(published, repoDir) {
|
|
57864
|
+
const local = localComponentSchemas(repoDir);
|
|
57865
|
+
const drift = [];
|
|
57866
|
+
for (const [contentType, schema] of Object.entries(published)) {
|
|
57867
|
+
const remote = publishedComponentSchemas(schema);
|
|
57868
|
+
for (const [componentKey, localShape] of Object.entries(local)) {
|
|
57869
|
+
const remoteShape = remote[componentKey];
|
|
57870
|
+
if (!remoteShape)
|
|
57871
|
+
continue;
|
|
57872
|
+
const missingProps = localShape.properties.filter((p) => !remoteShape.properties.includes(p));
|
|
57873
|
+
const newlyRequiredProps = localShape.required.filter((p) => remoteShape.properties.includes(p) && !remoteShape.required.includes(p));
|
|
57874
|
+
if (missingProps.length > 0 || newlyRequiredProps.length > 0) {
|
|
57875
|
+
drift.push({ contentType, componentKey, missingProps, newlyRequiredProps });
|
|
57876
|
+
}
|
|
57877
|
+
}
|
|
57878
|
+
}
|
|
57879
|
+
return drift;
|
|
57880
|
+
}
|
|
57790
57881
|
|
|
57791
57882
|
// src/commands/cms.ts
|
|
57792
57883
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
57884
|
+
var DICT_SHAPE_CONTENT_TYPES = new Set(["globalSections"]);
|
|
57885
|
+
function withDataPlaneShape(contentType, data) {
|
|
57886
|
+
if (DICT_SHAPE_CONTENT_TYPES.has(contentType))
|
|
57887
|
+
return data;
|
|
57888
|
+
return toDataPlaneShape(data);
|
|
57889
|
+
}
|
|
57793
57890
|
function config() {
|
|
57794
57891
|
const account = process.env.PARITY_CMS_ACCOUNT;
|
|
57795
57892
|
const store = process.env.PARITY_CMS_STORE;
|
|
@@ -57845,26 +57942,39 @@ async function cmsDoctorCommand(opts, call = callCms) {
|
|
|
57845
57942
|
if (!cfg)
|
|
57846
57943
|
return 1;
|
|
57847
57944
|
const session = describeSession(sessionState(process.env.PARITY_CMS_ACCOUNT));
|
|
57945
|
+
const pluginAdvice = vtexContentPluginAdvice();
|
|
57848
57946
|
try {
|
|
57849
57947
|
const types = await getContentTypes(cfg, call);
|
|
57850
57948
|
const drift = schemaDrift(types, opts.repo);
|
|
57949
|
+
const propDrift = propertyDrift(types, opts.repo);
|
|
57950
|
+
const blockingProps = propDrift.filter((d) => d.missingProps.length > 0);
|
|
57851
57951
|
if (opts.json) {
|
|
57852
|
-
console.log(JSON.stringify({ session, contentTypes: Object.keys(types), drift }, null, 2));
|
|
57853
|
-
return drift.some((d) => d.missingOnAccount.length > 0) ? 1 : 0;
|
|
57952
|
+
console.log(JSON.stringify({ session, contentPlugin: pluginAdvice, contentTypes: Object.keys(types), drift, propDrift }, null, 2));
|
|
57953
|
+
return drift.some((d) => d.missingOnAccount.length > 0) || blockingProps.length > 0 ? 1 : 0;
|
|
57854
57954
|
}
|
|
57855
57955
|
if (session)
|
|
57856
57956
|
console.log(`${chalk7.green("✓")} ${session}`);
|
|
57957
|
+
if (pluginAdvice)
|
|
57958
|
+
console.log(`${chalk7.yellow("!")} ${pluginAdvice}`);
|
|
57857
57959
|
const blocking = drift.filter((d) => d.missingOnAccount.length > 0);
|
|
57858
|
-
if (blocking.length === 0) {
|
|
57960
|
+
if (blocking.length === 0 && propDrift.length === 0) {
|
|
57859
57961
|
console.log(`${chalk7.green("✓")} every section the repo declares is published on the account`);
|
|
57860
57962
|
}
|
|
57861
57963
|
for (const d of blocking) {
|
|
57862
57964
|
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.")}`);
|
|
57863
57965
|
}
|
|
57966
|
+
for (const d of propDrift) {
|
|
57967
|
+
if (d.missingProps.length > 0) {
|
|
57968
|
+
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.")}`);
|
|
57969
|
+
}
|
|
57970
|
+
if (d.newlyRequiredProps.length > 0) {
|
|
57971
|
+
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.")}`);
|
|
57972
|
+
}
|
|
57973
|
+
}
|
|
57864
57974
|
for (const d of drift.filter((x) => x.missingInRepo.length > 0)) {
|
|
57865
57975
|
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)")}`);
|
|
57866
57976
|
}
|
|
57867
|
-
return blocking.length > 0 ? 1 : 0;
|
|
57977
|
+
return blocking.length > 0 || blockingProps.length > 0 ? 1 : 0;
|
|
57868
57978
|
} catch (err) {
|
|
57869
57979
|
return fail(err);
|
|
57870
57980
|
}
|
|
@@ -58016,7 +58126,7 @@ async function cmsPushCommand(opts, call = callCms) {
|
|
|
58016
58126
|
entryId: local.entryId,
|
|
58017
58127
|
entryName: local.entryName,
|
|
58018
58128
|
baseHash: local.baseHash,
|
|
58019
|
-
data: local.data,
|
|
58129
|
+
data: withDataPlaneShape(local.contentType, local.data),
|
|
58020
58130
|
message: opts.message ?? "parity cms push",
|
|
58021
58131
|
author,
|
|
58022
58132
|
identifierKeys: local.identifierKeys,
|
|
@@ -58179,11 +58289,11 @@ async function cmsCreateCommand(opts, call = callCms) {
|
|
|
58179
58289
|
entryId,
|
|
58180
58290
|
entryName: name,
|
|
58181
58291
|
baseHash: head,
|
|
58182
|
-
data: {
|
|
58292
|
+
data: withDataPlaneShape(opts.contentType, {
|
|
58183
58293
|
slug: localeSwitch(opts.slug),
|
|
58184
58294
|
seo: { slug: localeSwitch(opts.slug), title: localeSwitch(name), description: localeSwitch("") },
|
|
58185
58295
|
sections: { $fnType: "array", values: {} }
|
|
58186
|
-
},
|
|
58296
|
+
}),
|
|
58187
58297
|
message: opts.message ?? `parity cms create ${opts.slug}`,
|
|
58188
58298
|
author,
|
|
58189
58299
|
identifierKeys: null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/parity",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.18",
|
|
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",
|