Skip to content

Commit c9223ec

Browse files
committed
update validation
1 parent f3e9728 commit c9223ec

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/schema/validator.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ function validateFeatureEnablementConditions(conditions: any) {
5050

5151
function validateClientFilters(client_filters: any) {
5252
if (!Array.isArray(client_filters)) {
53-
throw new TypeError("Client filters must be an array.");
53+
throw new TypeError("Client filter Collection must be an array.");
5454
}
5555

5656
for (const filter of client_filters) {
57+
if (typeof filter.type !== "object") {
58+
throw new TypeError("Client filter must be an object.");
59+
}
5760
if (typeof filter.name !== "string") {
5861
throw new TypeError("Client filter name must be a string.");
5962
}
@@ -70,17 +73,16 @@ function validateVariants(variants: any) {
7073
}
7174

7275
for (const variant of variants) {
76+
if (typeof variant !== "object") {
77+
throw new TypeError("Variant must be an object.");
78+
}
7379
if (typeof variant.name !== "string") {
7480
throw new TypeError("Variant name must be a string.");
7581
}
76-
7782
// skip configuration_value validation as it accepts any type
78-
79-
// Although configuration_reference is not supported in the current implementation, we validate it here for future compatibility.
80-
if (variant.configuration_reference !== undefined && typeof variant.configuration_reference !== "string") {
81-
throw new TypeError("Variant configuration reference must be a string.");
83+
if (variant.status_override !== undefined && typeof variant.status_override !== "string") {
84+
throw new TypeError("Variant status override must be a string.");
8285
}
83-
8486
if (variant.status_override !== undefined && variant.status_override !== "None" && variant.status_override !== "Enabled" && variant.status_override !== "Disabled") {
8587
throw new TypeError("Variant status override must be 'None', 'Enabled', or 'Disabled'.");
8688
}
@@ -119,6 +121,9 @@ function validateUserVariantAllocation(UserAllocations: any) {
119121
}
120122

121123
for (const allocation of UserAllocations) {
124+
if (typeof allocation !== "object") {
125+
throw new TypeError("User allocation must be an object.");
126+
}
122127
if (typeof allocation.variant !== "string") {
123128
throw new TypeError("User allocation variant must be a string.");
124129
}
@@ -139,6 +144,9 @@ function validateGroupVariantAllocation(groupAllocations: any) {
139144
}
140145

141146
for (const allocation of groupAllocations) {
147+
if (typeof allocation !== "object") {
148+
throw new TypeError("Group allocation must be an object.");
149+
}
142150
if (typeof allocation.variant !== "string") {
143151
throw new TypeError("Group allocation variant must be a string.");
144152
}
@@ -159,14 +167,17 @@ function validatePercentileVariantAllocation(percentileAllocations: any) {
159167
}
160168

161169
for (const allocation of percentileAllocations) {
170+
if (typeof allocation !== "object") {
171+
throw new TypeError("Percentile allocation must be an object.");
172+
}
162173
if (typeof allocation.variant !== "string") {
163174
throw new TypeError("Percentile allocation variant must be a string.");
164175
}
165-
if (typeof allocation.from !== "number") {
166-
throw new TypeError("Percentile allocation from must be a number.");
176+
if (typeof allocation.from !== "number" || allocation.from < 0 || allocation.from > 100) {
177+
throw new TypeError("Percentile allocation from must be a number between 0 and 100.");
167178
}
168-
if (typeof allocation.to !== "number") {
169-
throw new TypeError("Percentile allocation to must be a number.");
179+
if (typeof allocation.to !== "number" || allocation.to < 0 || allocation.to > 100) {
180+
throw new TypeError("Percentile allocation to must be a number between 0 and 100.");
170181
}
171182
}
172183
}

0 commit comments

Comments
 (0)