@contentful/experience-design-system-types 2.24.1-dev-build-5ff9f2f.0 → 2.24.1-dev-build-3ddd9a7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experience-design-system-types",
3
- "version": "2.24.1-dev-build-5ff9f2f.0",
3
+ "version": "2.24.1-dev-build-3ddd9a7.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/src/index.js",
@@ -1,4 +1,4 @@
1
1
  export { validateCDF, parseCDFComponents } from './validate.js';
2
2
  export { CDF_V1_SCHEMA_URL } from './schema.js';
3
3
  export { CDF_PROPERTY_TYPES, CDF_PROPERTY_CATEGORIES } from './vocabularies.js';
4
- export { CDFComponentSchema, CDFPropertySchema, CDFSlotSchema, type CDFComponentEntry, type CDFPropertyDefinition, type CDFSlotDefinition, type CDFValidationError, } from './types.js';
4
+ export { CDFComponentSchema, CDFPropertySchema, CDFSlotSchema, type CDFComponentEntry, type CDFPropertyDefinition, type CDFSlotDefinition, type CDFValidationError, type CDFValidationWarning, } from './types.js';
@@ -76,6 +76,18 @@ export declare const cdfV1JsonSchema: {
76
76
  readonly '$token.kind': {
77
77
  readonly type: "string";
78
78
  };
79
+ readonly '$token.sets': {
80
+ readonly type: "array";
81
+ readonly items: {
82
+ readonly type: "string";
83
+ };
84
+ };
85
+ readonly '$token.allowed': {
86
+ readonly type: "array";
87
+ readonly items: {
88
+ readonly type: "string";
89
+ };
90
+ };
79
91
  };
80
92
  readonly additionalProperties: false;
81
93
  };
@@ -42,6 +42,8 @@ export const cdfV1JsonSchema = {
42
42
  $default: {},
43
43
  $values: { type: 'array', items: { type: 'string' } },
44
44
  '$token.kind': { type: 'string' },
45
+ '$token.sets': { type: 'array', items: { type: 'string' } },
46
+ '$token.allowed': { type: 'array', items: { type: 'string' } },
45
47
  },
46
48
  additionalProperties: false,
47
49
  },
@@ -20,6 +20,8 @@ export declare const CDFPropertySchema: z.ZodMiniObject<{
20
20
  $default: z.ZodMiniOptional<z.ZodMiniAny>;
21
21
  $values: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
22
22
  '$token.kind': z.ZodMiniOptional<z.ZodMiniString<string>>;
23
+ '$token.sets': z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
24
+ '$token.allowed': z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
23
25
  }, z.core.$strict>;
24
26
  export type CDFPropertyDefinition = z.infer<typeof CDFPropertySchema>;
