@contentful/experiences-validators 1.11.0-prerelease-20240723T1849-cedcf84.0 → 1.11.0-prerelease-20240726T1510-9e11672.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/index.d.ts CHANGED
@@ -1,61 +1,7 @@
1
1
  import { z } from 'zod';
2
2
 
3
- declare const PrimitiveValueSchema: z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>;
4
3
  declare const DefinitionPropertyTypeSchema: z.ZodEnum<["Text", "RichText", "Number", "Date", "Boolean", "Location", "Media", "Object", "Hyperlink", "Array", "Link"]>;
5
- declare const ComponentDefinitionSchema: z.ZodObject<{
6
- id: z.ZodString;
7
- variables: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<{
8
- displayName: z.ZodOptional<z.ZodString>;
9
- type: z.ZodEnum<["Text", "RichText", "Number", "Date", "Boolean", "Location", "Media", "Object", "Hyperlink", "Array", "Link"]>;
10
- description: z.ZodOptional<z.ZodString>;
11
- group: z.ZodOptional<z.ZodString>;
12
- defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>>;
13
- }, "strip", z.ZodTypeAny, {
14
- type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
15
- displayName?: string | undefined;
16
- description?: string | undefined;
17
- group?: string | undefined;
18
- defaultValue?: string | number | boolean | Record<any, any> | undefined;
19
- }, {
20
- type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
21
- displayName?: string | undefined;
22
- description?: string | undefined;
23
- group?: string | undefined;
24
- defaultValue?: string | number | boolean | Record<any, any> | undefined;
25
- }>, {
26
- type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
27
- displayName?: string | undefined;
28
- description?: string | undefined;
29
- group?: string | undefined;
30
- defaultValue?: string | number | boolean | Record<any, any> | undefined;
31
- }, {
32
- type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
33
- displayName?: string | undefined;
34
- description?: string | undefined;
35
- group?: string | undefined;
36
- defaultValue?: string | number | boolean | Record<any, any> | undefined;
37
- }>>;
38
- }, "strip", z.ZodTypeAny, {
39
- id: string;
40
- variables: Record<string, {
41
- type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
42
- displayName?: string | undefined;
43
- description?: string | undefined;
44
- group?: string | undefined;
45
- defaultValue?: string | number | boolean | Record<any, any> | undefined;
46
- }>;
47
- }, {
48
- id: string;
49
- variables: Record<string, {
50
- type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
51
- displayName?: string | undefined;
52
- description?: string | undefined;
53
- group?: string | undefined;
54
- defaultValue?: string | number | boolean | Record<any, any> | undefined;
55
- }>;
56
- }>;
57
- type ComponentDefinitionPropertyType = z.infer<typeof DefinitionPropertyTypeSchema>;
58
-
4
+ declare const PrimitiveValueSchema: z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>;
59
5
  declare const DataSourceSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
60
6
  sys: z.ZodObject<{
61
7
  type: z.ZodLiteral<"Link">;
@@ -182,15 +128,15 @@ declare const BreakpointSchema: z.ZodObject<{
182
128
  displayIcon: z.ZodOptional<z.ZodEnum<["desktop", "tablet", "mobile"]>>;
183
129
  }, "strict", z.ZodTypeAny, {
184
130
  id: string;
185
- displayName: string;
186
131
  query: string;
187
132
  previewSize: string;
133
+ displayName: string;
188
134
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
189
135
  }, {
190
136
  id: string;
191
- displayName: string;
192
137
  query: string;
193
138
  previewSize: string;
139
+ displayName: string;
194
140
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
195
141
  }>;
196
142
  declare const UnboundValuesSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -254,6 +200,7 @@ declare const BaseComponentTreeNodeSchema: z.ZodObject<{
254
200
  key: string;
255
201
  }>]>>;
