@contentful/experience-design-system-cli 2.41.1-dev-build-0eca66e2.0 → 2.41.1-dev-build-c89e0adf.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.
package/dist/app.js CHANGED
@@ -1691,9 +1691,12 @@ var init_schema = __esm({
1691
1691
  $required: { type: "boolean" },
1692
1692
  $default: {},
1693
1693
  $values: { type: "array", items: { type: "string" } },
1694
- "$token.kind": { type: "string" },
1694
+ "$token.kind": { type: "string", minLength: 1 },
1695
1695
  "$token.allowed": { type: "array", items: { type: "string" } }
1696
1696
  },
1697
+ // The API rejects a token property that does not say which kind of token it takes.
1698
+ if: { type: "object", properties: { $type: { const: "token" } }, required: ["$type"] },
1699
+ then: { type: "object", required: ["$token.kind"] },
1697
1700
  additionalProperties: false
1698
1701
  },
1699
1702
  slot: {
@@ -22536,9 +22539,12 @@ var cdfJsonSchema2 = {
22536
22539
  $required: { type: "boolean" },
22537
22540
  $default: {},
22538
22541
  $values: { type: "array", items: { type: "string" } },
22539
- "$token.kind": { type: "string" },
22542
+ "$token.kind": { type: "string", minLength: 1 },
22540
22543
  "$token.allowed": { type: "array", items: { type: "string" } }
22541
22544
  },
22545
+ // The API rejects a token property that does not say which kind of token it takes.
22546
+ if: { type: "object", properties: { $type: { const: "token" } }, required: ["$type"] },
22547
+ then: { type: "object", required: ["$token.kind"] },
22542
22548
  additionalProperties: false
22543
22549
  },
22544
22550
  slot: {
@@ -22597,14 +22603,42 @@ function parseCDFComponents(obj, prefix = "") {
22597
22603
  }
22598
22604
  return { components, tokens };
22599
22605
  }
