@@ -33,6 +33,9 @@ export function validateFeatureFlag(featureFlag: any): void {
3333}
3434
3535function validateFeatureEnablementConditions ( conditions : any ) {
36+ if ( typeof conditions !== "object" ) {
37+ throw new TypeError ( "Feature flag 'conditions' must be an object." ) ;
38+ }
3639 if ( conditions . requirement_type !== undefined && conditions . requirement_type !== "Any" && conditions . requirement_type !== "All" ) {
3740 throw new TypeError ( "'requirement_type' must be 'Any' or 'All'." ) ;
3841 }
@@ -43,7 +46,7 @@ function validateFeatureEnablementConditions(conditions: any) {
4346
4447function validateClientFilters ( client_filters : any ) {
4548 if ( ! Array . isArray ( client_filters ) ) {
46- throw new TypeError ( "'client_filters' must be an array." ) ;
49+ throw new TypeError ( "Feature flag conditions 'client_filters' must be an array." ) ;
4750 }
4851
4952 for ( const filter of client_filters ) {
@@ -58,7 +61,7 @@ function validateClientFilters(client_filters: any) {
5861
5962function validateVariants ( variants : any ) {
6063 if ( ! Array . isArray ( variants ) ) {
61- throw new TypeError ( "'variants' must be an array." ) ;
64+ throw new TypeError ( "Feature flag 'variants' must be an array." ) ;
6265 }
6366
6467 for ( const variant of variants ) {
@@ -102,10 +105,13 @@ function validateVariantAllocation(allocation: any) {
102105
103106function validateUserVariantAllocation ( UserAllocations : any ) {
104107 if ( ! Array . isArray ( UserAllocations ) ) {
105- throw new TypeError ( "User allocation 'user' must be an array." ) ;
108+ throw new TypeError ( "Variant 'user' allocation must be an array." ) ;
106109 }
107110
108111 for ( const allocation of UserAllocations ) {
112+ if ( typeof allocation !== "object" ) {
113+ throw new TypeError ( "Elements in 'user' allocation must be an object." ) ;
114+ }
109115 if ( typeof allocation . variant !== "string" ) {
110116 throw new TypeError ( "User allocation 'variant' must be a string." ) ;
111117 }
@@ -114,18 +120,21 @@ function validateUserVariantAllocation(UserAllocations: any) {
114120 }
115121 for ( const user of allocation . users ) {
116122 if ( typeof user !== "string" ) {
117- throw new TypeError ( "Elements in User allocation 'users' must be strings." ) ;
123+ throw new TypeError ( "Elements in user allocation 'users' must be strings." ) ;
118124 }
119125 }
120126 }
121127}
122128
123129function validateGroupVariantAllocation ( groupAllocations : any ) {
124130 if ( ! Array . isArray ( groupAllocations ) ) {
125- throw new TypeError ( "Group allocation 'group' must be an array." ) ;
131+ throw new TypeError ( "Variant 'group' allocation must be an array." ) ;
126132 }
127133
128134 for ( const allocation of groupAllocations ) {
135+ if ( typeof allocation !== "object" ) {
136+ throw new TypeError ( "Elements in 'group' allocation must be an object." ) ;
137+ }
129138 if ( typeof allocation . variant !== "string" ) {
130139 throw new TypeError ( "Group allocation 'variant' must be a string." ) ;
131140 }
@@ -134,18 +143,21 @@ function validateGroupVariantAllocation(groupAllocations: any) {
134143 }
135144 for ( const group of allocation . groups ) {
136145 if ( typeof group !== "string" ) {
137- throw new TypeError ( "Elements in Group allocation 'groups' must be strings." ) ;
146+ throw new TypeError ( "Elements in group allocation 'groups' must be strings." ) ;
138147 }
139148 }
140149 }
141150}
142151
143152function validatePercentileVariantAllocation ( percentileAllocations : any ) {
144153 if ( ! Array . isArray ( percentileAllocations ) ) {
145- throw new TypeError ( "Percentile allocation 'percentile' must be an array." ) ;
154+ throw new TypeError ( "Variant 'percentile' allocation must be an array." ) ;
146155 }
147156
148157 for ( const allocation of percentileAllocations ) {
158+ if ( typeof allocation !== "object" ) {
159+ throw new TypeError ( "Elements in 'percentile' allocation must be an object." ) ;
160+ }
149161 if ( typeof allocation . variant !== "string" ) {
150162 throw new TypeError ( "Percentile allocation 'variant' must be a string." ) ;
151163 }
@@ -162,7 +174,7 @@ function validatePercentileVariantAllocation(percentileAllocations: any) {
162174// #region Telemetry
163175function validateTelemetryOptions ( telemetry : any ) {
164176 if ( typeof telemetry !== "object" ) {
165- throw new TypeError ( "Telemetry option 'telemetry' must be an object." ) ;
177+ throw new TypeError ( "Feature flag 'telemetry' must be an object." ) ;
166178 }
167179 if ( telemetry . enabled !== undefined && typeof telemetry . enabled !== "boolean" ) {
168180 throw new TypeError ( "Telemetry 'enabled' must be a boolean." ) ;
0 commit comments