Skip to content

Commit d586dc1

Browse files
fix(validators): improve campaignRequest schema validation error message
- Add strict mode to prevent undefined coercion to empty object - Add custom test to check for undefined/null/empty object before field validation - Fix error message to show 'campaignRequest is required' instead of 'sign is a required field' when campaignRequest is undefined
1 parent f90e143 commit d586dc1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/utils/validators.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,14 @@ export const campaignRequestSchema = () =>
117117
trust: positiveIntegerStringSchema().required(),
118118
salt: stringSchema().required(),
119119
sign: stringSchema().required(),
120-
}).typeError('${path} should be a BulkRequest object');
120+
})
121+
.strict()
122+
.typeError('${path} should be a BulkRequest object')
123+
.test('is-defined', '${path} is required', (value) => {
124+
// Check if value is undefined, null, or an empty object (which would be coerced from undefined)
125+
return (
126+
value !== undefined &&
127+
value !== null &&
128+
!(typeof value === 'object' && Object.keys(value).length === 0)
129+
);
130+
});

0 commit comments

Comments
 (0)