@contentful/experience-design-system-cli 2.41.1-dev-build-36ec74af.0 → 2.41.1-dev-build-699ca2d9.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
@@ -1676,9 +1676,12 @@ var init_schema = __esm({
1676
1676
  $required: { type: "boolean" },
1677
1677
  $default: {},
1678
1678
  $values: { type: "array", items: { type: "string" } },
1679
- "$token.kind": { type: "string" },
1679
+ "$token.kind": { type: "string", minLength: 1 },
1680
1680
  "$token.allowed": { type: "array", items: { type: "string" } }
1681
1681
  },
1682
+ // The API rejects a token property that does not say which kind of token it takes.
1683
+ if: { type: "object", properties: { $type: { const: "token" } }, required: ["$type"] },
1684
+ then: { type: "object", required: ["$token.kind"] },
1682
1685
  additionalProperties: false
1683
1686
  },
1684
1687
  slot: {
@@ -22215,9 +22218,12 @@ var cdfJsonSchema2 = {
22215
22218
  $required: { type: "boolean" },
22216
22219
  $default: {},
22217
22220
  $values: { type: "array", items: { type: "string" } },
22218
- "$token.kind": { type: "string" },
22221
+ "$token.kind": { type: "string", minLength: 1 },
22219
22222
  "$token.allowed": { type: "array", items: { type: "string" } }
22220
22223
  },
22224
+ // The API rejects a token property that does not say which kind of token it takes.
22225
+ if: { type: "object", properties: { $type: { const: "token" } }, required: ["$type"] },
22226
+ then: { type: "object", required: ["$token.kind"] },
22221
22227
  additionalProperties: false
22222
22228
  },
22223
22229
  slot: {
@@ -22276,14 +22282,42 @@ function parseCDFComponents(obj, prefix = "") {
22276
22282
  }
22277
22283
  return { components, tokens };
22278
22284
  }
