
- Complete NestJS TypeScript implementation with WebSocket support - Direct messaging (DM) and group chat functionality - End-to-end encryption with AES encryption and key pairs - Media file support (images, videos, audio, documents) up to 100MB - Push notifications with Firebase Cloud Messaging integration - Mention alerts and real-time typing indicators - User authentication with JWT and Passport - SQLite database with TypeORM entities and relationships - Comprehensive API documentation with Swagger/OpenAPI - File upload handling with secure access control - Online/offline status tracking and presence management - Message editing, deletion, and reply functionality - Notification management with automatic cleanup - Health check endpoint for monitoring - CORS configuration for cross-origin requests - Environment-based configuration management - Structured for Flutter SDK integration Features implemented: ✅ Real-time messaging with Socket.IO ✅ User registration and authentication ✅ Direct messages and group chats ✅ Media file uploads and management ✅ End-to-end encryption ✅ Push notifications ✅ Mention alerts ✅ Typing indicators ✅ Message read receipts ✅ Online status tracking ✅ File access control ✅ Comprehensive API documentation Ready for Flutter SDK development and production deployment.
59 lines
2.5 KiB
JavaScript
59 lines
2.5 KiB
JavaScript
import Metadata from './metadata.js'
|
|
import matchesEntirely from './helpers/matchesEntirely.js'
|
|
import getNumberType from './helpers/getNumberType.js'
|
|
|
|
/**
|
|
* Checks if a given phone number is valid.
|
|
*
|
|
* isValid(phoneNumberInstance, { ..., v2: true }, metadata)
|
|
*
|
|
* isPossible({ phone: '8005553535', country: 'RU' }, { ... }, metadata)
|
|
* isPossible({ phone: '8005553535', country: 'RU' }, undefined, metadata)
|
|
*
|
|
* If the `number` is a string, it will be parsed to an object,
|
|
* but only if it contains only valid phone number characters (including punctuation).
|
|
* If the `number` is an object, it is used as is.
|
|
*
|
|
* The optional `defaultCountry` argument is the default country.
|
|
* I.e. it does not restrict to just that country,
|
|
* e.g. in those cases where several countries share
|
|
* the same phone numbering rules (NANPA, Britain, etc).
|
|
* For example, even though the number `07624 369230`
|
|
* belongs to the Isle of Man ("IM" country code)
|
|
* calling `isValidNumber('07624369230', 'GB', metadata)`
|
|
* still returns `true` because the country is not restricted to `GB`,
|
|
* it's just that `GB` is the default one for the phone numbering rules.
|
|
* For restricting the country see `isValidNumberForRegion()`
|
|
* though restricting a country might not be a good idea.
|
|
* https://github.com/googlei18n/libphonenumber/blob/master/FAQ.md#when-should-i-use-isvalidnumberforregion
|
|
*
|
|
* Examples:
|
|
*
|
|
* ```js
|
|
* isValidNumber('+78005553535', metadata)
|
|
* isValidNumber('8005553535', 'RU', metadata)
|
|
* isValidNumber('88005553535', 'RU', metadata)
|
|
* isValidNumber({ phone: '8005553535', country: 'RU' }, metadata)
|
|
* ```
|
|
*/
|
|
export default function isValidNumber(input, options, metadata)
|
|
{
|
|
// If assigning the `{}` default value is moved to the arguments above,
|
|
// code coverage would decrease for some weird reason.
|
|
options = options || {}
|
|
|
|
metadata = new Metadata(metadata)
|
|
|
|
metadata.selectNumberingPlan(input.country, input.countryCallingCode)
|
|
|
|
// By default, countries only have type regexps when it's required for
|
|
// distinguishing different countries having the same `countryCallingCode`.
|
|
if (metadata.hasTypes()) {
|
|
return getNumberType(input, options, metadata.metadata) !== undefined
|
|
}
|
|
|
|
// If there are no type regexps for this country in metadata then use
|
|
// `nationalNumberPattern` as a "better than nothing" replacement.
|
|
const nationalNumber = options.v2 ? input.nationalNumber : input.phone
|
|
return matchesEntirely(nationalNumber, metadata.nationalNumberPattern())
|
|
} |