MCPcopy Create free account
hub / github.com/omkarcloud/botasaurus / validateView

Function validateView

js/botasaurus-server-js/src/validation.ts:202–217  ·  view source on GitHub ↗
(jsonData: any, allowedViews: string[])

Source from the content-addressed store, hash-verified

200}
201
202export function validateView(jsonData: any, allowedViews: string[]): string | undefined {
203 let view = jsonData.view;
204
205 if (isNotNullish(view)) {
206 if (!isStringOfMinLength(view)) {
207 throw new JsonHTTPResponseWithMessage('View must be a string with at least one character');
208 }
209
210 view = view.toLowerCase();
211 if (!allowedViews.includes(view)) {
212 throw new JsonHTTPResponseWithMessage(`Invalid view. Must be one of: ${allowedViews.join(', ')}.`);
213 }
214 }
215
216 return view;
217}
218
219export function validateSort(jsonData: any, allowedSorts: string[], defaultSort: string): string | null {
220 let sort = jsonData.sort ?? defaultSort;

Callers 2

validateResultsRequestFunction · 0.85
validateDownloadParamsFunction · 0.85

Calls 3

isNotNullishFunction · 0.90
isStringOfMinLengthFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected