Skip to content

Commit 54a0666

Browse files
committed
Add validation for publisherId
1 parent 3e379f8 commit 54a0666

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

validate.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const PUBLISHER_ID_MIN_LENGTH = 1;
2+
const PUBLISHER_ID_MAX_LENGTH = 50;
3+
14
function validateQuery(query, schema) {
25
if (query == null) {
36
throw new Error('Invalid query - The query was null or undefined');
@@ -22,6 +25,21 @@ function validateQuery(query, schema) {
2225
if (!schema[query.type]) {
2326
throw new Error(`Invalid query - The query type ${query.type} was not defined on the schema`);
2427
}
28+
if (query.publisherId != null) {
29+
if (
30+
typeof query.publisherId !== 'string' ||
31+
query.publisherId.length > PUBLISHER_ID_MAX_LENGTH ||
32+
query.publisherId.length < PUBLISHER_ID_MIN_LENGTH
33+
) {
34+
throw new Error(
35+
`Invalid query - The optional publisherId property must be a string between ${
36+
PUBLISHER_ID_MIN_LENGTH
37+
} and ${
38+
PUBLISHER_ID_MAX_LENGTH
39+
} characters in length`
40+
);
41+
}
42+
}
2543

2644
let fieldIsSet = !!query.field;
2745
let idIsSet = !!query.id;

0 commit comments

Comments
 (0)