-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvalidation.ts
More file actions
40 lines (32 loc) · 933 Bytes
/
validation.ts
File metadata and controls
40 lines (32 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import log from './log';
import type { AffectedUser, EventContext } from '@hawk.so/types';
import Sanitizer from '../modules/sanitizer';
/**
* Validates user data - basic security checks
*
* @param user
*/
export function validateUser(user: AffectedUser): boolean {
if (!user || !Sanitizer.isObject(user)) {
log('validateUser: User must be an object', 'warn');
return false;
}
// Validate required ID
if (!user.id || typeof user.id !== 'string' || user.id.trim() === '') {
log('validateUser: User ID is required and must be a non-empty string', 'warn');
return false;
}
return true;
}
/**
* Validates context data - basic security checks
*
* @param context
*/
export function validateContext(context: EventContext | undefined): boolean {
if (context && !Sanitizer.isObject(context)) {
log('validateContext: Context must be an object', 'warn');
return false;
}
return true;
}