Files
SRCmail/lib/push/validation.ts
T

11 lines
542 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export function isValidSubscriptionId(id: unknown): id is string {
return typeof id === 'string' && /^[A-Za-z0-9_-]{8,128}$/.test(id);
}
export function isValidFcmToken(value: unknown): value is string {
// FCM registration tokens are opaque. In practice they're ~140250 chars of
// [A-Za-z0-9:_-]. Be permissive on length; strict on charset to block
// obvious garbage without rejecting future token formats.
return typeof value === 'string' && value.length >= 64 && value.length <= 4096 && /^[A-Za-z0-9:_\-]+$/.test(value);
}