22606
+ function entryValidator(name) {
22607
+ const check = ajv2.getSchema(`${CDF_SCHEMA_URL2}#/definitions/${name}`);
22608
+ if (!check)
22609
+ throw new Error(`the CDF schema has no "${name}" definition`);
22610
+ return check;
22611
+ }
22612
+ var validateComponentEntry = entryValidator("component");
22613
+ var validateTokenEntry = entryValidator("token");
22614
+ function toValidationErrors(errors, prefix = "") {
22615
+ return (errors ?? []).filter((err) => err.keyword !== "if").map((err) => ({
22616
+ path: `${prefix}${err.instancePath}` || "/",
22617
+ message: err.message ?? "Unknown validation error",
22618
+ expected: err.params ? JSON.stringify(err.params) : void 0
22619
+ }));
22620
+ }
22621
+ function entryErrors(node, prefix) {
22622
+ const errors = [];
22623
+ for (const [key, value] of Object.entries(node)) {
22624
+ if (key.startsWith("$") || typeof value !== "object" || value === null)
22625
+ continue;
22626
+ const path5 = `${prefix}/${key}`;
22627
+ const type = value["$type"];
22628
+ const check = type === "component" ? validateComponentEntry : TOKEN_TYPE_SET3.has(type) ? validateTokenEntry : void 0;
22629
+ if (!check) {
22630
+ errors.push(...entryErrors(value, path5));
22631
+ } else if (!check(value)) {
22632
+ errors.push(...toValidationErrors(check.errors, path5));
22633
+ }
22634
+ }
22635
+ return errors;
22636
+ }
22600
22637
  function validateCDF2(input) {
22601
22638
  const valid = validate2(input);
22602
22639
  if (!valid) {
22603
- const errors = (validate2.errors ?? []).map((err) => ({
22604
- path: err.instancePath || "/",
22605
- message: err.message ?? "Unknown validation error",
22606
- expected: err.params ? JSON.stringify(err.params) : void 0
22607
- }));
22640
+ const focused = typeof input === "object" && input !== null ? entryErrors(input, "") : [];
22641
+ const errors = focused.length > 0 ? focused : toValidationErrors(validate2.errors);
22608
22642
  return { valid: false, errors, components: [], tokens: [] };
22609
22643
  }
22610
22644
  const file = input;
@@ -22656,6 +22690,45 @@ var CDFTokenSchema2 = z3.strictObject({
22656
22690
  $description: z3.optional(z3.string())
22657
22691
  });
22658
22692
 
22693
+ // packages/experience-design-system-types/dist/src/cdf/repair-token-kinds.js
22694
+ var UNRESOLVED_WARNING = /\s*WARNING: token_kind unknown[^\n]*/;
22695
+ function inferTokenKind(propName, prop, tokens) {
22696
+ const bound = typeof prop.$default === "string" ? tokens.find(({ path: path5 }) => path5 === prop.$default) : void 0;
22697
+ if (bound)
22698
+ return bound.entry.$type;
22699
+ const name = propName.toLowerCase();
22700
+ const kinds = new Set(tokens.filter(({ path: path5 }) => path5.toLowerCase().split(".").includes(name)).map(({ entry }) => entry.$type));
22701
+ return kinds.size === 1 ? [...kinds][0] : void 0;
22702
+ }
22703
+ function withoutWarning(prop) {
22704
+ if (prop.$description === void 0)
22705
+ return prop;
22706
+ const description = prop.$description.replace(UNRESOLVED_WARNING, "").trim();
22707
+ const { $description: _stale, ...rest } = prop;
22708
+ return description ? { ...rest, $description: description } : rest;
22709
+ }
22710
+ function repairTokenKinds(entry, componentKey, tokens, note) {
22711
+ const properties = { ...entry.$properties };
22712
+ let repaired = false;
22713
+ for (const [name, prop] of Object.entries(entry.$properties)) {
22714
+ if (prop.$type !== "token" || prop["$token.kind"])
22715
+ continue;
22716
+ repaired = true;
22717
+ const kind = inferTokenKind(name, prop, tokens);
22718
+ if (kind) {
22719
+ properties[name] = { ...withoutWarning(prop), "$token.kind": kind };
22720
+ note?.(`${componentKey}.${name} had no token kind, so "${kind}" was taken from the token file`);
22721
+ } else {
22722
+ const plain = { ...withoutWarning(prop), $type: "string" };
22723
+ delete plain["$token.allowed"];
22724
+ delete plain.$default;
22725
+ properties[name] = plain;
22726
+ note?.(`${componentKey}.${name} had no token kind and none could be told, so it was saved as a string property`);
22727
+ }
22728
+ }
22729
+ return repaired ? { ...entry, $properties: properties } : entry;
22730
+ }
22731
+
22659
22732
  // packages/experience-design-system-types/dist/src/cdf/build.js
22660
22733
  function stripUnsupportedSlotFields(entry) {
22661
22734
  if (!entry.$slots)
@@ -22692,7 +22765,7 @@ function buildCDF2(components, tokens, opts = {}) {
22692
22765
  return void 0;
22693
22766
  const doc = { $schema: CDF_SCHEMA_URL2 };
22694
22767
  for (const { key, entry } of components) {
22695
- setAtPath(doc, key, stripUnsupportedSlotFields(entry));
22768
+ setAtPath(doc, key, stripUnsupportedSlotFields(repairTokenKinds(entry, key, tokens, opts.onRepair)));
22696
22769
  }
22697
22770
  for (const { path: path5, entry } of resolveTokenPathCollisions(tokens)) {
22698
22771
  setAtPath(doc, path5, entry);
@@ -29832,12 +29905,13 @@ function nextStateAfterPrint(opts) {
29832
29905
 
29833
29906
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/save.ts
29834
29907
  var SAVE_CONFIRMATION_DELAY_MS = 1e3;
29908
+ var describeCdfError = (error) => `${error.path.replace(/^\//, "").replace("/$properties/", ".").replaceAll("/", ".")}: ${error.message}`;
29835
29909
  function buildSavedCDF(components, tokens, opts = {}) {
29836
29910
  const cdf = buildCDF2(components, toCdfTokens(tokens), opts);
29837
29911
  if (!cdf) throw new Error("nothing to save \u2014 no components or tokens resolved");
29838
29912
  const validation = validateCDF2(cdf);
29839
29913
  if (!validation.valid) {
29840
- throw new Error(`generated CDF failed validation: ${validation.errors.map((error) => error.message).join(", ")}`);
29914
+ throw new Error(`generated CDF failed validation: ${validation.errors.map(describeCdfError).join("; ")}`);
29841
29915
  }
29842
29916
  return cdf;
29843
29917
  }
@@ -29864,7 +29938,11 @@ async function runPrintFiles(input, deps, onPatch) {
29864
29938
  db.close();
29865
29939
  }
29866
29940
  if (!input.tokenSessionId && input.tokensPath) tokens = await deps.readTokens(input.tokensPath);
29867
- const cdf = buildSavedCDF(components, tokens, { deleteAll: input.allowEmpty });
29941
+ const cdf = buildSavedCDF(components, tokens, {
29942
+ deleteAll: input.allowEmpty,
29943
+ onRepair: (message) => deps.warn(`${message}
29944
+ `)
29945
+ });
29868
29946
  await deps.writeFile(componentsPath, `${JSON.stringify(cdf, null, 2)}
29869
29947
  `);
29870
29948
  deps.warn(
package/dist/index.js CHANGED
@@ -1986,9 +1986,12 @@ var init_schema = __esm({
1986
1986
  $required: { type: "boolean" },
1987
1987
  $default: {},
1988
1988
  $values: { type: "array", items: { type: "string" } },
1989
- "$token.kind": { type: "string" },
1989
+ "$token.kind": { type: "string", minLength: 1 },
1990
1990
  "$token.allowed": { type: "array", items: { type: "string" } }
1991
1991
  },
1992
+ // The API rejects a token property that does not say which kind of token it takes.
1993
+ if: { type: "object", properties: { $type: { const: "token" } }, required: ["$type"] },
1994
+ then: { type: "object", required: ["$token.kind"] },
1992
1995
  additionalProperties: false
1993
1996
  },
1994
1997
  slot: {
@@ -25729,9 +25732,12 @@ var init_schema2 = __esm({
25729
25732
  $required: { type: "boolean" },
25730
25733
  $default: {},
25731
25734
  $values: { type: "array", items: { type: "string" } },
25732
- "$token.kind": { type: "string" },
25735
+ "$token.kind": { type: "string", minLength: 1 },
25733
25736
  "$token.allowed": { type: "array", items: { type: "string" } }
25734
25737
  },
25738
+ // The API rejects a token property that does not say which kind of token it takes.
25739
+ if: { type: "object", properties: { $type: { const: "token" } }, required: ["$type"] },
25740
+ then: { type: "object", required: ["$token.kind"] },
25735
25741
  additionalProperties: false
25736
25742
  },
25737
25743
  slot: {
@@ -25790,14 +25796,40 @@ function parseCDFComponents(obj, prefix = "") {
25790
25796
  }
25791
25797
  return { components, tokens };
25792
25798
  }
25799
+ function entryValidator(name) {
25800
+ const check = ajv2.getSchema(`${CDF_SCHEMA_URL2}#/definitions/${name}`);
25801
+ if (!check)
25802
+ throw new Error(`the CDF schema has no "${name}" definition`);
25803
+ return check;
25804
+ }
25805
+ function toValidationErrors(errors, prefix = "") {
25806
+ return (errors ?? []).filter((err) => err.keyword !== "if").map((err) => ({
25807
+ path: `${prefix}${err.instancePath}` || "/",
25808
+ message: err.message ?? "Unknown validation error",
25809
+ expected: err.params ? JSON.stringify(err.params) : void 0
25810
+ }));
25811
+ }
25812
+ function entryErrors(node, prefix) {
25813
+ const errors = [];
25814
+ for (const [key, value] of Object.entries(node)) {
25815
+ if (key.startsWith("$") || typeof value !== "object" || value === null)
25816
+ continue;
25817
+ const path5 = `${prefix}/${key}`;
25818
+ const type = value["$type"];
25819
+ const check = type === "component" ? validateComponentEntry : TOKEN_TYPE_SET3.has(type) ? validateTokenEntry : void 0;
25820
+ if (!check) {
25821
+ errors.push(...entryErrors(value, path5));
25822
+ } else if (!check(value)) {
25823
+ errors.push(...toValidationErrors(check.errors, path5));
25824
+ }
25825
+ }
25826
+ return errors;
25827
+ }
25793
25828
  function validateCDF2(input) {
25794
25829
  const valid = validate2(input);
25795
25830
  if (!valid) {
25796
- const errors = (validate2.errors ?? []).map((err) => ({
25797
- path: err.instancePath || "/",
25798
- message: err.message ?? "Unknown validation error",
25799
- expected: err.params ? JSON.stringify(err.params) : void 0
25800
- }));
25831
+ const focused = typeof input === "object" && input !== null ? entryErrors(input, "") : [];
25832
+ const errors = focused.length > 0 ? focused : toValidationErrors(validate2.errors);
25801
25833
  return { valid: false, errors, components: [], tokens: [] };
25802
25834
  }
25803
25835
  const file = input;
@@ -25819,7 +25851,7 @@ function validateCDF2(input) {
25819
25851
  const { components, tokens } = parseCDFComponents(file);
25820
25852
  return { valid: true, errors: [], components, tokens };
25821
25853
  }
25822
- var ajv2, validate2, TOKEN_TYPE_SET3;
25854
+ var ajv2, validate2, TOKEN_TYPE_SET3, validateComponentEntry, validateTokenEntry;
25823
25855
  var init_validate5 = __esm({
25824
25856
  "packages/experience-design-system-types/dist/src/cdf/validate.js"() {
25825
25857
  "use strict";
@@ -25828,6 +25860,8 @@ var init_validate5 = __esm({
25828
25860
  ajv2 = new Ajv2({ allErrors: true });
25829
25861
  validate2 = ajv2.compile(cdfJsonSchema2);
25830
25862
  TOKEN_TYPE_SET3 = new Set(DESIGN_TOKEN_TYPES2);
25863
+ validateComponentEntry = entryValidator("component");
25864
+ validateTokenEntry = entryValidator("token");
25831
25865
  }
25832
25866
  });
25833
25867
 
@@ -25868,6 +25902,51 @@ var init_types7 = __esm({
25868
25902
  }
25869
25903
  });
25870
25904
 
25905
+ // packages/experience-design-system-types/dist/src/cdf/repair-token-kinds.js
25906
+ function inferTokenKind(propName, prop, tokens) {
25907
+ const bound = typeof prop.$default === "string" ? tokens.find(({ path: path5 }) => path5 === prop.$default) : void 0;
25908
+ if (bound)
25909
+ return bound.entry.$type;
25910
+ const name = propName.toLowerCase();
25911
+ const kinds = new Set(tokens.filter(({ path: path5 }) => path5.toLowerCase().split(".").includes(name)).map(({ entry }) => entry.$type));
25912
+ return kinds.size === 1 ? [...kinds][0] : void 0;
25913
+ }
25914
+ function withoutWarning(prop) {
25915
+ if (prop.$description === void 0)
25916
+ return prop;
25917
+ const description = prop.$description.replace(UNRESOLVED_WARNING, "").trim();
25918
+ const { $description: _stale, ...rest } = prop;
25919
+ return description ? { ...rest, $description: description } : rest;
25920
+ }
25921
+ function repairTokenKinds(entry, componentKey, tokens, note) {
25922
+ const properties = { ...entry.$properties };
25923
+ let repaired = false;
25924
+ for (const [name, prop] of Object.entries(entry.$properties)) {
25925
+ if (prop.$type !== "token" || prop["$token.kind"])
25926
+ continue;
25927
+ repaired = true;
25928
+ const kind = inferTokenKind(name, prop, tokens);
25929
+ if (kind) {
25930
+ properties[name] = { ...withoutWarning(prop), "$token.kind": kind };
25931
+ note?.(`${componentKey}.${name} had no token kind, so "${kind}" was taken from the token file`);
25932
+ } else {
25933
+ const plain = { ...withoutWarning(prop), $type: "string" };
25934
+ delete plain["$token.allowed"];
25935
+ delete plain.$default;
25936
+ properties[name] = plain;
25937
+ note?.(`${componentKey}.${name} had no token kind and none could be told, so it was saved as a string property`);
25938
+ }
25939
+ }
25940
+ return repaired ? { ...entry, $properties: properties } : entry;
25941
+ }
25942
+ var UNRESOLVED_WARNING;
25943
+ var init_repair_token_kinds = __esm({
25944
+ "packages/experience-design-system-types/dist/src/cdf/repair-token-kinds.js"() {
25945
+ "use strict";
25946
+ UNRESOLVED_WARNING = /\s*WARNING: token_kind unknown[^\n]*/;
25947
+ }
25948
+ });
25949
+
25871
25950
  // packages/experience-design-system-types/dist/src/cdf/build.js
25872
25951
  function stripUnsupportedSlotFields(entry) {
25873
25952
  if (!entry.$slots)
@@ -25903,7 +25982,7 @@ function buildCDF2(components, tokens, opts = {}) {
25903
25982
  return void 0;
25904
25983
  const doc = { $schema: CDF_SCHEMA_URL2 };
25905
25984
  for (const { key, entry } of components) {
25906
- setAtPath(doc, key, stripUnsupportedSlotFields(entry));
25985
+ setAtPath(doc, key, stripUnsupportedSlotFields(repairTokenKinds(entry, key, tokens, opts.onRepair)));
25907
25986
  }
25908
25987
  for (const { path: path5, entry } of resolveTokenPathCollisions(tokens)) {
25909
25988
  setAtPath(doc, path5, entry);
@@ -25945,6 +26024,7 @@ var COLLISION_LEAF_KEY;
25945
26024
  var init_build2 = __esm({
25946
26025
  "packages/experience-design-system-types/dist/src/cdf/build.js"() {
25947
26026
  "use strict";
26027
+ init_repair_token_kinds();
25948
26028
  init_schema2();
25949
26029
  COLLISION_LEAF_KEY = "default";
25950
26030
  }
@@ -33626,7 +33706,7 @@ function buildSavedCDF(components, tokens, opts = {}) {
33626
33706
  if (!cdf) throw new Error("nothing to save \u2014 no components or tokens resolved");
33627
33707
  const validation = validateCDF2(cdf);
33628
33708
  if (!validation.valid) {
33629
- throw new Error(`generated CDF failed validation: ${validation.errors.map((error) => error.message).join(", ")}`);
33709
+ throw new Error(`generated CDF failed validation: ${validation.errors.map(describeCdfError).join("; ")}`);
33630
33710
  }
33631
33711
  return cdf;
33632
33712
  }
@@ -33644,7 +33724,11 @@ async function runPrintFiles(input, deps, onPatch) {
33644
33724
  db.close();
33645
33725
  }
33646
33726
  if (!input.tokenSessionId && input.tokensPath) tokens = await deps.readTokens(input.tokensPath);
33647
- const cdf = buildSavedCDF(components, tokens, { deleteAll: input.allowEmpty });
33727
+ const cdf = buildSavedCDF(components, tokens, {
33728
+ deleteAll: input.allowEmpty,
33729
+ onRepair: (message) => deps.warn(`${message}
33730
+ `)
33731
+ });
33648
33732
  await deps.writeFile(componentsPath, `${JSON.stringify(cdf, null, 2)}
33649
33733
  `);
33650
33734
  deps.warn(
@@ -33705,7 +33789,7 @@ async function recordRun(input, deps) {
33705
33789
  return null;
33706
33790
  }
33707
33791
  }
33708
- var SAVE_CONFIRMATION_DELAY_MS, realSaveDeps;
33792
+ var SAVE_CONFIRMATION_DELAY_MS, describeCdfError, realSaveDeps;
33709
33793
  var init_save = __esm({
33710
33794
  "packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/save.ts"() {
33711
33795
  "use strict";
@@ -33713,6 +33797,7 @@ var init_save = __esm({
33713
33797
  init_src4();
33714
33798
  init_run_print_files_helpers();
33715
33799
  SAVE_CONFIRMATION_DELAY_MS = 1e3;
33800
+ describeCdfError = (error) => `${error.path.replace(/^\//, "").replace("/$properties/", ".").replaceAll("/", ".")}: ${error.message}`;
33716
33801
  realSaveDeps = () => ({
33717
33802
  openDb: openPipelineDb,
33718
33803
  readTokens: (path5) => readTokensFromPath2({ flag: "tokens", path: path5 }),
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experience-design-system-cli",
3
- "version": "2.41.1-dev-build-0eca66e2.0",
3
+ "version": "2.41.1-dev-build-c89e0adf.0",
4
4
  "description": "Contentful Experiences design system import CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experience-design-system-cli",
3
- "version": "2.41.1-dev-build-0eca66e2.0",
3
+ "version": "2.41.1-dev-build-c89e0adf.0",
4
4
  "description": "Contentful Experiences design system import CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -45,7 +45,7 @@
45
45
  "ts-morph": "^27.0.2",
46
46
  "typescript": "^5.9.3",
47
47
  "zod": "^4.6.5",
48
- "@contentful/experience-design-system-types": "2.41.1-dev-build-0eca66e2.0"
48
+ "@contentful/experience-design-system-types": "2.41.1-dev-build-c89e0adf.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@tsconfig/node24": "^24.0.4",
@@ -59,7 +59,7 @@
59
59
  "ink-testing-library": "^4.0.0",
60
60
  "typescript-eslint": "^8.67.0",
61
61
  "vitest": "^4.0.16",
62
- "@contentful/experience-design-system-backend-pipeline": "2.41.1-dev-build-0eca66e2.0"
62
+ "@contentful/experience-design-system-backend-pipeline": "2.41.1-dev-build-c89e0adf.0"
63
63
  },
64
64
  "repository": {
65
65
  "type": "git",