256
202
  }, "strip", z.ZodTypeAny, {
203
+ definitionId: string;
257
204
  variables: Record<string, {
258
205
  type: "DesignValue";
259
206
  valuesByBreakpoint: Record<string, string | number | boolean | Record<any, any> | undefined>;
@@ -271,10 +218,10 @@ declare const BaseComponentTreeNodeSchema: z.ZodObject<{
271
218
  type: "ComponentValue";
272
219
  key: string;
273
220
  }>;
274
- definitionId: string;
275
221
  displayName?: string | undefined;
276
222
  slotId?: string | undefined;
277
223
  }, {
224
+ definitionId: string;
278
225
  variables: Record<string, {
279
226
  type: "DesignValue";
280
227
  valuesByBreakpoint: Record<string, string | number | boolean | Record<any, any> | undefined>;
@@ -292,7 +239,6 @@ declare const BaseComponentTreeNodeSchema: z.ZodObject<{
292
239
  type: "ComponentValue";
293
240
  key: string;
294
241
  }>;
295
- definitionId: string;
296
242
  displayName?: string | undefined;
297
243
  slotId?: string | undefined;
298
244
  }>;
@@ -303,6 +249,8 @@ declare const ComponentSettingsSchema: z.ZodObject<{
303
249
  variableDefinitions: z.ZodRecord<z.ZodString, z.ZodObject<{
304
250
  displayName: z.ZodOptional<z.ZodString>;
305
251
  type: z.ZodEnum<["Text", "RichText", "Number", "Date", "Boolean", "Location", "Media", "Object", "Hyperlink", "Array", "Link"]>;
252
+ description: z.ZodOptional<z.ZodString>;
253
+ group: z.ZodOptional<z.ZodString>;
306
254
  defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>, z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
307
255
  type: z.ZodLiteral<"DesignValue">;
308
256
  valuesByBreakpoint: z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>>>;
@@ -352,8 +300,6 @@ declare const ComponentSettingsSchema: z.ZodObject<{
352
300
  type: "ComponentValue";
353
301
  key: string;
354
302
  }>]>]>>;
355
- description: z.ZodOptional<z.ZodString>;
356
- group: z.ZodOptional<z.ZodString>;
357
303
  validations: z.ZodOptional<z.ZodObject<{
358
304
  required: z.ZodOptional<z.ZodBoolean>;
359
305
  format: z.ZodOptional<z.ZodLiteral<"URL">>;
@@ -544,27 +490,27 @@ declare const ComponentTreeSchema: z.ZodObject<{
544
490
  displayIcon: z.ZodOptional<z.ZodEnum<["desktop", "tablet", "mobile"]>>;
545
491
  }, "strict", z.ZodTypeAny, {
546
492
  id: string;
547
- displayName: string;
548
493
  query: string;
549
494
  previewSize: string;
495
+ displayName: string;
550
496
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
551
497
  }, {
552
498
  id: string;
553
- displayName: string;
554
499
  query: string;
555
500
  previewSize: string;
501
+ displayName: string;
556
502
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
557
503
  }>, "many">, {
558
504
  id: string;
559
- displayName: string;
560
505
  query: string;
561
506
  previewSize: string;
507
+ displayName: string;
562
508
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
563
509
  }[], {
564
510
  id: string;
565
- displayName: string;
566
511
  query: string;
567
512
  previewSize: string;
513
+ displayName: string;
568
514
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
569
515
  }[]>;
570
516
  children: z.ZodArray<z.ZodType<ComponentTreeNode, z.ZodTypeDef, ComponentTreeNode>, "many">;
@@ -573,9 +519,9 @@ declare const ComponentTreeSchema: z.ZodObject<{
573
519
  children: ComponentTreeNode[];
574
520
  breakpoints: {
575
521
  id: string;
576
- displayName: string;
577
522
  query: string;
578
523
  previewSize: string;
524
+ displayName: string;
579
525
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
580
526
  }[];
581
527
  schemaVersion: "2023-09-28";
@@ -583,9 +529,9 @@ declare const ComponentTreeSchema: z.ZodObject<{
583
529
  children: ComponentTreeNode[];
584
530
  breakpoints: {
585
531
  id: string;
586
- displayName: string;
587
532
  query: string;
588
533
  previewSize: string;
534
+ displayName: string;
589
535
  displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
590
536
  }[];
591
537
  schemaVersion: "2023-09-28";
@@ -635,6 +581,186 @@ type BoundValue = z.infer<typeof BoundValueSchema>;
635
581
  type UnboundValue = z.infer<typeof UnboundValueSchema>;
636
582
  type ComponentValue = z.infer<typeof ComponentValueSchema>;
637
583
 
584
+ declare const ComponentDefinitionSchema: z.ZodObject<{
585
+ id: z.ZodString;
586
+ variables: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<z.objectUtil.extendShape<{
587
+ displayName: z.ZodOptional<z.ZodString>;
588
+ type: z.ZodEnum<["Text", "RichText", "Number", "Date", "Boolean", "Location", "Media", "Object", "Hyperlink", "Array", "Link"]>;
589
+ description: z.ZodOptional<z.ZodString>;
590
+ group: z.ZodOptional<z.ZodString>;
591
+ defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>, z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
592
+ type: z.ZodLiteral<"DesignValue">;
593
+ valuesByBreakpoint: z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>>>;
594
+ }, "strict", z.ZodTypeAny, {
595
+ type: "DesignValue";
596
+ valuesByBreakpoint: Record<string, string | number | boolean | Record<any, any> | undefined>;
597
+ }, {
598
+ type: "DesignValue";
599
+ valuesByBreakpoint: Record<string, string | number | boolean | Record<any, any> | undefined>;
600
+ }>, z.ZodObject<{
601
+ type: z.ZodLiteral<"BoundValue">;
602
+ path: z.ZodString;
603
+ }, "strict", z.ZodTypeAny, {
604
+ path: string;
605
+ type: "BoundValue";
606
+ }, {
607
+ path: string;
608
+ type: "BoundValue";
609
+ }>, z.ZodObject<{
610
+ type: z.ZodLiteral<"UnboundValue">;
611
+ key: z.ZodString;
612
+ }, "strict", z.ZodTypeAny, {
613
+ type: "UnboundValue";
614
+ key: string;
615
+ }, {
616
+ type: "UnboundValue";
617
+ key: string;
618
+ }>, z.ZodObject<{
619
+ type: z.ZodLiteral<"HyperlinkValue">;
620
+ linkTargetKey: z.ZodString;
621
+ overrides: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
622
+ }, "strict", z.ZodTypeAny, {
623
+ type: "HyperlinkValue";
624
+ linkTargetKey: string;
625
+ overrides?: {} | undefined;
626
+ }, {
627
+ type: "HyperlinkValue";
628
+ linkTargetKey: string;
629
+ overrides?: {} | undefined;
630
+ }>, z.ZodObject<{
631
+ type: z.ZodLiteral<"ComponentValue">;
632
+ key: z.ZodString;
633
+ }, "strict", z.ZodTypeAny, {
634
+ type: "ComponentValue";
635
+ key: string;
636
+ }, {
637
+ type: "ComponentValue";
638
+ key: string;
639
+ }>]>]>>;
640
+ validations: z.ZodOptional<z.ZodObject<{
641
+ required: z.ZodOptional<z.ZodBoolean>;
642
+ format: z.ZodOptional<z.ZodLiteral<"URL">>;
643
+ in: z.ZodOptional<z.ZodArray<z.ZodObject<{
644
+ value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
645
+ displayName: z.ZodOptional<z.ZodString>;
646
+ }, "strip", z.ZodTypeAny, {
647
+ value: string | number;
648
+ displayName?: string | undefined;
649
+ }, {
650
+ value: string | number;
651
+ displayName?: string | undefined;
652
+ }>, "many">>;
653
+ }, "strip", z.ZodTypeAny, {
654
+ required?: boolean | undefined;
655
+ format?: "URL" | undefined;
656
+ in?: {
657
+ value: string | number;
658
+ displayName?: string | undefined;
659
+ }[] | undefined;
660
+ }, {
661
+ required?: boolean | undefined;
662
+ format?: "URL" | undefined;
663
+ in?: {
664
+ value: string | number;
665
+ displayName?: string | undefined;
666
+ }[] | undefined;
667
+ }>>;
668
+ }, {
669
+ defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>>;
670
+ }>, "strip", z.ZodTypeAny, {
671
+ type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
672
+ displayName?: string | undefined;
673
+ description?: string | undefined;
674
+ group?: string | undefined;
675
+ defaultValue?: string | number | boolean | Record<any, any> | undefined;
676
+ validations?: {
677
+ required?: boolean | undefined;
678
+ format?: "URL" | undefined;
679
+ in?: {
680
+ value: string | number;
681
+ displayName?: string | undefined;
682
+ }[] | undefined;
683
+ } | undefined;
684
+ }, {
685
+ type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
686
+ displayName?: string | undefined;
687
+ description?: string | undefined;
688
+ group?: string | undefined;
689
+ defaultValue?: string | number | boolean | Record<any, any> | undefined;
690
+ validations?: {
691
+ required?: boolean | undefined;
692
+ format?: "URL" | undefined;
693
+ in?: {
694
+ value: string | number;
695
+ displayName?: string | undefined;
696
+ }[] | undefined;
697
+ } | undefined;
698
+ }>, {
699
+ type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
700
+ displayName?: string | undefined;
701
+ description?: string | undefined;
702
+ group?: string | undefined;
703
+ defaultValue?: string | number | boolean | Record<any, any> | undefined;
704
+ validations?: {
705
+ required?: boolean | undefined;
706
+ format?: "URL" | undefined;
707
+ in?: {
708
+ value: string | number;
709
+ displayName?: string | undefined;
710
+ }[] | undefined;
711
+ } | undefined;
712
+ }, {
713
+ type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
714
+ displayName?: string | undefined;
715
+ description?: string | undefined;
716
+ group?: string | undefined;
717
+ defaultValue?: string | number | boolean | Record<any, any> | undefined;
718
+ validations?: {
719
+ required?: boolean | undefined;
720
+ format?: "URL" | undefined;
721
+ in?: {
722
+ value: string | number;
723
+ displayName?: string | undefined;
724
+ }[] | undefined;
725
+ } | undefined;
726
+ }>>;
727
+ }, "strip", z.ZodTypeAny, {
728
+ id: string;
729
+ variables: Record<string, {
730
+ type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
731
+ displayName?: string | undefined;
732
+ description?: string | undefined;
733
+ group?: string | undefined;
734
+ defaultValue?: string | number | boolean | Record<any, any> | undefined;
735
+ validations?: {
736
+ required?: boolean | undefined;
737
+ format?: "URL" | undefined;
738
+ in?: {
739
+ value: string | number;
740
+ displayName?: string | undefined;
741
+ }[] | undefined;
742
+ } | undefined;
743
+ }>;
744
+ }, {
745
+ id: string;
746
+ variables: Record<string, {
747
+ type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
748
+ displayName?: string | undefined;
749
+ description?: string | undefined;
750
+ group?: string | undefined;
751
+ defaultValue?: string | number | boolean | Record<any, any> | undefined;
752
+ validations?: {
753
+ required?: boolean | undefined;
754
+ format?: "URL" | undefined;
755
+ in?: {
756
+ value: string | number;
757
+ displayName?: string | undefined;
758
+ }[] | undefined;
759
+ } | undefined;
760
+ }>;
761
+ }>;
762
+ type ComponentDefinitionPropertyType = z.infer<typeof DefinitionPropertyTypeSchema>;
763
+
638
764
  declare const SchemaVersions: z.ZodLiteral<"2023-09-28">;
639
765
  type SchemaVersions = z.infer<typeof SchemaVersions>;
640
766
 
package/dist/index.js CHANGED
@@ -9,13 +9,6 @@ z.union([
9
9
  z.literal('2023-06-27'),
10
10
  ]);
11
11
 
12
- const PrimitiveValueSchema = z.union([
13
- z.string(),
14
- z.boolean(),
15
- z.number(),
16
- z.record(z.any(), z.any()),
17
- z.undefined(),
18
- ]);
19
12
  const DefinitionPropertyTypeSchema = z.enum([
20
13
  'Text',
21
14
  'RichText',
@@ -32,122 +25,13 @@ const DefinitionPropertyTypeSchema = z.enum([
32
25
  const DefinitionPropertyKeySchema = z
33
26
  .string()
34
27
  .regex(/^[a-zA-Z0-9-_]{1,32}$/, { message: 'Property needs to match: /^[a-zA-Z0-9-_]{1,32}$/' });
35
- const ComponentDefinitionSchema = z.object({
36
- id: DefinitionPropertyKeySchema,
37
- variables: z.record(DefinitionPropertyKeySchema, z
38
- .object({
39
- // TODO - extend with definition of validations and defaultValue
40
- displayName: z.string().optional(),
41
- type: DefinitionPropertyTypeSchema,
42
- description: z.string().optional(),
43
- group: z.string().optional(),
44
- defaultValue: PrimitiveValueSchema.optional(),
45
- })
46
- .superRefine((val, ctx) => {
47
- switch (val.type) {
48
- case 'Array':
49
- if (typeof val.defaultValue !== 'undefined') {
50
- ctx.addIssue({
51
- code: z.ZodIssueCode.custom,
52
- message: `defaultValue is not supported for "Array" type for ${ctx.path.join('.')}`,
53
- fatal: false,
54
- });
55
- }
56
- break;
57
- case 'Boolean':
58
- if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'boolean') {
59
- ctx.addIssue({
60
- code: z.ZodIssueCode.custom,
61
- message: `defaultValue must be a boolean when type is "Boolean" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
62
- fatal: false,
63
- });
64
- }
65
- break;
66
- case 'Date':
67
- if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
68
- ctx.addIssue({
69
- code: z.ZodIssueCode.custom,
70
- message: `defaultValue must be a string when type is "Date" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
71
- fatal: false,
72
- });
73
- }
74
- break;
75
- case 'Hyperlink':
76
- if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
77
- ctx.addIssue({
78
- code: z.ZodIssueCode.custom,
79
- message: `defaultValue must be a string when type is "Hyperlink" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
80
- fatal: false,
81
- });
82
- }
83
- break;
84
- case 'Link':
85
- if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
86
- ctx.addIssue({
87
- code: z.ZodIssueCode.custom,
88
- message: `defaultValue is not supported for "Link" type for ${ctx.path.join('.')}`,
89
- fatal: false,
90
- });
91
- }
92
- break;
93
- case 'Location':
94
- if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
95
- ctx.addIssue({
96
- code: z.ZodIssueCode.custom,
97
- message: `defaultValue must be an object when type is "Location" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
98
- fatal: false,
99
- });
100
- }
101
- break;
102
- case 'Media':
103
- if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
104
- ctx.addIssue({
105
- code: z.ZodIssueCode.custom,
106
- message: `defaultValue must be a string when type is "Media" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
107
- fatal: false,
108
- });
109
- }
110
- break;
111
- case 'Number':
112
- if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'number') {
113
- ctx.addIssue({
114
- code: z.ZodIssueCode.custom,
115
- message: `defaultValue must be a number when type is "Number" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
116
- fatal: false,
117
- });
118
- }
119
- break;
120
- case 'Object':
121
- if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
122
- ctx.addIssue({
123
- code: z.ZodIssueCode.custom,
124
- message: `defaultValue must be an object when type is "Object" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
125
- fatal: false,
126
- });
127
- }
128
- break;
129
- case 'RichText':
130
- if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
131
- ctx.addIssue({
132
- code: z.ZodIssueCode.custom,
133
- message: `defaultValue must be an object when type is "RichText" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
134
- fatal: false,
135
- });
136
- }
137
- break;
138
- case 'Text':
139
- if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
140
- ctx.addIssue({
141
- code: z.ZodIssueCode.custom,
142
- message: `defaultValue must be a string when type is "Text" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
143
- fatal: false,
144
- });
145
- }
146
- break;
147
- }
148
- })),
149
- });
150
-
28
+ const PrimitiveValueSchema = z.union([
29
+ z.string(),
30
+ z.boolean(),
31
+ z.number(),
32
+ z.record(z.any(), z.any()),
33
+ z.undefined(),
34
+ ]);
151
35
  const uuidKeySchema = z
152
36
  .string()
153
37
  .regex(/^[a-zA-Z0-9-_]{1,21}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,21}$/' });
@@ -227,27 +111,29 @@ const BaseComponentTreeNodeSchema = z.object({
227
111
  const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
228
112
  children: z.lazy(() => ComponentTreeNodeSchema.array()),
229
113
  });
230
- const ComponentSettingsSchema = z.object({
231
- variableDefinitions: z.record(z.string().regex(/^[a-zA-Z0-9-_]{1,54}$/), // Here the key is <variableName>_<nanoidId> so we need to allow for a longer length
232
- z.object({
233
- displayName: z.string().optional(),
234
- type: DefinitionPropertyTypeSchema,
235
- defaultValue: PrimitiveValueSchema.or(ComponentPropertyValueSchema).optional(),
236
- description: z.string().optional(),
237
- group: z.string().optional(),
238
- validations: z
239
- .object({
240
- required: z.boolean().optional(),
241
- format: z.literal('URL').optional(),
242
- in: z
243
- .array(z.object({
244
- value: z.union([z.string(), z.number()]),
245
- displayName: z.string().optional(),
246
- }))
247
- .optional(),
248
- })
114
+ const ComponentVariableSchema = z.object({
115
+ displayName: z.string().optional(),
116
+ type: DefinitionPropertyTypeSchema,
117
+ description: z.string().optional(),
118
+ group: z.string().optional(),
119
+ defaultValue: PrimitiveValueSchema.or(ComponentPropertyValueSchema).optional(),
120
+ validations: z
121
+ .object({
122
+ required: z.boolean().optional(),
123
+ format: z.literal('URL').optional(),
124
+ in: z
125
+ .array(z.object({
126
+ value: z.union([z.string(), z.number()]),
127
+ displayName: z.string().optional(),
128
+ }))
249
129
  .optional(),
250
- })),
130
+ })
131
+ .optional(),
132
+ });
133
+ const ComponentVariablesSchema = z.record(z.string().regex(/^[a-zA-Z0-9-_]{1,54}$/), // Here the key is <variableName>_<nanoidId> so we need to allow for a longer length
134
+ ComponentVariableSchema);
135
+ const ComponentSettingsSchema = z.object({
136
+ variableDefinitions: ComponentVariablesSchema,
251
137
  });
252
138
  const UsedComponentsSchema = z.array(z.object({
253
139
  sys: z.object({
@@ -326,6 +212,115 @@ const ExperienceFieldsCMAShapeSchema = z
326
212
  })
327
213
  .superRefine(componentSettingsRefinement);
328
214
 
215
+ const ComponentDefinitionSchema = z.object({
216
+ id: DefinitionPropertyKeySchema,
217
+ variables: z.record(DefinitionPropertyKeySchema, ComponentVariableSchema.extend({
218
+ defaultValue: PrimitiveValueSchema.optional(),
219
+ }).superRefine((val, ctx) => {
220
+ switch (val.type) {
221
+ case 'Array':
222
+ if (typeof val.defaultValue !== 'undefined') {
223
+ ctx.addIssue({
224
+ code: z.ZodIssueCode.custom,
225
+ message: `defaultValue is not supported for "Array" type for ${ctx.path.join('.')}`,
226
+ fatal: false,
227
+ });
228
+ }
229
+ break;
230
+ case 'Boolean':
231
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'boolean') {
232
+ ctx.addIssue({
233
+ code: z.ZodIssueCode.custom,
234
+ message: `defaultValue must be a boolean when type is "Boolean" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
235
+ fatal: false,
236
+ });
237
+ }
238
+ break;
239
+ case 'Date':
240
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
241
+ ctx.addIssue({
242
+ code: z.ZodIssueCode.custom,
243
+ message: `defaultValue must be a string when type is "Date" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
244
+ fatal: false,
245
+ });
246
+ }
247
+ break;
248
+ case 'Hyperlink':
249
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
250
+ ctx.addIssue({
251
+ code: z.ZodIssueCode.custom,
252
+ message: `defaultValue must be a string when type is "Hyperlink" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
253
+ fatal: false,
254
+ });
255
+ }
256
+ break;
257
+ case 'Link':
258
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
259
+ ctx.addIssue({
260
+ code: z.ZodIssueCode.custom,
261
+ message: `defaultValue is not supported for "Link" type for ${ctx.path.join('.')}`,
262
+ fatal: false,
263
+ });
264
+ }
265
+ break;
266
+ case 'Location':
267
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
268
+ ctx.addIssue({
269
+ code: z.ZodIssueCode.custom,
270
+ message: `defaultValue must be an object when type is "Location" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
271
+ fatal: false,
272
+ });
273
+ }
274
+ break;
275
+ case 'Media':
276
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
277
+ ctx.addIssue({
278
+ code: z.ZodIssueCode.custom,
279
+ message: `defaultValue must be a string when type is "Media" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
280
+ fatal: false,
281
+ });
282
+ }
283
+ break;
284
+ case 'Number':
285
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'number') {
286
+ ctx.addIssue({
287
+ code: z.ZodIssueCode.custom,
288
+ message: `defaultValue must be a number when type is "Number" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
289
+ fatal: false,
290
+ });
291
+ }
292
+ break;
293
+ case 'Object':
294
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
295
+ ctx.addIssue({
296
+ code: z.ZodIssueCode.custom,
297
+ message: `defaultValue must be an object when type is "Object" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
298
+ fatal: false,
299
+ });
300
+ }
301
+ break;
302
+ case 'RichText':
303
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'object') {
304
+ ctx.addIssue({
305
+ code: z.ZodIssueCode.custom,
306
+ message: `defaultValue must be an object when type is "RichText" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
307
+ fatal: false,
308
+ });
309
+ }
310
+ break;
311
+ case 'Text':
312
+ if (typeof val.defaultValue !== 'undefined' && typeof val.defaultValue !== 'string') {
313
+ ctx.addIssue({
314
+ code: z.ZodIssueCode.custom,
315
+ message: `defaultValue must be a string when type is "Text" for ${ctx.path.join('.')}, got ${typeof val.defaultValue} instead`,
316
+ fatal: false,
317
+ });
318
+ }
319
+ break;
320
+ }
321
+ })),
322
+ });
323
+
329
324
  var CodeNames;
330
325
  (function (CodeNames) {
331
326
  CodeNames["Type"] = "type";