25
27
  export declare const CDFSlotSchema: z.ZodMiniObject<{
@@ -52,6 +54,8 @@ export declare const CDFComponentSchema: z.ZodMiniObject<{
52
54
  $default: z.ZodMiniOptional<z.ZodMiniAny>;
53
55
  $values: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
54
56
  '$token.kind': z.ZodMiniOptional<z.ZodMiniString<string>>;
57
+ '$token.sets': z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
58
+ '$token.allowed': z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
55
59
  }, z.core.$strict>>;
56
60
  $slots: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniObject<{
57
61
  $description: z.ZodMiniOptional<z.ZodMiniString<string>>;
@@ -70,9 +74,14 @@ export interface CDFValidationError {
70
74
  expected?: string;
71
75
  actual?: string;
72
76
  }
77
+ export interface CDFValidationWarning {
78
+ path: string;
79
+ message: string;
80
+ }
73
81
  export interface CDFValidationResult {
74
82
  valid: boolean;
75
83
  errors: CDFValidationError[];
84
+ warnings: CDFValidationWarning[];
76
85
  components: Array<{
77
86
  key: string;
78
87
  entry: CDFComponentEntry;
@@ -8,6 +8,8 @@ export const CDFPropertySchema = z.strictObject({
8
8
  $default: z.optional(z.any()),
9
9
  $values: z.optional(z.array(z.string())),
10
10
  '$token.kind': z.optional(z.string()),
11
+ '$token.sets': z.optional(z.array(z.string())),
12
+ '$token.allowed': z.optional(z.array(z.string())),
11
13
  });
12
14
  export const CDFSlotSchema = z.strictObject({
13
15
  $description: z.optional(z.string()),
@@ -22,6 +22,58 @@ export function parseCDFComponents(obj, prefix = '') {
22
22
  }
23
23
  return results;
24
24
  }
25
+ function validatePropertyTokenConstraints(path, prop, errors, warnings) {
26
+ const sets = prop['$token.sets'];
27
+ const allowed = prop['$token.allowed'];
28
+ if (sets === undefined && allowed === undefined)
29
+ return;
30
+ const isTokenDesignProperty = prop['$type'] === 'token' && prop['$category'] === 'design';
31
+ if (!isTokenDesignProperty) {
32
+ if (sets !== undefined) {
33
+ errors.push({
34
+ path: `${path}/$token.sets`,
35
+ message: '"$token.sets" is only allowed on properties with $type "token" and $category "design"',
36
+ });
37
+ }
38
+ if (allowed !== undefined) {
39
+ errors.push({
40
+ path: `${path}/$token.allowed`,
41
+ message: '"$token.allowed" is only allowed on properties with $type "token" and $category "design"',
42
+ });
43
+ }
44
+ return;
45
+ }
46
+ if (allowed !== undefined && sets !== undefined) {
47
+ const offending = allowed.filter((tokenPath) => !sets.includes(tokenPath));
48
+ if (offending.length > 0) {
49
+ errors.push({
50
+ path: `${path}/$token.allowed`,
51
+ message: `"$token.allowed" must be a subset of "$token.sets"; not found in $token.sets: ${offending.join(', ')}`,
52
+ });
53
+ }
54
+ }
55
+ const values = prop['$values'];
56
+ if (allowed !== undefined && allowed.length > 0 && values !== undefined) {
57
+ const sameContents = allowed.length === values.length && allowed.every((v) => values.includes(v));
58
+ if (!sameContents) {
59
+ warnings.push({
60
+ path: `${path}/$token.allowed`,
61
+ message: '"$values" and "$token.allowed" have differing contents; "$token.allowed" is authoritative',
62
+ });
63
+ }
64
+ }
65
+ }
66
+ function validateTokenConstraints(components) {
67
+ const errors = [];
68
+ const warnings = [];
69
+ for (const { key, entry } of components) {
70
+ const componentPath = `/${key.replace(/\./g, '/')}`;
71
+ for (const [propKey, prop] of Object.entries(entry.$properties ?? {})) {
72
+ validatePropertyTokenConstraints(`${componentPath}/$properties/${propKey}`, prop, errors, warnings);
73
+ }
74
+ }
75
+ return { errors, warnings };
76
+ }
25
77
  export function validateCDF(input) {
26
78
  const valid = validate(input);
27
79
  if (!valid) {
@@ -30,7 +82,7 @@ export function validateCDF(input) {
30
82
  message: err.message ?? 'Unknown validation error',
31
83
  expected: err.params ? JSON.stringify(err.params) : undefined,
32
84
  }));
33
- return { valid: false, errors, components: [] };
85
+ return { valid: false, errors, warnings: [], components: [] };
34
86
  }
35
87
  const file = input;
36
88
  if (file.$schema !== CDF_V1_SCHEMA_URL) {
@@ -44,9 +96,11 @@ export function validateCDF(input) {
44
96
  actual: file.$schema,
45
97
  },
46
98
  ],
99
+ warnings: [],
47
100
  components: [],
48
101
  };
49
102
  }
50
103
  const components = parseCDFComponents(file);
51
- return { valid: true, errors: [], components };
104
+ const { errors, warnings } = validateTokenConstraints(components);
105
+ return { valid: errors.length === 0, errors, warnings, components };
52
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experience-design-system-types",
3
- "version": "2.24.1-dev-build-5ff9f2f.0",
3
+ "version": "2.24.1-dev-build-3ddd9a7.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/src/index.js",