22285
+ function entryValidator(name) {
22286
+ const check = ajv2.getSchema(`${CDF_SCHEMA_URL2}#/definitions/${name}`);
22287
+ if (!check)
22288
+ throw new Error(`the CDF schema has no "${name}" definition`);
22289
+ return check;
22290
+ }
22291
+ var validateComponentEntry = entryValidator("component");
22292
+ var validateTokenEntry = entryValidator("token");
22293
+ function toValidationErrors(errors, prefix = "") {
22294
+ return (errors ?? []).filter((err) => err.keyword !== "if").map((err) => ({
22295
+ path: `${prefix}${err.instancePath}` || "/",
22296
+ message: err.message ?? "Unknown validation error",
22297
+ expected: err.params ? JSON.stringify(err.params) : void 0
22298
+ }));
22299
+ }
22300
+ function entryErrors(node, prefix) {
22301
+ const errors = [];
22302
+ for (const [key, value] of Object.entries(node)) {
22303
+ if (key.startsWith("$") || typeof value !== "object" || value === null)
22304
+ continue;
22305
+ const path5 = `${prefix}/${key}`;
22306
+ const type = value["$type"];
22307
+ const check = type === "component" ? validateComponentEntry : TOKEN_TYPE_SET3.has(type) ? validateTokenEntry : void 0;
22308
+ if (!check) {
22309
+ errors.push(...entryErrors(value, path5));
22310
+ } else if (!check(value)) {
22311
+ errors.push(...toValidationErrors(check.errors, path5));
22312
+ }
22313
+ }
22314
+ return errors;
22315
+ }
22279
22316
  function validateCDF2(input) {
22280
22317
  const valid = validate2(input);
22281
22318
  if (!valid) {
22282
- const errors = (validate2.errors ?? []).map((err) => ({
22283
- path: err.instancePath || "/",
22284
- message: err.message ?? "Unknown validation error",
22285
- expected: err.params ? JSON.stringify(err.params) : void 0
22286
- }));
22319
+ const focused = typeof input === "object" && input !== null ? entryErrors(input, "") : [];
22320
+ const errors = focused.length > 0 ? focused : toValidationErrors(validate2.errors);
22287
22321
  return { valid: false, errors, components: [], tokens: [] };
22288
22322
  }
22289
22323
  const file = input;
@@ -22335,6 +22369,45 @@ var CDFTokenSchema2 = z3.strictObject({
22335
22369
  $description: z3.optional(z3.string())
22336
22370
  });
22337
22371
 
22372
+ // packages/experience-design-system-types/dist/src/cdf/repair-token-kinds.js
22373
+ var UNRESOLVED_WARNING = /\s*WARNING: token_kind unknown[^\n]*/;
22374
+ function inferTokenKind(propName, prop, tokens) {
22375
+ const bound = typeof prop.$default === "string" ? tokens.find(({ path: path5 }) => path5 === prop.$default) : void 0;
22376
+ if (bound)
22377
+ return bound.entry.$type;
22378
+ const name = propName.toLowerCase();
22379
+ const kinds = new Set(tokens.filter(({ path: path5 }) => path5.toLowerCase().split(".").includes(name)).map(({ entry }) => entry.$type));
22380
+ return kinds.size === 1 ? [...kinds][0] : void 0;
22381
+ }
22382
+ function withoutWarning(prop) {
22383
+ if (prop.$description === void 0)
22384
+ return prop;
22385
+ const description = prop.$description.replace(UNRESOLVED_WARNING, "").trim();
22386
+ const { $description: _stale, ...rest } = prop;
22387
+ return description ? { ...rest, $description: description } : rest;
22388
+ }
22389
+ function repairTokenKinds(entry, componentKey, tokens, note) {
22390
+ const properties = { ...entry.$properties };
22391
+ let repaired = false;
22392
+ for (const [name, prop] of Object.entries(entry.$properties)) {
22393
+ if (prop.$type !== "token" || prop["$token.kind"])
22394
+ continue;
22395
+ repaired = true;
22396
+ const kind = inferTokenKind(name, prop, tokens);
22397
+ if (kind) {
22398
+ properties[name] = { ...withoutWarning(prop), "$token.kind": kind };
22399
+ note?.(`${componentKey}.${name} had no token kind, so "${kind}" was taken from the token file`);
22400
+ } else {
22401
+ const plain = { ...withoutWarning(prop), $type: "string" };
22402
+ delete plain["$token.allowed"];
22403
+ delete plain.$default;
22404
+ properties[name] = plain;
22405
+ note?.(`${componentKey}.${name} had no token kind and none could be told, so it was saved as a string property`);
22406
+ }
22407
+ }
22408
+ return repaired ? { ...entry, $properties: properties } : entry;
22409
+ }
22410
+
22338
22411
  // packages/experience-design-system-types/dist/src/cdf/build.js
22339
22412
  function stripUnsupportedSlotFields(entry) {
22340
22413
  if (!entry.$slots)
@@ -22371,7 +22444,7 @@ function buildCDF2(components, tokens, opts = {}) {
22371
22444
  return void 0;
22372
22445
  const doc = { $schema: CDF_SCHEMA_URL2 };
22373
22446
  for (const { key, entry } of components) {
22374
- setAtPath(doc, key, stripUnsupportedSlotFields(entry));
22447
+ setAtPath(doc, key, stripUnsupportedSlotFields(repairTokenKinds(entry, key, tokens, opts.onRepair)));
22375
22448
  }
22376
22449
  for (const { path: path5, entry } of resolveTokenPathCollisions(tokens)) {
22377
22450
  setAtPath(doc, path5, entry);
@@ -29195,12 +29268,13 @@ function nextStateAfterPrint(opts) {
29195
29268
 
29196
29269
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/save.ts
29197
29270
  var SAVE_CONFIRMATION_DELAY_MS = 1e3;
29271
+ var describeCdfError = (error) => `${error.path.replace(/^\//, "").replace("/$properties/", ".").replaceAll("/", ".")}: ${error.message}`;
29198
29272
  function buildSavedCDF(components, tokens, opts = {}) {
29199
29273
  const cdf = buildCDF2(components, toCdfTokens(tokens), opts);
29200
29274
  if (!cdf) throw new Error("nothing to save \u2014 no components or tokens resolved");
29201
29275
  const validation = validateCDF2(cdf);
29202
29276
  if (!validation.valid) {
29203
- throw new Error(`generated CDF failed validation: ${validation.errors.map((error) => error.message).join(", ")}`);
29277
+ throw new Error(`generated CDF failed validation: ${validation.errors.map(describeCdfError).join("; ")}`);
29204
29278
  }
29205
29279
  return cdf;
29206
29280
  }
@@ -29227,7 +29301,11 @@ async function runPrintFiles(input, deps, onPatch) {
29227
29301
  db.close();
29228
29302
  }
29229
29303
  if (!input.tokenSessionId && input.tokensPath) tokens = await deps.readTokens(input.tokensPath);
29230
- const cdf = buildSavedCDF(components, tokens, { deleteAll: input.allowEmpty });
29304
+ const cdf = buildSavedCDF(components, tokens, {
29305
+ deleteAll: input.allowEmpty,
29306
+ onRepair: (message) => deps.warn(`${message}
29307
+ `)
29308
+ });
29231
29309
  await deps.writeFile(componentsPath, `${JSON.stringify(cdf, null, 2)}
29232
29310
  `);
29233
29311
  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: {
@@ -25393,9 +25396,12 @@ var init_schema2 = __esm({
25393
25396
  $required: { type: "boolean" },
25394
25397
  $default: {},
25395
25398
  $values: { type: "array", items: { type: "string" } },
25396
- "$token.kind": { type: "string" },
25399
+ "$token.kind": { type: "string", minLength: 1 },
25397
25400
  "$token.allowed": { type: "array", items: { type: "string" } }
25398
25401
  },
25402
+ // The API rejects a token property that does not say which kind of token it takes.
25403
+ if: { type: "object", properties: { $type: { const: "token" } }, required: ["$type"] },
25404
+ then: { type: "object", required: ["$token.kind"] },
25399
25405
  additionalProperties: false
25400
25406
  },
25401
25407
  slot: {
@@ -25454,14 +25460,40 @@ function parseCDFComponents(obj, prefix = "") {
25454
25460
  }
25455
25461
  return { components, tokens };
25456
25462
  }
25463
+ function entryValidator(name) {
25464
+ const check = ajv2.getSchema(`${CDF_SCHEMA_URL2}#/definitions/${name}`);
25465
+ if (!check)
25466
+ throw new Error(`the CDF schema has no "${name}" definition`);
25467
+ return check;
25468
+ }
25469
+ function toValidationErrors(errors, prefix = "") {
25470
+ return (errors ?? []).filter((err) => err.keyword !== "if").map((err) => ({
25471
+ path: `${prefix}${err.instancePath}` || "/",
25472
+ message: err.message ?? "Unknown validation error",
25473
+ expected: err.params ? JSON.stringify(err.params) : void 0
25474
+ }));
25475
+ }
25476
+ function entryErrors(node, prefix) {
25477
+ const errors = [];
25478
+ for (const [key, value] of Object.entries(node)) {
25479
+ if (key.startsWith("$") || typeof value !== "object" || value === null)
25480
+ continue;
25481
+ const path5 = `${prefix}/${key}`;
25482
+ const type = value["$type"];
25483
+ const check = type === "component" ? validateComponentEntry : TOKEN_TYPE_SET3.has(type) ? validateTokenEntry : void 0;
25484
+ if (!check) {
25485
+ errors.push(...entryErrors(value, path5));
25486
+ } else if (!check(value)) {
25487
+ errors.push(...toValidationErrors(check.errors, path5));
25488
+ }
25489
+ }
25490
+ return errors;
25491
+ }
25457
25492
  function validateCDF2(input) {
25458
25493
  const valid = validate2(input);
25459
25494
  if (!valid) {
25460
- const errors = (validate2.errors ?? []).map((err) => ({
25461
- path: err.instancePath || "/",
25462
- message: err.message ?? "Unknown validation error",
25463
- expected: err.params ? JSON.stringify(err.params) : void 0
25464
- }));
25495
+ const focused = typeof input === "object" && input !== null ? entryErrors(input, "") : [];
25496
+ const errors = focused.length > 0 ? focused : toValidationErrors(validate2.errors);
25465
25497
  return { valid: false, errors, components: [], tokens: [] };
25466
25498
  }
25467
25499
  const file = input;
@@ -25483,7 +25515,7 @@ function validateCDF2(input) {
25483
25515
  const { components, tokens } = parseCDFComponents(file);
25484
25516
  return { valid: true, errors: [], components, tokens };
25485
25517
  }
25486
- var ajv2, validate2, TOKEN_TYPE_SET3;
25518
+ var ajv2, validate2, TOKEN_TYPE_SET3, validateComponentEntry, validateTokenEntry;
25487
25519
  var init_validate5 = __esm({
25488
25520
  "packages/experience-design-system-types/dist/src/cdf/validate.js"() {
25489
25521
  "use strict";
@@ -25492,6 +25524,8 @@ var init_validate5 = __esm({
25492
25524
  ajv2 = new Ajv2({ allErrors: true });
25493
25525
  validate2 = ajv2.compile(cdfJsonSchema2);
25494
25526
  TOKEN_TYPE_SET3 = new Set(DESIGN_TOKEN_TYPES2);
25527
+ validateComponentEntry = entryValidator("component");
25528
+ validateTokenEntry = entryValidator("token");
25495
25529
  }
25496
25530
  });
25497
25531
 
@@ -25532,6 +25566,51 @@ var init_types7 = __esm({
25532
25566
  }
25533
25567
  });
25534
25568
 
25569
+ // packages/experience-design-system-types/dist/src/cdf/repair-token-kinds.js
25570
+ function inferTokenKind(propName, prop, tokens) {
25571
+ const bound = typeof prop.$default === "string" ? tokens.find(({ path: path5 }) => path5 === prop.$default) : void 0;
25572
+ if (bound)
25573
+ return bound.entry.$type;
25574
+ const name = propName.toLowerCase();
25575
+ const kinds = new Set(tokens.filter(({ path: path5 }) => path5.toLowerCase().split(".").includes(name)).map(({ entry }) => entry.$type));
25576
+ return kinds.size === 1 ? [...kinds][0] : void 0;
25577
+ }
25578
+ function withoutWarning(prop) {
25579
+ if (prop.$description === void 0)
25580
+ return prop;
25581
+ const description = prop.$description.replace(UNRESOLVED_WARNING, "").trim();
25582
+ const { $description: _stale, ...rest } = prop;
25583
+ return description ? { ...rest, $description: description } : rest;
25584
+ }
25585
+ function repairTokenKinds(entry, componentKey, tokens, note) {
25586
+ const properties = { ...entry.$properties };
25587
+ let repaired = false;
25588
+ for (const [name, prop] of Object.entries(entry.$properties)) {
25589
+ if (prop.$type !== "token" || prop["$token.kind"])
25590
+ continue;
25591
+ repaired = true;
25592
+ const kind = inferTokenKind(name, prop, tokens);
25593
+ if (kind) {
25594
+ properties[name] = { ...withoutWarning(prop), "$token.kind": kind };
25595
+ note?.(`${componentKey}.${name} had no token kind, so "${kind}" was taken from the token file`);
25596
+ } else {
25597
+ const plain = { ...withoutWarning(prop), $type: "string" };
25598
+ delete plain["$token.allowed"];
25599
+ delete plain.$default;
25600
+ properties[name] = plain;
25601
+ note?.(`${componentKey}.${name} had no token kind and none could be told, so it was saved as a string property`);
25602
+ }
25603
+ }
25604
+ return repaired ? { ...entry, $properties: properties } : entry;
25605
+ }
25606
+ var UNRESOLVED_WARNING;
25607
+ var init_repair_token_kinds = __esm({
25608
+ "packages/experience-design-system-types/dist/src/cdf/repair-token-kinds.js"() {
25609
+ "use strict";
25610
+ UNRESOLVED_WARNING = /\s*WARNING: token_kind unknown[^\n]*/;
25611
+ }
25612
+ });
25613
+
25535
25614
  // packages/experience-design-system-types/dist/src/cdf/build.js
25536
25615
  function stripUnsupportedSlotFields(entry) {
25537
25616
  if (!entry.$slots)
@@ -25567,7 +25646,7 @@ function buildCDF2(components, tokens, opts = {}) {
25567
25646
  return void 0;
25568
25647
  const doc = { $schema: CDF_SCHEMA_URL2 };
25569
25648
  for (const { key, entry } of components) {
25570
- setAtPath(doc, key, stripUnsupportedSlotFields(entry));
25649
+ setAtPath(doc, key, stripUnsupportedSlotFields(repairTokenKinds(entry, key, tokens, opts.onRepair)));
25571
25650
  }
25572
25651
  for (const { path: path5, entry } of resolveTokenPathCollisions(tokens)) {
25573
25652
  setAtPath(doc, path5, entry);
@@ -25609,6 +25688,7 @@ var COLLISION_LEAF_KEY;
25609
25688
  var init_build2 = __esm({
25610
25689
  "packages/experience-design-system-types/dist/src/cdf/build.js"() {
25611
25690
  "use strict";
25691
+ init_repair_token_kinds();
25612
25692
  init_schema2();
25613
25693
  COLLISION_LEAF_KEY = "default";
25614
25694
  }
@@ -32951,7 +33031,7 @@ function buildSavedCDF(components, tokens, opts = {}) {
32951
33031
  if (!cdf) throw new Error("nothing to save \u2014 no components or tokens resolved");
32952
33032
  const validation = validateCDF2(cdf);
32953
33033
  if (!validation.valid) {
32954
- throw new Error(`generated CDF failed validation: ${validation.errors.map((error) => error.message).join(", ")}`);
33034
+ throw new Error(`generated CDF failed validation: ${validation.errors.map(describeCdfError).join("; ")}`);
32955
33035
  }
32956
33036
  return cdf;
32957
33037
  }
@@ -32969,7 +33049,11 @@ async function runPrintFiles(input, deps, onPatch) {
32969
33049
  db.close();
32970
33050
  }
32971
33051
  if (!input.tokenSessionId && input.tokensPath) tokens = await deps.readTokens(input.tokensPath);
32972
- const cdf = buildSavedCDF(components, tokens, { deleteAll: input.allowEmpty });
33052
+ const cdf = buildSavedCDF(components, tokens, {
33053
+ deleteAll: input.allowEmpty,
33054
+ onRepair: (message) => deps.warn(`${message}
33055
+ `)
33056
+ });
32973
33057
  await deps.writeFile(componentsPath, `${JSON.stringify(cdf, null, 2)}
32974
33058
  `);
32975
33059
  deps.warn(
@@ -33030,7 +33114,7 @@ async function recordRun(input, deps) {
33030
33114
  return null;
33031
33115
  }
33032
33116
  }
33033
- var SAVE_CONFIRMATION_DELAY_MS, realSaveDeps;
33117
+ var SAVE_CONFIRMATION_DELAY_MS, describeCdfError, realSaveDeps;
33034
33118
  var init_save = __esm({
33035
33119
  "packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/save.ts"() {
33036
33120
  "use strict";
@@ -33038,6 +33122,7 @@ var init_save = __esm({
33038
33122
  init_src4();
33039
33123
  init_run_print_files_helpers();
33040
33124
  SAVE_CONFIRMATION_DELAY_MS = 1e3;
33125
+ describeCdfError = (error) => `${error.path.replace(/^\//, "").replace("/$properties/", ".").replaceAll("/", ".")}: ${error.message}`;
33041
33126
  realSaveDeps = () => ({
33042
33127
  openDb: openPipelineDb,
33043
33128
  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-36ec74af.0",
3
+ "version": "2.41.1-dev-build-699ca2d9.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-36ec74af.0",
3
+ "version": "2.41.1-dev-build-699ca2d9.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-36ec74af.0"
48
+ "@contentful/experience-design-system-types": "2.41.1-dev-build-699ca2d9.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-36ec74af.0"
62
+ "@contentful/experience-design-system-backend-pipeline": "2.41.1-dev-build-699ca2d9.0"
63
63
  },
64
64
  "repository": {
65
65
  "type": "git",