@contentful/experiences-validators 1.11.3-dev-20240808T2101-c1fe341.0 → 1.12.0-beta.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.cjs +163 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +164 -18
- package/dist/index.js +163 -61
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +14 -14
- package/package.json +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
declare const DefinitionPropertyTypeSchema: z.ZodEnum<["Text", "RichText", "Number", "Date", "Boolean", "Location", "Media", "Object", "Hyperlink", "Array", "Link"]>;
|
|
4
|
+
declare const PrimitiveValueSchema: z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>;
|
|
3
5
|
declare const DataSourceSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
4
6
|
sys: z.ZodObject<{
|
|
5
7
|
type: z.ZodLiteral<"Link">;
|
|
@@ -27,7 +29,6 @@ declare const DataSourceSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
|
27
29
|
linkType: "Entry" | "Asset";
|
|
28
30
|
};
|
|
29
31
|
}>>;
|
|
30
|
-
declare const PrimitiveValueSchema: z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>;
|
|
31
32
|
declare const ValuesByBreakpointSchema: z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>>>;
|
|
32
33
|
declare const DesignValueSchema: z.ZodObject<{
|
|
33
34
|
type: z.ZodLiteral<"DesignValue">;
|
|
@@ -127,15 +128,15 @@ declare const BreakpointSchema: z.ZodObject<{
|
|
|
127
128
|
displayIcon: z.ZodOptional<z.ZodEnum<["desktop", "tablet", "mobile"]>>;
|
|
128
129
|
}, "strict", z.ZodTypeAny, {
|
|
129
130
|
id: string;
|
|
130
|
-
displayName: string;
|
|
131
131
|
query: string;
|
|
132
132
|
previewSize: string;
|
|
133
|
+
displayName: string;
|
|
133
134
|
displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
|
|
134
135
|
}, {
|
|
135
136
|
id: string;
|
|
136
|
-
displayName: string;
|
|
137
137
|
query: string;
|
|
138
138
|
previewSize: string;
|
|
139
|
+
displayName: string;
|
|
139
140
|
displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
|
|
140
141
|
}>;
|
|
141
142
|
declare const UnboundValuesSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
@@ -199,6 +200,7 @@ declare const BaseComponentTreeNodeSchema: z.ZodObject<{
|
|
|
199
200
|
key: string;
|
|
200
201
|
}>]>>;
|
|
201
202
|
}, "strip", z.ZodTypeAny, {
|
|
203
|
+
definitionId: string;
|
|
202
204
|
variables: Record<string, {
|
|
203
205
|
type: "DesignValue";
|
|
204
206
|
valuesByBreakpoint: Record<string, string | number | boolean | Record<any, any> | undefined>;
|
|
@@ -216,10 +218,10 @@ declare const BaseComponentTreeNodeSchema: z.ZodObject<{
|
|
|
216
218
|
type: "ComponentValue";
|
|
217
219
|
key: string;
|
|
218
220
|
}>;
|
|
219
|
-
definitionId: string;
|
|
220
221
|
displayName?: string | undefined;
|
|
221
222
|
slotId?: string | undefined;
|
|
222
223
|
}, {
|
|
224
|
+
definitionId: string;
|
|
223
225
|
variables: Record<string, {
|
|
224
226
|
type: "DesignValue";
|
|
225
227
|
valuesByBreakpoint: Record<string, string | number | boolean | Record<any, any> | undefined>;
|
|
@@ -237,7 +239,6 @@ declare const BaseComponentTreeNodeSchema: z.ZodObject<{
|
|
|
237
239
|
type: "ComponentValue";
|
|
238
240
|
key: string;
|
|
239
241
|
}>;
|
|
240
|
-
definitionId: string;
|
|
241
242
|
displayName?: string | undefined;
|
|
242
243
|
slotId?: string | undefined;
|
|
243
244
|
}>;
|
|
@@ -248,6 +249,8 @@ declare const ComponentSettingsSchema: z.ZodObject<{
|
|
|
248
249
|
variableDefinitions: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
249
250
|
displayName: z.ZodOptional<z.ZodString>;
|
|
250
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>;
|
|
251
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<{
|
|
252
255
|
type: z.ZodLiteral<"DesignValue">;
|
|
253
256
|
valuesByBreakpoint: z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodRecord<z.ZodAny, z.ZodAny>, z.ZodUndefined]>>>;
|
|
@@ -297,8 +300,6 @@ declare const ComponentSettingsSchema: z.ZodObject<{
|
|
|
297
300
|
type: "ComponentValue";
|
|
298
301
|
key: string;
|
|
299
302
|
}>]>]>>;
|
|
300
|
-
description: z.ZodOptional<z.ZodString>;
|
|
301
|
-
group: z.ZodOptional<z.ZodString>;
|
|
302
303
|
validations: z.ZodOptional<z.ZodObject<{
|
|
303
304
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
304
305
|
format: z.ZodOptional<z.ZodLiteral<"URL">>;
|
|
@@ -489,27 +490,27 @@ declare const ComponentTreeSchema: z.ZodObject<{
|
|
|
489
490
|
displayIcon: z.ZodOptional<z.ZodEnum<["desktop", "tablet", "mobile"]>>;
|
|
490
491
|
}, "strict", z.ZodTypeAny, {
|
|
491
492
|
id: string;
|
|
492
|
-
displayName: string;
|
|
493
493
|
query: string;
|
|
494
494
|
previewSize: string;
|
|
495
|
+
displayName: string;
|
|
495
496
|
displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
|
|
496
497
|
}, {
|
|
497
498
|
id: string;
|
|
498
|
-
displayName: string;
|
|
499
499
|
query: string;
|
|
500
500
|
previewSize: string;
|
|
501
|
+
displayName: string;
|
|
501
502
|
displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
|
|
502
503
|
}>, "many">, {
|
|
503
504
|
id: string;
|
|
504
|
-
displayName: string;
|
|
505
505
|
query: string;
|
|
506
506
|
previewSize: string;
|
|
507
|
+
displayName: string;
|
|
507
508
|
displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
|
|
508
509
|
}[], {
|
|
509
510
|
id: string;
|
|
510
|
-
displayName: string;
|
|
511
511
|
query: string;
|
|
512
512
|
previewSize: string;
|
|
513
|
+
displayName: string;
|
|
513
514
|
displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
|
|
514
515
|
}[]>;
|
|
515
516
|
children: z.ZodArray<z.ZodType<ComponentTreeNode, z.ZodTypeDef, ComponentTreeNode>, "many">;
|
|
@@ -518,9 +519,9 @@ declare const ComponentTreeSchema: z.ZodObject<{
|
|
|
518
519
|
children: ComponentTreeNode[];
|
|
519
520
|
breakpoints: {
|
|
520
521
|
id: string;
|
|
521
|
-
displayName: string;
|
|
522
522
|
query: string;
|
|
523
523
|
previewSize: string;
|
|
524
|
+
displayName: string;
|
|
524
525
|
displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
|
|
525
526
|
}[];
|
|
526
527
|
schemaVersion: "2023-09-28";
|
|
@@ -528,9 +529,9 @@ declare const ComponentTreeSchema: z.ZodObject<{
|
|
|
528
529
|
children: ComponentTreeNode[];
|
|
529
530
|
breakpoints: {
|
|
530
531
|
id: string;
|
|
531
|
-
displayName: string;
|
|
532
532
|
query: string;
|
|
533
533
|
previewSize: string;
|
|
534
|
+
displayName: string;
|
|
534
535
|
displayIcon?: "desktop" | "tablet" | "mobile" | undefined;
|
|
535
536
|
}[];
|
|
536
537
|
schemaVersion: "2023-09-28";
|
|
@@ -580,24 +581,148 @@ type BoundValue = z.infer<typeof BoundValueSchema>;
|
|
|
580
581
|
type UnboundValue = z.infer<typeof UnboundValueSchema>;
|
|
581
582
|
type ComponentValue = z.infer<typeof ComponentValueSchema>;
|
|
582
583
|
|
|
583
|
-
declare const DefinitionPropertyTypeSchema: z.ZodEnum<["Text", "RichText", "Number", "Date", "Boolean", "Location", "Media", "Object", "Hyperlink", "Array", "Link"]>;
|
|
584
584
|
declare const ComponentDefinitionSchema: z.ZodObject<{
|
|
585
585
|
id: z.ZodString;
|
|
586
|
-
variables: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
586
|
+
variables: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<z.objectUtil.extendShape<{
|
|
587
587
|
displayName: z.ZodOptional<z.ZodString>;
|
|
588
588
|
type: z.ZodEnum<["Text", "RichText", "Number", "Date", "Boolean", "Location", "Media", "Object", "Hyperlink", "Array", "Link"]>;
|
|
589
589
|
description: z.ZodOptional<z.ZodString>;
|
|
590
590
|
group: z.ZodOptional<z.ZodString>;
|
|
591
|
-
|
|
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, {
|
|
592
671
|
type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
|
|
593
672
|
displayName?: string | undefined;
|
|
594
673
|
description?: string | undefined;
|
|
595
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;
|
|
596
684
|
}, {
|
|
597
685
|
type: "Text" | "RichText" | "Number" | "Date" | "Boolean" | "Location" | "Media" | "Object" | "Hyperlink" | "Array" | "Link";
|
|
598
686
|
displayName?: string | undefined;
|
|
599
687
|
description?: string | undefined;
|
|
600
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;
|
|
601
726
|
}>>;
|
|
602
727
|
}, "strip", z.ZodTypeAny, {
|
|
603
728
|
id: string;
|
|
@@ -606,6 +731,15 @@ declare const ComponentDefinitionSchema: z.ZodObject<{
|
|
|
606
731
|
displayName?: string | undefined;
|
|
607
732
|
description?: string | undefined;
|
|
608
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;
|
|
609
743
|
}>;
|
|
610
744
|
}, {
|
|
611
745
|
id: string;
|
|
@@ -614,6 +748,15 @@ declare const ComponentDefinitionSchema: z.ZodObject<{
|
|
|
614
748
|
displayName?: string | undefined;
|
|
615
749
|
description?: string | undefined;
|
|
616
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;
|
|
617
760
|
}>;
|
|
618
761
|
}>;
|
|
619
762
|
type ComponentDefinitionPropertyType = z.infer<typeof DefinitionPropertyTypeSchema>;
|
|
@@ -644,6 +787,11 @@ type ValidatorReturnValue = {
|
|
|
644
787
|
success: boolean;
|
|
645
788
|
errors?: ContentfulErrorDetails[];
|
|
646
789
|
};
|
|
790
|
+
|
|
791
|
+
declare const validateBreakpointsDefinition: (breakpoints: any) => ValidatorReturnValue;
|
|
792
|
+
|
|
793
|
+
declare const validateComponentDefinition: (definition: any) => ValidatorReturnValue;
|
|
794
|
+
|
|
647
795
|
/**
|
|
648
796
|
*
|
|
649
797
|
* @param experience The experience entry to validate
|
|
@@ -651,7 +799,5 @@ type ValidatorReturnValue = {
|
|
|
651
799
|
* @returns object with success property and optional errors array
|
|
652
800
|
*/
|
|
653
801
|
declare const validateExperienceFields: (experience: any, schemaVersionOverride?: SchemaVersions) => ValidatorReturnValue;
|
|
654
|
-
declare const validateComponentDefinition: (definition: any) => ValidatorReturnValue;
|
|
655
|
-
declare const validateBreakpointsDefinition: (breakpoints: any) => ValidatorReturnValue;
|
|
656
802
|
|
|
657
803
|
export { type BoundValue, type Breakpoint, type ComponentDefinitionPropertyType, ComponentDefinitionSchema, type ComponentPropertyValue, type ComponentTreeNode, type ComponentValue, type DesignValue, type ExperienceComponentSettings, type ExperienceComponentTree, type ExperienceDataSource, type ExperienceFields, type ExperienceUnboundValues, type ExperienceUsedComponents, type PrimitiveValue, SchemaVersions, ExperienceFieldsCMAShapeSchema as Schema_2023_09_28, type UnboundValue, type ValuesByBreakpoint, validateBreakpointsDefinition, validateComponentDefinition, validateExperienceFields };
|
package/dist/index.js
CHANGED
|
@@ -25,17 +25,13 @@ const DefinitionPropertyTypeSchema = z.enum([
|
|
|
25
25
|
const DefinitionPropertyKeySchema = z
|
|
26
26
|
.string()
|
|
27
27
|
.regex(/^[a-zA-Z0-9-_]{1,32}$/, { message: 'Property needs to match: /^[a-zA-Z0-9-_]{1,32}$/' });
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
group: z.string().optional(),
|
|
36
|
-
})),
|
|
37
|
-
});
|
|
38
|
-
|
|
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
|
+
]);
|
|
39
35
|
const uuidKeySchema = z
|
|
40
36
|
.string()
|
|
41
37
|
.regex(/^[a-zA-Z0-9-_]{1,21}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,21}$/' });
|
|
@@ -54,13 +50,6 @@ const DataSourceSchema = z.record(uuidKeySchema, z.object({
|
|
|
54
50
|
linkType: z.enum(['Entry', 'Asset']),
|
|
55
51
|
}),
|
|
56
52
|
}));
|
|
57
|
-
const PrimitiveValueSchema = z.union([
|
|
58
|
-
z.string(),
|
|
59
|
-
z.boolean(),
|
|
60
|
-
z.number(),
|
|
61
|
-
z.record(z.any(), z.any()),
|
|
62
|
-
z.undefined(),
|
|
63
|
-
]);
|
|
64
53
|
const ValuesByBreakpointSchema = z.record(z.lazy(() => PrimitiveValueSchema));
|
|
65
54
|
const DesignValueSchema = z
|
|
66
55
|
.object({
|
|
@@ -122,27 +111,29 @@ const BaseComponentTreeNodeSchema = z.object({
|
|
|
122
111
|
const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
|
|
123
112
|
children: z.lazy(() => ComponentTreeNodeSchema.array()),
|
|
124
113
|
});
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
displayName: z.string().optional(),
|
|
141
|
-
}))
|
|
142
|
-
.optional(),
|
|
143
|
-
})
|
|
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
|
+
}))
|
|
144
129
|
.optional(),
|
|
145
|
-
})
|
|
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,
|
|
146
137
|
});
|
|
147
138
|
const UsedComponentsSchema = z.array(z.object({
|
|
148
139
|
sys: z.object({
|
|
@@ -221,6 +212,115 @@ const ExperienceFieldsCMAShapeSchema = z
|
|
|
221
212
|
})
|
|
222
213
|
.superRefine(componentSettingsRefinement);
|
|
223
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
|
+
|
|
224
324
|
var CodeNames;
|
|
225
325
|
(function (CodeNames) {
|
|
226
326
|
CodeNames["Type"] = "type";
|
|
@@ -322,6 +422,31 @@ const zodToContentfulError = (issue) => {
|
|
|
322
422
|
}
|
|
323
423
|
};
|
|
324
424
|
|
|
425
|
+
const validateBreakpointsDefinition = (breakpoints) => {
|
|
426
|
+
const result = z
|
|
427
|
+
.array(BreakpointSchema)
|
|
428
|
+
.superRefine(breakpointsRefinement)
|
|
429
|
+
.safeParse(breakpoints);
|
|
430
|
+
if (!result.success) {
|
|
431
|
+
return {
|
|
432
|
+
success: false,
|
|
433
|
+
errors: result.error.issues.map(zodToContentfulError),
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
return { success: true };
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
const validateComponentDefinition = (definition) => {
|
|
440
|
+
const result = ComponentDefinitionSchema.safeParse(definition);
|
|
441
|
+
if (!result.success) {
|
|
442
|
+
return {
|
|
443
|
+
success: false,
|
|
444
|
+
errors: result.error.issues.map(zodToContentfulError),
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
return { success: true };
|
|
448
|
+
};
|
|
449
|
+
|
|
325
450
|
const VERSION_SCHEMAS = {
|
|
326
451
|
'2023-09-28': ExperienceFieldsCMAShapeSchema,
|
|
327
452
|
};
|
|
@@ -370,29 +495,6 @@ const validateExperienceFields = (experience, schemaVersionOverride) => {
|
|
|
370
495
|
}
|
|
371
496
|
return { success: true };
|
|
372
497
|
};
|
|
373
|
-
const validateComponentDefinition = (definition) => {
|
|
374
|
-
const result = ComponentDefinitionSchema.safeParse(definition);
|
|
375
|
-
if (!result.success) {
|
|
376
|
-
return {
|
|
377
|
-
success: false,
|
|
378
|
-
errors: result.error.issues.map(zodToContentfulError),
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
return { success: true };
|
|
382
|
-
};
|
|
383
|
-
const validateBreakpointsDefinition = (breakpoints) => {
|
|
384
|
-
const result = z
|
|
385
|
-
.array(BreakpointSchema)
|
|
386
|
-
.superRefine(breakpointsRefinement)
|
|
387
|
-
.safeParse(breakpoints);
|
|
388
|
-
if (!result.success) {
|
|
389
|
-
return {
|
|
390
|
-
success: false,
|
|
391
|
-
errors: result.error.issues.map(zodToContentfulError),
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
return { success: true };
|
|
395
|
-
};
|
|
396
498
|
|
|
397
499
|
export { ComponentDefinitionSchema, ExperienceFieldsCMAShapeSchema as Schema_2023_09_28, validateBreakpointsDefinition, validateComponentDefinition, validateExperienceFields };
|
|
398
500
|
//# sourceMappingURL=index.js.map
|